1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 g_basic
, g_player
, e_graphics
, Classes
, g_res_downloader
,
23 SysUtils
, g_sound
, g_gui
, MAPSTRUCT
, wadreader
, md5
, xprofiler
;
26 TGameSettings
= record
42 TDelayedEvent
= record
50 TPlayerSettings
= record
69 function g_Game_IsNet(): Boolean;
70 function g_Game_IsServer(): Boolean;
71 function g_Game_IsClient(): Boolean;
72 procedure g_Game_Init();
73 procedure g_Game_Free();
74 procedure g_Game_LoadData();
75 procedure g_Game_FreeData();
76 procedure g_Game_Update();
77 procedure g_Game_Draw();
78 procedure g_Game_Quit();
79 procedure g_Game_SetupScreenSize();
80 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
81 function g_Game_ModeToText(Mode
: Byte): string;
82 function g_Game_TextToMode(Mode
: string): Byte;
83 procedure g_Game_ExecuteEvent(Name
: String);
84 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
85 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
86 procedure g_Game_RemovePlayer();
87 procedure g_Game_Spectate();
88 procedure g_Game_SpectateCenterView();
89 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
90 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
91 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
92 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
93 procedure g_Game_Restart();
94 procedure g_Game_RestartLevel();
95 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
96 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
97 procedure g_Game_SaveOptions();
98 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
99 procedure g_Game_ChangeMap(MapPath
: String);
100 procedure g_Game_ExitLevel(Map
: Char16
);
101 function g_Game_GetFirstMap(WAD
: String): String;
102 function g_Game_GetNextMap(): String;
103 procedure g_Game_NextLevel();
104 procedure g_Game_Pause(Enable
: Boolean);
105 procedure g_Game_InGameMenu(Show
: Boolean);
106 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
107 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
108 procedure g_Game_Message(Msg
: String; Time
: Word);
109 procedure g_Game_LoadMapList(FileName
: String);
110 procedure g_Game_PauseAllSounds(Enable
: Boolean);
111 procedure g_Game_StopAllSounds(all
: Boolean);
112 procedure g_Game_UpdateTriggerSounds();
113 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
114 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
115 procedure g_Game_Announce_KillCombo(Param
: Integer);
116 procedure g_Game_StartVote(Command
, Initiator
: string);
117 procedure g_Game_CheckVote
;
118 procedure g_TakeScreenShot();
119 procedure g_FatalError(Text: String);
120 procedure g_SimpleError(Text: String);
121 function g_Game_IsTestMap(): Boolean;
122 procedure g_Game_DeleteTestMap();
123 procedure GameCVars(P
: SArray
);
124 procedure GameCommands(P
: SArray
);
125 procedure GameCheats(P
: SArray
);
126 procedure DebugCommands(P
: SArray
);
127 procedure ProfilerCommands(P
: SArray
);
128 procedure g_Game_Process_Params
;
129 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
130 procedure g_Game_StepLoading();
131 procedure g_Game_ClearLoading();
132 procedure g_Game_SetDebugMode();
133 procedure DrawLoadingStat();
135 { procedure SetWinPause(Enable: Boolean); }
140 LOADING_SHOW_STEP
= 100;
141 LOADING_INTERLINE
= 20;
156 MESSAGE_DIKEY
= WM_USER
+ 1;
161 EXIT_ENDLEVELSINGLE
= 4;
162 EXIT_ENDLEVELCUSTOM
= 5;
164 GAME_OPTION_RESERVED
= 1;
165 GAME_OPTION_TEAMDAMAGE
= 2;
166 GAME_OPTION_ALLOWEXIT
= 4;
167 GAME_OPTION_WEAPONSTAY
= 8;
168 GAME_OPTION_MONSTERS
= 16;
169 GAME_OPTION_BOTVSPLAYER
= 32;
170 GAME_OPTION_BOTVSMONSTER
= 64;
175 STATE_INTERCUSTOM
= 3;
176 STATE_INTERSINGLE
= 4;
182 LMS_RESPAWN_NONE
= 0;
183 LMS_RESPAWN_WARMUP
= 1;
184 LMS_RESPAWN_FINAL
= 2;
200 CONFIG_FILENAME
= 'Doom2DF.cfg';
201 LOG_FILENAME
= 'Doom2DF.log';
203 TEST_MAP_NAME
= '$$$_TEST_$$$';
205 STD_PLAYER_MODEL
= 'Doomer';
209 gGameSettings
: TGameSettings
;
210 gPlayer1Settings
: TPlayerSettings
;
211 gPlayer2Settings
: TPlayerSettings
;
213 gPlayerScreenSize
: TPoint
;
214 gPlayer1ScreenCoord
: TPoint
;
215 gPlayer2ScreenCoord
: TPoint
;
216 gPlayer1
: TPlayer
= nil;
217 gPlayer2
: TPlayer
= nil;
218 gPlayerDrawn
: TPlayer
= nil;
220 gSwitchGameMode
: Byte = GM_DM
;
221 gHearPoint1
, gHearPoint2
: THearPoint
;
222 gSoundEffectsDF
: Boolean = False;
223 gSoundTriggerTime
: Word = 0;
224 gAnnouncer
: Byte = ANNOUNCE_NONE
;
225 goodsnd
: array[0..3] of TPlayableSound
;
226 killsnd
: array[0..3] of TPlayableSound
;
227 gDefInterTime
: ShortInt = -1;
228 gInterEndTime
: LongWord = 0;
229 gInterTime
: LongWord = 0;
230 gServInterTime
: Byte = 0;
231 gGameStartTime
: LongWord = 0;
232 gTotalMonsters
: Integer = 0;
234 gShowTime
: Boolean = True;
235 gShowFPS
: Boolean = False;
236 gShowGoals
: Boolean = True;
237 gShowStat
: Boolean = True;
238 gShowKillMsg
: Boolean = True;
239 gShowLives
: Boolean = True;
240 gShowPing
: Boolean = False;
241 gShowMap
: Boolean = False;
243 gState
: Byte = STATE_NONE
;
245 sWidth
, sHeight
: Word;
246 gSpectMode
: Byte = SPECT_NONE
;
247 gSpectHUD
: Boolean = True;
248 gSpectKeyPress
: Boolean = False;
249 gSpectX
: Integer = 0;
250 gSpectY
: Integer = 0;
251 gSpectStep
: Byte = 8;
252 gSpectViewTwo
: Boolean = False;
253 gSpectPID1
: Integer = -1;
254 gSpectPID2
: Integer = -1;
255 gMusic
: TMusic
= nil;
256 gLoadGameMode
: Boolean;
257 gCheats
: Boolean = False;
258 gMapOnce
: Boolean = False;
259 gMapToDelete
: String;
260 gTempDelete
: Boolean = False;
261 gLastMap
: Boolean = False;
262 gWinPosX
, gWinPosY
: Integer;
263 gWinSizeX
, gWinSizeY
: Integer;
264 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
265 gWinActive
: Boolean = True; // by default window is active, lol
266 gResolutionChange
: Boolean = False;
267 gRC_Width
, gRC_Height
: Word;
268 gRC_FullScreen
, gRC_Maximized
: Boolean;
269 gLanguageChange
: Boolean = False;
270 gDebugMode
: Boolean = False;
271 g_debug_Sounds
: Boolean = False;
272 g_debug_Frames
: Boolean = False;
273 g_debug_WinMsgs
: Boolean = False;
274 g_debug_MonsterOff
: Boolean = False;
275 g_debug_BotAIOff
: Byte = 0;
276 g_debug_HealthBar
: Boolean = False;
277 g_Debug_Player
: Boolean = False;
278 gCoopMonstersKilled
: Word = 0;
279 gCoopSecretsFound
: Word = 0;
280 gCoopTotalMonstersKilled
: Word = 0;
281 gCoopTotalSecretsFound
: Word = 0;
282 gCoopTotalMonsters
: Word = 0;
283 gCoopTotalSecrets
: Word = 0;
284 gStatsOff
: Boolean = False;
285 gStatsPressed
: Boolean = False;
286 gExitByTrigger
: Boolean = False;
287 gNextMap
: String = '';
288 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
289 gLMSRespawnTime
: Cardinal = 0;
290 gLMSSoftSpawn
: Boolean = False;
291 gMissionFailed
: Boolean = False;
292 gVoteInProgress
: Boolean = False;
293 gVotePassed
: Boolean = False;
294 gVoteCommand
: string = '';
295 gVoteTimer
: Cardinal = 0;
296 gVoteCmdTimer
: Cardinal = 0;
297 gVoteCount
: Integer = 0;
298 gVoteTimeout
: Cardinal = 30;
299 gVoted
: Boolean = False;
300 gVotesEnabled
: Boolean = True;
301 gEvents
: Array of TGameEvent
;
302 gDelayedEvents
: Array of TDelayedEvent
;
304 // move button values:
305 // bits 0-1: l/r state:
306 // 0: neither left, nor right pressed
309 // bits 4-5: l/r state when strafe was pressed
310 P1MoveButton
: Byte = 0;
311 P2MoveButton
: Byte = 0;
313 g_profile_frame_update
: Boolean = false;
314 g_profile_frame_draw
: Boolean = false;
315 g_profile_collision
: Boolean = false;
316 g_profile_los
: Boolean = false;
317 g_profile_history_size
: Integer = 1000;
320 procedure g_ResetDynlights ();
321 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
322 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
328 g_textures
, g_main
, g_window
, g_menu
,
329 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
330 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
331 g_triggers
, MAPDEF
, g_monsters
, e_sound
, CONFIG
,
332 BinEditor
, g_language
, g_net
, SDL
,
333 ENet
, e_msg
, g_netmsg
, g_netmaster
, GL
, GLExt
,
334 utils
, sfs
, g_holmes
;
337 // ////////////////////////////////////////////////////////////////////////// //
339 profileFrameDraw
: TProfiler
= nil;
342 // ////////////////////////////////////////////////////////////////////////// //
345 x
, y
, radius
: Integer;
348 exploRadius
: Integer;
352 g_dynLights
: array of TDynLight
= nil;
353 g_dynLightCount
: Integer = 0;
354 g_playerLight
: Boolean = false;
356 procedure g_ResetDynlights ();
360 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
362 for idx
:= 0 to g_dynLightCount
-1 do
364 if g_dynLights
[idx
].exploCount
= -666 then
371 Inc(g_dynLights
[idx
].exploCount
);
372 if (g_dynLights
[idx
].exploCount
< 10) then
374 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
375 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
376 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
377 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
382 g_dynLightCount
:= lnum
;
385 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
387 if not gwin_has_stencil
then exit
;
388 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
389 g_dynLights
[g_dynLightCount
].x
:= x
;
390 g_dynLights
[g_dynLightCount
].y
:= y
;
391 g_dynLights
[g_dynLightCount
].radius
:= radius
;
392 g_dynLights
[g_dynLightCount
].r
:= r
;
393 g_dynLights
[g_dynLightCount
].g
:= g
;
394 g_dynLights
[g_dynLightCount
].b
:= b
;
395 g_dynLights
[g_dynLightCount
].a
:= a
;
396 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
397 Inc(g_dynLightCount
);
400 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
402 if not gwin_has_stencil
then exit
;
403 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
404 g_dynLights
[g_dynLightCount
].x
:= x
;
405 g_dynLights
[g_dynLightCount
].y
:= y
;
406 g_dynLights
[g_dynLightCount
].radius
:= 0;
407 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
408 g_dynLights
[g_dynLightCount
].r
:= r
;
409 g_dynLights
[g_dynLightCount
].g
:= g
;
410 g_dynLights
[g_dynLightCount
].b
:= b
;
411 g_dynLights
[g_dynLightCount
].a
:= 0;
412 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
413 Inc(g_dynLightCount
);
417 // ////////////////////////////////////////////////////////////////////////// //
418 function calcProfilesHeight (prof
: TProfiler
): Integer;
421 if (prof
= nil) then exit
;
422 if (length(prof
.bars
) = 0) then exit
;
423 result
:= length(prof
.bars
)*(16+2);
427 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
434 if (prof
= nil) then exit
;
436 if (length(prof
.bars
) = 0) then exit
;
438 hgt
:= calcProfilesHeight(prof
);
439 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
440 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
442 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
443 e_DrawFillQuad(x
, y
, x
+wdt
-1, y
+hgt
-1, 20, 20, 20, 0, B_NONE
);
446 for ii
:= 0 to High(prof
.bars
) do
448 e_TextureFontPrintEx(x
+2+4*prof
.bars
[ii
].level
, yy
, Format('%s: %d', [prof
.bars
[ii
].name
, prof
.bars
[ii
].value
]), gStdFont
, 255, 255, 0, 1, false);
455 // ////////////////////////////////////////////////////////////////////////// //
457 TEndCustomGameStat
= record
458 PlayerStat
: TPlayerStatArray
;
462 Map
, MapName
: String;
465 TEndSingleGameStat
= record
466 PlayerStat
: Array [0..1] of record
472 TotalSecrets
: Integer;
475 TLoadingStat
= record
479 Msgs
: Array of String;
483 TParamStrValue
= record
488 TParamStrValues
= Array of TParamStrValue
;
491 INTER_ACTION_TEXT
= 1;
492 INTER_ACTION_PIC
= 2;
493 INTER_ACTION_MUSIC
= 3;
497 FPSCounter
, UPSCounter
: Word;
498 FPSTime
, UPSTime
: LongWord;
499 DataLoaded
: Boolean = False;
500 LastScreenShot
: Int64;
501 IsDrawStat
: Boolean = False;
502 CustomStat
: TEndCustomGameStat
;
503 SingleStat
: TEndSingleGameStat
;
504 LoadingStat
: TLoadingStat
;
505 EndingGameCounter
: Byte = 0;
508 MapList
: SArray
= nil;
509 MapIndex
: Integer = -1;
515 text: Array of ShortString;
516 anim
: Array of ShortString;
517 pic
: Array of ShortString;
518 mus
: Array of ShortString;
520 triggers
: Array of record
522 actions
: Array of record
523 action
, p1
, p2
: Integer;
526 cur_trigger
: Integer;
539 function Compare(a
, b
: TPlayerStat
): Integer;
541 if a
.Spectator
then Result
:= 1
542 else if b
.Spectator
then Result
:= -1
543 else if a
.Frags
< b
.Frags
then Result
:= 1
544 else if a
.Frags
> b
.Frags
then Result
:= -1
545 else if a
.Deaths
< b
.Deaths
then Result
:= -1
546 else if a
.Deaths
> b
.Deaths
then Result
:= 1
547 else if a
.Kills
< b
.Kills
then Result
:= -1
551 procedure SortGameStat(var stat
: TPlayerStatArray
);
556 if stat
= nil then Exit
;
558 for I
:= High(stat
) downto Low(stat
) do
559 for J
:= Low(stat
) to High(stat
) - 1 do
560 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
563 stat
[J
] := stat
[J
+ 1];
568 function g_Game_ModeToText(Mode
: Byte): string;
572 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
573 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
574 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
575 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
576 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
580 function g_Game_TextToMode(Mode
: string): Byte;
583 Mode
:= UpperCase(Mode
);
584 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
589 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
594 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
599 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
604 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
611 function g_Game_IsNet(): Boolean;
613 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
616 function g_Game_IsServer(): Boolean;
618 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
621 function g_Game_IsClient(): Boolean;
623 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
626 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
633 Result
.name
:= ExtractFileName(WAD
);
634 Result
.description
:= '';
637 w
:= TWADFile
.Create();
640 if not w
.GetResource('INTERSCRIPT', p
, len
) then
646 cfg
:= TConfig
.CreateMem(p
, len
);
647 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
648 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
649 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
650 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
656 procedure g_Game_FreeWAD();
660 for a
:= 0 to High(MegaWAD
.res
.pic
) do
661 if MegaWAD
.res
.pic
[a
] <> '' then
662 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
664 for a
:= 0 to High(MegaWAD
.res
.mus
) do
665 if MegaWAD
.res
.mus
[a
] <> '' then
666 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
668 MegaWAD
.res
.pic
:= nil;
669 MegaWAD
.res
.text := nil;
670 MegaWAD
.res
.anim
:= nil;
671 MegaWAD
.res
.mus
:= nil;
672 MegaWAD
.triggers
:= nil;
674 g_Texture_Delete('TEXTURE_endpic');
675 g_Sound_Delete('MUSIC_endmus');
677 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
678 gGameSettings
.WAD
:= '';
681 procedure g_Game_LoadWAD(WAD
: string);
690 gGameSettings
.WAD
:= WAD
;
691 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
694 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
696 w
:= TWADFile
.Create();
697 w
.ReadFile(MapsDir
+ WAD
);
699 if not w
.GetResource('INTERSCRIPT', p
, len
) then
705 cfg
:= TConfig
.CreateMem(p
, len
);
710 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
711 if s = '' then Break;
714 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
715 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
717 g_Texture_CreateWADEx(s, s);
723 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
724 if s = '' then Break;
727 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
728 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
730 g_Music_CreateWADEx(s, s);
733 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
734 if MegaWAD
.endpic
<> '' then
736 s
:= g_ExtractWadName(MegaWAD
.endpic
);
737 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
738 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
740 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
741 if MegaWAD
.endmus
<> '' then
743 s
:= g_ExtractWadName(MegaWAD
.endmus
);
744 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
745 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
753 {procedure start_trigger(t: string);
757 function next_trigger(): Boolean;
761 procedure DisableCheats();
767 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
768 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
769 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
770 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
772 {$IF DEFINED(D2F_DEBUG)}
773 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
778 procedure g_Game_ExecuteEvent(Name
: String);
784 if gEvents
= nil then
786 for a
:= 0 to High(gEvents
) do
787 if gEvents
[a
].Name
= Name
then
789 if gEvents
[a
].Command
<> '' then
790 g_Console_Process(gEvents
[a
].Command
, True);
795 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
800 if gDelayedEvents
<> nil then
801 for a
:= 0 to High(gDelayedEvents
) do
802 if not gDelayedEvents
[a
].Pending
then
809 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
810 n
:= High(gDelayedEvents
);
812 gDelayedEvents
[n
].Pending
:= True;
813 gDelayedEvents
[n
].DEType
:= DEType
;
814 gDelayedEvents
[n
].DENum
:= Num
;
815 gDelayedEvents
[n
].DEStr
:= Str
;
816 if DEType
= DE_GLOBEVENT
then
817 gDelayedEvents
[n
].Time
:= (GetTimer() {div 1000}) + Time
819 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
828 if g_Game_IsNet
and g_Game_IsServer
then
829 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
835 g_Game_StopAllSounds(False);
840 EndingGameCounter
:= 0;
841 g_ActiveWindow
:= nil;
843 gLMSRespawn
:= LMS_RESPAWN_NONE
;
844 gLMSRespawnTime
:= 0;
847 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
852 begin // Ýòî áûë òåñò
856 begin // Âûõîä â ãëàâíîå ìåíþ
857 gMusic
.SetByName('MUSIC_MENU');
859 if gState
<> STATE_SLIST
then
861 g_GUI_ShowWindow('MainMenu');
862 gState
:= STATE_MENU
;
865 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
866 slReturnPressed
:= True;
867 if g_Net_Slist_Fetch(slCurrent
) then
869 if slCurrent
= nil then
870 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
873 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
876 g_Game_ExecuteEvent('ongameend');
880 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
882 if not g_Game_IsClient
then g_Game_Restart();
885 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
887 // Ñòàòèñòèêà Ñâîåé èãðû:
888 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
890 CustomStat
.GameTime
:= gTime
;
891 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
892 CustomStat
.MapName
:= gMapInfo
.Name
;
893 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
894 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
895 CustomStat
.TeamStat
:= gTeamStat
;
897 CustomStat
.PlayerStat
:= nil;
899 // Ñòàòèñòèêà èãðîêîâ:
900 if gPlayers
<> nil then
902 for a
:= 0 to High(gPlayers
) do
903 if gPlayers
[a
] <> nil then
905 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
906 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
908 Name
:= gPlayers
[a
].Name
;
909 Frags
:= gPlayers
[a
].Frags
;
910 Deaths
:= gPlayers
[a
].Death
;
911 Kills
:= gPlayers
[a
].Kills
;
912 Team
:= gPlayers
[a
].Team
;
913 Color
:= gPlayers
[a
].Model
.Color
;
914 Spectator
:= gPlayers
[a
].FSpectator
;
918 SortGameStat(CustomStat
.PlayerStat
);
921 g_Game_ExecuteEvent('onmapend');
924 EndingGameCounter
:= 255;
925 gState
:= STATE_FOLD
;
927 if gDefInterTime
< 0 then
928 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
930 gInterEndTime
:= gDefInterTime
* 1000;
933 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
935 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
936 SingleStat
.GameTime
:= gTime
;
937 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
938 SingleStat
.TotalSecrets
:= gSecretsCount
;
939 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
940 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
941 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
942 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
943 if SingleStat
.TwoPlayers
then
945 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
946 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
949 g_Game_ExecuteEvent('onmapend');
952 if gNextMap
<> '' then
954 gMusic
.SetByName('MUSIC_INTERMUS');
956 gState
:= STATE_INTERSINGLE
;
958 g_Game_ExecuteEvent('oninter');
960 else // Áîëüøå íåò êàðò
963 EndingGameCounter
:= 255;
964 gState
:= STATE_FOLD
;
969 // Îêîí÷àíèå îáðàáîòàíî:
970 if gExit
<> EXIT_QUIT
then
974 procedure DrawStat();
976 pc
, x
, y
, w
, h
: Integer;
977 w1
, w2
, w3
, w4
: Integer;
979 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
982 stat
: TPlayerStatArray
;
989 pc
:= g_Player_GetCount
;
990 e_TextureFontGetSize(gStdFont
, cw
, ch
);
992 w
:= gScreenWidth
-(gScreenWidth
div 5);
993 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
996 h
:= 40+ch
*5+(ch
+8)*pc
;
997 x
:= (gScreenWidth
div 2)-(w
div 2);
998 y
:= (gScreenHeight
div 2)-(h
div 2);
1000 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1001 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1003 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1004 map
:= g_ExtractFileName(gMapInfo
.Map
);
1005 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1007 case gGameSettings
.GameMode
of
1010 if gGameSettings
.MaxLives
= 0 then
1011 s1
:= _lc
[I_GAME_DM
]
1013 s1
:= _lc
[I_GAME_LMS
];
1014 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1015 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1020 if gGameSettings
.MaxLives
= 0 then
1021 s1
:= _lc
[I_GAME_TDM
]
1023 s1
:= _lc
[I_GAME_TLMS
];
1024 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1025 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1030 s1
:= _lc
[I_GAME_CTF
];
1031 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1032 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1037 if gGameSettings
.MaxLives
= 0 then
1038 s1
:= _lc
[I_GAME_COOP
]
1040 s1
:= _lc
[I_GAME_SURV
];
1041 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1042 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1053 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1055 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1057 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1059 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1060 gStdFont
, 200, 200, 200, 1);
1062 if NetMode
= NET_SERVER
then
1063 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1065 if NetMode
= NET_CLIENT
then
1066 e_TextureFontPrintEx(x
+8, y
+ 8,
1067 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1071 stat
:= g_Player_GetStats();
1074 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1075 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1077 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1079 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1083 for a
:= TEAM_RED
to TEAM_BLUE
do
1085 if a
= TEAM_RED
then
1087 s1
:= _lc
[I_GAME_TEAM_RED
];
1094 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1100 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1101 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1102 gStdFont
, r
, g
, b
, 1);
1104 _y
:= _y
+ch
+(ch
div 4);
1105 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1106 _y
:= _y
+(ch
div 4);
1108 for aa
:= 0 to High(stat
) do
1109 if stat
[aa
].Team
= a
then
1125 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1127 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1129 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1131 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1138 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1141 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1142 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1143 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1144 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1147 for aa
:= 0 to High(stat
) do
1161 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1162 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1164 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1166 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1168 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1170 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1176 procedure g_Game_Init();
1182 gTempDelete
:= False;
1184 sfsGCDisable(); // temporary disable removing of temporary volumes
1187 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1188 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1189 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1190 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1192 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1193 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1194 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1196 g_Game_ClearLoading();
1197 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1198 g_Game_SetLoadingText('', 0, False);
1200 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1203 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1204 g_PlayerModel_LoadData();
1206 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1208 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1209 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1210 until FindNext(SR
) <> 0;
1213 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1215 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1216 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1217 until FindNext(SR
) <> 0;
1220 if FindFirst(ModelsDir
+'*.zip', faAnyFile
, SR
) = 0 then
1222 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1223 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1224 until FindNext(SR
) <> 0;
1230 LastScreenShot
:= 0;
1232 {e_MouseInfo.Accel := 1.0;}
1234 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1237 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1238 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1239 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1240 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1241 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1243 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1246 gMusic
:= TMusic
.Create();
1247 gMusic
.SetByName('MUSIC_MENU');
1250 gGameSettings
.WarmupTime
:= 30;
1252 gState
:= STATE_MENU
;
1254 SetLength(gEvents
, 6);
1255 gEvents
[0].Name
:= 'ongamestart';
1256 gEvents
[1].Name
:= 'ongameend';
1257 gEvents
[2].Name
:= 'onmapstart';
1258 gEvents
[3].Name
:= 'onmapend';
1259 gEvents
[4].Name
:= 'oninter';
1260 gEvents
[5].Name
:= 'onwadend';
1262 sfsGCEnable(); // enable releasing unused volumes
1266 procedure g_Game_Free();
1268 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1269 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1273 g_Player_RemoveAllCorpses();
1275 gGameSettings
.GameType
:= GT_NONE
;
1276 if gGameSettings
.GameMode
= GM_SINGLE
then
1277 gGameSettings
.GameMode
:= GM_DM
;
1278 gSwitchGameMode
:= gGameSettings
.GameMode
;
1281 gExitByTrigger
:= False;
1284 function IsActivePlayer(p
: TPlayer
): Boolean;
1289 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1292 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1299 if gPlayers
= nil then
1301 for a
:= Low(gPlayers
) to High(gPlayers
) do
1302 if IsActivePlayer(gPlayers
[a
]) then
1304 if gPlayers
[a
].UID
<> ID
then
1306 Result
:= gPlayers
[a
];
1311 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1317 if gPlayers
= nil then
1321 for a
:= Low(gPlayers
) to High(gPlayers
) do
1322 if IsActivePlayer(gPlayers
[a
]) then
1324 SetLength(ids
, Length(ids
) + 1);
1325 ids
[High(ids
)] := gPlayers
[a
].UID
;
1326 if gPlayers
[a
].UID
= Skip
then
1329 if Length(ids
) = 0 then
1334 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1337 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1343 if gPlayers
= nil then
1347 for a
:= Low(gPlayers
) to High(gPlayers
) do
1348 if IsActivePlayer(gPlayers
[a
]) then
1350 SetLength(ids
, Length(ids
) + 1);
1351 ids
[High(ids
)] := gPlayers
[a
].UID
;
1352 if gPlayers
[a
].UID
= Skip
then
1355 if Length(ids
) = 0 then
1358 Result
:= ids
[Length(ids
) - 1]
1360 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1363 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
1365 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
1366 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
1370 procedure processPlayerControls (plr
: TPlayer
; var ctrl
: TPlayerControl
; var MoveButton
: Byte; p2hack
: Boolean=false);
1376 if (plr
= nil) then exit
;
1377 if (p2hack
) then time
:= 1000 else time
:= 1;
1378 strafeDir
:= MoveButton
shr 4;
1379 MoveButton
:= MoveButton
and $0F;
1382 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1383 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1384 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1386 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1387 if MoveButton
= 1 then plr
.PressKey(KEY_LEFT
, time
)
1388 else if MoveButton
= 2 then plr
.PressKey(KEY_RIGHT
, time
);
1390 // if we have "strafe" key, turn off old strafe mechanics
1391 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
1393 // new strafe mechanics
1394 if (strafeDir
= 0) then strafeDir
:= MoveButton
; // start strafing
1395 // now set direction according to strafe (reversed)
1396 if (strafeDir
= 2) then plr
.SetDirection(D_LEFT
)
1397 else if (strafeDir
= 1) then plr
.SetDirection(D_RIGHT
);
1401 strafeDir
:= 0; // not strafing anymore
1402 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1403 if (MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then plr
.SetDirection(D_LEFT
)
1404 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1405 else if (MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then plr
.SetDirection(D_RIGHT
)
1406 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1407 else if MoveButton
<> 0 then plr
.SetDirection(TDirection(MoveButton
-1));
1410 // fix movebutton state
1411 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1413 // Îñòàëüíûå êëàâèøè:
1414 if isKeyPressed(KeyJump
, KeyJump2
) then plr
.PressKey(KEY_JUMP
, time
);
1415 if isKeyPressed(KeyUp
, KeyUp2
) then plr
.PressKey(KEY_UP
, time
);
1416 if isKeyPressed(KeyDown
, KeyDown2
) then plr
.PressKey(KEY_DOWN
, time
);
1417 if isKeyPressed(KeyFire
, KeyFire2
) then plr
.PressKey(KEY_FIRE
);
1418 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then plr
.PressKey(KEY_NEXTWEAPON
);
1419 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then plr
.PressKey(KEY_PREVWEAPON
);
1420 if isKeyPressed(KeyOpen
, KeyOpen2
) then plr
.PressKey(KEY_OPEN
);
1422 for i
:= 0 to High(KeyWeapon
) do
1423 if isKeyPressed(KeyWeapon
[i
], KeyWeapon2
[i
]) then
1424 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1427 // HACK: add dynlight here
1428 if gwin_k8_enable_light_experiments
then
1430 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1432 g_playerLight
:= true;
1434 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1436 g_playerLight
:= false;
1440 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1443 procedure g_Game_Update();
1445 Msg
: g_gui
.TMessage
;
1451 function sendMonsPos (mon
: TMonster
): Boolean;
1453 result
:= false; // don't stop
1454 if (mon
.MonsterType
= MONSTER_BARREL
) then
1456 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1459 if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1461 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then
1463 MH_SEND_MonsterPos(mon
.UID
);
1470 // Ïîðà âûêëþ÷àòü èãðó:
1471 if gExit
= EXIT_QUIT
then
1473 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1477 if gExit
= EXIT_QUIT
then
1481 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
1484 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1487 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1489 gExit
:= EXIT_SIMPLE
;
1495 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1496 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1497 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1498 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1500 if g_Game_IsNet
and g_Game_IsServer
then
1502 gInterTime
:= gInterTime
+ GAME_TICK
;
1503 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1504 if a
<> gServInterTime
then
1506 gServInterTime
:= a
;
1507 MH_SEND_TimeSync(gServInterTime
);
1511 if (not g_Game_IsClient
) and
1514 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1515 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1516 and (g_ActiveWindow
= nil)
1518 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1521 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1522 g_Game_StopAllSounds(True);
1524 if gMapOnce
then // Ýòî áûë òåñò
1525 gExit
:= EXIT_SIMPLE
1527 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1528 g_Game_ChangeMap(gNextMap
)
1529 else // Ñëåäóþùåé êàðòû íåò
1531 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1533 // Âûõîä â ãëàâíîå ìåíþ:
1535 g_GUI_ShowWindow('MainMenu');
1536 gMusic
.SetByName('MUSIC_MENU');
1538 gState
:= STATE_MENU
;
1541 // Ôèíàëüíàÿ êàðòèíêà:
1542 g_Game_ExecuteEvent('onwadend');
1544 if not gMusic
.SetByName('MUSIC_endmus') then
1545 gMusic
.SetByName('MUSIC_STDENDMUS');
1547 gState
:= STATE_ENDPIC
;
1549 g_Game_ExecuteEvent('ongameend');
1555 if gState
= STATE_INTERTEXT
then
1556 if InterText
.counter
> 0 then
1557 InterText
.counter
:= InterText
.counter
- 1;
1560 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1562 if EndingGameCounter
= 0 then
1564 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1565 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1567 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1569 g_Game_ExecuteEvent('onwadend');
1570 if not gMusic
.SetByName('MUSIC_endmus') then
1571 gMusic
.SetByName('MUSIC_STDENDMUS');
1574 gMusic
.SetByName('MUSIC_ROUNDMUS');
1577 gState
:= STATE_INTERCUSTOM
;
1579 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1581 gMusic
.SetByName('MUSIC_INTERMUS');
1583 gState
:= STATE_INTERSINGLE
;
1585 g_Game_ExecuteEvent('oninter');
1588 DecMin(EndingGameCounter
, 6, 0);
1591 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1593 if gMapOnce
then // Ýòî áûë òåñò
1595 gExit
:= EXIT_SIMPLE
;
1601 g_Serverlist_Control(slCurrent
);
1604 if g_Game_IsNet
then
1605 if not gConsoleShow
then
1606 if not gChatShow
then
1608 if g_ActiveWindow
= nil then
1610 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1611 g_Console_Chat_Switch(False)
1612 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1613 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1614 g_Console_Chat_Switch(True);
1617 if not gChatEnter
then
1618 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1619 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1622 // Ñòàòèñòèêà ïî Tab:
1624 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1625 (gGameSettings
.GameType
<> GT_SINGLE
) and
1626 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1629 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1631 // Âðåìÿ += 28 ìèëëèñåêóíä:
1632 gTime
:= gTime
+ GAME_TICK
;
1634 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1635 if MessageTime
= 0 then
1637 if MessageTime
> 0 then
1638 MessageTime
:= MessageTime
- 1;
1640 if (g_Game_IsServer
) then
1642 // Áûë çàäàí ëèìèò âðåìåíè:
1643 if (gGameSettings
.TimeLimit
> 0) then
1644 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1645 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1650 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1651 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1652 g_Game_RestartRound(gLMSSoftSpawn
);
1654 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1655 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1657 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1659 g_Console_Process(gVoteCommand
);
1661 gVotePassed
:= False;
1664 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1665 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1666 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1667 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1668 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1670 // Áûë çàäàí ëèìèò ïîáåä:
1671 if (gGameSettings
.GoalLimit
> 0) then
1675 if gGameSettings
.GameMode
= GM_DM
then
1676 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1677 for i
:= 0 to High(gPlayers
) do
1678 if gPlayers
[i
] <> nil then
1679 if gPlayers
[i
].Frags
> b
then
1680 b
:= gPlayers
[i
].Frags
;
1683 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1684 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1685 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1688 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1689 if b
>= gGameSettings
.GoalLimit
then
1696 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1697 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1698 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1699 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1701 processPlayerControls(gPlayer1
, gGameControls
.P1Control
, P1MoveButton
);
1702 processPlayerControls(gPlayer2
, gGameControls
.P2Control
, P2MoveButton
, true);
1703 end // if not console
1706 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1708 // process weapon switch queue
1712 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1713 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1715 if not gSpectKeyPress
then
1717 if isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
) then
1719 // switch spect mode
1721 SPECT_NONE
: ; // not spectator
1723 SPECT_MAPVIEW
: Inc(gSpectMode
);
1724 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1726 gSpectKeyPress
:= True;
1728 if gSpectMode
= SPECT_MAPVIEW
then
1730 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1731 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1732 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1733 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1734 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1735 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1736 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1737 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1738 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1741 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1742 gSpectKeyPress
:= True;
1744 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1747 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1748 gSpectKeyPress
:= True;
1751 if gSpectMode
= SPECT_PLAYERS
then
1753 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1756 gSpectViewTwo
:= True;
1757 gSpectKeyPress
:= True;
1759 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1761 // remove second view
1762 gSpectViewTwo
:= False;
1763 gSpectKeyPress
:= True;
1765 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1767 // prev player (view 1)
1768 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1769 gSpectKeyPress
:= True;
1771 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1773 // next player (view 1)
1774 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1775 gSpectKeyPress
:= True;
1777 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1779 // prev player (view 2)
1780 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1781 gSpectKeyPress
:= True;
1783 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1785 // next player (view 2)
1786 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1787 gSpectKeyPress
:= True;
1792 if (not isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)) and
1793 (not isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
)) and
1794 (not isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
)) and
1795 (not isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
)) and
1796 (not isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
)) and
1797 (not isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
)) and
1798 (not isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
)) then
1799 gSpectKeyPress
:= False;
1802 // Îáíîâëÿåì âñå îñòàëüíîå:
1805 g_Triggers_Update();
1807 g_Monsters_Update();
1809 g_Player_UpdateAll();
1810 g_Player_UpdatePhysicalObjects();
1811 if gGameSettings
.GameType
= GT_SERVER
then
1812 if Length(gMonstersSpawned
) > 0 then
1814 for I
:= 0 to High(gMonstersSpawned
) do
1815 MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1816 SetLength(gMonstersSpawned
, 0);
1819 if (gSoundTriggerTime
> 8) then
1821 g_Game_UpdateTriggerSounds();
1822 gSoundTriggerTime
:= 0;
1825 Inc(gSoundTriggerTime
);
1827 if (NetMode
= NET_SERVER
) then
1829 Inc(NetTimeToUpdate
);
1830 Inc(NetTimeToReliable
);
1831 if NetTimeToReliable
>= NetRelupdRate
then
1833 for I
:= 0 to High(gPlayers
) do
1834 if gPlayers
[I
] <> nil then
1835 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
);
1837 g_Mons_ForEach(sendMonsPos
);
1839 NetTimeToReliable
:= 0;
1840 NetTimeToUpdate
:= NetUpdateRate
;
1842 else if NetTimeToUpdate
>= NetUpdateRate
then
1844 if gPlayers
<> nil then
1845 for I
:= 0 to High(gPlayers
) do
1846 if gPlayers
[I
] <> nil then
1847 MH_SEND_PlayerPos(False, gPlayers
[I
].UID
);
1849 g_Mons_ForEach(sendMonsPos
);
1851 NetTimeToUpdate
:= 0;
1854 if NetUseMaster
then
1855 if gTime
>= NetTimeToMaster
then
1857 if (NetMHost
= nil) or (NetMPeer
= nil) then
1858 if not g_Net_Slist_Connect
then
1859 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1862 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1866 if NetMode
= NET_CLIENT
then
1867 MC_SEND_PlayerPos();
1868 end; // if gameOn ...
1870 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1871 if g_ActiveWindow
<> nil then
1873 w
:= e_GetFirstKeyPressed();
1875 if (w
<> IK_INVALID
) then
1877 Msg
.Msg
:= MESSAGE_DIKEY
;
1879 g_ActiveWindow
.OnMessage(Msg
);
1882 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1883 if g_ActiveWindow
<> nil then
1884 g_ActiveWindow
.Update();
1886 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1887 if gResolutionChange
then
1889 e_WriteLog('Changing resolution', MSG_NOTIFY
);
1890 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1891 gResolutionChange
:= False;
1894 // Íóæíî ñìåíèòü ÿçûê:
1895 if gLanguageChange
then
1897 //e_WriteLog('Read language file', MSG_NOTIFY);
1898 //g_Language_Load(DataDir + gLanguage + '.txt');
1899 g_Language_Set(gLanguage
);
1901 gLanguageChange
:= False;
1905 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1906 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
1907 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
1910 LastScreenShot
:= GetTimer();
1913 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
1914 if e_KeyPressed(IK_F10
) and
1916 (not gConsoleShow
) and
1917 (g_ActiveWindow
= nil) then
1922 Time
:= GetTimer() {div 1000};
1924 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
1925 if gDelayedEvents
<> nil then
1926 for a
:= 0 to High(gDelayedEvents
) do
1927 if gDelayedEvents
[a
].Pending
and
1929 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
1930 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
1933 case gDelayedEvents
[a
].DEType
of
1935 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
1938 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
1942 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
1943 if g_Game_IsNet
and g_Game_IsServer
then
1944 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
1947 gDelayedEvents
[a
].Pending
:= False;
1950 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
1951 UPSCounter
:= UPSCounter
+ 1;
1952 if Time
- UPSTime
>= 1000 then
1959 if gGameOn
then g_Weapon_AddDynLights();
1962 procedure g_Game_LoadData();
1964 if DataLoaded
then Exit
;
1966 e_WriteLog('Loading game data...', MSG_NOTIFY
);
1968 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
1969 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
1970 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
1971 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
1972 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
1973 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
1974 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_RB');
1975 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_RS');
1976 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_RD');
1977 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_BB');
1978 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_BS');
1979 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_BD');
1980 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
1981 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
1982 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
1983 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
1984 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
1985 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
1986 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
1987 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
1988 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
1989 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
1990 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
1991 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
1992 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
1993 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
1994 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
1995 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
1996 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
1997 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
1998 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
1999 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2000 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2001 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2003 goodsnd
[0] := TPlayableSound
.Create();
2004 goodsnd
[1] := TPlayableSound
.Create();
2005 goodsnd
[2] := TPlayableSound
.Create();
2006 goodsnd
[3] := TPlayableSound
.Create();
2008 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2009 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2010 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2011 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2013 killsnd
[0] := TPlayableSound
.Create();
2014 killsnd
[1] := TPlayableSound
.Create();
2015 killsnd
[2] := TPlayableSound
.Create();
2016 killsnd
[3] := TPlayableSound
.Create();
2018 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2019 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2020 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2021 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2023 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2026 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2027 g_Weapon_LoadData();
2029 g_Monsters_LoadData();
2034 procedure g_Game_FreeData();
2036 if not DataLoaded
then Exit
;
2039 g_Weapon_FreeData();
2040 g_Monsters_FreeData();
2042 e_WriteLog('Releasing game data...', MSG_NOTIFY
);
2044 g_Texture_Delete('NOTEXTURE');
2045 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2046 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2047 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2048 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2049 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2050 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2051 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2052 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2053 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2054 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2055 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2056 g_Frames_DeleteByName('FRAMES_TELEPORT');
2057 g_Sound_Delete('SOUND_GAME_TELEPORT');
2058 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2059 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2060 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2061 g_Sound_Delete('SOUND_GAME_BULK1');
2062 g_Sound_Delete('SOUND_GAME_BULK2');
2063 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2064 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2065 g_Sound_Delete('SOUND_GAME_SWITCH1');
2066 g_Sound_Delete('SOUND_GAME_SWITCH0');
2073 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2074 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2075 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2076 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2083 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2084 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2085 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2086 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2088 DataLoaded
:= False;
2091 procedure DrawCustomStat();
2097 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2098 s1
, s2
, topstr
: String;
2100 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2103 if e_KeyPressed(IK_TAB
) then
2105 if not gStatsPressed
then
2107 gStatsOff
:= not gStatsOff
;
2108 gStatsPressed
:= True;
2112 gStatsPressed
:= False;
2116 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2117 w
:= (Length(s1
) * ww2
) div 2;
2118 x
:= gScreenWidth
div 2 - w
;
2120 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2124 if (gGameSettings
.GameMode
= GM_COOP
) then
2126 if gMissionFailed
then
2127 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2129 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2132 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2134 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2135 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2137 if g_Game_IsNet
then
2139 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2140 if not gChatShow
then
2141 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2142 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2145 if g_Game_IsClient
then
2146 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2148 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2149 if not gChatShow
then
2150 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2151 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2156 w
:= gScreenWidth
-x
*2;
2162 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2163 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2165 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2167 case CustomStat
.GameMode
of
2170 if gGameSettings
.MaxLives
= 0 then
2171 s1
:= _lc
[I_GAME_DM
]
2173 s1
:= _lc
[I_GAME_LMS
];
2177 if gGameSettings
.MaxLives
= 0 then
2178 s1
:= _lc
[I_GAME_TDM
]
2180 s1
:= _lc
[I_GAME_TLMS
];
2182 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2185 if gGameSettings
.MaxLives
= 0 then
2186 s1
:= _lc
[I_GAME_COOP
]
2188 s1
:= _lc
[I_GAME_SURV
];
2194 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2198 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2199 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2202 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2203 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2204 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2205 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2207 pc
:= Length(CustomStat
.PlayerStat
);
2208 if pc
= 0 then Exit
;
2210 if CustomStat
.GameMode
= GM_COOP
then
2212 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2214 s2
:= _lc
[I_GAME_MONSTERS
];
2215 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2216 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2218 s2
:= _lc
[I_GAME_SECRETS
];
2219 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2220 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2223 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2225 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2226 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2227 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2229 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2230 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2231 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2235 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2240 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2241 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2242 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2244 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2247 for t
:= TEAM_RED
to TEAM_BLUE
do
2249 if t
= TEAM_RED
then
2251 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2252 gStdFont
, 255, 0, 0, 1);
2253 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2254 gStdFont
, 255, 0, 0, 1);
2261 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2262 gStdFont
, 0, 0, 255, 1);
2263 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2264 gStdFont
, 0, 0, 255, 1);
2270 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2273 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2274 if CustomStat
.PlayerStat
[p
].Team
= t
then
2275 with CustomStat
.PlayerStat
[p
] do
2289 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2290 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2291 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2298 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2301 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2302 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2303 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2306 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2307 with CustomStat
.PlayerStat
[p
] do
2309 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2316 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2317 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2318 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2324 procedure DrawSingleStat();
2326 tm
, key_x
, val_x
, y
: Integer;
2330 procedure player_stat(n
: Integer);
2336 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2337 s2
:= Format(' %d', [gTotalMonsters
]);
2339 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2340 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2341 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2342 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2344 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2345 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2347 // "Kills-per-minute: ##.#":
2348 s1
:= _lc
[I_MENU_INTER_KPM
];
2350 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2352 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2353 s2
:= Format(' %.1f', [kpm
]);
2355 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2356 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2358 // "Secrets found: # / #":
2359 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2360 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2362 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2363 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2364 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2365 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2367 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2368 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2372 // "Level Complete":
2373 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2374 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2376 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2377 s1
:= _lc
[I_MENU_INTER_KPM
];
2378 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2381 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2383 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2384 val_x
:= key_x
+ w1
;
2387 tm
:= SingleStat
.GameTime
div 1000;
2388 s1
:= _lc
[I_MENU_INTER_TIME
];
2389 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2391 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2392 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2394 if SingleStat
.TwoPlayers
then
2397 s1
:= _lc
[I_MENU_PLAYER_1
];
2398 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2399 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2401 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2406 s1
:= _lc
[I_MENU_PLAYER_2
];
2407 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2408 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2410 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2416 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2422 procedure DrawLoadingStat();
2428 if Length(LoadingStat
.Msgs
) = 0 then
2431 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2432 yy
:= (gScreenHeight
div 3);
2433 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2434 xx
:= (gScreenWidth
div 3);
2437 for i
:= 0 to NextMsg
-1 do
2439 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2440 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2444 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2445 yy
:= yy
+ LOADING_INTERLINE
;
2449 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2451 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2453 function monDraw (mon
: TMonster
): Boolean;
2455 result
:= false; // don't stop
2460 // Ëåâûé âåðõíèé óãîë
2461 aX
:= Obj
.X
div ScaleSz
+ 1;
2462 aY
:= Obj
.Y
div ScaleSz
+ 1;
2464 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2465 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2466 // Ïðàâûé íèæíèé óãîë
2467 aX2
:= aX
+ aX2
- 1;
2468 aY2
:= aY
+ aY2
- 1;
2469 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2475 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2476 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2479 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2480 ScaleSz
:= 16 div Scale
;
2481 // Ðàçìåðû ìèíè-êàðòû:
2482 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2483 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2485 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2487 if gWalls
<> nil then
2490 for a
:= 0 to High(gWalls
) do
2492 if PanelType
<> 0 then
2494 // Ëåâûé âåðõíèé óãîë:
2495 aX
:= X
div ScaleSz
;
2496 aY
:= Y
div ScaleSz
;
2498 aX2
:= max(Width
div ScaleSz
, 1);
2499 aY2
:= max(Height
div ScaleSz
, 1);
2500 // Ïðàâûé íèæíèé óãîë:
2501 aX2
:= aX
+ aX2
- 1;
2502 aY2
:= aY
+ aY2
- 1;
2505 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2506 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2507 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2511 if gSteps
<> nil then
2514 for a
:= 0 to High(gSteps
) do
2516 if PanelType
<> 0 then
2518 // Ëåâûé âåðõíèé óãîë:
2519 aX
:= X
div ScaleSz
;
2520 aY
:= Y
div ScaleSz
;
2522 aX2
:= max(Width
div ScaleSz
, 1);
2523 aY2
:= max(Height
div ScaleSz
, 1);
2524 // Ïðàâûé íèæíèé óãîë:
2525 aX2
:= aX
+ aX2
- 1;
2526 aY2
:= aY
+ aY2
- 1;
2528 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2531 if gLifts
<> nil then
2534 for a
:= 0 to High(gLifts
) do
2536 if PanelType
<> 0 then
2538 // Ëåâûé âåðõíèé óãîë:
2539 aX
:= X
div ScaleSz
;
2540 aY
:= Y
div ScaleSz
;
2542 aX2
:= max(Width
div ScaleSz
, 1);
2543 aY2
:= max(Height
div ScaleSz
, 1);
2544 // Ïðàâûé íèæíèé óãîë:
2545 aX2
:= aX
+ aX2
- 1;
2546 aY2
:= aY
+ aY2
- 1;
2549 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2550 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2551 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2552 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2556 if gWater
<> nil then
2559 for a
:= 0 to High(gWater
) do
2561 if PanelType
<> 0 then
2563 // Ëåâûé âåðõíèé óãîë:
2564 aX
:= X
div ScaleSz
;
2565 aY
:= Y
div ScaleSz
;
2567 aX2
:= max(Width
div ScaleSz
, 1);
2568 aY2
:= max(Height
div ScaleSz
, 1);
2569 // Ïðàâûé íèæíèé óãîë:
2570 aX2
:= aX
+ aX2
- 1;
2571 aY2
:= aY
+ aY2
- 1;
2573 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2576 if gAcid1
<> nil then
2578 // Ðèñóåì êèñëîòó 1:
2579 for a
:= 0 to High(gAcid1
) do
2581 if PanelType
<> 0 then
2583 // Ëåâûé âåðõíèé óãîë:
2584 aX
:= X
div ScaleSz
;
2585 aY
:= Y
div ScaleSz
;
2587 aX2
:= max(Width
div ScaleSz
, 1);
2588 aY2
:= max(Height
div ScaleSz
, 1);
2589 // Ïðàâûé íèæíèé óãîë:
2590 aX2
:= aX
+ aX2
- 1;
2591 aY2
:= aY
+ aY2
- 1;
2593 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2596 if gAcid2
<> nil then
2598 // Ðèñóåì êèñëîòó 2:
2599 for a
:= 0 to High(gAcid2
) do
2601 if PanelType
<> 0 then
2603 // Ëåâûé âåðõíèé óãîë:
2604 aX
:= X
div ScaleSz
;
2605 aY
:= Y
div ScaleSz
;
2607 aX2
:= max(Width
div ScaleSz
, 1);
2608 aY2
:= max(Height
div ScaleSz
, 1);
2609 // Ïðàâûé íèæíèé óãîë:
2610 aX2
:= aX
+ aX2
- 1;
2611 aY2
:= aY
+ aY2
- 1;
2613 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2616 if gPlayers
<> nil then
2619 for a
:= 0 to High(gPlayers
) do
2620 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2622 // Ëåâûé âåðõíèé óãîë:
2623 aX
:= Obj
.X
div ScaleSz
+ 1;
2624 aY
:= Obj
.Y
div ScaleSz
+ 1;
2626 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2627 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2628 // Ïðàâûé íèæíèé óãîë:
2629 aX2
:= aX
+ aX2
- 1;
2630 aY2
:= aY
+ aY2
- 1;
2632 if gPlayers
[a
] = p
then
2633 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2636 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2637 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2638 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2643 g_Mons_ForEach(monDraw
);
2648 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
2649 procedure renderDynLightsInternal ();
2652 lx
, ly
, lrad
: Integer;
2654 //TODO: lights should be in separate grid, i think
2655 // but on the other side: grid may be slower for dynlights, as their lifetime is short
2656 if not gwin_has_stencil
or (g_dynLightCount
< 1) then exit
;
2658 // setup OpenGL parameters
2659 glStencilMask($FFFFFFFF);
2660 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
2661 glEnable(GL_STENCIL_TEST
);
2662 glEnable(GL_SCISSOR_TEST
);
2663 glClear(GL_STENCIL_BUFFER_BIT
);
2664 glStencilFunc(GL_EQUAL
, 0, $ff);
2666 for lln
:= 0 to g_dynLightCount
-1 do
2668 lx
:= g_dynLights
[lln
].x
;
2669 ly
:= g_dynLights
[lln
].y
;
2670 lrad
:= g_dynLights
[lln
].radius
;
2671 if lrad
< 3 then continue
;
2673 if lx
-sX
+lrad
< 0 then continue
;
2674 if ly
-sY
+lrad
< 0 then continue
;
2675 if lx
-sX
-lrad
>= gPlayerScreenSize
.X
then continue
;
2676 if ly
-sY
-lrad
>= gPlayerScreenSize
.Y
then continue
;
2678 // set scissor to optimize drawing
2679 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
2680 // no need to clear stencil buffer, light blitting will do it for us
2681 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
2682 // draw extruded panels
2683 glDisable(GL_TEXTURE_2D
);
2684 glDisable(GL_BLEND
);
2685 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
2686 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
2687 // render light texture
2688 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
2689 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
2692 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
2693 glEnable(GL_TEXTURE_2D
);
2694 // color and opacity
2695 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
2696 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
2698 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
2699 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
2700 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
2701 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
2706 glDisable(GL_STENCIL_TEST
);
2707 glDisable(GL_BLEND
);
2708 glDisable(GL_SCISSOR_TEST
);
2709 glScissor(0, 0, sWidth
, sHeight
);
2713 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
2714 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
2715 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; transX
, transY
: Integer; setTransMatrix
: Boolean);
2717 TDrawCB
= procedure ();
2719 procedure drawPanelType (profname
: AnsiString; panType
: DWord
);
2724 profileFrameDraw
.sectionBegin(profname
);
2725 if gdbg_map_use_accel_render
then
2727 tagmask
:= panelTypeToTag(panType
);
2729 while (gDrawPanelList
.count
> 0) do
2731 pan
:= TPanel(gDrawPanelList
.front());
2732 if ((pan
.tag
and tagmask
) = 0) then break
;
2734 gDrawPanelList
.popFront();
2737 e_WriteLog(Format('=== PANELS: %d ===', [gDrawPanelList
.count
]), MSG_NOTIFY
);
2738 while (gDrawPanelList
.count
> 0) do
2740 pan
:= TPanel(gDrawPanelList
.front());
2741 e_WriteLog(Format('tagmask: 0x%04x; pan.tag: 0x%04x; pan.arrIdx: %d', [tagmask
, pan
.tag
, pan
.arrIdx
]), MSG_NOTIFY
);
2743 gDrawPanelList
.popFront();
2749 g_Map_DrawPanels(panType
);
2751 profileFrameDraw
.sectionEnd();
2754 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
2756 profileFrameDraw
.sectionBegin(profname
);
2757 if assigned(cb
) then cb();
2758 profileFrameDraw
.sectionEnd();
2762 profileFrameDraw
.sectionBegin('total');
2764 // our accelerated renderer will collect all panels to gDrawPanelList
2765 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
2766 profileFrameDraw
.sectionBegin('collect');
2767 if gdbg_map_use_accel_render
then
2769 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
2771 profileFrameDraw
.sectionEnd();
2773 profileFrameDraw
.sectionBegin('skyback');
2774 g_Map_DrawBack(backXOfs
, backYOfs
);
2775 profileFrameDraw
.sectionEnd();
2777 if (setTransMatrix
) then glTranslatef(transX
, transY
, 0);
2779 drawPanelType('*back', PANEL_BACK
);
2780 drawPanelType('*step', PANEL_STEP
);
2781 drawOther('items', @g_Items_Draw
);
2782 drawOther('weapons', @g_Weapon_Draw
);
2783 drawOther('shells', @g_Player_DrawShells
);
2784 drawOther('drawall', @g_Player_DrawAll
);
2785 drawOther('corpses', @g_Player_DrawCorpses
);
2786 drawPanelType('*wall', PANEL_WALL
);
2787 drawOther('monsters', @g_Monsters_Draw
);
2788 drawPanelType('*door', PANEL_CLOSEDOOR
);
2789 drawOther('gfx', @g_GFX_Draw
);
2790 drawOther('flags', @g_Map_DrawFlags
);
2791 drawPanelType('*acid1', PANEL_ACID1
);
2792 drawPanelType('*acid2', PANEL_ACID2
);
2793 drawPanelType('*water', PANEL_WATER
);
2794 drawOther('dynlights', @renderDynLightsInternal
);
2795 drawPanelType('*fore', PANEL_FORE
);
2797 if g_debug_HealthBar
then
2799 g_Monsters_DrawHealth();
2800 g_Player_DrawHealth();
2803 profileFrameDraw
.mainEnd(); // map rendering
2807 procedure DrawMapView(x
, y
, w
, h
: Integer);
2814 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
2815 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
2822 renderMapInternal(-bx
, -by
, -x
, -y
, true);
2828 procedure DrawPlayer(p
: TPlayer
);
2830 px
, py
, a
, b
, c
, d
: Integer;
2834 if (p
= nil) or (p
.FDummy
) then
2837 g_Map_DrawBack(0, 0);
2842 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
2843 profileFrameDraw
.mainBegin(g_profile_frame_draw
);
2849 px
:= p
.GameX
+ PLAYER_RECT_CX
;
2850 py
:= p
.GameY
+ PLAYER_RECT_CY
;
2852 if px
> (gPlayerScreenSize
.X
div 2) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
2853 if py
> (gPlayerScreenSize
.Y
div 2) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
2855 if px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
2856 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
2858 if gMapInfo
.Width
<= gPlayerScreenSize
.X
then a
:= 0;
2859 if gMapInfo
.Height
<= gPlayerScreenSize
.Y
then b
:= 0;
2861 if p
.IncCam
<> 0 then
2863 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
2865 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
2867 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
2871 if py
< gPlayerScreenSize
.Y
div 2 then
2873 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
2875 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
2879 if p
.IncCam
< 0 then
2881 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
2884 if p
.IncCam
> 0 then
2886 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
2890 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
2891 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
2892 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
2894 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
2895 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
2896 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
2899 sY
:= -(b
+p
.IncCam
);
2900 sWidth
:= gPlayerScreenSize
.X
;
2901 sHeight
:= gPlayerScreenSize
.Y
;
2903 //glTranslatef(a, b+p.IncCam, 0);
2907 p
.viewPortW
:= sWidth
;
2908 p
.viewPortH
:= sHeight
;
2910 if (p
= gPlayer1
) then
2912 g_Holmes_plrView(p
.viewPortX
, p
.viewPortY
, p
.viewPortW
, p
.viewPortH
);
2915 renderMapInternal(-c
, -d
, a
, b
+p
.IncCam
, true);
2917 if p
.FSpectator
then
2918 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
2919 p
.GameY
+ PLAYER_RECT_CY
- 4,
2920 'X', gStdFont
, 255, 255, 255, 1, True);
2922 for a := 0 to High(gCollideMap) do
2923 for b := 0 to High(gCollideMap[a]) do
2926 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
2928 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
2932 1: e_DrawPoint(1, b, a, 200, 200, 200);
2933 2: e_DrawPoint(1, b, a, 64, 64, 255);
2934 3: e_DrawPoint(1, b, a, 255, 0, 255);
2944 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
2945 if g_Debug_Player
then
2946 g_Player_DrawDebug(p
);
2950 procedure drawProfilers ();
2955 if g_profile_frame_draw
then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
2956 if g_profile_collision
then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
2957 if g_profile_los
then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
2960 procedure g_Game_Draw();
2967 plView1
, plView2
: TPlayer
;
2970 if gExit
= EXIT_QUIT
then Exit
;
2972 Time
:= GetTimer() {div 1000};
2973 FPSCounter
:= FPSCounter
+1;
2974 if Time
- FPSTime
>= 1000 then
2981 if gGameOn
or (gState
= STATE_FOLD
) then
2983 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2985 gSpectMode
:= SPECT_NONE
;
2986 if not gRevertPlayers
then
2988 plView1
:= gPlayer1
;
2989 plView2
:= gPlayer2
;
2993 plView1
:= gPlayer2
;
2994 plView2
:= gPlayer1
;
2998 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3000 gSpectMode
:= SPECT_NONE
;
3001 if gPlayer2
= nil then
3004 plView1
:= gPlayer2
;
3013 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3014 gSpectMode
:= SPECT_STATS
;
3016 if gSpectMode
= SPECT_PLAYERS
then
3017 if gPlayers
<> nil then
3019 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3020 if plView1
= nil then
3022 gSpectPID1
:= GetActivePlayerID_Next();
3023 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3025 if gSpectViewTwo
then
3027 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3028 if plView2
= nil then
3030 gSpectPID2
:= GetActivePlayerID_Next();
3031 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3036 if gSpectMode
= SPECT_MAPVIEW
then
3038 // Ðåæèì ïðîñìîòðà êàðòû
3040 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3041 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3042 gHearPoint1
.Active
:= True;
3043 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3044 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3045 gHearPoint2
.Active
:= False;
3049 Split
:= (plView1
<> nil) and (plView2
<> nil);
3051 // Òî÷êè ñëóõà èãðîêîâ
3052 if plView1
<> nil then
3054 gHearPoint1
.Active
:= True;
3055 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
3056 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
3058 gHearPoint1
.Active
:= False;
3059 if plView2
<> nil then
3061 gHearPoint2
.Active
:= True;
3062 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
3063 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
3065 gHearPoint2
.Active
:= False;
3067 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3068 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3071 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3072 if gScreenHeight
mod 2 = 0 then
3073 Dec(gPlayerScreenSize
.Y
);
3076 gPlayerScreenSize
.Y
:= gScreenHeight
;
3079 if gScreenHeight
mod 2 = 0 then
3080 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3082 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3084 DrawPlayer(plView1
);
3085 gPlayer1ScreenCoord
.X
:= sX
;
3086 gPlayer1ScreenCoord
.Y
:= sY
;
3090 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3092 DrawPlayer(plView2
);
3093 gPlayer2ScreenCoord
.X
:= sX
;
3094 gPlayer2ScreenCoord
.Y
:= sY
;
3097 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3100 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3103 if MessageText
<> '' then
3107 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3109 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3110 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3112 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3113 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3116 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3118 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
3120 // Draw spectator GUI
3123 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3126 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3128 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3130 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3132 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3133 if gSpectMode
= SPECT_MAPVIEW
then
3135 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
3136 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
3137 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
3138 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
3139 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
3141 if gSpectMode
= SPECT_PLAYERS
then
3143 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
3144 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
3145 if gSpectViewTwo
then
3147 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
3148 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
3149 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3150 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3154 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3155 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3161 if gPause
and gGameOn
and (g_ActiveWindow
= nil) then
3163 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3165 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
3166 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3167 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
3172 if (gState
= STATE_MENU
) then
3174 if ((g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '')) then
3176 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3177 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3178 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3180 if g_ActiveWindow
<> nil then
3181 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3184 if gState
= STATE_FOLD
then
3185 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3187 if gState
= STATE_INTERCUSTOM
then
3189 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
3191 back
:= 'TEXTURE_endpic';
3192 if not g_Texture_Get(back
, ID
) then
3193 back
:= _lc
[I_TEXTURE_ENDPIC
];
3198 if g_Texture_Get(back
, ID
) then
3199 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3201 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3205 if g_ActiveWindow
<> nil then
3206 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3209 if gState
= STATE_INTERSINGLE
then
3211 if EndingGameCounter
> 0 then
3212 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
)
3217 if g_Texture_Get(back
, ID
) then
3218 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3220 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3224 if g_ActiveWindow
<> nil then
3225 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3229 if gState
= STATE_ENDPIC
then
3232 if not g_Texture_Get('TEXTURE_endpic', ID
) then
3233 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
3235 if ID
<> DWORD(-1) then
3236 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3238 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3240 if g_ActiveWindow
<> nil then
3241 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3244 if gState
= STATE_SLIST
then
3246 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3248 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
3249 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3251 g_Serverlist_Draw(slCurrent
);
3255 if g_ActiveWindow
<> nil then
3258 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3259 g_ActiveWindow
.Draw();
3263 if (g_holmes_enabled
) then g_Holmes_Draw();
3267 if g_debug_Sounds
and gGameOn
then
3269 for w
:= 0 to High(e_SoundsArray
) do
3270 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
3271 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
3276 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3277 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3280 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3281 e_TextureFontPrint(gScreenWidth
-72, 0,
3282 Format('%d:%.2d:%.2d', [gTime
div 1000 div 3600, (gTime
div 1000 div 60) mod 60, gTime
div 1000 mod 60]),
3285 if gGameOn
then drawProfilers();
3288 procedure g_Game_Quit();
3290 g_Game_StopAllSounds(True);
3292 g_Game_SaveOptions();
3294 g_PlayerModel_FreeData();
3295 g_Texture_DeleteAll();
3296 g_Frames_DeleteAll();
3299 if NetInitDone
then g_Net_Free
;
3301 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3302 if gMapToDelete
<> '' then
3303 g_Game_DeleteTestMap();
3309 procedure g_FatalError(Text: String);
3311 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3312 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), MSG_WARNING
);
3314 gExit
:= EXIT_SIMPLE
;
3317 procedure g_SimpleError(Text: String);
3319 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3320 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), MSG_WARNING
);
3323 procedure g_Game_SetupScreenSize();
3325 RES_FACTOR
= 4.0 / 3.0;
3331 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3332 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3333 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3334 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3336 gPlayerScreenSize
.Y
:= gScreenHeight
;
3338 // Ðàçìåð çàäíåãî ïëàíà:
3339 if BackID
<> DWORD(-1) then
3342 if (gScreenWidth
*s
> gMapInfo
.Width
) or
3343 (gScreenHeight
*s
> gMapInfo
.Height
) then
3345 gBackSize
.X
:= gScreenWidth
;
3346 gBackSize
.Y
:= gScreenHeight
;
3350 e_GetTextureSize(BackID
, @bw
, @bh
);
3351 rf
:= Single(bw
) / Single(bh
);
3352 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
3353 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
3354 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
3355 if (s
< 1.0) then s
:= 1.0;
3356 gBackSize
.X
:= Round(bw
*s
);
3357 gBackSize
.Y
:= Round(bh
*s
);
3362 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3364 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3367 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3369 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3370 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3372 if gPlayer1
= nil then
3374 if g_Game_IsClient
then
3376 if NetPlrUID1
> -1 then
3378 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3379 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3384 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3385 Team
:= gPlayer1Settings
.Team
;
3387 // Ñîçäàíèå ïåðâîãî èãðîêà:
3388 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3389 gPlayer1Settings
.Color
,
3391 if gPlayer1
= nil then
3392 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3395 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3396 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3397 if g_Game_IsServer
and g_Game_IsNet
then
3398 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3399 gPlayer1
.Respawn(False, True);
3401 if g_Game_IsNet
and NetUseMaster
then
3407 if gPlayer2
= nil then
3409 if g_Game_IsClient
then
3411 if NetPlrUID2
> -1 then
3412 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3416 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3417 Team
:= gPlayer2Settings
.Team
;
3419 // Ñîçäàíèå âòîðîãî èãðîêà:
3420 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3421 gPlayer2Settings
.Color
,
3423 if gPlayer2
= nil then
3424 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3427 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3428 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3429 if g_Game_IsServer
and g_Game_IsNet
then
3430 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3431 gPlayer2
.Respawn(False, True);
3433 if g_Game_IsNet
and NetUseMaster
then
3441 procedure g_Game_RemovePlayer();
3445 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3446 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3451 if g_Game_IsServer
then
3454 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3455 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3456 g_Player_Remove(Pl
.UID
);
3458 if g_Game_IsNet
and NetUseMaster
then
3467 if g_Game_IsServer
then
3470 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3471 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3472 g_Player_Remove(Pl
.UID
);
3474 if g_Game_IsNet
and NetUseMaster
then
3479 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3485 procedure g_Game_Spectate();
3487 g_Game_RemovePlayer();
3488 if gPlayer1
<> nil then
3489 g_Game_RemovePlayer();
3492 procedure g_Game_SpectateCenterView();
3494 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3495 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3498 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3504 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY
);
3506 g_Game_ClearLoading();
3509 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3512 gGameSettings
.GameType
:= GT_SINGLE
;
3513 gGameSettings
.MaxLives
:= 0;
3514 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3515 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3516 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3517 gSwitchGameMode
:= GM_SINGLE
;
3519 g_Game_ExecuteEvent('ongamestart');
3521 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3522 g_Game_SetupScreenSize();
3524 // Ñîçäàíèå ïåðâîãî èãðîêà:
3525 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3526 gPlayer1Settings
.Color
,
3527 gPlayer1Settings
.Team
, False));
3528 if gPlayer1
= nil then
3530 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3534 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3537 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3540 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3541 gPlayer2Settings
.Color
,
3542 gPlayer2Settings
.Team
, False));
3543 if gPlayer2
= nil then
3545 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3549 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3553 // Çàãðóçêà è çàïóñê êàðòû:
3554 if not g_Game_StartMap(MAP
, True) then
3556 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + MAP
]));
3560 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3564 for i
:= nPl
+1 to nPlayers
do
3565 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3568 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3569 TimeLimit
, GoalLimit
: Word;
3571 Options
: LongWord; nPlayers
: Byte);
3577 e_WriteLog('Starting custom game...', MSG_NOTIFY
);
3579 g_Game_ClearLoading();
3582 gGameSettings
.GameType
:= GT_CUSTOM
;
3583 gGameSettings
.GameMode
:= GameMode
;
3584 gSwitchGameMode
:= GameMode
;
3585 gGameSettings
.TimeLimit
:= TimeLimit
;
3586 gGameSettings
.GoalLimit
:= GoalLimit
;
3587 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3588 gGameSettings
.Options
:= Options
;
3590 gCoopTotalMonstersKilled
:= 0;
3591 gCoopTotalSecretsFound
:= 0;
3592 gCoopTotalMonsters
:= 0;
3593 gCoopTotalSecrets
:= 0;
3597 g_Game_ExecuteEvent('ongamestart');
3599 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3600 g_Game_SetupScreenSize();
3602 // Ðåæèì íàáëþäàòåëÿ:
3603 if nPlayers
= 0 then
3610 if nPlayers
>= 1 then
3612 // Ñîçäàíèå ïåðâîãî èãðîêà:
3613 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3614 gPlayer1Settings
.Color
,
3615 gPlayer1Settings
.Team
, False));
3616 if gPlayer1
= nil then
3618 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3622 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3626 if nPlayers
>= 2 then
3628 // Ñîçäàíèå âòîðîãî èãðîêà:
3629 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3630 gPlayer2Settings
.Color
,
3631 gPlayer2Settings
.Team
, False));
3632 if gPlayer2
= nil then
3634 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3638 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3642 // Çàãðóçêà è çàïóñê êàðòû:
3643 if not g_Game_StartMap(Map
, True) then
3645 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3649 // Íåò òî÷åê ïîÿâëåíèÿ:
3650 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3651 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3652 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3653 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3654 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3656 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3660 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3664 for i
:= nPl
+1 to nPlayers
do
3665 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3668 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3669 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3670 Options
: LongWord; nPlayers
: Byte;
3671 IPAddr
: LongWord; Port
: Word);
3675 e_WriteLog('Starting net game (server)...', MSG_NOTIFY
);
3677 g_Game_ClearLoading();
3680 gGameSettings
.GameType
:= GT_SERVER
;
3681 gGameSettings
.GameMode
:= GameMode
;
3682 gSwitchGameMode
:= GameMode
;
3683 gGameSettings
.TimeLimit
:= TimeLimit
;
3684 gGameSettings
.GoalLimit
:= GoalLimit
;
3685 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3686 gGameSettings
.Options
:= Options
;
3688 gCoopTotalMonstersKilled
:= 0;
3689 gCoopTotalSecretsFound
:= 0;
3690 gCoopTotalMonsters
:= 0;
3691 gCoopTotalSecrets
:= 0;
3695 g_Game_ExecuteEvent('ongamestart');
3697 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3698 g_Game_SetupScreenSize();
3700 // Ðåæèì íàáëþäàòåëÿ:
3701 if nPlayers
= 0 then
3707 if nPlayers
>= 1 then
3709 // Ñîçäàíèå ïåðâîãî èãðîêà:
3710 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3711 gPlayer1Settings
.Color
,
3712 gPlayer1Settings
.Team
, False));
3713 if gPlayer1
= nil then
3715 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3719 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3722 if nPlayers
>= 2 then
3724 // Ñîçäàíèå âòîðîãî èãðîêà:
3725 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3726 gPlayer2Settings
.Color
,
3727 gPlayer2Settings
.Team
, False));
3728 if gPlayer2
= nil then
3730 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3734 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3738 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3740 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
3744 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
3746 // Çàãðóçêà è çàïóñê êàðòû:
3747 if not g_Game_StartMap(Map
, True) then
3749 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3753 // Íåò òî÷åê ïîÿâëåíèÿ:
3754 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3755 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3756 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3757 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3758 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3760 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3764 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3767 NetState
:= NET_STATE_GAME
;
3770 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3785 e_WriteLog('Starting net game (client)...', MSG_NOTIFY
);
3786 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', MSG_NOTIFY
);
3788 g_Game_ClearLoading();
3791 gGameSettings
.GameType
:= GT_CLIENT
;
3793 gCoopTotalMonstersKilled
:= 0;
3794 gCoopTotalSecretsFound
:= 0;
3795 gCoopTotalMonsters
:= 0;
3796 gCoopTotalSecrets
:= 0;
3800 g_Game_ExecuteEvent('ongamestart');
3802 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3803 g_Game_SetupScreenSize();
3805 NetState
:= NET_STATE_AUTH
;
3807 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3809 if not g_Net_Connect(Addr
, Port
) then
3811 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3812 NetState
:= NET_STATE_NONE
;
3816 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3818 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3823 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
3825 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3827 Ptr
:= NetEvent
.packet
^.data
;
3828 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3831 MID
:= InMsg
.ReadByte();
3833 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3835 NetMyID
:= InMsg
.ReadByte();
3836 NetPlrUID1
:= InMsg
.ReadWord();
3838 WadName
:= InMsg
.ReadString();
3839 Map
:= InMsg
.ReadString();
3841 gWADHash
:= InMsg
.ReadMD5();
3843 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3844 gSwitchGameMode
:= gGameSettings
.GameMode
;
3845 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
3846 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3847 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3848 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3849 T
:= InMsg
.ReadLongWord();
3851 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
3852 if newResPath
= '' then
3854 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3855 newResPath
:= g_Res_DownloadWAD(WadName
);
3856 if newResPath
= '' then
3858 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3859 enet_packet_destroy(NetEvent
.packet
);
3860 NetState
:= NET_STATE_NONE
;
3864 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
3866 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3867 gPlayer1Settings
.Color
,
3868 gPlayer1Settings
.Team
, False));
3870 if gPlayer1
= nil then
3872 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3874 enet_packet_destroy(NetEvent
.packet
);
3875 NetState
:= NET_STATE_NONE
;
3879 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3880 gPlayer1
.UID
:= NetPlrUID1
;
3881 gPlayer1
.Reset(True);
3883 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
3885 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3887 enet_packet_destroy(NetEvent
.packet
);
3888 NetState
:= NET_STATE_NONE
;
3896 enet_packet_destroy(NetEvent
.packet
);
3900 enet_packet_destroy(NetEvent
.packet
);
3903 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3906 if (NetEvent
.data
<= NET_DISC_MAX
) then
3907 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3908 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3918 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
3927 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3928 NetState
:= NET_STATE_NONE
;
3932 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3933 gLMSRespawnTime
:= 0;
3936 NetState
:= NET_STATE_GAME
;
3937 MC_SEND_FullStateRequest
;
3938 e_WriteLog('NET: Connection successful.', MSG_NOTIFY
);
3941 procedure g_Game_SaveOptions();
3943 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
3946 procedure g_Game_ChangeMap(MapPath
: String);
3950 g_Game_ClearLoading();
3952 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3953 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3954 if gExitByTrigger
then
3957 gExitByTrigger
:= False;
3959 if not g_Game_StartMap(MapPath
, Force
) then
3960 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3963 procedure g_Game_Restart();
3967 if g_Game_IsClient
then
3969 map
:= g_ExtractFileName(gMapInfo
.Map
);
3973 g_Game_ClearLoading();
3974 g_Game_StartMap(Map
, True);
3977 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
3979 NewWAD
, ResName
: String;
3983 g_Player_RemoveAllCorpses();
3985 if (not g_Game_IsClient
) and
3986 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3987 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3989 if gSwitchGameMode
= GM_CTF
then
3990 gGameSettings
.MaxLives
:= 0;
3991 gGameSettings
.GameMode
:= gSwitchGameMode
;
3994 gSwitchGameMode
:= gGameSettings
.GameMode
;
3996 g_Player_ResetTeams();
3998 if Pos(':\', Map
) > 0 then
4000 NewWAD
:= g_ExtractWadName(Map
);
4001 ResName
:= g_ExtractFileName(Map
);
4002 if g_Game_IsServer
then
4004 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
4005 g_Game_LoadWAD(NewWAD
);
4007 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
4008 g_Game_ClientWAD(NewWAD
, gWADHash
);
4012 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
4015 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4017 gState
:= STATE_NONE
;
4018 g_ActiveWindow
:= nil;
4024 if gGameSettings
.GameMode
= GM_CTF
then
4026 g_Map_ResetFlag(FLAG_RED
);
4027 g_Map_ResetFlag(FLAG_BLUE
);
4028 // CTF, à ôëàãîâ íåò:
4029 if not g_Map_HaveFlagPoints() then
4030 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4035 gState
:= STATE_MENU
;
4042 NetTimeToUpdate
:= 1;
4043 NetTimeToReliable
:= 0;
4044 NetTimeToMaster
:= NetMasterRate
;
4045 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4046 gLMSRespawnTime
:= 0;
4047 gMissionFailed
:= False;
4050 gCoopMonstersKilled
:= 0;
4051 gCoopSecretsFound
:= 0;
4053 gVoteInProgress
:= False;
4054 gVotePassed
:= False;
4060 if not gGameOn
then Exit
;
4062 g_Game_SpectateCenterView();
4064 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
4066 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4067 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
4068 gLMSSoftSpawn
:= True;
4069 if NetMode
= NET_SERVER
then
4070 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
4072 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
4075 if NetMode
= NET_SERVER
then
4077 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
4080 if NetUseMaster
then
4082 if (NetMHost
= nil) or (NetMPeer
= nil) then
4083 if not g_Net_Slist_Connect
then
4084 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4089 if NetClients
<> nil then
4090 for I
:= 0 to High(NetClients
) do
4091 if NetClients
[I
].Used
then
4093 NetClients
[I
].Voted
:= False;
4094 if NetClients
[I
].RequestedFullUpdate
then
4096 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
4097 NetClients
[I
].RequestedFullUpdate
:= False;
4101 g_Net_UnbanNonPermHosts();
4106 gCoopTotalMonstersKilled
:= 0;
4107 gCoopTotalSecretsFound
:= 0;
4108 gCoopTotalMonsters
:= 0;
4109 gCoopTotalSecrets
:= 0;
4113 g_Game_ExecuteEvent('onmapstart');
4116 procedure SetFirstLevel();
4120 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4121 if MapList
= nil then
4124 SortSArray(MapList
);
4125 gNextMap
:= MapList
[Low(MapList
)];
4130 procedure g_Game_ExitLevel(Map
: Char16
);
4134 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
4135 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
4136 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
4137 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
4139 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4140 if gGameSettings
.GameType
= GT_SINGLE
then
4141 gExit
:= EXIT_ENDLEVELSINGLE
4142 else // Âûøëè â âûõîä â Ñâîåé èãðå
4144 gExit
:= EXIT_ENDLEVELCUSTOM
;
4145 if gGameSettings
.GameMode
= GM_COOP
then
4146 g_Player_RememberAll
;
4148 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4151 if gGameSettings
.GameMode
= GM_COOP
then
4154 gStatsPressed
:= True;
4155 gNextMap
:= 'MAP01';
4157 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4160 if g_Game_IsNet
then
4162 MH_SEND_GameStats();
4163 MH_SEND_CoopStats();
4169 procedure g_Game_RestartLevel();
4173 if gGameSettings
.GameMode
= GM_SINGLE
then
4178 gExit
:= EXIT_ENDLEVELCUSTOM
;
4179 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4183 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
4187 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
4189 if not g_Game_IsClient
then
4191 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
4194 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4195 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
4199 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
4203 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
4204 g_Game_LoadWAD(NewWAD
);
4207 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
4209 i
, n
, nb
, nr
: Integer;
4211 function monRespawn (mon
: TMonster
): Boolean;
4213 result
:= false; // don't stop
4214 if not mon
.FNoRespawn
then mon
.Respawn();
4218 if not g_Game_IsServer
then Exit
;
4219 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
4220 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4221 gLMSRespawnTime
:= 0;
4224 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
4226 gMissionFailed
:= True;
4227 g_Game_RestartLevel
;
4231 n
:= 0; nb
:= 0; nr
:= 0;
4232 for i
:= Low(gPlayers
) to High(gPlayers
) do
4233 if (gPlayers
[i
] <> nil) and
4234 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
4235 (gPlayers
[i
] is TBot
)) then
4238 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
4239 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
4242 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
4244 // wait a second until the fuckers finally decide to join
4245 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4246 gLMSRespawnTime
:= gTime
+ 1000;
4247 gLMSSoftSpawn
:= NoMapRestart
;
4251 g_Player_RemoveAllCorpses
;
4252 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
4253 if g_Game_IsNet
then
4254 MH_SEND_GameEvent(NET_EV_LMS_START
);
4256 for i
:= Low(gPlayers
) to High(gPlayers
) do
4258 if gPlayers
[i
] = nil then continue
;
4259 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
4260 // don't touch normal spectators
4261 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
4263 gPlayers
[i
].FNoRespawn
:= True;
4264 gPlayers
[i
].Lives
:= 0;
4265 if g_Game_IsNet
then
4266 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
4269 gPlayers
[i
].FNoRespawn
:= False;
4270 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
4271 gPlayers
[i
].Respawn(False, True);
4272 if gGameSettings
.GameMode
= GM_COOP
then
4274 gPlayers
[i
].Frags
:= 0;
4275 gPlayers
[i
].RecallState
;
4277 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
4278 gPlayer1
:= g_Player_Get(gLMSPID1
);
4279 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
4280 gPlayer2
:= g_Player_Get(gLMSPID2
);
4283 g_Items_RestartRound();
4286 g_Mons_ForEach(monRespawn
);
4288 gLMSSoftSpawn
:= False;
4291 function g_Game_GetFirstMap(WAD
: String): String;
4295 MapList
:= g_Map_GetMapsList(WAD
);
4296 if MapList
= nil then
4299 SortSArray(MapList
);
4300 Result
:= MapList
[Low(MapList
)];
4302 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4308 function g_Game_GetNextMap(): String;
4315 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4316 if MapList
= nil then
4319 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4321 SortSArray(MapList
);
4323 for I
:= Low(MapList
) to High(MapList
) do
4324 if Map
= MapList
[I
] then
4330 if MapIndex
<> -255 then
4332 if MapIndex
= High(MapList
) then
4333 Result
:= MapList
[Low(MapList
)]
4335 Result
:= MapList
[MapIndex
+ 1];
4337 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4343 procedure g_Game_NextLevel();
4345 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4346 gExit
:= EXIT_ENDLEVELCUSTOM
4349 gExit
:= EXIT_ENDLEVELSINGLE
;
4353 if gNextMap
<> '' then Exit
;
4354 gNextMap
:= g_Game_GetNextMap();
4357 function g_Game_IsTestMap(): Boolean;
4359 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4362 procedure g_Game_DeleteTestMap();
4373 a
:= Pos('.wad:\', gMapToDelete
);
4377 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4378 WadName
:= Copy(gMapToDelete
, 1, a
+ 3);
4379 Delete(gMapToDelete
, 1, a
+ 5);
4380 gMapToDelete
:= UpperCase(gMapToDelete
);
4382 CopyMemory(@MapName
[0], @gMapToDelete
[1], Min(16, Length(gMapToDelete
)));
4385 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4386 if MapName <> TEST_MAP_NAME then
4389 if not gTempDelete then
4391 time := g_GetFileTime(WadName);
4392 WAD := TWADFile.Create();
4395 if not WAD.ReadFile(WadName) then
4396 begin // Íåò òàêîãî WAD-ôàéëà
4401 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4403 MapList := WAD.GetResourcesList('');
4405 if MapList <> nil then
4406 for a := 0 to High(MapList) do
4407 if MapList[a] = MapName then
4409 // Óäàëÿåì è ñîõðàíÿåì:
4410 WAD.RemoveResource('', MapName);
4411 WAD.SaveTo(WadName);
4416 g_SetFileTime(WadName, time);
4419 if gTempDelete
then DeleteFile(WadName
);
4422 procedure GameCVars(P
: SArray
);
4425 stat
: TPlayerStatArray
;
4430 cmd
:= LowerCase(P
[0]);
4431 if cmd
= 'r_showfps' then
4433 if (Length(P
) > 1) and
4434 ((P
[1] = '1') or (P
[1] = '0')) then
4435 gShowFPS
:= (P
[1][1] = '1');
4438 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4440 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4442 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4444 with gGameSettings
do
4446 if (Length(P
) > 1) and
4447 ((P
[1] = '1') or (P
[1] = '0')) then
4449 if (P
[1][1] = '1') then
4450 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4452 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4455 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4456 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4458 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4460 if g_Game_IsNet
then MH_SEND_GameSettings
;
4463 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4465 with gGameSettings
do
4467 if (Length(P
) > 1) and
4468 ((P
[1] = '1') or (P
[1] = '0')) then
4470 if (P
[1][1] = '1') then
4471 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4473 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4476 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4477 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4479 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4481 if g_Game_IsNet
then MH_SEND_GameSettings
;
4484 else if cmd
= 'g_gamemode' then
4486 a
:= g_Game_TextToMode(P
[1]);
4487 if a
= GM_SINGLE
then a
:= GM_COOP
;
4488 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4490 gSwitchGameMode
:= a
;
4491 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4492 (gState
= STATE_INTERSINGLE
) then
4493 gSwitchGameMode
:= GM_SINGLE
;
4495 gGameSettings
.GameMode
:= gSwitchGameMode
;
4497 if gSwitchGameMode
= gGameSettings
.GameMode
then
4498 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4499 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4501 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4502 [g_Game_ModeToText(gGameSettings
.GameMode
),
4503 g_Game_ModeToText(gSwitchGameMode
)]));
4505 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4507 with gGameSettings
do
4509 if (Length(P
) > 1) and
4510 ((P
[1] = '1') or (P
[1] = '0')) then
4512 if (P
[1][1] = '1') then
4513 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4515 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4518 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4519 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4521 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4522 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4524 if g_Game_IsNet
then MH_SEND_GameSettings
;
4527 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4529 with gGameSettings
do
4531 if (Length(P
) > 1) and
4532 ((P
[1] = '1') or (P
[1] = '0')) then
4534 if (P
[1][1] = '1') then
4535 Options
:= Options
or GAME_OPTION_MONSTERS
4537 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4540 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4541 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4543 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
4544 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4546 if g_Game_IsNet
then MH_SEND_GameSettings
;
4549 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
4551 with gGameSettings
do
4553 if (Length(P
) > 1) and
4554 ((P
[1] = '1') or (P
[1] = '0')) then
4556 if (P
[1][1] = '1') then
4557 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
4559 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
4562 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
4563 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
4565 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
4567 if g_Game_IsNet
then MH_SEND_GameSettings
;
4570 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
4572 with gGameSettings
do
4574 if (Length(P
) > 1) and
4575 ((P
[1] = '1') or (P
[1] = '0')) then
4577 if (P
[1][1] = '1') then
4578 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
4580 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
4583 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
4584 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
4586 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
4588 if g_Game_IsNet
then MH_SEND_GameSettings
;
4591 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
4593 if Length(P
) > 1 then
4595 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
4596 gGameSettings
.WarmupTime
:= 30
4598 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
4601 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
4602 [gGameSettings
.WarmupTime
]));
4603 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4605 else if cmd
= 'net_interp' then
4607 if (Length(P
) > 1) then
4608 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
4610 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
4611 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4612 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
4613 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4616 else if cmd
= 'net_forceplayerupdate' then
4618 if (Length(P
) > 1) and
4619 ((P
[1] = '1') or (P
[1] = '0')) then
4620 NetForcePlayerUpdate
:= (P
[1][1] = '1');
4622 if NetForcePlayerUpdate
then
4623 g_Console_Add('net_forceplayerupdate = 1')
4625 g_Console_Add('net_forceplayerupdate = 0');
4626 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4627 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
4628 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4631 else if cmd
= 'net_predictself' then
4633 if (Length(P
) > 1) and
4634 ((P
[1] = '1') or (P
[1] = '0')) then
4635 NetPredictSelf
:= (P
[1][1] = '1');
4637 if NetPredictSelf
then
4638 g_Console_Add('net_predictself = 1')
4640 g_Console_Add('net_predictself = 0');
4641 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4642 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
4643 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4646 else if cmd
= 'sv_name' then
4648 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4650 NetServerName
:= P
[1];
4651 if Length(NetServerName
) > 64 then
4652 SetLength(NetServerName
, 64);
4653 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4657 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
4659 else if cmd
= 'sv_passwd' then
4661 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4663 NetPassword
:= P
[1];
4664 if Length(NetPassword
) > 24 then
4665 SetLength(NetPassword
, 24);
4666 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4670 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
4672 else if cmd
= 'sv_maxplrs' then
4674 if (Length(P
) > 1) then
4676 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
4677 if g_Game_IsServer
and g_Game_IsNet
then
4680 for a
:= 0 to High(NetClients
) do
4681 if NetClients
[a
].Used
then
4684 if b
> NetMaxClients
then
4686 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
4687 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
4688 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4689 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4692 if NetUseMaster
then
4697 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
4699 else if cmd
= 'sv_public' then
4701 if (Length(P
) > 1) then
4703 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
4704 if g_Game_IsServer
and g_Game_IsNet
then
4705 if NetUseMaster
then
4707 if NetMPeer
= nil then
4708 if not g_Net_Slist_Connect() then
4709 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4710 g_Net_Slist_Update();
4713 if NetMPeer
<> nil then
4714 g_Net_Slist_Disconnect();
4717 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
4719 else if cmd
= 'sv_intertime' then
4721 if (Length(P
) > 1) then
4722 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4724 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4726 else if cmd
= 'p1_name' then
4728 if (Length(P
) > 1) and gGameOn
then
4730 if g_Game_IsClient
then
4732 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4733 MC_SEND_PlayerSettings
;
4736 if gPlayer1
<> nil then
4738 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4739 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4742 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4745 else if cmd
= 'p2_name' then
4747 if (Length(P
) > 1) and gGameOn
then
4749 if g_Game_IsClient
then
4751 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4752 MC_SEND_PlayerSettings
;
4755 if gPlayer2
<> nil then
4757 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4758 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4761 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4764 else if cmd
= 'p1_color' then
4766 if Length(P
) > 3 then
4767 if g_Game_IsClient
then
4769 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4770 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4771 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4772 MC_SEND_PlayerSettings
;
4775 if gPlayer1
<> nil then
4777 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4778 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4779 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4780 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4783 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4784 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4785 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4787 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
4789 if Length(P
) > 3 then
4790 if g_Game_IsClient
then
4792 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4793 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4794 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4795 MC_SEND_PlayerSettings
;
4798 if gPlayer2
<> nil then
4800 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4801 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4802 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4803 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4806 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4807 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4808 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4810 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4812 if cmd
= 'r_showtime' then
4814 if (Length(P
) > 1) and
4815 ((P
[1] = '1') or (P
[1] = '0')) then
4816 gShowTime
:= (P
[1][1] = '1');
4819 g_Console_Add(_lc
[I_MSG_TIME_ON
])
4821 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
4823 else if cmd
= 'r_showscore' then
4825 if (Length(P
) > 1) and
4826 ((P
[1] = '1') or (P
[1] = '0')) then
4827 gShowGoals
:= (P
[1][1] = '1');
4830 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
4832 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
4834 else if cmd
= 'r_showstat' then
4836 if (Length(P
) > 1) and
4837 ((P
[1] = '1') or (P
[1] = '0')) then
4838 gShowStat
:= (P
[1][1] = '1');
4841 g_Console_Add(_lc
[I_MSG_STATS_ON
])
4843 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
4845 else if cmd
= 'r_showkillmsg' then
4847 if (Length(P
) > 1) and
4848 ((P
[1] = '1') or (P
[1] = '0')) then
4849 gShowKillMsg
:= (P
[1][1] = '1');
4851 if gShowKillMsg
then
4852 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
4854 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
4856 else if cmd
= 'r_showlives' then
4858 if (Length(P
) > 1) and
4859 ((P
[1] = '1') or (P
[1] = '0')) then
4860 gShowLives
:= (P
[1][1] = '1');
4863 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
4865 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
4867 else if cmd
= 'r_showspect' then
4869 if (Length(P
) > 1) and
4870 ((P
[1] = '1') or (P
[1] = '0')) then
4871 gSpectHUD
:= (P
[1][1] = '1');
4874 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
4876 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
4878 else if cmd
= 'r_showping' then
4880 if (Length(P
) > 1) and
4881 ((P
[1] = '1') or (P
[1] = '0')) then
4882 gShowPing
:= (P
[1][1] = '1');
4885 g_Console_Add(_lc
[I_MSG_PING_ON
])
4887 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
4889 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
4891 if Length(P
) > 1 then
4893 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
4894 gGameSettings
.GoalLimit
:= 0
4899 if gGameSettings
.GameMode
= GM_DM
then
4901 stat
:= g_Player_GetStats();
4903 for a
:= 0 to High(stat
) do
4904 if stat
[a
].Frags
> b
then
4908 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4910 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
4913 if g_Game_IsNet
then MH_SEND_GameSettings
;
4916 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
4918 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
4920 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
4921 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
4923 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4924 [gGameSettings
.TimeLimit
div 3600,
4925 (gGameSettings
.TimeLimit
div 60) mod 60,
4926 gGameSettings
.TimeLimit
mod 60]));
4927 if g_Game_IsNet
then MH_SEND_GameSettings
;
4929 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
4931 if Length(P
) > 1 then
4933 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
4934 gGameSettings
.MaxLives
:= 0
4938 stat
:= g_Player_GetStats();
4940 for a
:= 0 to High(stat
) do
4941 if stat
[a
].Lives
> b
then
4943 gGameSettings
.MaxLives
:=
4944 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
4948 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
4949 [gGameSettings
.MaxLives
]));
4950 if g_Game_IsNet
then MH_SEND_GameSettings
;
4955 // profiler console commands
4956 procedure ProfilerCommands (P
: SArray
);
4960 function getBool (idx
: Integer): Integer;
4962 if (idx
< 0) or (idx
> High(P
)) then begin result
:= -1; exit
; end;
4964 if (P
[idx
] = '1') or (P
[idx
] = 'on') or (P
[idx
] = 'true') or (P
[idx
] = 'tan') then result
:= 1;
4967 procedure binaryFlag (var flag
: Boolean; msg
: string);
4969 if (Length(p
) > 2) then
4971 g_Console_Add('too many arguments to '''+P
[0]+'''');
4980 if flag
then g_Console_Add(msg
+': tan') else g_Console_Add(msg
+': ona');
4985 //if not gDebugMode then exit;
4986 cmd
:= LowerCase(P
[0]);
4988 if (cmd
= 'pf_draw_frame') then begin binaryFlag(g_profile_frame_draw
, 'render profiles'); exit
; end;
4989 if (cmd
= 'pf_update_frame') then begin binaryFlag(g_profile_frame_update
, 'update profiles (not yet)'); exit
; end;
4990 if (cmd
= 'pf_coldet') then begin binaryFlag(g_profile_collision
, 'coldet profiles'); exit
; end;
4991 if (cmd
= 'pf_los') then begin binaryFlag(g_profile_los
, 'monster LOS profiles'); exit
; end;
4992 if (cmd
= 'r_sq_draw') then begin binaryFlag(gdbg_map_use_accel_render
, 'accelerated rendering'); exit
; end;
4993 if (cmd
= 'cd_sq_enabled') then begin binaryFlag(gdbg_map_use_accel_coldet
, 'accelerated map coldet'); exit
; end;
4994 if (cmd
= 'mon_sq_enabled') then begin binaryFlag(gmon_debug_use_sqaccel
, 'accelerated monster coldet'); exit
; end;
4995 if (cmd
= 'wtrace_sq_enabled') then begin binaryFlag(gwep_debug_fast_trace
, 'accelerated weapon hitscan'); exit
; end;
4996 if (cmd
= 'pr_enabled') then begin binaryFlag(gpart_dbg_enabled
, 'particles'); exit
; end;
4997 if (cmd
= 'pr_phys_enabled') then begin binaryFlag(gpart_dbg_phys_enabled
, 'particle physics'); exit
; end;
4998 if (cmd
= 'los_enabled') then begin binaryFlag(gmon_dbg_los_enabled
, 'LOS calculations'); exit
; end;
5000 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
5001 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then exit
;
5003 if (cmd
= 'mon_think') then begin binaryFlag(gmon_debug_think
, 'monster thinking'); exit
; end;
5004 if (cmd
= 'dbg_holmes') then begin binaryFlag(g_holmes_enabled
, 'Holmes'); exit
; end;
5008 procedure DebugCommands(P
: SArray
);
5015 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5018 cmd
:= LowerCase(P
[0]);
5019 if cmd
= 'd_window' then
5021 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
5022 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
5023 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5024 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5025 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
5027 else if cmd
= 'd_sounds' then
5029 if (Length(P
) > 1) and
5030 ((P
[1] = '1') or (P
[1] = '0')) then
5031 g_Debug_Sounds
:= (P
[1][1] = '1');
5033 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5035 else if cmd
= 'd_frames' then
5037 if (Length(P
) > 1) and
5038 ((P
[1] = '1') or (P
[1] = '0')) then
5039 g_Debug_Frames
:= (P
[1][1] = '1');
5041 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5043 else if cmd
= 'd_winmsg' then
5045 if (Length(P
) > 1) and
5046 ((P
[1] = '1') or (P
[1] = '0')) then
5047 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5049 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5051 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5053 if (Length(P
) > 1) and
5054 ((P
[1] = '1') or (P
[1] = '0')) then
5055 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5057 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5059 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5061 if Length(P
) > 1 then
5063 '0': g_debug_BotAIOff
:= 0;
5064 '1': g_debug_BotAIOff
:= 1;
5065 '2': g_debug_BotAIOff
:= 2;
5066 '3': g_debug_BotAIOff
:= 3;
5069 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5071 else if cmd
= 'd_monster' then
5073 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.Live
) and (not g_Game_IsNet
) then
5074 if Length(P
) < 2 then
5076 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5077 g_Console_Add('ID | Name');
5078 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5079 g_Console_Add(Format('%2d | %s', [b
, g_Monsters_GetNameByID(b
)]));
5082 a
:= StrToIntDef(P
[1], 0);
5083 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5084 a
:= g_Monsters_GetIDByName(P
[1]);
5086 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5087 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5090 with gPlayer1
.Obj
do
5092 mon
:= g_Monsters_Create(a
,
5093 X
+ Rect
.X
+ (Rect
.Width
div 2),
5094 Y
+ Rect
.Y
+ Rect
.Height
,
5095 gPlayer1
.Direction
, True);
5097 if (Length(P
) > 2) and (mon
<> nil) then
5098 mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5102 else if (cmd
= 'd_health') then
5104 if (Length(P
) > 1) and
5105 ((P
[1] = '1') or (P
[1] = '0')) then
5106 g_debug_HealthBar
:= (P
[1][1] = '1');
5108 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5110 else if (cmd
= 'd_player') then
5112 if (Length(P
) > 1) and
5113 ((P
[1] = '1') or (P
[1] = '0')) then
5114 g_debug_Player
:= (P
[1][1] = '1');
5116 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5118 else if (cmd
= 'd_joy') then
5121 g_Console_Add(e_JoystickStateToString(a
));
5125 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5129 procedure GameCheats(P
: SArray
);
5135 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
5136 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then
5138 g_Console_Add('not available');
5144 g_Console_Add('where is the player?!');
5147 cmd
:= LowerCase(P
[0]);
5151 plr
.GodMode
:= not plr
.GodMode
;
5152 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5155 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5156 if cmd
= 'give' then
5158 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
5159 for f
:= 1 to High(P
) do
5161 cmd
:= LowerCase(P
[f
]);
5162 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
5163 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
5164 if cmd
= 'exit' then
5166 if gTriggers
<> nil then
5168 for a
:= 0 to High(gTriggers
) do
5170 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5172 g_Console_Add('player left the map');
5173 gExitByTrigger
:= True;
5174 g_Game_ExitLevel(gTriggers
[a
].Data
.MapName
);
5182 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
5183 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
5184 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
5185 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
5186 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
5188 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
5189 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
5191 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
5192 if (cmd
= 'medkit') or (cmd
= 'medikit') or (cmd
= 'medpack') or (cmd
= 'medipack') then begin plr
.GiveItem(ITEM_MEDKIT_LARGE
); g_Console_Add('player got a '+cmd
); continue
; end;
5194 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
5195 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
5197 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
5198 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
5200 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
5201 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
5203 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
5204 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
5205 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
5207 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
5208 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
5209 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
5210 if (cmd
= 'launcher') or (cmd
= 'rocketlauncher') or (cmd
= 'rl') then begin plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
); g_Console_Add('player got a rocket launcher'); continue
; end;
5211 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
5212 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
5214 if (cmd
= 'shotgunzz') or (cmd
= 'sgzz') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a shotgun'); continue
; end;
5215 if (cmd
= 'supershotgunzz') or (cmd
= 'ssgzz') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a supershotgun'); continue
; end;
5216 if cmd
= 'chaingunzz' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a chaingun'); continue
; end;
5217 if (cmd
= 'launcherzz') or (cmd
= 'rocketlauncherzz') or (cmd
= 'rlzz') then begin plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
); plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got a rocket launcher'); continue
; end;
5218 if cmd
= 'plasmagunzz' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got a plasma gun'); continue
; end;
5219 if cmd
= 'bfgzz' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got a BFG-9000'); continue
; end;
5221 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
5222 if cmd
= 'superchaingunzz' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a superchaingun'); continue
; end;
5224 if (cmd
= 'flamer') or (cmd
= 'flamethrower') or (cmd
= 'ft') then begin plr
.GiveItem(ITEM_WEAPON_FLAMETHROWER
); g_Console_Add('player got a flame thrower'); continue
; end;
5225 if (cmd
= 'flamerzz') or (cmd
= 'flamethrowerzz') or (cmd
= 'ftzz') then begin plr
.GiveItem(ITEM_WEAPON_FLAMETHROWER
); plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got a flame thrower'); continue
; end;
5227 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
5229 if cmd
= 'ammo' then
5231 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
5232 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
5233 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
5234 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
5235 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
5236 g_Console_Add('player got some ammo');
5240 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
5241 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
5243 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
5244 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
5246 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
5247 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
5249 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
5250 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
5252 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
5254 if cmd
= 'weapons' then
5256 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
5257 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
5258 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
5259 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
5260 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
5261 plr
.GiveItem(ITEM_WEAPON_BFG
);
5262 g_Console_Add('player got weapons');
5266 if cmd
= 'keys' then
5268 plr
.GiveItem(ITEM_KEY_RED
);
5269 plr
.GiveItem(ITEM_KEY_GREEN
);
5270 plr
.GiveItem(ITEM_KEY_BLUE
);
5271 g_Console_Add('player got all keys');
5275 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
5280 if cmd
= 'open' then
5282 g_Console_Add('player activated sesame');
5283 g_Triggers_OpenAll();
5290 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
5294 if cmd
= 'noclip' then
5297 g_Console_Add('wall hardeness adjusted');
5301 if cmd
= 'notarget' then
5303 plr
.NoTarget
:= not plr
.NoTarget
;
5304 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
5308 if cmd
= 'noreload' then
5310 plr
.NoReload
:= not plr
.NoReload
;
5311 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
5315 if cmd
= 'speedy' then
5317 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
5318 g_Console_Add('speed adjusted');
5322 if cmd
= 'jumpy' then
5324 VEL_JUMP
:= 30-VEL_JUMP
;
5325 g_Console_Add('jump height adjusted');
5329 if cmd
= 'automap' then
5331 gShowMap
:= not gShowMap
;
5332 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
5336 if cmd
= 'aimline' then
5338 gAimLine
:= not gAimLine
;
5339 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
5344 procedure GameCommands(P
: SArray
);
5350 pl
: pTNetClient
= nil;
5357 cmd
:= LowerCase(P
[0]);
5359 if (cmd
= 'quit') or
5366 else if cmd
= 'pause' then
5368 if (g_ActiveWindow
= nil) then
5369 g_Game_Pause(not gPause
);
5371 else if cmd
= 'endgame' then
5372 gExit
:= EXIT_SIMPLE
5373 else if cmd
= 'restart' then
5375 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5377 if g_Game_IsClient
then
5379 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5384 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5386 else if cmd
= 'kick' then
5388 if g_Game_IsServer
then
5390 if Length(P
) < 2 then
5392 g_Console_Add('kick <name>');
5397 g_Console_Add('kick <name>');
5401 if g_Game_IsNet
then
5402 pl
:= g_Net_Client_ByName(P
[1]);
5405 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5406 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
5407 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5408 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5409 if NetUseMaster
then
5411 end else if gPlayers
<> nil then
5412 for a
:= Low(gPlayers
) to High(gPlayers
) do
5413 if gPlayers
[a
] <> nil then
5414 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5416 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
5417 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5419 gPlayers
[a
].Lives
:= 0;
5420 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5421 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5422 g_Player_Remove(gPlayers
[a
].UID
);
5423 if NetUseMaster
then
5425 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
5429 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5431 else if cmd
= 'kick_id' then
5433 if g_Game_IsServer
and g_Game_IsNet
then
5435 if Length(P
) < 2 then
5437 g_Console_Add('kick_id <client ID>');
5442 g_Console_Add('kick_id <client ID>');
5446 a
:= StrToIntDef(P
[1], 0);
5447 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5449 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5451 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5452 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5453 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5454 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5455 if NetUseMaster
then
5460 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5462 else if cmd
= 'ban' then
5464 if g_Game_IsServer
and g_Game_IsNet
then
5466 if Length(P
) < 2 then
5468 g_Console_Add('ban <name>');
5473 g_Console_Add('ban <name>');
5477 pl
:= g_Net_Client_ByName(P
[1]);
5480 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5481 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5482 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5483 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5484 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5485 if NetUseMaster
then
5488 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5490 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5492 else if cmd
= 'ban_id' then
5494 if g_Game_IsServer
and g_Game_IsNet
then
5496 if Length(P
) < 2 then
5498 g_Console_Add('ban_id <client ID>');
5503 g_Console_Add('ban_id <client ID>');
5507 a
:= StrToIntDef(P
[1], 0);
5508 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5509 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5511 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5512 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5513 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5514 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5515 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5516 if NetUseMaster
then
5520 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5522 else if cmd
= 'permban' then
5524 if g_Game_IsServer
and g_Game_IsNet
then
5526 if Length(P
) < 2 then
5528 g_Console_Add('permban <name>');
5533 g_Console_Add('permban <name>');
5537 pl
:= g_Net_Client_ByName(P
[1]);
5540 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5541 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5542 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5543 g_Net_SaveBanList();
5544 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5545 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5546 if NetUseMaster
then
5549 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5551 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5553 else if cmd
= 'permban_id' then
5555 if g_Game_IsServer
and g_Game_IsNet
then
5557 if Length(P
) < 2 then
5559 g_Console_Add('permban_id <client ID>');
5564 g_Console_Add('permban_id <client ID>');
5568 a
:= StrToIntDef(P
[1], 0);
5569 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5570 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5572 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5573 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5574 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5575 g_Net_SaveBanList();
5576 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5577 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5578 if NetUseMaster
then
5582 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5584 else if cmd
= 'unban' then
5586 if g_Game_IsServer
and g_Game_IsNet
then
5588 if Length(P
) < 2 then
5590 g_Console_Add('unban <IP Address>');
5595 g_Console_Add('unban <IP Address>');
5599 if g_Net_UnbanHost(P
[1]) then
5601 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5602 g_Net_SaveBanList();
5604 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5606 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5608 else if cmd
= 'clientlist' then
5610 if g_Game_IsServer
and g_Game_IsNet
then
5613 if NetClients
<> nil then
5614 for a
:= Low(NetClients
) to High(NetClients
) do
5615 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5617 plr
:= g_Player_Get(NetClients
[a
].Player
);
5618 if plr
= nil then continue
;
5620 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5621 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5624 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5626 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5628 else if cmd
= 'connect' then
5630 if (NetMode
= NET_NONE
) then
5632 if Length(P
) < 2 then
5634 g_Console_Add('connect <IP> [port] [password]');
5639 g_Console_Add('connect <IP> [port] [password]');
5643 if Length(P
) > 2 then
5644 prt
:= StrToIntDef(P
[2], 25666)
5648 if Length(P
) > 3 then
5653 g_Game_StartClient(P
[1], prt
, pw
);
5656 else if cmd
= 'disconnect' then
5658 if (NetMode
= NET_CLIENT
) then
5661 else if cmd
= 'reconnect' then
5663 if (NetMode
= NET_SERVER
) then
5666 if (NetMode
= NET_CLIENT
) then
5669 gExit
:= EXIT_SIMPLE
;
5673 //TODO: Use last successful password to reconnect, instead of ''
5674 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5676 else if (cmd
= 'addbot') or
5677 (cmd
= 'bot_add') then
5679 if Length(P
) > 1 then
5680 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5682 g_Bot_Add(TEAM_NONE
, 2);
5684 else if cmd
= 'bot_addlist' then
5686 if Length(P
) > 1 then
5687 if Length(P
) = 2 then
5688 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5690 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5692 else if cmd
= 'bot_removeall' then
5694 else if cmd
= 'chat' then
5696 if g_Game_IsNet
then
5698 if Length(P
) > 1 then
5700 for a
:= 1 to High(P
) do
5701 chstr
:= chstr
+ P
[a
] + ' ';
5703 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5705 if Length(chstr
) < 1 then
5707 g_Console_Add('chat <text>');
5711 chstr
:= b_Text_Format(chstr
);
5712 if g_Game_IsClient
then
5713 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5715 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5718 g_Console_Add('chat <text>');
5720 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5722 else if cmd
= 'teamchat' then
5724 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5726 if Length(P
) > 1 then
5728 for a
:= 1 to High(P
) do
5729 chstr
:= chstr
+ P
[a
] + ' ';
5731 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5733 if Length(chstr
) < 1 then
5735 g_Console_Add('teamchat <text>');
5739 chstr
:= b_Text_Format(chstr
);
5740 if g_Game_IsClient
then
5741 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5743 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5744 gPlayer1Settings
.Team
);
5747 g_Console_Add('teamchat <text>');
5749 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5751 else if cmd
= 'game' then
5753 if gGameSettings
.GameType
<> GT_NONE
then
5755 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5758 if Length(P
) = 1 then
5760 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5763 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5764 P
[1] := addWadExtension(P
[1]);
5765 if FileExists(MapsDir
+ P
[1]) then
5767 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5768 if Length(P
) < 3 then
5771 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5774 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5776 if g_Map_Exist(MapsDir
+ s
) then
5778 // Çàïóñêàåì ñâîþ èãðó
5780 with gGameSettings
do
5782 GameMode
:= g_Game_TextToMode(gcGameMode
);
5783 if gSwitchGameMode
<> GM_NONE
then
5784 GameMode
:= gSwitchGameMode
;
5785 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5786 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5788 if Length(P
) >= 4 then
5789 b
:= StrToIntDef(P
[3], 1);
5790 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5791 GoalLimit
, MaxLives
, Options
, b
);
5796 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5798 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[2])]));
5800 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5802 else if cmd
= 'host' then
5804 if gGameSettings
.GameType
<> GT_NONE
then
5806 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5809 if Length(P
) < 4 then
5811 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5814 if not StrToIp(P
[1], listen
) then
5816 prt
:= StrToIntDef(P
[2], 25666);
5818 P
[3] := addWadExtension(P
[3]);
5819 if FileExists(MapsDir
+ P
[3]) then
5821 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5822 if Length(P
) < 5 then
5825 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5828 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5830 if g_Map_Exist(MapsDir
+ s
) then
5832 // Çàïóñêàåì ñâîþ èãðó
5834 with gGameSettings
do
5836 GameMode
:= g_Game_TextToMode(gcGameMode
);
5837 if gSwitchGameMode
<> GM_NONE
then
5838 GameMode
:= gSwitchGameMode
;
5839 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5840 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5842 if Length(P
) >= 6 then
5843 b
:= StrToIntDef(P
[5], 0);
5844 g_Game_StartServer(s
, GameMode
, TimeLimit
,
5845 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
5850 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5852 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[4])]));
5854 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
5856 else if cmd
= 'map' then
5858 if Length(P
) = 1 then
5860 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5862 g_Console_Add(cmd
+ ' <MAP>');
5863 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5865 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5867 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5869 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5870 if Length(P
) < 3 then
5872 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5873 s
:= UpperCase(P
[1]);
5874 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5875 begin // Êàðòà íàøëàñü
5876 gExitByTrigger
:= False;
5878 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5880 gExit
:= EXIT_ENDLEVELCUSTOM
;
5882 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5883 g_Game_ChangeMap(s
);
5886 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5887 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5888 P
[1] := addWadExtension(P
[1]);
5889 if FileExists(MapsDir
+ P
[1]) then
5891 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5893 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5895 s
:= P
[1] + ':\' + P
[2];
5897 if g_Map_Exist(MapsDir
+ s
) then
5899 gExitByTrigger
:= False;
5901 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5903 gExit
:= EXIT_ENDLEVELCUSTOM
;
5905 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5906 g_Game_ChangeMap(s
);
5909 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5911 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5913 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5917 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5918 P
[1] := addWadExtension(P
[1]);
5919 if FileExists(MapsDir
+ P
[1]) then
5922 P
[2] := UpperCase(P
[2]);
5923 s
:= P
[1] + ':\' + P
[2];
5925 if g_Map_Exist(MapsDir
+ s
) then
5926 begin // Íàøëè êàðòó
5927 gExitByTrigger
:= False;
5929 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5931 gExit
:= EXIT_ENDLEVELCUSTOM
;
5933 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5934 g_Game_ChangeMap(s
);
5936 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5938 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5941 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5943 else if cmd
= 'nextmap' then
5945 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5946 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5949 if Length(P
) = 1 then
5951 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5953 g_Console_Add(cmd
+ ' <MAP>');
5954 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5957 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5962 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5964 if Length(P
) < 3 then
5966 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5967 s
:= UpperCase(P
[1]);
5968 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5969 begin // Êàðòà íàøëàñü
5970 gExitByTrigger
:= False;
5975 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5976 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5977 P
[1] := addWadExtension(P
[1]);
5978 if FileExists(MapsDir
+ P
[1]) then
5980 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5982 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5984 s
:= P
[1] + ':\' + P
[2];
5986 if g_Map_Exist(MapsDir
+ s
) then
5987 begin // Óñòàíàâëèâàåì êàðòó
5988 gExitByTrigger
:= False;
5993 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5995 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5997 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6001 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6002 P
[1] := addWadExtension(P
[1]);
6003 if FileExists(MapsDir
+ P
[1]) then
6006 P
[2] := UpperCase(P
[2]);
6007 s
:= P
[1] + ':\' + P
[2];
6009 if g_Map_Exist(MapsDir
+ s
) then
6010 begin // Íàøëè êàðòó
6011 gExitByTrigger
:= False;
6015 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6017 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6020 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6023 if gNextMap
= '' then
6024 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
6026 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
6029 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
6032 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6034 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6036 gExitByTrigger
:= False;
6037 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6038 if (gNextMap
= '') and (gTriggers
<> nil) then
6039 for a
:= 0 to High(gTriggers
) do
6040 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6042 gExitByTrigger
:= True;
6043 gNextMap
:= gTriggers
[a
].Data
.MapName
;
6046 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6047 if gNextMap
= '' then
6048 gNextMap
:= g_Game_GetNextMap();
6049 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6050 if Pos(':\', gNextMap
) = 0 then
6051 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
6054 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6055 if g_Map_Exist(MapsDir
+ s
) then
6056 gExit
:= EXIT_ENDLEVELCUSTOM
6058 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
6060 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6062 else if (cmd
= 'event') then
6064 if (Length(P
) <= 1) then
6066 for a
:= 0 to High(gEvents
) do
6067 if gEvents
[a
].Command
= '' then
6068 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6070 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6073 if (Length(P
) = 2) then
6075 for a
:= 0 to High(gEvents
) do
6076 if gEvents
[a
].Name
= P
[1] then
6077 if gEvents
[a
].Command
= '' then
6078 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6080 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6083 for a
:= 0 to High(gEvents
) do
6084 if gEvents
[a
].Name
= P
[1] then
6086 gEvents
[a
].Command
:= '';
6087 for b
:= 2 to High(P
) do
6088 if Pos(' ', P
[b
]) = 0 then
6089 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6091 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6092 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6096 // Êîìàíäû Ñâîåé èãðû:
6097 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6099 if cmd
= 'bot_addred' then
6101 if Length(P
) > 1 then
6102 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6104 g_Bot_Add(TEAM_RED
, 2);
6106 else if cmd
= 'bot_addblue' then
6108 if Length(P
) > 1 then
6109 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6111 g_Bot_Add(TEAM_BLUE
, 2);
6113 else if cmd
= 'suicide' then
6117 if g_Game_IsClient
then
6118 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6121 if gPlayer1
<> nil then
6122 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6123 if gPlayer2
<> nil then
6124 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6128 else if cmd
= 'spectate' then
6134 else if cmd
= 'say' then
6136 if g_Game_IsServer
and g_Game_IsNet
then
6138 if Length(P
) > 1 then
6141 for a
:= 1 to High(P
) do
6142 chstr
:= chstr
+ P
[a
] + ' ';
6144 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6146 if Length(chstr
) < 1 then
6148 g_Console_Add('say <text>');
6152 chstr
:= b_Text_Format(chstr
);
6153 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6155 else g_Console_Add('say <text>');
6157 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6159 else if cmd
= 'tell' then
6161 if g_Game_IsServer
and g_Game_IsNet
then
6163 if (Length(P
) > 2) and (P
[1] <> '') then
6166 for a
:= 2 to High(P
) do
6167 chstr
:= chstr
+ P
[a
] + ' ';
6169 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6171 if Length(chstr
) < 1 then
6173 g_Console_Add('tell <playername> <text>');
6177 pl
:= g_Net_Client_ByName(P
[1]);
6179 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6181 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6183 else g_Console_Add('tell <playername> <text>');
6185 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6187 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6189 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6191 // Äîïîëíèòåëüíîå âðåìÿ:
6192 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6194 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6195 [gGameSettings
.TimeLimit
div 3600,
6196 (gGameSettings
.TimeLimit
div 60) mod 60,
6197 gGameSettings
.TimeLimit
mod 60]));
6198 if g_Game_IsNet
then MH_SEND_GameSettings
;
6200 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6202 if (Length(P
) <= 1) then
6203 g_Console_Add('rcon_password <password>')
6205 MC_SEND_RCONPassword(P
[1]);
6207 else if cmd
= 'rcon' then
6209 if g_Game_IsClient
then
6211 if Length(P
) > 1 then
6214 for a
:= 1 to High(P
) do
6215 chstr
:= chstr
+ P
[a
] + ' ';
6217 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6219 if Length(chstr
) < 1 then
6221 g_Console_Add('rcon <command>');
6225 MC_SEND_RCONCommand(chstr
);
6227 else g_Console_Add('rcon <command>');
6230 else if cmd
= 'ready' then
6232 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6233 gLMSRespawnTime
:= gTime
+ 100;
6235 else if (cmd
= 'callvote') and g_Game_IsNet
then
6237 if Length(P
) > 1 then
6240 for a
:= 1 to High(P
) do begin
6241 if a
> 1 then chstr
:= chstr
+ ' ';
6242 chstr
:= chstr
+ P
[a
];
6245 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6247 if Length(chstr
) < 1 then
6249 g_Console_Add('callvote <command>');
6253 if g_Game_IsClient
then
6254 MC_SEND_Vote(True, chstr
)
6256 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6257 g_Console_Process('vote', True);
6260 g_Console_Add('callvote <command>');
6262 else if (cmd
= 'vote') and g_Game_IsNet
then
6264 if g_Game_IsClient
then
6266 else if gVoteInProgress
then
6268 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6269 a
:= Floor((NetClientCount
+1)/2.0) + 1
6271 a
:= Floor(NetClientCount
/2.0) + 1;
6276 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6277 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6283 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6284 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6292 procedure g_TakeScreenShot();
6300 if e_NoGraphics
then Exit
;
6301 ssdir
:= GameDir
+'/screenshots';
6302 if not findFileCI(ssdir
, true) then
6304 // try to create dir
6309 if not findFileCI(ssdir
, true) then exit
; // alas
6312 for a
:= 1 to High(Word) do
6314 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
6316 if findFileCI(t
, true) then continue
;
6317 if not findFileCI(FileName
) then
6320 st
:= createDiskFile(FileName
);
6322 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
6327 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
6335 procedure g_Game_InGameMenu(Show
: Boolean);
6337 if (g_ActiveWindow
= nil) and Show
then
6339 if gGameSettings
.GameType
= GT_SINGLE
then
6340 g_GUI_ShowWindow('GameSingleMenu')
6343 if g_Game_IsClient
then
6344 g_GUI_ShowWindow('GameClientMenu')
6346 if g_Game_IsNet
then
6347 g_GUI_ShowWindow('GameServerMenu')
6349 g_GUI_ShowWindow('GameCustomMenu');
6351 g_Sound_PlayEx('MENU_OPEN');
6353 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6354 if (not g_Game_IsNet
) then
6358 if (g_ActiveWindow
<> nil) and (not Show
) then
6360 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6361 if (not g_Game_IsNet
) then
6362 g_Game_Pause(False);
6366 procedure g_Game_Pause(Enable
: Boolean);
6371 if gPause
= Enable
then
6374 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then
6378 g_Game_PauseAllSounds(Enable
);
6381 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6386 if gTriggers
<> nil then
6387 for i
:= 0 to High(gTriggers
) do
6388 with gTriggers
[i
] do
6389 if (TriggerType
= TRIGGER_SOUND
) and
6391 Sound
.IsPlaying() then
6393 Sound
.Pause(Enable
);
6397 if gPlayers
<> nil then
6398 for i
:= 0 to High(gPlayers
) do
6399 if gPlayers
[i
] <> nil then
6400 gPlayers
[i
].PauseSounds(Enable
);
6403 if gMusic
<> nil then
6404 gMusic
.Pause(Enable
);
6407 procedure g_Game_StopAllSounds(all
: Boolean);
6411 if gTriggers
<> nil then
6412 for i
:= 0 to High(gTriggers
) do
6413 with gTriggers
[i
] do
6414 if (TriggerType
= TRIGGER_SOUND
) and
6418 if gMusic
<> nil then
6425 procedure g_Game_UpdateTriggerSounds();
6429 if gTriggers
<> nil then
6430 for i
:= 0 to High(gTriggers
) do
6431 with gTriggers
[i
] do
6432 if (TriggerType
= TRIGGER_SOUND
) and
6435 Sound
.IsPlaying() then
6437 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
6438 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
6440 Sound
.SetPan(0.5 - Data
.Pan
/255.0);
6441 Sound
.SetVolume(Data
.Volume
/255.0);
6444 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0);
6448 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6451 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6456 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6461 if gSpectMode
<> SPECT_PLAYERS
then
6463 if gSpectPID1
= UID
then
6468 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6475 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6480 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6485 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6490 if gSpectMode
<> SPECT_PLAYERS
then
6492 Pl
:= g_Player_Get(gSpectPID1
);
6493 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6498 if gSpectViewTwo
then
6500 Pl
:= g_Player_Get(gSpectPID2
);
6501 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6509 procedure g_Game_Message(Msg
: string; Time
: Word);
6511 MessageText
:= b_Text_Format(Msg
);
6512 MessageTime
:= Time
;
6515 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6524 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6528 if goodsnd
[a
].IsPlaying() then
6531 goodsnd
[Random(4)].Play();
6534 procedure g_Game_Announce_KillCombo(Param
: Integer);
6541 UID
:= Param
and $FFFF;
6546 Pl
:= g_Player_Get(UID
);
6555 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6559 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6563 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6567 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6575 if not g_Game_IsWatchedPlayer(UID
) then
6578 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6582 if killsnd
[n
].IsPlaying() then
6587 procedure g_Game_StartVote(Command
, Initiator
: string);
6591 if not gVotesEnabled
then Exit
;
6592 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6593 if gVoteInProgress
or gVotePassed
then
6595 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6596 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6599 gVoteInProgress
:= True;
6600 gVotePassed
:= False;
6601 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6604 gVoteCommand
:= Command
;
6606 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6607 Need
:= Floor((NetClientCount
+1)/2.0)+1
6609 Need
:= Floor(NetClientCount
/2.0)+1;
6610 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6611 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6614 procedure g_Game_CheckVote
;
6618 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6619 if not gVoteInProgress
then Exit
;
6621 if (gTime
>= gVoteTimer
) then
6623 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6624 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6626 Need
:= Floor(NetClientCount
/2.0) + 1;
6627 if gVoteCount
>= Need
then
6629 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6630 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6631 gVotePassed
:= True;
6632 gVoteCmdTimer
:= gTime
+ 5000;
6636 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6637 MH_SEND_VoteEvent(NET_VE_FAILED
);
6639 if NetClients
<> nil then
6640 for I
:= Low(NetClients
) to High(NetClients
) do
6641 if NetClients
[i
].Used
then
6642 NetClients
[i
].Voted
:= False;
6643 gVoteInProgress
:= False;
6649 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6650 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6652 Need
:= Floor(NetClientCount
/2.0) + 1;
6653 if gVoteCount
>= Need
then
6655 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6656 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6657 gVoteInProgress
:= False;
6658 gVotePassed
:= True;
6659 gVoteCmdTimer
:= gTime
+ 5000;
6662 if NetClients
<> nil then
6663 for I
:= Low(NetClients
) to High(NetClients
) do
6664 if NetClients
[i
].Used
then
6665 NetClients
[i
].Voted
:= False;
6670 procedure g_Game_LoadMapList(FileName
: string);
6678 if not FileExists(FileName
) then Exit
;
6680 AssignFile(ListFile
, FileName
);
6682 while not EOF(ListFile
) do
6684 ReadLn(ListFile
, s
);
6687 if s
= '' then Continue
;
6689 SetLength(MapList
, Length(MapList
)+1);
6690 MapList
[High(MapList
)] := s
;
6692 CloseFile(ListFile
);
6695 procedure g_Game_SetDebugMode();
6698 // ×èòû (äàæå â ñâîåé èãðå):
6702 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6706 if Length(LoadingStat
.Msgs
) = 0 then
6712 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6713 if NextMsg
= Length(Msgs
) then
6715 for i
:= 0 to High(Msgs
)-1 do
6716 Msgs
[i
] := Msgs
[i
+1];
6724 Msgs
[NextMsg
-1] := Text;
6730 g_ActiveWindow
:= nil;
6735 procedure g_Game_StepLoading();
6741 if (ShowCount
> LOADING_SHOW_STEP
) then
6749 procedure g_Game_ClearLoading();
6758 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6759 if len
< 1 then len
:= 1;
6760 SetLength(Msgs
, len
);
6761 for len
:= Low(Msgs
) to High(Msgs
) do
6767 procedure Parse_Params(var pars
: TParamStrValues
);
6774 while i
<= ParamCount
do
6777 if (s
[1] = '-') and (Length(s
) > 1) then
6779 if (s
[2] = '-') and (Length(s
) > 2) then
6780 begin // Îäèíî÷íûé ïàðàìåòð
6781 SetLength(pars
, Length(pars
) + 1);
6782 with pars
[High(pars
)] do
6784 Name
:= LowerCase(s
);
6789 if (i
< ParamCount
) then
6790 begin // Ïàðàìåòð ñî çíà÷åíèåì
6792 SetLength(pars
, Length(pars
) + 1);
6793 with pars
[High(pars
)] do
6795 Name
:= LowerCase(s
);
6796 Value
:= LowerCase(ParamStr(i
));
6805 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6810 for i
:= 0 to High(pars
) do
6811 if pars
[i
].Name
= aName
then
6813 Result
:= pars
[i
].Value
;
6818 procedure g_Game_Process_Params();
6820 pars
: TParamStrValues
;
6823 LimT
, LimS
: Integer;
6834 s
:= Find_Param_Value(pars
, '--debug');
6837 g_Game_SetDebugMode();
6838 s
:= Find_Param_Value(pars
, '--netdump');
6843 // Connect when game loads
6844 ip
:= Find_Param_Value(pars
, '-connect');
6848 s
:= Find_Param_Value(pars
, '-port');
6849 if (s
= '') or not TryStrToInt(s
, Port
) then
6852 s
:= Find_Param_Value(pars
, '-pw');
6854 g_Game_StartClient(ip
, Port
, s
);
6858 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6861 gDefaultMegawadStart
:= s
;
6864 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6865 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6867 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6870 // Start map when game loads:
6871 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6872 if isWadPath(map
) then
6875 s
:= Find_Param_Value(pars
, '-gm');
6876 GMode
:= g_Game_TextToMode(s
);
6877 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6878 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6881 s
:= Find_Param_Value(pars
, '-limt');
6882 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6888 s
:= Find_Param_Value(pars
, '-lims');
6889 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6895 s
:= Find_Param_Value(pars
, '-lives');
6896 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6902 s
:= Find_Param_Value(pars
, '-opt');
6904 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
6906 Opt
:= StrToIntDef(s
, 0);
6908 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
6911 s
:= Find_Param_Value(pars
, '--close');
6915 // Delete test map after play:
6916 s
:= Find_Param_Value(pars
, '--testdelete');
6919 gMapToDelete
:= MapsDir
+ map
;
6920 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR
);
6924 // Delete temporary WAD after play:
6925 s
:= Find_Param_Value(pars
, '--tempdelete');
6928 gMapToDelete
:= MapsDir
+ map
;
6929 gTempDelete
:= True;
6932 // Number of players:
6933 s
:= Find_Param_Value(pars
, '-pl');
6937 n
:= StrToIntDef(s
, 1);
6940 s
:= Find_Param_Value(pars
, '-port');
6941 if (s
= '') or not TryStrToInt(s
, Port
) then
6942 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6944 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6947 // Execute script when game loads:
6948 s
:= Find_Param_Value(pars
, '-exec');
6951 if Pos(':\', s
) = 0 then
6952 s
:= GameDir
+ '/' + s
;
6957 if IOResult
<> 0 then
6959 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6960 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6964 e_WriteLog('Executing script: ' + s
, MSG_NOTIFY
);
6965 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6970 if IOResult
<> 0 then
6972 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6973 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6977 if Pos('#', s
) <> 1 then // script comment
6978 g_Console_Process(s
, True);