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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
24 SysUtils
, Classes
, MAPDEF
,
25 g_base
, g_basic
, g_player
, g_res_downloader
,
26 g_sound
, utils
, md5
, mempool
, xprofiler
,
31 TGameSettings
= record
38 ItemRespawnTime
: Word;
49 TDelayedEvent
= record
58 Sound
: TPlayableSound
;
59 Tags
: Array of String;
63 TPlayerSettings
= record
82 function g_Game_IsNet(): Boolean;
83 function g_Game_IsServer(): Boolean;
84 function g_Game_IsClient(): Boolean;
85 procedure g_Game_Init();
86 procedure g_Game_Free (freeTextures
: Boolean=true);
87 procedure g_Game_LoadData();
88 procedure g_Game_FreeData();
89 procedure g_Game_Update();
90 procedure g_Game_PreUpdate();
91 procedure g_Game_Quit();
92 function g_Game_ModeToText(Mode
: Byte): string;
93 function g_Game_TextToMode(Mode
: string): Byte;
94 procedure g_Game_ExecuteEvent(Name
: String);
95 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
96 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
97 procedure g_Game_RemovePlayer();
98 procedure g_Game_Spectate();
99 procedure g_Game_SpectateCenterView();
100 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
101 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
102 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
103 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
104 procedure g_Game_Restart();
105 procedure g_Game_RestartLevel();
106 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
107 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
108 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
109 procedure g_Game_ChangeMap(const MapPath
: String);
110 procedure g_Game_ExitLevel(const Map
: AnsiString);
111 function g_Game_GetFirstMap(WAD
: String): String;
112 function g_Game_GetNextMap(): String;
113 procedure g_Game_NextLevel();
114 procedure g_Game_Pause(Enable
: Boolean);
115 procedure g_Game_HolmesPause(Enable
: Boolean);
116 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
117 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
118 procedure g_Game_Message(Msg
: String; Time
: Word);
119 procedure g_Game_LoadMapList(FileName
: String);
120 procedure g_Game_PauseAllSounds(Enable
: Boolean);
121 procedure g_Game_StopAllSounds(all
: Boolean);
122 procedure g_Game_UpdateTriggerSounds();
123 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
124 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
125 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
126 procedure g_Game_Announce_KillCombo(Param
: Integer);
127 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
128 procedure g_Game_StartVote(Command
, Initiator
: string);
129 procedure g_Game_CheckVote
;
131 procedure g_TakeScreenShot(Filename
: string = '');
133 procedure g_FatalError(Text: String);
134 procedure g_SimpleError(Text: String);
135 function g_Game_IsTestMap(): Boolean;
136 procedure g_Game_DeleteTestMap();
137 procedure GameCVars(P
: SSArray
);
138 procedure PlayerSettingsCVars(P
: SSArray
);
139 procedure SystemCommands(P
: SSArray
);
140 procedure GameCommands(P
: SSArray
);
141 procedure GameCheats(P
: SSArray
);
142 procedure DebugCommands(P
: SSArray
);
143 procedure g_Game_Process_Params
;
144 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
145 procedure g_Game_StepLoading(Value
: Integer = -1);
146 procedure g_Game_ClearLoading();
147 procedure g_Game_SetDebugMode();
149 function IsActivePlayer(p
: TPlayer
): Boolean;
150 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
151 procedure SortGameStat(var stat
: TPlayerStatArray
);
155 procedure g_Game_InGameMenu(Show
: Boolean);
158 procedure CharPress (C
: AnsiChar);
160 procedure KeyPress (K
: Word);
162 { procedure SetWinPause(Enable: Boolean); }
167 LOADING_SHOW_STEP
= 100;
168 LOADING_INTERLINE
= 20;
186 EXIT_ENDLEVELSINGLE
= 4;
187 EXIT_ENDLEVELCUSTOM
= 5;
189 GAME_OPTION_RESERVED
= 1;
190 GAME_OPTION_TEAMDAMAGE
= 2;
191 GAME_OPTION_ALLOWEXIT
= 4;
192 GAME_OPTION_WEAPONSTAY
= 8;
193 GAME_OPTION_MONSTERS
= 16;
194 GAME_OPTION_BOTVSPLAYER
= 32;
195 GAME_OPTION_BOTVSMONSTER
= 64;
196 GAME_OPTION_DMKEYS
= 128;
197 GAME_OPTION_TEAMHITTRACE
= 256;
198 GAME_OPTION_TEAMHITPROJECTILE
= 512;
199 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
204 STATE_INTERCUSTOM
= 3;
205 STATE_INTERSINGLE
= 4;
211 LMS_RESPAWN_NONE
= 0;
212 LMS_RESPAWN_WARMUP
= 1;
213 LMS_RESPAWN_FINAL
= 2;
230 CONFIG_FILENAME
= 'Doom2DF.cfg';
232 TEST_MAP_NAME
= '$$$_TEST_$$$';
234 STD_PLAYER_MODEL
= 'Doomer';
242 STATFILE_VERSION
= $03;
245 gGameSettings
: TGameSettings
;
246 gPlayer1Settings
: TPlayerSettings
;
247 gPlayer2Settings
: TPlayerSettings
;
249 gPlayerScreenSize
: TDFPoint
;
250 gPlayer1ScreenCoord
: TDFPoint
;
251 gPlayer2ScreenCoord
: TDFPoint
;
252 gPlayer1
: TPlayer
= nil;
253 gPlayer2
: TPlayer
= nil;
254 gPlayerDrawn
: TPlayer
= nil;
256 gLerpFactor
: Single = 1.0;
257 gSwitchGameMode
: Byte = GM_DM
;
258 gHearPoint1
, gHearPoint2
: THearPoint
;
259 gSoundEffectsDF
: Boolean = False;
260 gSoundTriggerTime
: Word = 0;
261 gAnnouncer
: Integer = ANNOUNCE_NONE
;
262 goodsnd
: array[0..3] of TPlayableSound
;
263 killsnd
: array[0..3] of TPlayableSound
;
264 hahasnd
: array[0..2] of TPlayableSound
;
265 sound_get_flag
: array[0..1] of TPlayableSound
;
266 sound_lost_flag
: array[0..1] of TPlayableSound
;
267 sound_ret_flag
: array[0..1] of TPlayableSound
;
268 sound_cap_flag
: array[0..1] of TPlayableSound
;
269 gBodyKillEvent
: Integer = -1;
270 gDefInterTime
: ShortInt = -1;
271 gInterEndTime
: LongWord = 0;
272 gInterTime
: LongWord = 0;
273 gServInterTime
: Byte = 0;
274 gGameStartTime
: LongWord = 0;
275 gTotalMonsters
: Integer = 0;
276 gPauseMain
: Boolean = false;
277 gPauseHolmes
: Boolean = false;
278 gShowTime
: Boolean = False;
279 gShowFPS
: Boolean = False;
280 gShowGoals
: Boolean = True;
281 gShowStat
: Boolean = True;
282 gShowPIDs
: Boolean = False;
283 gShowKillMsg
: Boolean = True;
284 gShowLives
: Boolean = True;
285 gShowPing
: Boolean = False;
286 gShowMap
: Boolean = False;
288 gState
: Byte = STATE_NONE
;
290 sWidth
, sHeight
: Word;
291 gSpectMode
: Byte = SPECT_NONE
;
292 gSpectHUD
: Boolean = True;
293 gSpectKeyPress
: Boolean = False;
294 gSpectX
: Integer = 0;
295 gSpectY
: Integer = 0;
296 gSpectStep
: Byte = 8;
297 gSpectViewTwo
: Boolean = False;
298 gSpectPID1
: Integer = -1;
299 gSpectPID2
: Integer = -1;
300 gSpectAuto
: Boolean = False;
301 gSpectAutoNext
: LongWord;
302 gSpectAutoStepX
: Integer;
303 gSpectAutoStepY
: Integer;
304 gMusic
: TMusic
= nil;
305 gLoadGameMode
: Boolean;
306 gCheats
: Boolean = False;
307 gMapOnce
: Boolean = False;
308 gMapToDelete
: String;
309 gTempDelete
: Boolean = False;
310 gLastMap
: Boolean = False;
313 gResolutionChange
: Boolean = False;
314 gRC_Width
, gRC_Height
: Integer;
315 gRC_FullScreen
, gRC_Maximized
: Boolean;
316 gLanguageChange
: Boolean = False;
317 gDebugMode
: Boolean = False;
318 g_debug_Sounds
: Boolean = False;
319 g_debug_Frames
: Boolean = False;
320 g_debug_WinMsgs
: Boolean = False;
321 g_debug_MonsterOff
: Boolean = False;
322 g_debug_BotAIOff
: Byte = 0;
323 g_debug_HealthBar
: Boolean = False;
324 g_Debug_Player
: Boolean = False;
325 gCoopMonstersKilled
: Word = 0;
326 gCoopSecretsFound
: Word = 0;
327 gCoopTotalMonstersKilled
: Word = 0;
328 gCoopTotalSecretsFound
: Word = 0;
329 gCoopTotalMonsters
: Word = 0;
330 gCoopTotalSecrets
: Word = 0;
331 gStatsOff
: Boolean = False;
332 gStatsPressed
: Boolean = False;
333 gExitByTrigger
: Boolean = False;
334 gNextMap
: String = '';
335 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
336 gLMSRespawnTime
: Cardinal = 0;
337 gLMSSoftSpawn
: Boolean = False;
338 gMissionFailed
: Boolean = False;
339 gVoteInProgress
: Boolean = False;
340 gVotePassed
: Boolean = False;
341 gVoteCommand
: string = '';
342 gVoteTimer
: Cardinal = 0;
343 gVoteCmdTimer
: Cardinal = 0;
344 gVoteCount
: Integer = 0;
345 gVoteTimeout
: Cardinal = 30;
346 gVoted
: Boolean = False;
347 gVotesEnabled
: Boolean = True;
348 gEvents
: Array of TGameEvent
;
349 gDelayedEvents
: Array of TDelayedEvent
;
350 gUseChatSounds
: Boolean = True;
351 gChatSounds
: Array of TChatSound
;
352 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
353 gInterReadyCount
: Integer = 0;
355 g_dbg_ignore_bounds
: Boolean = false;
356 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
357 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
359 // move button values:
360 // bits 0-1: l/r state:
361 // 0: neither left, nor right pressed
364 // bits 4-5: l/r state when strafe was pressed
365 P1MoveButton
: Byte = 0;
366 P2MoveButton
: Byte = 0;
368 g_profile_frame_update
: Boolean = false;
369 g_profile_frame_draw
: Boolean = false;
370 g_profile_collision
: Boolean = false;
371 g_profile_los
: Boolean = false;
372 g_profile_history_size
: Integer = 1000;
374 g_rlayer_back
: Boolean = true;
375 g_rlayer_step
: Boolean = true;
376 g_rlayer_wall
: Boolean = true;
377 g_rlayer_door
: Boolean = true;
378 g_rlayer_acid1
: Boolean = true;
379 g_rlayer_acid2
: Boolean = true;
380 g_rlayer_water
: Boolean = true;
381 g_rlayer_fore
: Boolean = true;
383 wNeedTimeReset
: Boolean = false;
385 procedure g_ResetDynlights ();
386 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
387 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
389 function conIsCheatsEnabled (): Boolean; inline;
390 function gPause (): Boolean; inline;
392 type (* private state *)
393 TEndCustomGameStat
= record
394 PlayerStat
: TPlayerStatArray
;
398 Map
, MapName
: String;
401 TEndSingleGameStat
= record
402 PlayerStat
: Array [0..1] of record
408 TotalSecrets
: Integer;
411 TLoadingStat
= record
415 Msgs
: Array of String;
417 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
421 x
, y
, radius
: Integer;
424 exploRadius
: Integer;
427 var (* private state *)
428 CustomStat
: TEndCustomGameStat
;
429 StatShotDone
: Boolean;
430 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
431 SingleStat
: TEndSingleGameStat
;
432 LoadingStat
: TLoadingStat
;
435 EndingGameCounter
: Byte;
437 g_playerLight
: Boolean;
438 g_dynLights
: array of TDynLight
= nil;
439 g_dynLightCount
: Integer = 0;
440 EndPicPath
: AnsiString; // full path, used by render
445 {$IFDEF ENABLE_HOLMES}
458 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
459 g_playermodel
, g_options
, Math
,
460 g_triggers
, g_monsters
, e_sound
, CONFIG
,
461 g_language
, g_net
, g_phys
,
462 ENet
, e_msg
, g_netmsg
, g_netmaster
,
466 charbuff
: packed array [0..15] of AnsiChar = (
467 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
470 function Translit (const S
: AnsiString): AnsiString;
475 for i
:= 1 to Length(Result
) do
478 #
$C9: Result
[i
] := 'Q';
479 #
$D6: Result
[i
] := 'W';
480 #
$D3: Result
[i
] := 'E';
481 #
$CA: Result
[i
] := 'R';
482 #
$C5: Result
[i
] := 'T';
483 #
$CD: Result
[i
] := 'Y';
484 #
$C3: Result
[i
] := 'U';
485 #
$D8: Result
[i
] := 'I';
486 #
$D9: Result
[i
] := 'O';
487 #
$C7: Result
[i
] := 'P';
488 #
$D5: Result
[i
] := '['; //Chr(219);
489 #
$DA: Result
[i
] := ']'; //Chr(221);
490 #
$D4: Result
[i
] := 'A';
491 #
$DB: Result
[i
] := 'S';
492 #
$C2: Result
[i
] := 'D';
493 #
$C0: Result
[i
] := 'F';
494 #
$CF: Result
[i
] := 'G';
495 #
$D0: Result
[i
] := 'H';
496 #
$CE: Result
[i
] := 'J';
497 #
$CB: Result
[i
] := 'K';
498 #
$C4: Result
[i
] := 'L';
499 #
$C6: Result
[i
] := ';'; //Chr(186);
500 #
$DD: Result
[i
] := #39; //Chr(222);
501 #
$DF: Result
[i
] := 'Z';
502 #
$D7: Result
[i
] := 'X';
503 #
$D1: Result
[i
] := 'C';
504 #
$CC: Result
[i
] := 'V';
505 #
$C8: Result
[i
] := 'B';
506 #
$D2: Result
[i
] := 'N';
507 #
$DC: Result
[i
] := 'M';
508 #
$C1: Result
[i
] := ','; //Chr(188);
509 #
$DE: Result
[i
] := '.'; //Chr(190);
515 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
520 ls2
:= Translit(CheatRus
[ct
]);
521 if length(ls1
) = 0 then ls1
:= '~';
522 if length(ls2
) = 0 then ls2
:= '~';
524 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
525 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
526 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
527 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
529 if ct = I_GAME_CHEAT_JETPACK then
531 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
532 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
533 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
534 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
535 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
536 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
552 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
553 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
554 or g_Game_IsNet then Exit;
556 if not gGameOn
then exit
;
557 if not conIsCheatsEnabled
then exit
;
559 s
:= 'SOUND_GAME_RADIO';
562 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
564 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
565 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
569 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
571 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
572 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
576 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
578 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
579 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
583 if CheckCheat(I_GAME_CHEAT_DEATH
) then
585 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
586 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
587 s
:= 'SOUND_MONSTER_HAHA';
591 if CheckCheat(I_GAME_CHEAT_DOORS
) then
593 g_Triggers_OpenAll();
597 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
599 if gTriggers
<> nil then
600 for a
:= 0 to High(gTriggers
) do
601 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
603 gExitByTrigger
:= True;
604 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
605 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
611 s2
:= Copy(charbuff
, 15, 2);
612 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
614 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
622 if CheckCheat(I_GAME_CHEAT_FLY
) then
628 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
630 VEL_JUMP
:= 30-VEL_JUMP
;
634 if CheckCheat(I_GAME_CHEAT_SPEED
) then
636 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
640 if CheckCheat(I_GAME_CHEAT_SUIT
) then
642 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
643 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
647 if CheckCheat(I_GAME_CHEAT_AIR
) then
649 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
650 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
654 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
656 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
657 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
661 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
663 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
664 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
668 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
670 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
671 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
675 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
677 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
678 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
682 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
684 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
685 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
688 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
690 gAimLine
:= not gAimLine
;
693 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
695 gShowMap
:= not gShowMap
;
706 procedure KeyPress (K
: Word);
707 var Msg
: g_gui
.TMessage
;
712 if (g_ActiveWindow
<> nil) then
714 Msg
.Msg
:= WM_KEYDOWN
;
715 Msg
.WParam
:= VK_ESCAPE
;
716 g_ActiveWindow
.OnMessage(Msg
);
717 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
719 else if (gState
<> STATE_FOLD
) then
721 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
723 g_Game_InGameMenu(True);
725 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
727 if (gState
<> STATE_MENU
) then
729 if (NetMode
<> NET_NONE
) then
731 g_Game_StopAllSounds(True);
733 gState
:= STATE_MENU
;
737 g_GUI_ShowWindow('MainMenu');
738 g_Sound_PlayEx('MENU_OPEN');
743 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
744 begin // <F2> .. <F6> � <F12>
745 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
747 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
748 if (not g_Game_IsNet
) then g_Game_Pause(True);
750 IK_F2
: g_Menu_Show_SaveMenu();
751 IK_F3
: g_Menu_Show_LoadMenu();
752 IK_F4
: g_Menu_Show_GameSetGame();
753 IK_F5
: g_Menu_Show_OptionsVideo();
754 IK_F6
: g_Menu_Show_OptionsSound();
755 IK_F7
: g_Menu_Show_EndGameMenu();
756 IK_F10
: g_Menu_Show_QuitGameMenu();
763 gJustChatted
:= False;
764 if gConsoleShow
or gChatShow
then
766 g_Console_Control(K
);
768 else if (g_ActiveWindow
<> nil) then
770 Msg
.Msg
:= WM_KEYDOWN
;
772 g_ActiveWindow
.OnMessage(Msg
);
774 else if (gState
= STATE_MENU
) then
776 g_GUI_ShowWindow('MainMenu');
777 g_Sound_PlayEx('MENU_OPEN');
783 procedure KeyPress (K
: Word);
785 gJustChatted
:= False;
786 if gConsoleShow
or gChatShow
then
788 g_Console_Control(K
);
794 procedure CharPress (C
: AnsiChar);
796 var Msg
: g_gui
.TMessage
;
800 if gConsoleShow
or gChatShow
then
805 else if g_ActiveWindow
<> nil then
808 Msg
.WParam
:= Ord(C
);
809 g_ActiveWindow
.OnMessage(Msg
);
816 charbuff
[a
] := charbuff
[a
+ 1];
818 charbuff
[15] := upcase1251(C
);
825 // ////////////////////////////////////////////////////////////////////////// //
826 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
828 procedure g_ResetDynlights ();
832 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
834 for idx
:= 0 to g_dynLightCount
-1 do
836 if g_dynLights
[idx
].exploCount
= -666 then
843 Inc(g_dynLights
[idx
].exploCount
);
844 if (g_dynLights
[idx
].exploCount
< 10) then
846 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
847 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
848 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
849 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
854 g_dynLightCount
:= lnum
;
857 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
859 if not gwin_has_stencil
then exit
;
860 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
861 g_dynLights
[g_dynLightCount
].x
:= x
;
862 g_dynLights
[g_dynLightCount
].y
:= y
;
863 g_dynLights
[g_dynLightCount
].radius
:= radius
;
864 g_dynLights
[g_dynLightCount
].r
:= r
;
865 g_dynLights
[g_dynLightCount
].g
:= g
;
866 g_dynLights
[g_dynLightCount
].b
:= b
;
867 g_dynLights
[g_dynLightCount
].a
:= a
;
868 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
869 Inc(g_dynLightCount
);
872 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
874 if not gwin_has_stencil
then exit
;
875 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
876 g_dynLights
[g_dynLightCount
].x
:= x
;
877 g_dynLights
[g_dynLightCount
].y
:= y
;
878 g_dynLights
[g_dynLightCount
].radius
:= 0;
879 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
880 g_dynLights
[g_dynLightCount
].r
:= r
;
881 g_dynLights
[g_dynLightCount
].g
:= g
;
882 g_dynLights
[g_dynLightCount
].b
:= b
;
883 g_dynLights
[g_dynLightCount
].a
:= 0;
884 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
885 Inc(g_dynLightCount
);
888 // ////////////////////////////////////////////////////////////////////////// //
889 function conIsCheatsEnabled (): Boolean; inline;
892 if g_Game_IsNet
then exit
;
893 if not gDebugMode
then
895 //if not gCheats then exit;
896 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
897 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
902 // ////////////////////////////////////////////////////////////////////////// //
904 TParamStrValue
= record
909 TParamStrValues
= Array of TParamStrValue
;
912 INTER_ACTION_TEXT
= 1;
913 INTER_ACTION_PIC
= 2;
914 INTER_ACTION_MUSIC
= 3;
919 DataLoaded
: Boolean = False;
921 MapList
: SSArray
= nil;
922 MapIndex
: Integer = -1;
923 InterReadyTime
: Integer = -1;
924 StatDate
: string = '';
939 function Compare(a
, b
: TPlayerStat
): Integer;
941 if a
.Spectator
then Result
:= 1
942 else if b
.Spectator
then Result
:= -1
943 else if a
.Frags
< b
.Frags
then Result
:= 1
944 else if a
.Frags
> b
.Frags
then Result
:= -1
945 else if a
.Deaths
< b
.Deaths
then Result
:= -1
946 else if a
.Deaths
> b
.Deaths
then Result
:= 1
947 else if a
.Kills
< b
.Kills
then Result
:= -1
951 procedure SortGameStat(var stat
: TPlayerStatArray
);
956 if stat
= nil then Exit
;
958 for I
:= High(stat
) downto Low(stat
) do
959 for J
:= Low(stat
) to High(stat
) - 1 do
960 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
963 stat
[J
] := stat
[J
+ 1];
968 // saves a shitty CSV containing the game stats passed to it
969 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
972 dir
, fname
, map
, mode
, etime
: String;
976 dir
:= e_GetWriteableDir(StatsDirs
);
977 // stats are placed in stats/yy/mm/dd/*.csv
978 fname
:= e_CatPath(dir
, Path
);
979 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
980 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
981 AssignFile(s
, fname
);
984 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
985 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
986 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
987 mode
:= g_Game_ModeToText(Stat
.GameMode
);
988 etime
:= Format('%d:%.2d:%.2d', [
989 Stat
.GameTime
div 1000 div 3600,
990 (Stat
.GameTime
div 1000 div 60) mod 60,
991 Stat
.GameTime
div 1000 mod 60
993 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
994 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
1000 gGameSettings
.TimeLimit
,
1001 gGameSettings
.GoalLimit
,
1002 gGameSettings
.Options
,
1004 Length(Stat
.PlayerStat
)
1006 // line 2: game specific shit
1007 // if it's a team game: red score, blue score
1008 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1009 // otherwise nothing
1010 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1012 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
1013 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1015 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1016 // lines 3-...: team, player name, frags, deaths
1017 WriteLn(s
, 'team,name,frags,deaths');
1018 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1019 with Stat
.PlayerStat
[I
] do
1020 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1022 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1025 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1030 function g_Game_ModeToText(Mode
: Byte): string;
1034 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1035 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1036 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1037 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1038 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1042 function g_Game_TextToMode(Mode
: string): Byte;
1045 Mode
:= UpperCase(Mode
);
1046 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1051 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1056 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1061 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1066 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1068 Result
:= GM_SINGLE
;
1073 function g_Game_IsNet(): Boolean;
1075 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1078 function g_Game_IsServer(): Boolean;
1080 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1083 function g_Game_IsClient(): Boolean;
1085 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1088 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1095 Result
.name
:= ExtractFileName(WAD
);
1096 Result
.description
:= '';
1097 Result
.author
:= '';
1099 w
:= TWADFile
.Create();
1102 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1108 cfg
:= TConfig
.CreateMem(p
, len
);
1109 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1110 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1111 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1112 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1118 procedure g_Game_FreeWAD
;
1121 g_Sound_Delete('MUSIC_endmus');
1122 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1123 gGameSettings
.WAD
:= '';
1126 procedure g_Game_LoadWAD(WAD
: string);
1135 gGameSettings
.WAD
:= WAD
;
1136 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1139 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1141 w
:= TWADFile
.Create();
1144 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1150 cfg
:= TConfig
.CreateMem(p
, len
);
1153 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1154 if MegaWAD
.endpic
<> '' then
1155 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1157 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1158 if MegaWAD
.endmus
<> '' then
1160 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1161 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1169 {procedure start_trigger(t: string);
1173 function next_trigger(): Boolean;
1177 procedure DisableCheats();
1183 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1184 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1185 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1186 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1188 {$IF DEFINED(D2F_DEBUG)}
1189 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1190 gAimLine
:= g_dbg_aimline_on
;
1194 procedure g_Game_ExecuteEvent(Name
: String);
1200 if gEvents
= nil then
1202 for a
:= 0 to High(gEvents
) do
1203 if gEvents
[a
].Name
= Name
then
1205 if gEvents
[a
].Command
<> '' then
1206 g_Console_Process(gEvents
[a
].Command
, True);
1211 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1216 if gDelayedEvents
<> nil then
1217 for a
:= 0 to High(gDelayedEvents
) do
1218 if not gDelayedEvents
[a
].Pending
then
1225 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1226 n
:= High(gDelayedEvents
);
1228 gDelayedEvents
[n
].Pending
:= True;
1229 gDelayedEvents
[n
].DEType
:= DEType
;
1230 gDelayedEvents
[n
].DENum
:= Num
;
1231 gDelayedEvents
[n
].DEStr
:= Str
;
1232 if DEType
= DE_GLOBEVENT
then
1233 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1235 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1239 procedure EndGame();
1245 if g_Game_IsNet
and g_Game_IsServer
then
1246 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1249 gPauseMain
:= false;
1250 gPauseHolmes
:= false;
1253 g_Game_StopAllSounds(False);
1258 EndingGameCounter
:= 0;
1260 {$IFDEF ENABLE_MENU}
1261 g_ActiveWindow
:= nil;
1264 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1265 gLMSRespawnTime
:= 0;
1268 EXIT_SIMPLE
: // Выход через меню или конец теста
1272 begin // Это был тест
1276 begin // Выход в главное меню
1277 {$IFDEF DISABLE_MENU}
1278 gState
:= STATE_MENU
; // ???
1280 gMusic
.SetByName('MUSIC_MENU');
1282 if gState
<> STATE_SLIST
then
1284 g_GUI_ShowWindow('MainMenu');
1285 gState
:= STATE_MENU
;
1289 // Обновляем список серверов
1290 slReturnPressed
:= True;
1291 if g_Net_Slist_Fetch(slCurrent
) then
1293 if slCurrent
= nil then
1294 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1297 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1298 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1301 g_Game_ExecuteEvent('ongameend');
1305 EXIT_RESTART
: // Начать уровень сначала
1307 if not g_Game_IsClient
then g_Game_Restart();
1310 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1312 // Статистика Своей игры:
1313 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1315 CustomStat
.GameTime
:= gTime
;
1316 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1317 CustomStat
.MapName
:= gMapInfo
.Name
;
1318 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1319 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1320 CustomStat
.TeamStat
:= gTeamStat
;
1322 CustomStat
.PlayerStat
:= nil;
1324 // Статистика игроков:
1325 if gPlayers
<> nil then
1327 for a
:= 0 to High(gPlayers
) do
1328 if gPlayers
[a
] <> nil then
1330 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1331 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1334 Name
:= gPlayers
[a
].Name
;
1335 Frags
:= gPlayers
[a
].Frags
;
1336 Deaths
:= gPlayers
[a
].Death
;
1337 Kills
:= gPlayers
[a
].Kills
;
1338 Team
:= gPlayers
[a
].Team
;
1339 Color
:= gPlayers
[a
].Model
.Color
;
1340 Spectator
:= gPlayers
[a
].FSpectator
;
1344 SortGameStat(CustomStat
.PlayerStat
);
1346 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1349 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1350 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1351 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1352 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1354 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1357 StatShotDone
:= False;
1360 g_Game_ExecuteEvent('onmapend');
1361 if not g_Game_IsClient
then g_Player_ResetReady
;
1362 gInterReadyCount
:= 0;
1364 // Затухающий экран:
1365 EndingGameCounter
:= 255;
1366 gState
:= STATE_FOLD
;
1368 if gDefInterTime
< 0 then
1369 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1371 gInterEndTime
:= gDefInterTime
* 1000;
1374 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1376 // Статистика Одиночной игры:
1377 SingleStat
.GameTime
:= gTime
;
1378 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1379 SingleStat
.TotalSecrets
:= gSecretsCount
;
1380 // Статистика первого игрока:
1381 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1382 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1383 // Статистика второго игрока (если есть):
1384 if SingleStat
.TwoPlayers
then
1386 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1387 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1390 g_Game_ExecuteEvent('onmapend');
1393 if gNextMap
<> '' then
1395 gMusic
.SetByName('MUSIC_INTERMUS');
1397 gState
:= STATE_INTERSINGLE
;
1400 g_Game_ExecuteEvent('oninter');
1402 else // Больше нет карт
1404 // Затухающий экран:
1405 EndingGameCounter
:= 255;
1406 gState
:= STATE_FOLD
;
1411 // Окончание обработано:
1412 if gExit
<> EXIT_QUIT
then
1416 procedure g_Game_Init();
1420 gTempDelete
:= False;
1422 sfsGCDisable(); // temporary disable removing of temporary volumes
1425 g_Game_ClearLoading();
1426 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1427 g_Game_SetLoadingText('', 0, False);
1429 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1432 gPauseMain
:= false;
1433 gPauseHolmes
:= false;
1436 {e_MouseInfo.Accel := 1.0;}
1438 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1441 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1442 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1443 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1444 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1445 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1447 gMusic
:= TMusic
.Create();
1448 gMusic
.SetByName('MUSIC_MENU');
1451 gGameSettings
.WarmupTime
:= 30;
1453 gState
:= STATE_MENU
;
1455 SetLength(gEvents
, 6);
1456 gEvents
[0].Name
:= 'ongamestart';
1457 gEvents
[1].Name
:= 'ongameend';
1458 gEvents
[2].Name
:= 'onmapstart';
1459 gEvents
[3].Name
:= 'onmapend';
1460 gEvents
[4].Name
:= 'oninter';
1461 gEvents
[5].Name
:= 'onwadend';
1463 sfsGCEnable(); // enable releasing unused volumes
1467 procedure g_Game_Free(freeTextures
: Boolean=true);
1469 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1470 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1472 g_Map_Free(freeTextures
);
1474 g_Player_RemoveAllCorpses();
1476 gGameSettings
.GameType
:= GT_NONE
;
1477 if gGameSettings
.GameMode
= GM_SINGLE
then
1478 gGameSettings
.GameMode
:= GM_DM
;
1479 gSwitchGameMode
:= gGameSettings
.GameMode
;
1482 gExitByTrigger
:= False;
1485 function IsActivePlayer(p
: TPlayer
): Boolean;
1490 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1493 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1499 if gPlayers
= nil then
1503 for a
:= Low(gPlayers
) to High(gPlayers
) do
1504 if IsActivePlayer(gPlayers
[a
]) then
1506 SetLength(ids
, Length(ids
) + 1);
1507 ids
[High(ids
)] := gPlayers
[a
].UID
;
1508 if gPlayers
[a
].UID
= Skip
then
1511 if Length(ids
) = 0 then
1516 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1519 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1525 if gPlayers
= nil then
1529 for a
:= Low(gPlayers
) to High(gPlayers
) do
1530 if IsActivePlayer(gPlayers
[a
]) then
1532 SetLength(ids
, Length(ids
) + 1);
1533 ids
[High(ids
)] := gPlayers
[a
].UID
;
1534 if gPlayers
[a
].UID
= Skip
then
1537 if Length(ids
) = 0 then
1540 Result
:= ids
[Length(ids
) - 1]
1542 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1545 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1551 if gPlayers
= nil then
1555 for a
:= Low(gPlayers
) to High(gPlayers
) do
1556 if IsActivePlayer(gPlayers
[a
]) then
1558 SetLength(ids
, Length(ids
) + 1);
1559 ids
[High(ids
)] := gPlayers
[a
].UID
;
1560 if gPlayers
[a
].UID
= Skip
then
1563 if Length(ids
) = 0 then
1565 if Length(ids
) = 1 then
1570 Result
:= ids
[Random(Length(ids
))];
1572 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1574 Result
:= ids
[Random(Length(ids
))];
1579 function GetRandomSpectMode(Current
: Byte): Byte;
1586 0: Result
:= SPECT_STATS
;
1587 1: Result
:= SPECT_MAPVIEW
;
1588 2: Result
:= SPECT_MAPVIEW
;
1589 3: Result
:= SPECT_PLAYERS
;
1590 4: Result
:= SPECT_PLAYERS
;
1591 5: Result
:= SPECT_PLAYERS
;
1592 6: Result
:= SPECT_PLAYERS
;
1594 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1598 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1604 if (plr
= nil) then exit
;
1605 if (p
= 2) then time
:= 1000 else time
:= 1;
1606 strafeDir
:= MoveButton
shr 4;
1607 MoveButton
:= MoveButton
and $0F;
1609 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1610 MoveButton
:= 1 // Нажата только "Влево"
1611 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1612 MoveButton
:= 2 // Нажата только "Вправо"
1613 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1614 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1616 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1617 if MoveButton
= 1 then
1618 plr
.PressKey(KEY_LEFT
, time
)
1619 else if MoveButton
= 2 then
1620 plr
.PressKey(KEY_RIGHT
, time
);
1622 // if we have "strafe" key, turn off old strafe mechanics
1623 if gPlayerAction
[p
, ACTION_STRAFE
] then
1625 // new strafe mechanics
1626 if (strafeDir
= 0) then
1627 strafeDir
:= MoveButton
; // start strafing
1628 // now set direction according to strafe (reversed)
1629 if (strafeDir
= 2) then
1630 plr
.SetDirection(TDirection
.D_LEFT
)
1631 else if (strafeDir
= 1) then
1632 plr
.SetDirection(TDirection
.D_RIGHT
)
1636 strafeDir
:= 0; // not strafing anymore
1637 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1638 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1639 plr
.SetDirection(TDirection
.D_LEFT
)
1640 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1641 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1642 plr
.SetDirection(TDirection
.D_RIGHT
)
1643 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1644 else if MoveButton
<> 0 then
1645 plr
.SetDirection(TDirection(MoveButton
-1))
1648 // fix movebutton state
1649 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1651 // Остальные клавиши:
1652 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1653 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1654 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1655 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1656 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1657 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1658 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1660 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1661 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1663 for i
:= WP_FIRST
to WP_LAST
do
1665 if gSelectWeapon
[p
, i
] then
1667 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1668 gSelectWeapon
[p
, i
] := False
1672 {$IFDEF ENABLE_MENU}
1673 // HACK: add dynlight here
1674 if gwin_k8_enable_light_experiments
then
1676 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1678 g_playerLight
:= true;
1680 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1682 g_playerLight
:= false;
1686 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1690 // HACK: don't have a "key was pressed" function
1691 procedure InterReady();
1693 if InterReadyTime
> gTime
then Exit
;
1694 InterReadyTime
:= gTime
+ 3000;
1695 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1698 procedure g_Game_PreUpdate();
1700 // these are in separate PreUpdate functions because they can interact during Update()
1701 // and are synced over the net
1702 // we don't care that much about corpses and gibs
1703 g_Player_PreUpdate();
1704 g_Monsters_PreUpdate();
1705 g_Items_PreUpdate();
1706 g_Weapon_PreUpdate();
1709 procedure g_Game_Update();
1711 {$IFDEF ENABLE_MENU}
1712 Msg
: g_gui
.TMessage
;
1719 function sendMonsPos (mon
: TMonster
): Boolean;
1721 result
:= false; // don't stop
1722 // this will also reset "need-send" flag
1723 if mon
.gncNeedSend
then
1725 MH_SEND_MonsterPos(mon
.UID
);
1727 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1729 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1731 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1733 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1737 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1739 result
:= false; // don't stop
1740 // this will also reset "need-send" flag
1741 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1745 reliableUpdate
: Boolean;
1750 // Пора выключать игру:
1751 if gExit
= EXIT_QUIT
then
1753 // Игра закончилась - обрабатываем:
1757 if gExit
= EXIT_QUIT
then
1761 // Читаем клавиатуру и джойстик, если окно активно
1762 // no need to, as we'll do it in event handler
1764 // Обновляем консоль (движение и сообщения):
1767 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1769 gExit
:= EXIT_SIMPLE
;
1774 // process master server communications
1775 g_Net_Slist_Pulse();
1778 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1779 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1780 STATE_INTERTEXT
, // Текст между уровнями
1781 STATE_INTERPIC
: // Картинка между уровнями
1783 if g_Game_IsNet
and g_Game_IsServer
then
1785 gInterTime
:= gInterTime
+ GAME_TICK
;
1786 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1787 if a
<> gServInterTime
then
1789 gServInterTime
:= a
;
1790 MH_SEND_TimeSync(gServInterTime
);
1794 if (not g_Game_IsClient
) and
1798 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1799 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1800 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1801 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1803 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1804 {$IFDEF ENABLE_MENU}
1805 and (g_ActiveWindow
= nil)
1808 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1811 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1812 g_Game_StopAllSounds(True);
1814 if gMapOnce
then // Это был тест
1815 gExit
:= EXIT_SIMPLE
1817 if gNextMap
<> '' then // Переходим на следующую карту
1818 g_Game_ChangeMap(gNextMap
)
1819 else // Следующей карты нет
1821 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1823 // Выход в главное меню:
1825 {$IFDEF ENABLE_MENU}
1826 g_GUI_ShowWindow('MainMenu');
1827 gMusic
.SetByName('MUSIC_MENU');
1830 gState
:= STATE_MENU
;
1833 // Финальная картинка:
1834 g_Game_ExecuteEvent('onwadend');
1836 if not gMusic
.SetByName('MUSIC_endmus') then
1837 gMusic
.SetByName('MUSIC_STDENDMUS');
1839 gState
:= STATE_ENDPIC
;
1841 g_Game_ExecuteEvent('ongameend');
1846 else if g_Game_IsClient
and
1849 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1850 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1851 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1852 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1854 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1855 {$IFDEF ENABLE_MENU}
1856 and (g_ActiveWindow
= nil)
1865 if gState
= STATE_INTERTEXT
then
1866 if InterText
.counter
> 0 then
1867 InterText
.counter
:= InterText
.counter
- 1;
1870 STATE_FOLD
: // Затухание экрана
1872 if EndingGameCounter
= 0 then
1874 // Закончился уровень в Своей игре:
1875 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1877 InterReadyTime
:= -1;
1878 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1880 g_Game_ExecuteEvent('onwadend');
1881 if not gMusic
.SetByName('MUSIC_endmus') then
1882 gMusic
.SetByName('MUSIC_STDENDMUS');
1885 gMusic
.SetByName('MUSIC_ROUNDMUS');
1888 gState
:= STATE_INTERCUSTOM
;
1891 else // Закончилась последняя карта в Одиночной игре
1893 gMusic
.SetByName('MUSIC_INTERMUS');
1895 gState
:= STATE_INTERSINGLE
;
1898 g_Game_ExecuteEvent('oninter');
1901 DecMin(EndingGameCounter
, 6, 0);
1904 STATE_ENDPIC
: // Картинка окончания мегаВада
1906 if gMapOnce
then // Это был тест
1908 gExit
:= EXIT_SIMPLE
;
1914 g_Serverlist_Control(slCurrent
, slTable
);
1917 // Статистика по Tab:
1919 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1922 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1924 // Время += 28 миллисекунд:
1925 gTime
:= gTime
+ GAME_TICK
;
1927 // Сообщение посередине экрана:
1928 if MessageTime
= 0 then
1930 if MessageTime
> 0 then
1931 MessageTime
:= MessageTime
- 1;
1933 if (g_Game_IsServer
) then
1935 // Был задан лимит времени:
1936 if (gGameSettings
.TimeLimit
> 0) then
1937 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1938 begin // Он прошел => конец уровня
1943 // Надо респавнить игроков в LMS:
1944 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1945 g_Game_RestartRound(gLMSSoftSpawn
);
1947 // Проверим результат голосования, если время прошло
1948 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1950 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1952 g_Console_Process(gVoteCommand
);
1954 gVotePassed
:= False;
1957 // Замеряем время захвата флагов
1958 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1959 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1960 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1961 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1963 // Был задан лимит побед:
1964 if (gGameSettings
.GoalLimit
> 0) then
1968 if gGameSettings
.GameMode
= GM_DM
then
1969 begin // В DM ищем игрока с max фрагами
1970 for i
:= 0 to High(gPlayers
) do
1971 if gPlayers
[i
] <> nil then
1972 if gPlayers
[i
].Frags
> b
then
1973 b
:= gPlayers
[i
].Frags
;
1976 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1977 begin // В CTF/TDM выбираем команду с наибольшим счетом
1978 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1981 // Лимит побед набран => конец уровня:
1982 if b
>= gGameSettings
.GoalLimit
then
1989 // Обрабатываем клавиши игроков:
1990 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1991 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1992 {$IFDEF DISABLE_MENU}
1993 if (not gConsoleShow
) and (not gChatShow
) then
1995 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1998 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1999 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2000 end // if not console
2003 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2005 // process weapon switch queue
2009 if (gPlayer1
= nil) and (gPlayer2
= nil)
2010 and (not gConsoleShow
) and (not gChatShow
)
2011 {$IFDEF ENABLE_MENU}
2012 and (g_ActiveWindow
= nil)
2016 if not gSpectKeyPress
then
2018 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2020 // switch spect mode
2022 SPECT_NONE
: ; // not spectator
2024 SPECT_MAPVIEW
: Inc(gSpectMode
);
2025 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2027 gSpectKeyPress
:= True;
2029 if (gSpectMode
= SPECT_MAPVIEW
)
2030 and (not gSpectAuto
) then
2032 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2033 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2034 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2035 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2036 if gPlayerAction
[0, ACTION_LOOKUP
] then
2037 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2038 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2039 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2040 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2043 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2044 gSpectKeyPress
:= True;
2046 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2049 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2050 gSpectKeyPress
:= True;
2053 if (gSpectMode
= SPECT_PLAYERS
)
2054 and (not gSpectAuto
) then
2056 if gPlayerAction
[0, ACTION_LOOKUP
] then
2059 gSpectViewTwo
:= True;
2060 gSpectKeyPress
:= True;
2062 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2064 // remove second view
2065 gSpectViewTwo
:= False;
2066 gSpectKeyPress
:= True;
2068 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2070 // prev player (view 1)
2071 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2072 gSpectKeyPress
:= True;
2074 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2076 // next player (view 1)
2077 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2078 gSpectKeyPress
:= True;
2080 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2082 // prev player (view 2)
2083 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2084 gSpectKeyPress
:= True;
2086 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2088 // next player (view 2)
2089 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2090 gSpectKeyPress
:= True;
2093 if gPlayerAction
[0, ACTION_ATTACK
] then
2095 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2098 gSpectAutoNext
:= 0;
2099 gSpectViewTwo
:= False;
2100 gSpectKeyPress
:= True;
2105 gSpectMode
:= SPECT_STATS
;
2106 gSpectAuto
:= False;
2107 gSpectKeyPress
:= True;
2112 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2113 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2114 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2115 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2116 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2117 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2118 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2119 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2120 gSpectKeyPress
:= False;
2124 if gSpectMode
= SPECT_MAPVIEW
then
2126 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2128 gSpectAutoNext
:= gTime
2131 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2133 gSpectAutoNext
:= gTime
2137 if gSpectAutoNext
<= gTime
then
2139 if gSpectAutoNext
> 0 then
2141 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2145 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2146 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2147 gSpectAutoStepX
:= Random(9) - 4;
2148 gSpectAutoStepY
:= Random(9) - 4;
2149 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2150 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2151 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2152 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2153 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2154 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2158 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2163 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2164 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2165 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2171 // Обновляем все остальное:
2174 g_Triggers_Update();
2176 g_Monsters_Update();
2180 g_Player_UpdateAll();
2181 g_Player_UpdatePhysicalObjects();
2183 // server: send newly spawned monsters unconditionally
2184 if (gGameSettings
.GameType
= GT_SERVER
) then
2186 if (Length(gMonstersSpawned
) > 0) then
2188 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2189 SetLength(gMonstersSpawned
, 0);
2193 if (gSoundTriggerTime
> 8) then
2195 g_Game_UpdateTriggerSounds();
2196 gSoundTriggerTime
:= 0;
2200 Inc(gSoundTriggerTime
);
2203 if (NetMode
= NET_SERVER
) then
2205 Inc(NetTimeToUpdate
);
2206 Inc(NetTimeToReliable
);
2208 // send monster updates
2209 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2211 // send all monsters (periodic sync)
2212 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2214 for I
:= 0 to High(gPlayers
) do
2216 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2219 g_Mons_ForEach(sendMonsPos
);
2221 if reliableUpdate
then
2223 NetTimeToReliable
:= 0;
2224 NetTimeToUpdate
:= NetUpdateRate
;
2228 NetTimeToUpdate
:= 0;
2233 // send only mosters with some unexpected changes
2234 g_Mons_ForEach(sendMonsPosUnexpected
);
2237 // send unexpected platform changes
2238 g_Map_NetSendInterestingPanels();
2240 g_Net_Slist_ServerUpdate();
2242 if NetUseMaster then
2244 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2246 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2248 NetTimeToMaster := gTime + NetMasterRate;
2253 else if (NetMode
= NET_CLIENT
) then
2255 MC_SEND_PlayerPos();
2257 end; // if gameOn ...
2259 // Активно окно интерфейса - передаем клавиши ему:
2260 {$IFDEF ENABLE_MENU}
2261 if g_ActiveWindow
<> nil then
2263 w
:= e_GetFirstKeyPressed();
2265 if (w
<> IK_INVALID
) then
2267 Msg
.Msg
:= MESSAGE_DIKEY
;
2269 g_ActiveWindow
.OnMessage(Msg
);
2272 // Если оно от этого не закрылось, то обновляем:
2273 if g_ActiveWindow
<> nil then
2274 g_ActiveWindow
.Update();
2276 // Нужно сменить разрешение:
2277 if gResolutionChange
then
2280 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2283 gResolutionChange
:= False;
2284 g_ActiveWindow
:= nil;
2287 // Нужно сменить язык:
2288 if gLanguageChange
then
2290 //e_WriteLog('Read language file', MSG_NOTIFY);
2291 //g_Language_Load(DataDir + gLanguage + '.txt');
2292 g_Language_Set(gLanguage
);
2294 gLanguageChange
:= False;
2298 // Горячая клавиша для вызова меню выхода из игры (F10):
2299 if e_KeyPressed(IK_F10
) and
2301 (not gConsoleShow
) and
2302 (g_ActiveWindow
= nil) then
2308 Time
:= GetTickCount64() {div 1000};
2310 // Обработка отложенных событий:
2311 if gDelayedEvents
<> nil then
2312 for a
:= 0 to High(gDelayedEvents
) do
2313 if gDelayedEvents
[a
].Pending
and
2315 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2316 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2319 case gDelayedEvents
[a
].DEType
of
2321 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2324 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2328 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2329 if g_Game_IsNet
and g_Game_IsServer
then
2330 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2334 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2336 gDelayedEvents
[a
].Pending
:= False;
2339 // Каждую секунду обновляем счетчик обновлений:
2340 UPSCounter
:= UPSCounter
+ 1;
2341 if Time
- UPSTime
>= 1000 then
2350 g_Weapon_AddDynLights();
2351 g_Items_AddDynLights();
2355 procedure g_Game_LoadChatSounds(Resource
: string);
2358 FileName
, Snd
: string;
2360 len
, cnt
, tags
, i
, j
: Integer;
2363 FileName
:= g_ExtractWadName(Resource
);
2365 WAD
:= TWADFile
.Create();
2366 WAD
.ReadFile(FileName
);
2368 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2375 cfg
:= TConfig
.CreateMem(p
, len
);
2376 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2378 SetLength(gChatSounds
, cnt
);
2379 for i
:= 0 to Length(gChatSounds
) - 1 do
2381 gChatSounds
[i
].Sound
:= nil;
2382 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2383 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2384 if (Snd
= '') or (Tags
<= 0) then
2386 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2387 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2388 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2389 SetLength(gChatSounds
[i
].Tags
, tags
);
2390 for j
:= 0 to tags
- 1 do
2391 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2392 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2399 procedure g_Game_FreeChatSounds();
2403 for i
:= 0 to Length(gChatSounds
) - 1 do
2405 gChatSounds
[i
].Sound
.Free();
2406 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2408 SetLength(gChatSounds
, 0);
2412 procedure g_Game_LoadData();
2414 if DataLoaded
then Exit
;
2416 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2418 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2419 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2420 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2421 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2422 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2423 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2424 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2425 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2426 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2427 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2428 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2429 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2430 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2431 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2432 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2433 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2434 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2435 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2436 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2437 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2438 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2439 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2440 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2441 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2442 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2443 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2444 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2445 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2446 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2447 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2448 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2449 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2451 goodsnd
[0] := TPlayableSound
.Create();
2452 goodsnd
[1] := TPlayableSound
.Create();
2453 goodsnd
[2] := TPlayableSound
.Create();
2454 goodsnd
[3] := TPlayableSound
.Create();
2456 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2457 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2458 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2459 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2461 killsnd
[0] := TPlayableSound
.Create();
2462 killsnd
[1] := TPlayableSound
.Create();
2463 killsnd
[2] := TPlayableSound
.Create();
2464 killsnd
[3] := TPlayableSound
.Create();
2466 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2467 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2468 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2469 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2471 hahasnd
[0] := TPlayableSound
.Create();
2472 hahasnd
[1] := TPlayableSound
.Create();
2473 hahasnd
[2] := TPlayableSound
.Create();
2475 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2476 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2477 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2479 sound_get_flag
[0] := TPlayableSound
.Create();
2480 sound_get_flag
[1] := TPlayableSound
.Create();
2481 sound_lost_flag
[0] := TPlayableSound
.Create();
2482 sound_lost_flag
[1] := TPlayableSound
.Create();
2483 sound_ret_flag
[0] := TPlayableSound
.Create();
2484 sound_ret_flag
[1] := TPlayableSound
.Create();
2485 sound_cap_flag
[0] := TPlayableSound
.Create();
2486 sound_cap_flag
[1] := TPlayableSound
.Create();
2488 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2489 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2490 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2491 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2492 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2493 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2494 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2495 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2497 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2499 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2502 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2503 g_Weapon_LoadData();
2505 g_Monsters_LoadData();
2510 procedure g_Game_Quit();
2512 g_Game_StopAllSounds(True);
2515 g_PlayerModel_FreeData();
2517 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2520 if NetInitDone
then g_Net_Free
;
2522 // remove map after test
2523 if gMapToDelete
<> '' then
2524 g_Game_DeleteTestMap();
2533 procedure g_Game_FreeData();
2535 if not DataLoaded
then Exit
;
2538 g_Weapon_FreeData();
2539 g_Monsters_FreeData();
2541 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2543 g_Sound_Delete('SOUND_GAME_TELEPORT');
2544 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2545 g_Sound_Delete('SOUND_GAME_SECRET');
2546 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2547 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2548 g_Sound_Delete('SOUND_GAME_BULK1');
2549 g_Sound_Delete('SOUND_GAME_BULK2');
2550 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2551 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2552 g_Sound_Delete('SOUND_GAME_BURNING');
2553 g_Sound_Delete('SOUND_GAME_SWITCH1');
2554 g_Sound_Delete('SOUND_GAME_SWITCH0');
2561 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2562 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2563 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2564 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2571 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2572 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2573 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2574 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2580 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2581 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2582 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2584 sound_get_flag
[0].Free();
2585 sound_get_flag
[1].Free();
2586 sound_lost_flag
[0].Free();
2587 sound_lost_flag
[1].Free();
2588 sound_ret_flag
[0].Free();
2589 sound_ret_flag
[1].Free();
2590 sound_cap_flag
[0].Free();
2591 sound_cap_flag
[1].Free();
2593 g_Sound_Delete('SOUND_CTF_GET1');
2594 g_Sound_Delete('SOUND_CTF_GET2');
2595 g_Sound_Delete('SOUND_CTF_LOST1');
2596 g_Sound_Delete('SOUND_CTF_LOST2');
2597 g_Sound_Delete('SOUND_CTF_RETURN1');
2598 g_Sound_Delete('SOUND_CTF_RETURN2');
2599 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2600 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2602 g_Game_FreeChatSounds();
2604 DataLoaded
:= False;
2607 procedure g_FatalError(Text: String);
2609 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2610 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2612 gExit
:= EXIT_SIMPLE
;
2613 if gGameOn
then EndGame
;
2616 procedure g_SimpleError(Text: String);
2618 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2619 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2622 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2624 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2625 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2628 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2631 if gPlayer1
= nil then
2633 if g_Game_IsClient
then
2635 if NetPlrUID1
> -1 then
2636 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2640 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2641 Team
:= gPlayer1Settings
.Team
;
2643 // Создание первого игрока:
2644 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2645 gPlayer1Settings
.Color
,
2647 if gPlayer1
= nil then
2648 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2651 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2652 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2653 if g_Game_IsServer
and g_Game_IsNet
then
2654 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2655 gPlayer1
.Respawn(False, True);
2656 g_Net_Slist_ServerPlayerComes();
2661 if gPlayer2
= nil then
2663 if g_Game_IsClient
then
2665 if NetPlrUID2
> -1 then
2666 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2670 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2671 Team
:= gPlayer2Settings
.Team
;
2673 // Создание второго игрока:
2674 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2675 gPlayer2Settings
.Color
,
2677 if gPlayer2
= nil then
2678 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2681 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2682 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2683 if g_Game_IsServer
and g_Game_IsNet
then
2684 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2685 gPlayer2
.Respawn(False, True);
2686 g_Net_Slist_ServerPlayerComes();
2693 procedure g_Game_RemovePlayer();
2697 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2698 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2703 if g_Game_IsServer
then
2706 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2707 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2708 g_Player_Remove(Pl
.UID
);
2709 g_Net_Slist_ServerPlayerLeaves();
2713 gSpectLatchPID2
:= Pl
.UID
;
2721 if g_Game_IsServer
then
2724 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2725 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2726 g_Player_Remove(Pl
.UID
);
2727 g_Net_Slist_ServerPlayerLeaves();
2730 gSpectLatchPID1
:= Pl
.UID
;
2732 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2736 g_Net_Slist_ServerPlayerLeaves();
2739 procedure g_Game_Spectate();
2741 g_Game_RemovePlayer();
2742 if gPlayer1
<> nil then
2743 g_Game_RemovePlayer();
2746 procedure g_Game_SpectateCenterView();
2748 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2749 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2752 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2759 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2761 g_Game_ClearLoading();
2764 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2767 gGameSettings
.GameType
:= GT_SINGLE
;
2768 gGameSettings
.MaxLives
:= 0;
2769 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2770 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2771 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2772 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2773 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2774 gSwitchGameMode
:= GM_SINGLE
;
2776 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2777 gLMSRespawnTime
:= 0;
2778 gSpectLatchPID1
:= 0;
2779 gSpectLatchPID2
:= 0;
2781 g_Game_ExecuteEvent('ongamestart');
2783 // Создание первого игрока:
2784 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2785 gPlayer1Settings
.Color
,
2786 gPlayer1Settings
.Team
, False));
2787 if gPlayer1
= nil then
2789 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2793 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2796 // Создание второго игрока, если есть:
2799 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2800 gPlayer2Settings
.Color
,
2801 gPlayer2Settings
.Team
, False));
2802 if gPlayer2
= nil then
2804 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2808 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2812 // Загрузка и запуск карты:
2813 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2815 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2816 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2820 // Настройки игроков и ботов:
2824 for i
:= nPl
+1 to nPlayers
do
2825 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2828 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2829 TimeLimit
, GoalLimit
: Word;
2831 Options
: LongWord; nPlayers
: Byte);
2837 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2839 g_Game_ClearLoading();
2842 gGameSettings
.GameType
:= GT_CUSTOM
;
2843 gGameSettings
.GameMode
:= GameMode
;
2844 gSwitchGameMode
:= GameMode
;
2845 gGameSettings
.TimeLimit
:= TimeLimit
;
2846 gGameSettings
.GoalLimit
:= GoalLimit
;
2847 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2848 gGameSettings
.Options
:= Options
;
2850 gCoopTotalMonstersKilled
:= 0;
2851 gCoopTotalSecretsFound
:= 0;
2852 gCoopTotalMonsters
:= 0;
2853 gCoopTotalSecrets
:= 0;
2857 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2858 gLMSRespawnTime
:= 0;
2859 gSpectLatchPID1
:= 0;
2860 gSpectLatchPID2
:= 0;
2862 g_Game_ExecuteEvent('ongamestart');
2864 // Режим наблюдателя:
2865 if nPlayers
= 0 then
2872 if nPlayers
>= 1 then
2874 // Создание первого игрока:
2875 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2876 gPlayer1Settings
.Color
,
2877 gPlayer1Settings
.Team
, False));
2878 if gPlayer1
= nil then
2880 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2884 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2888 if nPlayers
>= 2 then
2890 // Создание второго игрока:
2891 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2892 gPlayer2Settings
.Color
,
2893 gPlayer2Settings
.Team
, False));
2894 if gPlayer2
= nil then
2896 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2900 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2904 // Загрузка и запуск карты:
2905 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
2907 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2911 // Нет точек появления:
2912 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2913 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2914 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2915 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2916 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2918 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2922 // Настройки игроков и ботов:
2926 for i
:= nPl
+1 to nPlayers
do
2927 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2930 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
2931 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
2932 Options
: LongWord; nPlayers
: Byte;
2933 IPAddr
: LongWord; Port
: Word);
2936 g_Net_Slist_ServerClosed();
2938 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
2940 g_Game_ClearLoading();
2943 gGameSettings
.GameType
:= GT_SERVER
;
2944 gGameSettings
.GameMode
:= GameMode
;
2945 gSwitchGameMode
:= GameMode
;
2946 gGameSettings
.TimeLimit
:= TimeLimit
;
2947 gGameSettings
.GoalLimit
:= GoalLimit
;
2948 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2949 gGameSettings
.Options
:= Options
;
2951 gCoopTotalMonstersKilled
:= 0;
2952 gCoopTotalSecretsFound
:= 0;
2953 gCoopTotalMonsters
:= 0;
2954 gCoopTotalSecrets
:= 0;
2958 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2959 gLMSRespawnTime
:= 0;
2960 gSpectLatchPID1
:= 0;
2961 gSpectLatchPID2
:= 0;
2963 g_Game_ExecuteEvent('ongamestart');
2965 // Режим наблюдателя:
2966 if nPlayers
= 0 then
2972 if nPlayers
>= 1 then
2974 // Создание первого игрока:
2975 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2976 gPlayer1Settings
.Color
,
2977 gPlayer1Settings
.Team
, False));
2978 if gPlayer1
= nil then
2980 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2984 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2987 if nPlayers
>= 2 then
2989 // Создание второго игрока:
2990 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2991 gPlayer2Settings
.Color
,
2992 gPlayer2Settings
.Team
, False));
2993 if gPlayer2
= nil then
2995 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2999 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3002 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3003 if NetForwardPorts
then
3004 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3007 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3009 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3013 g_Net_Slist_Set(NetMasterList
);
3015 g_Net_Slist_ServerStarted();
3017 // Загрузка и запуск карты:
3018 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3020 g_Net_Slist_ServerClosed();
3021 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3025 // Нет точек появления:
3026 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3027 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3028 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3029 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3030 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3032 g_Net_Slist_ServerClosed();
3033 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3037 // Настройки игроков и ботов:
3040 g_Net_Slist_ServerMapStarted();
3041 NetState
:= NET_STATE_GAME
;
3044 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3059 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3060 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3062 g_Game_ClearLoading();
3065 gGameSettings
.GameType
:= GT_CLIENT
;
3067 gCoopTotalMonstersKilled
:= 0;
3068 gCoopTotalSecretsFound
:= 0;
3069 gCoopTotalMonsters
:= 0;
3070 gCoopTotalSecrets
:= 0;
3074 g_Game_ExecuteEvent('ongamestart');
3076 NetState
:= NET_STATE_AUTH
;
3078 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3080 // create (or update) map/resource databases
3081 g_Res_CreateDatabases(true);
3083 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3084 gLMSRespawnTime
:= 0;
3085 gSpectLatchPID1
:= 0;
3086 gSpectLatchPID2
:= 0;
3089 if not g_Net_Connect(Addr
, Port
) then
3091 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3092 NetState
:= NET_STATE_NONE
;
3096 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3098 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3103 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3104 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3105 // thank you, enet. let's ignore failures altogether then.
3106 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3108 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3110 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
3112 // ignore all download packets, they're processed by separate code
3113 enet_packet_destroy(NetEvent
.packet
);
3116 Ptr
:= NetEvent
.packet
^.data
;
3117 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3119 enet_packet_destroy(NetEvent
.packet
);
3123 InMsg
.ReadLongWord(); // skip size
3124 MID
:= InMsg
.ReadByte();
3126 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3128 NetMyID
:= InMsg
.ReadByte();
3129 NetPlrUID1
:= InMsg
.ReadWord();
3131 WadName
:= InMsg
.ReadString();
3132 Map
:= InMsg
.ReadString();
3134 gWADHash
:= InMsg
.ReadMD5();
3136 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3137 gSwitchGameMode
:= gGameSettings
.GameMode
;
3138 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
3139 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3140 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3141 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3142 T
:= InMsg
.ReadLongWord();
3144 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3145 //if newResPath = '' then
3147 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3148 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3149 if newResPath
= '' then
3151 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3152 enet_packet_destroy(NetEvent
.packet
);
3153 NetState
:= NET_STATE_NONE
;
3156 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3158 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3161 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3162 gPlayer1Settings
.Color
,
3163 gPlayer1Settings
.Team
, False));
3165 if gPlayer1
= nil then
3167 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3169 enet_packet_destroy(NetEvent
.packet
);
3170 NetState
:= NET_STATE_NONE
;
3174 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3175 gPlayer1
.UID
:= NetPlrUID1
;
3176 gPlayer1
.Reset(True);
3178 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3180 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3182 enet_packet_destroy(NetEvent
.packet
);
3183 NetState
:= NET_STATE_NONE
;
3191 enet_packet_destroy(NetEvent
.packet
);
3195 enet_packet_destroy(NetEvent
.packet
);
3199 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3202 if (NetEvent
.data
<= NET_DISC_MAX
) then
3203 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3204 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3211 ProcessLoading(true);
3213 if g_Net_UserRequestExit() then
3222 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3223 NetState
:= NET_STATE_NONE
;
3228 NetState
:= NET_STATE_GAME
;
3229 MC_SEND_FullStateRequest
;
3230 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3234 lastAsMegaWad
: Boolean = false;
3236 procedure g_Game_ChangeMap(const MapPath
: String);
3240 g_Game_ClearLoading();
3242 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3243 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3244 if gExitByTrigger
then
3247 gExitByTrigger
:= False;
3249 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3250 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3253 procedure g_Game_Restart();
3257 if g_Game_IsClient
then
3259 map
:= g_ExtractFileName(gMapInfo
.Map
);
3260 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3264 g_Game_ClearLoading();
3265 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3268 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3270 NewWAD
, ResName
: String;
3274 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3275 g_Player_RemoveAllCorpses();
3277 if (not g_Game_IsClient
) and
3278 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3279 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3281 if gSwitchGameMode
= GM_CTF
then
3282 gGameSettings
.MaxLives
:= 0;
3283 gGameSettings
.GameMode
:= gSwitchGameMode
;
3286 gSwitchGameMode
:= gGameSettings
.GameMode
;
3288 g_Player_ResetTeams();
3290 lastAsMegaWad
:= asMegawad
;
3291 if isWadPath(Map
) then
3293 NewWAD
:= g_ExtractWadName(Map
);
3294 ResName
:= g_ExtractFileName(Map
);
3295 if g_Game_IsServer
then
3297 nws
:= findDiskWad(NewWAD
);
3298 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3301 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3302 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3306 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3307 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3309 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3310 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3312 if (length(nws
) = 0) then
3314 ResName
:= ''; // failed
3319 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3320 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3321 g_Game_LoadWAD(NewWAD
);
3326 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3327 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3332 NewWAD
:= gGameSettings
.WAD
;
3338 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3340 if (ResName
<> '') and (NewWAD
<> '') then
3342 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3343 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3345 r_Render_LoadTextures
;
3350 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3352 gState
:= STATE_NONE
;
3353 {$IFDEF ENABLE_MENU}
3354 g_ActiveWindow
:= nil;
3359 wNeedTimeReset
:= True;
3361 if gGameSettings
.GameMode
= GM_CTF
then
3363 g_Map_ResetFlag(FLAG_RED
);
3364 g_Map_ResetFlag(FLAG_BLUE
);
3365 // CTF, а флагов нет:
3366 if not g_Map_HaveFlagPoints() then
3367 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3372 gState
:= STATE_MENU
;
3377 gPauseMain
:= false;
3378 gPauseHolmes
:= false;
3379 NetTimeToUpdate
:= 1;
3380 NetTimeToReliable
:= 0;
3381 NetTimeToMaster
:= NetMasterRate
;
3382 gSpectLatchPID1
:= 0;
3383 gSpectLatchPID2
:= 0;
3384 gMissionFailed
:= False;
3387 gCoopMonstersKilled
:= 0;
3388 gCoopSecretsFound
:= 0;
3390 gVoteInProgress
:= False;
3391 gVotePassed
:= False;
3397 if not gGameOn
then Exit
;
3399 g_Game_SpectateCenterView();
3401 if g_Game_IsServer
then
3403 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3405 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3406 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3407 gLMSSoftSpawn
:= True;
3408 if g_Game_IsNet
then
3409 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3413 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3414 gLMSRespawnTime
:= 0;
3418 if NetMode
= NET_SERVER
then
3420 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3423 g_Net_Slist_ServerMapStarted();
3425 if NetClients
<> nil then
3426 for I
:= 0 to High(NetClients
) do
3427 if NetClients
[I
].Used
then
3429 NetClients
[I
].Voted
:= False;
3430 if NetClients
[I
].RequestedFullUpdate
then
3432 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3433 NetClients
[I
].RequestedFullUpdate
:= False;
3437 g_Net_UnbanNonPermHosts();
3442 gCoopTotalMonstersKilled
:= 0;
3443 gCoopTotalSecretsFound
:= 0;
3444 gCoopTotalMonsters
:= 0;
3445 gCoopTotalSecrets
:= 0;
3449 g_Game_ExecuteEvent('onmapstart');
3452 procedure SetFirstLevel
;
3456 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3457 if MapList
= nil then
3460 SortSArray(MapList
);
3461 gNextMap
:= MapList
[Low(MapList
)];
3466 procedure g_Game_ExitLevel(const Map
: AnsiString);
3470 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3471 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3472 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3473 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3475 // Вышли в выход в Одиночной игре:
3476 if gGameSettings
.GameType
= GT_SINGLE
then
3477 gExit
:= EXIT_ENDLEVELSINGLE
3478 else // Вышли в выход в Своей игре
3480 gExit
:= EXIT_ENDLEVELCUSTOM
;
3481 if gGameSettings
.GameMode
= GM_COOP
then
3482 g_Player_RememberAll
;
3484 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3487 if gGameSettings
.GameMode
= GM_COOP
then
3490 gStatsPressed
:= True;
3491 gNextMap
:= 'MAP01';
3493 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3496 if g_Game_IsNet
then
3498 MH_SEND_GameStats();
3499 MH_SEND_CoopStats();
3505 procedure g_Game_RestartLevel();
3509 if gGameSettings
.GameMode
= GM_SINGLE
then
3514 gExit
:= EXIT_ENDLEVELCUSTOM
;
3515 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3519 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3521 gWAD
{, xwad}: String;
3524 if not g_Game_IsClient
then Exit
;
3525 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3527 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3532 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3536 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3539 g_Game_LoadWAD(NewWAD
);
3543 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3544 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3547 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3548 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3552 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3556 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3557 g_Game_LoadWAD(NewWAD);
3561 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3563 i
, n
, nb
, nr
: Integer;
3565 if not g_Game_IsServer
then Exit
;
3566 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3567 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3568 gLMSRespawnTime
:= 0;
3571 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3573 gMissionFailed
:= True;
3574 g_Game_RestartLevel
;
3578 n
:= 0; nb
:= 0; nr
:= 0;
3579 for i
:= Low(gPlayers
) to High(gPlayers
) do
3580 if (gPlayers
[i
] <> nil) and
3581 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3582 (gPlayers
[i
] is TBot
)) then
3585 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3586 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3589 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3591 // wait a second until the fuckers finally decide to join
3592 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3593 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3594 gLMSSoftSpawn
:= NoMapRestart
;
3595 if g_Game_IsNet
then
3596 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3600 g_Player_RemoveAllCorpses
;
3601 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3602 if g_Game_IsNet
then
3603 MH_SEND_GameEvent(NET_EV_LMS_START
);
3605 for i
:= Low(gPlayers
) to High(gPlayers
) do
3607 if gPlayers
[i
] = nil then continue
;
3608 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3609 // don't touch normal spectators
3610 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3612 gPlayers
[i
].FNoRespawn
:= True;
3613 gPlayers
[i
].Lives
:= 0;
3614 if g_Game_IsNet
then
3615 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3618 gPlayers
[i
].FNoRespawn
:= False;
3619 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3620 gPlayers
[i
].Respawn(False, True);
3621 if gGameSettings
.GameMode
= GM_COOP
then
3623 gPlayers
[i
].Frags
:= 0;
3624 gPlayers
[i
].RecallState
;
3626 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3627 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3628 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3629 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3632 g_Items_RestartRound();
3634 gLMSSoftSpawn
:= False;
3637 function g_Game_GetFirstMap(WAD
: String): String;
3641 MapList
:= g_Map_GetMapsList(WAD
);
3642 if MapList
= nil then
3645 SortSArray(MapList
);
3646 Result
:= MapList
[Low(MapList
)];
3648 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3654 function g_Game_GetNextMap(): String;
3661 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3662 if MapList
= nil then
3665 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3667 SortSArray(MapList
);
3669 for I
:= Low(MapList
) to High(MapList
) do
3670 if Map
= MapList
[I
] then
3676 if MapIndex
<> -255 then
3678 if MapIndex
= High(MapList
) then
3679 Result
:= MapList
[Low(MapList
)]
3681 Result
:= MapList
[MapIndex
+ 1];
3683 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3689 procedure g_Game_NextLevel();
3691 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3692 gExit
:= EXIT_ENDLEVELCUSTOM
3695 gExit
:= EXIT_ENDLEVELSINGLE
;
3699 if gNextMap
<> '' then Exit
;
3700 gNextMap
:= g_Game_GetNextMap();
3703 function g_Game_IsTestMap(): Boolean;
3705 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3708 procedure g_Game_DeleteTestMap();
3711 //MapName: AnsiString;
3719 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3720 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3721 if (a
= 0) then exit
;
3723 // Выделяем имя wad-файла и имя карты
3724 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3725 Delete(gMapToDelete
, 1, a
+5);
3726 gMapToDelete
:= UpperCase(gMapToDelete
);
3728 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3731 // Имя карты не стандартное тестовое:
3732 if MapName <> TEST_MAP_NAME then
3735 if not gTempDelete then
3737 time := g_GetFileTime(WadName);
3738 WAD := TWADFile.Create();
3741 if not WAD.ReadFile(WadName) then
3742 begin // Нет такого WAD-файла
3747 // Составляем список карт и ищем нужную:
3749 MapList := WAD.GetResourcesList('');
3751 if MapList <> nil then
3752 for a := 0 to High(MapList) do
3753 if MapList[a] = MapName then
3755 // Удаляем и сохраняем:
3756 WAD.RemoveResource('', MapName);
3757 WAD.SaveTo(WadName);
3762 g_SetFileTime(WadName, time);
3765 if gTempDelete
then DeleteFile(WadName
);
3768 procedure GameCVars(P
: SSArray
);
3771 stat
: TPlayerStatArray
;
3774 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3778 if Length(P
) > 1 then
3783 gsGameFlags
:= gsGameFlags
or Flag
3785 gsGameFlags
:= gsGameFlags
and (not Flag
);
3787 if g_Game_IsServer
then
3790 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3792 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3793 if g_Game_IsNet
then MH_SEND_GameSettings
;
3797 if LongBool(gsGameFlags
and Flag
) then
3798 g_Console_Add(_lc
[OnMsg
])
3800 g_Console_Add(_lc
[OffMsg
]);
3802 if OnMapChange
and g_Game_IsServer
then
3803 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3808 cmd
:= LowerCase(P
[0]);
3810 if cmd
= 'g_gamemode' then
3812 if (Length(P
) > 1) then
3814 a
:= g_Game_TextToMode(P
[1]);
3815 if a
= GM_SINGLE
then a
:= GM_COOP
;
3816 gsGameMode
:= g_Game_ModeToText(a
);
3817 if g_Game_IsServer
then
3819 gSwitchGameMode
:= a
;
3820 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3821 (gState
= STATE_INTERSINGLE
) then
3822 gSwitchGameMode
:= GM_SINGLE
;
3824 gGameSettings
.GameMode
:= gSwitchGameMode
;
3828 if gSwitchGameMode
= gGameSettings
.GameMode
then
3829 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3830 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3832 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3833 [g_Game_ModeToText(gGameSettings
.GameMode
),
3834 g_Game_ModeToText(gSwitchGameMode
)]));
3836 else if cmd
= 'g_friendlyfire' then
3838 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3840 else if cmd
= 'g_friendly_absorb_damage' then
3842 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3844 else if cmd
= 'g_friendly_hit_trace' then
3846 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3848 else if cmd
= 'g_friendly_hit_projectile' then
3850 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3852 else if cmd
= 'g_weaponstay' then
3854 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3856 else if cmd
= 'g_allow_exit' then
3858 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3860 else if cmd
= 'g_allow_monsters' then
3862 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3864 else if cmd
= 'g_bot_vsplayers' then
3866 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3868 else if cmd
= 'g_bot_vsmonsters' then
3870 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3872 else if cmd
= 'g_dm_keys' then
3874 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
3876 else if cmd
= 'g_gameflags' then
3878 if Length(P
) > 1 then
3880 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
3881 if g_Game_IsServer
then
3883 gGameSettings
.Options
:= gsGameFlags
;
3884 if g_Game_IsNet
then MH_SEND_GameSettings
;
3888 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
3890 else if cmd
= 'g_warmup_time' then
3892 if Length(P
) > 1 then
3894 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
3895 if g_Game_IsServer
then
3897 gGameSettings
.WarmupTime
:= gsWarmupTime
;
3898 // extend warmup if it's already going
3899 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
3901 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
3902 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3904 if g_Game_IsNet
then MH_SEND_GameSettings
;
3908 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
3909 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3911 else if cmd
= 'g_spawn_invul' then
3913 if Length(P
) > 1 then
3915 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
3916 if g_Game_IsServer
then
3918 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
3919 if g_Game_IsNet
then MH_SEND_GameSettings
;
3923 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
3925 else if cmd
= 'g_item_respawn_time' then
3927 if Length(P
) > 1 then
3929 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
3930 if g_Game_IsServer
then
3932 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
3933 if g_Game_IsNet
then MH_SEND_GameSettings
;
3937 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
3938 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3940 else if cmd
= 'sv_intertime' then
3942 if (Length(P
) > 1) then
3943 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
3945 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
3947 else if cmd
= 'g_max_particles' then
3949 if Length(p
) = 2 then
3952 a
:= Max(0, StrToInt(p
[1]));
3956 else if Length(p
) = 1 then
3959 e_LogWritefln('%s', [g_GFX_GetMax()])
3961 e_LogWritefln('%s', [0])
3966 e_LogWritefln('usage: %s <n>', [cmd
])
3969 else if cmd
= 'g_max_shells' then
3971 if Length(p
) = 2 then
3973 a
:= Max(0, StrToInt(p
[1]));
3976 else if Length(p
) = 1 then
3978 e_LogWritefln('%s', [g_Shells_GetMax()])
3982 e_LogWritefln('usage: %s <n>', [cmd
])
3985 else if cmd
= 'g_max_gibs' then
3987 if Length(p
) = 2 then
3989 a
:= Max(0, StrToInt(p
[1]));
3992 else if Length(p
) = 1 then
3994 e_LogWritefln('%s', [g_Gibs_GetMax()])
3998 e_LogWritefln('usage: %s <n>', [cmd
])
4001 else if cmd
= 'g_max_corpses' then
4003 if Length(p
) = 2 then
4005 a
:= Max(0, StrToInt(p
[1]));
4008 else if Length(p
) = 1 then
4010 e_LogWritefln('%s', [g_Corpses_GetMax()])
4014 e_LogWritefln('usage: %s <n>', [cmd
])
4017 else if cmd
= 'g_scorelimit' then
4019 if Length(P
) > 1 then
4021 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
4023 if g_Game_IsServer
then
4026 if gGameSettings
.GameMode
= GM_DM
then
4028 stat
:= g_Player_GetStats();
4030 for a
:= 0 to High(stat
) do
4031 if stat
[a
].Frags
> b
then
4035 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4037 // if someone has a higher score, set it to that instead
4038 gsGoalLimit
:= max(gsGoalLimit
, b
);
4039 gGameSettings
.GoalLimit
:= gsGoalLimit
;
4041 if g_Game_IsNet
then MH_SEND_GameSettings
;
4045 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
4047 else if cmd
= 'g_timelimit' then
4049 if Length(P
) > 1 then
4051 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4052 if g_Game_IsServer
then
4054 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4055 if g_Game_IsNet
then MH_SEND_GameSettings
;
4058 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4059 [gsTimeLimit
div 3600,
4060 (gsTimeLimit
div 60) mod 60,
4061 gsTimeLimit
mod 60]));
4063 else if cmd
= 'g_maxlives' then
4065 if Length(P
) > 1 then
4067 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4068 if g_Game_IsServer
then
4070 gGameSettings
.MaxLives
:= gsMaxLives
;
4071 if g_Game_IsNet
then MH_SEND_GameSettings
;
4075 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4079 procedure PlayerSettingsCVars(P
: SSArray
);
4084 function ParseTeam(s
: string): Byte;
4088 'red', '1': result
:= TEAM_RED
;
4089 'blue', '2': result
:= TEAM_BLUE
;
4090 else result
:= TEAM_NONE
;
4094 cmd
:= LowerCase(P
[0]);
4098 if (Length(P
) > 1) then
4100 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4101 if g_Game_IsClient
then
4102 MC_SEND_PlayerSettings
4103 else if gGameOn
and (gPlayer1
<> nil) then
4105 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4106 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4112 if (Length(P
) > 1) then
4114 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4115 if g_Game_IsClient
then
4116 MC_SEND_PlayerSettings
4117 else if gGameOn
and (gPlayer2
<> nil) then
4119 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4120 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4126 if Length(P
) > 3 then
4128 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4129 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4130 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4131 if g_Game_IsClient
then
4132 MC_SEND_PlayerSettings
4133 else if gGameOn
and (gPlayer1
<> nil) then
4135 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4136 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4142 if Length(P
) > 3 then
4144 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4145 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4146 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4147 if g_Game_IsClient
then
4148 MC_SEND_PlayerSettings
4149 else if gGameOn
and (gPlayer2
<> nil) then
4151 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4152 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4158 if (Length(P
) > 1) then
4160 gPlayer1Settings
.Model
:= P
[1];
4161 if g_Game_IsClient
then
4162 MC_SEND_PlayerSettings
4163 else if gGameOn
and (gPlayer1
<> nil) then
4165 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4166 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4167 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4173 if (Length(P
) > 1) then
4175 gPlayer2Settings
.Model
:= P
[1];
4176 if g_Game_IsClient
then
4177 MC_SEND_PlayerSettings
4178 else if gGameOn
and (gPlayer2
<> nil) then
4180 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4181 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4182 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4188 // TODO: switch teams if in game or store this separately
4189 if (Length(P
) > 1) then
4191 team
:= ParseTeam(P
[1]);
4192 if team
= TEAM_NONE
then
4193 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4194 else if not gGameOn
and not g_Game_IsNet
then
4195 gPlayer1Settings
.Team
:= team
4197 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4202 // TODO: switch teams if in game or store this separately
4203 if (Length(P
) > 1) then
4205 team
:= ParseTeam(P
[1]);
4206 if team
= TEAM_NONE
then
4207 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4208 else if not gGameOn
and not g_Game_IsNet
then
4209 gPlayer2Settings
.Team
:= team
4211 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4217 procedure PrintHeapStats();
4221 hs
:= GetFPCHeapStatus();
4222 e_LogWriteLn ('v===== heap status =====v');
4223 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4224 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4225 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4226 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4227 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4228 e_LogWriteLn ('^=======================^');
4231 procedure DebugCommands(P
: SSArray
);
4238 // Команды отладочного режима:
4239 if {gDebugMode}conIsCheatsEnabled
then
4241 cmd
:= LowerCase(P
[0]);
4242 if cmd
= 'd_window' then
4244 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4245 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4247 else if cmd
= 'd_sounds' then
4249 if (Length(P
) > 1) and
4250 ((P
[1] = '1') or (P
[1] = '0')) then
4251 g_Debug_Sounds
:= (P
[1][1] = '1');
4253 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4255 else if cmd
= 'd_frames' then
4257 if (Length(P
) > 1) and
4258 ((P
[1] = '1') or (P
[1] = '0')) then
4259 g_Debug_Frames
:= (P
[1][1] = '1');
4261 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4263 else if cmd
= 'd_winmsg' then
4265 if (Length(P
) > 1) and
4266 ((P
[1] = '1') or (P
[1] = '0')) then
4267 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4269 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4271 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4273 if (Length(P
) > 1) and
4274 ((P
[1] = '1') or (P
[1] = '0')) then
4275 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4277 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4279 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4281 if Length(P
) > 1 then
4283 '0': g_debug_BotAIOff
:= 0;
4284 '1': g_debug_BotAIOff
:= 1;
4285 '2': g_debug_BotAIOff
:= 2;
4286 '3': g_debug_BotAIOff
:= 3;
4289 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4291 else if cmd
= 'd_monster' then
4293 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4294 if Length(P
) < 2 then
4296 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4297 g_Console_Add('ID | Name');
4298 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4299 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4300 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4303 a
:= StrToIntDef(P
[1], 0);
4304 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4305 a
:= g_Mons_TypeIdByName(P
[1]);
4307 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4308 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4311 with gPlayer1
.Obj
do
4313 mon
:= g_Monsters_Create(a
,
4314 X
+ Rect
.X
+ (Rect
.Width
div 2),
4315 Y
+ Rect
.Y
+ Rect
.Height
,
4316 gPlayer1
.Direction
, True);
4318 if (Length(P
) > 2) and (mon
<> nil) then
4320 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4321 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4322 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4323 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4324 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4325 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4326 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4327 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4328 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4333 else if (cmd
= 'd_health') then
4335 if (Length(P
) > 1) and
4336 ((P
[1] = '1') or (P
[1] = '0')) then
4337 g_debug_HealthBar
:= (P
[1][1] = '1');
4339 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4341 else if (cmd
= 'd_player') then
4343 if (Length(P
) > 1) and
4344 ((P
[1] = '1') or (P
[1] = '0')) then
4345 g_debug_Player
:= (P
[1][1] = '1');
4347 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4349 else if (cmd
= 'd_mem') then
4355 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4359 procedure GameCheats(P
: SSArray
);
4365 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4367 g_Console_Add('not available');
4373 g_Console_Add('where is the player?!');
4376 cmd
:= LowerCase(P
[0]);
4380 plr
.GodMode
:= not plr
.GodMode
;
4381 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4384 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4385 if cmd
= 'give' then
4387 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4388 for f
:= 1 to High(P
) do
4390 cmd
:= LowerCase(P
[f
]);
4391 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4392 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4393 if cmd
= 'exit' then
4395 if gTriggers
<> nil then
4397 for a
:= 0 to High(gTriggers
) do
4399 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4401 g_Console_Add('player left the map');
4402 gExitByTrigger
:= True;
4403 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4404 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4412 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4413 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4414 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4415 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4416 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4418 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4419 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4421 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4422 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;
4424 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4425 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4427 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4428 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4430 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4431 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4433 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4434 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4435 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4437 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4438 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4439 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4440 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;
4441 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4442 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4444 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;
4445 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;
4446 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;
4447 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;
4448 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;
4449 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;
4451 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4452 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;
4454 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;
4455 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;
4457 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4459 if cmd
= 'ammo' then
4461 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4462 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4463 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4464 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4465 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4466 g_Console_Add('player got some ammo');
4470 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4471 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4473 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4474 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4476 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4477 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4479 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4480 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4482 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4484 if cmd
= 'weapons' then
4486 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4487 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4488 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4489 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4490 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4491 plr
.GiveItem(ITEM_WEAPON_BFG
);
4492 g_Console_Add('player got weapons');
4496 if cmd
= 'keys' then
4498 plr
.GiveItem(ITEM_KEY_RED
);
4499 plr
.GiveItem(ITEM_KEY_GREEN
);
4500 plr
.GiveItem(ITEM_KEY_BLUE
);
4501 g_Console_Add('player got all keys');
4505 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4510 if cmd
= 'open' then
4512 g_Console_Add('player activated sesame');
4513 g_Triggers_OpenAll();
4520 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4524 if cmd
= 'noclip' then
4527 g_Console_Add('wall hardeness adjusted');
4531 if cmd
= 'notarget' then
4533 plr
.NoTarget
:= not plr
.NoTarget
;
4534 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4538 if cmd
= 'noreload' then
4540 plr
.NoReload
:= not plr
.NoReload
;
4541 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4545 if cmd
= 'speedy' then
4547 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4548 g_Console_Add('speed adjusted');
4552 if cmd
= 'jumpy' then
4554 VEL_JUMP
:= 30-VEL_JUMP
;
4555 g_Console_Add('jump height adjusted');
4559 if cmd
= 'automap' then
4561 gShowMap
:= not gShowMap
;
4562 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4566 if cmd
= 'aimline' then
4568 gAimLine
:= not gAimLine
;
4569 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4574 procedure GameCommands(P
: SSArray
);
4580 pl
: pTNetClient
= nil;
4588 cmd
:= LowerCase(P
[0]);
4590 if cmd
= 'pause' then
4592 {$IFDEF ENABLE_MENU}
4593 if (g_ActiveWindow
= nil) then
4594 g_Game_Pause(not gPauseMain
);
4596 g_Game_Pause(not gPauseMain
);
4599 else if cmd
= 'endgame' then
4600 gExit
:= EXIT_SIMPLE
4601 else if cmd
= 'restart' then
4603 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4605 if g_Game_IsClient
then
4607 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4612 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4614 else if cmd
= 'kick' then
4616 if g_Game_IsServer
then
4618 if Length(P
) < 2 then
4620 g_Console_Add('kick <name>');
4625 g_Console_Add('kick <name>');
4629 if g_Game_IsNet
then
4630 pl
:= g_Net_Client_ByName(P
[1]);
4633 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4634 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4635 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4636 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4637 g_Net_Slist_ServerPlayerLeaves();
4638 end else if gPlayers
<> nil then
4639 for a
:= Low(gPlayers
) to High(gPlayers
) do
4640 if gPlayers
[a
] <> nil then
4641 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4643 // Не отключать основных игроков в сингле
4644 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4646 gPlayers
[a
].Lives
:= 0;
4647 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4648 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4649 g_Player_Remove(gPlayers
[a
].UID
);
4650 g_Net_Slist_ServerPlayerLeaves();
4651 // Если не перемешать, при добавлении новых ботов появятся старые
4655 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4657 else if cmd
= 'kick_id' then
4659 if g_Game_IsServer
and g_Game_IsNet
then
4661 if Length(P
) < 2 then
4663 g_Console_Add('kick_id <client ID>');
4668 g_Console_Add('kick_id <client ID>');
4672 a
:= StrToIntDef(P
[1], 0);
4673 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4675 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4677 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4678 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
4679 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4680 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4681 g_Net_Slist_ServerPlayerLeaves();
4685 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4687 else if cmd
= 'kick_pid' then
4689 if g_Game_IsServer
and g_Game_IsNet
then
4691 if Length(P
) < 2 then
4693 g_Console_Add('kick_pid <player ID>');
4698 g_Console_Add('kick_pid <player ID>');
4702 a
:= StrToIntDef(P
[1], 0);
4703 pl
:= g_Net_Client_ByPlayer(a
);
4704 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4706 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4707 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4708 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4709 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4710 g_Net_Slist_ServerPlayerLeaves();
4713 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4715 else if cmd
= 'ban' then
4717 if g_Game_IsServer
and g_Game_IsNet
then
4719 if Length(P
) < 2 then
4721 g_Console_Add('ban <name>');
4726 g_Console_Add('ban <name>');
4730 pl
:= g_Net_Client_ByName(P
[1]);
4733 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4734 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4735 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4736 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4737 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4738 g_Net_Slist_ServerPlayerLeaves();
4740 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4742 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4744 else if cmd
= 'ban_id' then
4746 if g_Game_IsServer
and g_Game_IsNet
then
4748 if Length(P
) < 2 then
4750 g_Console_Add('ban_id <client ID>');
4755 g_Console_Add('ban_id <client ID>');
4759 a
:= StrToIntDef(P
[1], 0);
4760 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4761 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4763 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4764 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
4765 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
4766 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4767 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4768 g_Net_Slist_ServerPlayerLeaves();
4771 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4773 else if cmd
= 'ban_pid' then
4775 if g_Game_IsServer
and g_Game_IsNet
then
4777 if Length(P
) < 2 then
4779 g_Console_Add('ban_pid <player ID>');
4784 g_Console_Add('ban_pid <player ID>');
4788 a
:= StrToIntDef(P
[1], 0);
4789 pl
:= g_Net_Client_ByPlayer(a
);
4790 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4792 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4793 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4794 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4795 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4796 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4797 g_Net_Slist_ServerPlayerLeaves();
4800 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4802 else if cmd
= 'permban' then
4804 if g_Game_IsServer
and g_Game_IsNet
then
4806 if Length(P
) < 2 then
4808 g_Console_Add('permban <name>');
4813 g_Console_Add('permban <name>');
4817 pl
:= g_Net_Client_ByName(P
[1]);
4820 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4821 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4822 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
4823 g_Net_SaveBanList();
4824 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4825 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4826 g_Net_Slist_ServerPlayerLeaves();
4828 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4830 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4832 else if cmd
= 'permban_id' then
4834 if g_Game_IsServer
and g_Game_IsNet
then
4836 if Length(P
) < 2 then
4838 g_Console_Add('permban_id <client ID>');
4843 g_Console_Add('permban_id <client ID>');
4847 a
:= StrToIntDef(P
[1], 0);
4848 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4849 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4851 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4852 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
4853 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
4854 g_Net_SaveBanList();
4855 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4856 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4857 g_Net_Slist_ServerPlayerLeaves();
4860 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4862 else if cmd
= 'permban_pid' then
4864 if g_Game_IsServer
and g_Game_IsNet
then
4866 if Length(P
) < 2 then
4868 g_Console_Add('permban_pid <player ID>');
4873 g_Console_Add('permban_pid <player ID>');
4877 a
:= StrToIntDef(P
[1], 0);
4878 pl
:= g_Net_Client_ByPlayer(a
);
4879 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4881 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4882 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4883 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
4884 g_Net_SaveBanList();
4885 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4886 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4887 g_Net_Slist_ServerPlayerLeaves();
4890 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4892 else if cmd
= 'permban_ip' then
4894 if g_Game_IsServer
and g_Game_IsNet
then
4896 if Length(P
) < 2 then
4898 g_Console_Add('permban_ip <IP address>');
4903 g_Console_Add('permban_ip <IP address>');
4907 g_Net_BanHost(P
[1]);
4908 g_Net_SaveBanList();
4909 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
4911 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4913 else if cmd
= 'unban' then
4915 if g_Game_IsServer
and g_Game_IsNet
then
4917 if Length(P
) < 2 then
4919 g_Console_Add('unban <IP Address>');
4924 g_Console_Add('unban <IP Address>');
4928 if g_Net_UnbanHost(P
[1]) then
4930 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
4931 g_Net_SaveBanList();
4933 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
4935 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4937 else if cmd
= 'clientlist' then
4939 if g_Game_IsServer
and g_Game_IsNet
then
4942 if NetClients
<> nil then
4943 for a
:= Low(NetClients
) to High(NetClients
) do
4944 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4946 plr
:= g_Player_Get(NetClients
[a
].Player
);
4947 if plr
= nil then continue
;
4949 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
4950 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
4953 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
4955 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4957 else if cmd
= 'connect' then
4959 if (NetMode
= NET_NONE
) then
4961 if Length(P
) < 2 then
4963 g_Console_Add('connect <IP> [port] [password]');
4968 g_Console_Add('connect <IP> [port] [password]');
4972 if Length(P
) > 2 then
4973 prt
:= StrToIntDef(P
[2], 25666)
4977 if Length(P
) > 3 then
4982 g_Game_StartClient(P
[1], prt
, pw
);
4985 else if cmd
= 'disconnect' then
4987 if (NetMode
= NET_CLIENT
) then
4990 else if cmd
= 'reconnect' then
4992 if (NetMode
= NET_SERVER
) then
4995 if (NetMode
= NET_CLIENT
) then
4998 gExit
:= EXIT_SIMPLE
;
5002 //TODO: Use last successful password to reconnect, instead of ''
5003 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5005 else if (cmd
= 'addbot') or
5006 (cmd
= 'bot_add') then
5008 if Length(P
) > 2 then
5009 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5010 else if Length(P
) > 1 then
5011 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5013 g_Bot_Add(TEAM_NONE
, 2);
5015 else if cmd
= 'bot_addlist' then
5017 if Length(P
) > 1 then
5019 if Length(P
) = 2 then
5020 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5021 else if Length(P
) = 3 then
5022 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5024 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5027 else if cmd
= 'bot_removeall' then
5029 else if cmd
= 'chat' then
5031 if g_Game_IsNet
then
5033 if Length(P
) > 1 then
5035 for a
:= 1 to High(P
) do
5036 chstr
:= chstr
+ P
[a
] + ' ';
5038 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5040 if Length(chstr
) < 1 then
5042 g_Console_Add('chat <text>');
5046 chstr
:= b_Text_Format(chstr
);
5047 if g_Game_IsClient
then
5048 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5050 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5053 g_Console_Add('chat <text>');
5055 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5057 else if cmd
= 'teamchat' then
5059 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5061 if Length(P
) > 1 then
5063 for a
:= 1 to High(P
) do
5064 chstr
:= chstr
+ P
[a
] + ' ';
5066 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5068 if Length(chstr
) < 1 then
5070 g_Console_Add('teamchat <text>');
5074 chstr
:= b_Text_Format(chstr
);
5075 if g_Game_IsClient
then
5076 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5078 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5079 gPlayer1Settings
.Team
);
5082 g_Console_Add('teamchat <text>');
5084 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5086 else if cmd
= 'game' then
5088 if gGameSettings
.GameType
<> GT_NONE
then
5090 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5093 if Length(P
) = 1 then
5095 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5098 // game not started yet, load fist map from some wad
5100 s
:= addWadExtension(P
[1]);
5101 found
:= e_FindResource(AllMapDirs
, s
);
5105 P
[1] := ExpandFileName(P
[1]);
5106 // if map not choosed then set first map
5107 if Length(P
) < 3 then
5110 P
[2] := g_Game_GetFirstMap(P
[1]);
5113 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5115 if g_Map_Exist(s
) then
5119 with gGameSettings
do
5121 Options
:= gsGameFlags
;
5122 GameMode
:= g_Game_TextToMode(gsGameMode
);
5123 if gSwitchGameMode
<> GM_NONE
then
5124 GameMode
:= gSwitchGameMode
;
5125 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5126 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5128 if Length(P
) >= 4 then
5129 b
:= StrToIntDef(P
[3], 1);
5130 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5131 GoalLimit
, MaxLives
, Options
, b
);
5136 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5138 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5140 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5142 else if cmd
= 'host' then
5144 if gGameSettings
.GameType
<> GT_NONE
then
5146 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5149 if Length(P
) < 4 then
5151 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5154 if not StrToIp(P
[1], listen
) then
5156 prt
:= StrToIntDef(P
[2], 25666);
5158 s
:= addWadExtension(P
[3]);
5159 found
:= e_FindResource(AllMapDirs
, s
);
5163 // get first map in wad, if not specified
5164 if Length(P
) < 5 then
5167 P
[4] := g_Game_GetFirstMap(P
[1]);
5169 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5170 if g_Map_Exist(s
) then
5174 with gGameSettings
do
5176 Options
:= gsGameFlags
;
5177 GameMode
:= g_Game_TextToMode(gsGameMode
);
5178 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5179 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5180 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5182 if Length(P
) >= 6 then
5183 b
:= StrToIntDef(P
[5], 0);
5184 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
5190 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5192 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5197 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5200 else if cmd
= 'map' then
5202 if Length(P
) = 1 then
5204 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5206 g_Console_Add(cmd
+ ' <MAP>');
5207 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5211 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5216 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5218 if Length(P
) < 3 then
5220 // first param is map or wad
5221 s
:= UpperCase(P
[1]);
5222 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5224 gExitByTrigger
:= False;
5227 // already in game, finish current map
5229 gExit
:= EXIT_ENDLEVELCUSTOM
;
5233 // intermission, so change map immediately
5240 found
:= e_FindResource(AllMapDirs
, s
);
5242 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5245 // no such map, found wad
5248 P
[1] := ExpandFileName(pw
);
5249 P
[2] := g_Game_GetFirstMap(P
[1]);
5250 s
:= P
[1] + ':\' + P
[2];
5251 if g_Map_Exist(s
) then
5253 gExitByTrigger
:= False;
5256 // already in game, finish current map
5258 gExit
:= EXIT_ENDLEVELCUSTOM
5262 // intermission, so change map immediately
5269 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5271 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5276 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5282 s
:= addWadExtension(P
[1]);
5283 found
:= e_FindResource(AllMapDirs
, s
);
5287 P
[2] := UpperCase(P
[2]);
5288 s
:= P
[1] + ':\' + P
[2];
5289 if g_Map_Exist(s
) then
5291 gExitByTrigger
:= False;
5295 gExit
:= EXIT_ENDLEVELCUSTOM
5304 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5309 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5315 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5319 else if cmd
= 'nextmap' then
5321 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5323 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5328 if Length(P
) = 1 then
5330 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5332 g_Console_Add(cmd
+ ' <MAP>');
5333 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5338 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5344 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5346 if Length(P
) < 3 then
5348 // first param is map or wad
5349 s
:= UpperCase(P
[1]);
5350 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5353 gExitByTrigger
:= False;
5359 // no such map, found wad
5360 pw
:= addWadExtension(P
[1]);
5361 found
:= e_FindResource(MapDirs
, pw
);
5363 found
:= e_FindResource(WadDirs
, pw
);
5365 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5368 // map not specified, select first map
5370 P
[2] := g_Game_GetFirstMap(P
[1]);
5371 s
:= P
[1] + ':\' + P
[2];
5372 if g_Map_Exist(s
) then
5374 gExitByTrigger
:= False;
5381 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5383 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5388 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5394 // specified two params wad + map
5395 pw
:= addWadExtension(P
[1]);
5396 found
:= e_FindResource(MapDirs
, pw
);
5398 found
:= e_FindResource(MapDirs
, pw
);
5402 P
[2] := UpperCase(P
[2]);
5403 s
:= P
[1] + ':\' + P
[2];
5404 if g_Map_Exist(s
) then
5406 gExitByTrigger
:= False;
5412 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5417 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5423 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5428 if gNextMap
= '' then
5429 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5431 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5435 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5439 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5443 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5445 gExitByTrigger
:= False;
5446 // next map not specified, try to find trigger EXIT
5447 if (gNextMap
= '') and (gTriggers
<> nil) then
5449 for a
:= 0 to High(gTriggers
) do
5451 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5453 gExitByTrigger
:= True;
5454 //gNextMap := gTriggers[a].Data.MapName;
5455 gNextMap
:= gTriggers
[a
].tgcMap
;
5460 if gNextMap
= '' then
5461 gNextMap
:= g_Game_GetNextMap();
5462 if not isWadPath(gNextMap
) then
5463 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5466 if g_Map_Exist(s
) then
5467 gExit
:= EXIT_ENDLEVELCUSTOM
5469 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5473 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5477 else if (cmd
= 'event') then
5479 if (Length(P
) <= 1) then
5481 for a
:= 0 to High(gEvents
) do
5482 if gEvents
[a
].Command
= '' then
5483 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5485 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5488 if (Length(P
) = 2) then
5490 for a
:= 0 to High(gEvents
) do
5491 if gEvents
[a
].Name
= P
[1] then
5492 if gEvents
[a
].Command
= '' then
5493 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5495 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5498 for a
:= 0 to High(gEvents
) do
5499 if gEvents
[a
].Name
= P
[1] then
5501 gEvents
[a
].Command
:= '';
5502 for b
:= 2 to High(P
) do
5503 if Pos(' ', P
[b
]) = 0 then
5504 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5506 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5507 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5511 else if cmd
= 'suicide' then
5515 if g_Game_IsClient
then
5516 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5519 if gPlayer1
<> nil then
5520 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5521 if gPlayer2
<> nil then
5522 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5526 else if cmd
= 'screenshot' then
5532 else if cmd
= 'weapon' then
5534 if Length(p
) = 2 then
5536 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
5537 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5538 gSelectWeapon
[0, a
] := True
5541 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5543 if Length(p
) = 2 then
5545 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
5546 b
:= ord(cmd
[2]) - ord('1');
5547 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5548 gSelectWeapon
[b
, a
] := True
5551 // Команды Своей игры:
5552 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5554 if cmd
= 'bot_addred' then
5556 if Length(P
) > 1 then
5557 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5559 g_Bot_Add(TEAM_RED
, 2);
5561 else if cmd
= 'bot_addblue' then
5563 if Length(P
) > 1 then
5564 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5566 g_Bot_Add(TEAM_BLUE
, 2);
5568 else if cmd
= 'spectate' then
5574 else if cmd
= 'say' then
5576 if g_Game_IsServer
and g_Game_IsNet
then
5578 if Length(P
) > 1 then
5581 for a
:= 1 to High(P
) do
5582 chstr
:= chstr
+ P
[a
] + ' ';
5584 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5586 if Length(chstr
) < 1 then
5588 g_Console_Add('say <text>');
5592 chstr
:= b_Text_Format(chstr
);
5593 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5595 else g_Console_Add('say <text>');
5597 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5599 else if cmd
= 'tell' then
5601 if g_Game_IsServer
and g_Game_IsNet
then
5603 if (Length(P
) > 2) and (P
[1] <> '') then
5606 for a
:= 2 to High(P
) do
5607 chstr
:= chstr
+ P
[a
] + ' ';
5609 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5611 if Length(chstr
) < 1 then
5613 g_Console_Add('tell <playername> <text>');
5617 pl
:= g_Net_Client_ByName(P
[1]);
5619 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5621 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5623 else g_Console_Add('tell <playername> <text>');
5625 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5627 else if cmd
= 'centerprint' then
5629 if (Length(P
) > 2) and (P
[1] <> '') then
5632 for a
:= 2 to High(P
) do
5633 chstr
:= chstr
+ P
[a
] + ' ';
5635 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5637 if Length(chstr
) < 1 then
5639 g_Console_Add('centerprint <timeout> <text>');
5643 a
:= StrToIntDef(P
[1], 100);
5644 chstr
:= b_Text_Format(chstr
);
5645 g_Game_Message(chstr
, a
);
5646 if g_Game_IsNet
and g_Game_IsServer
then
5647 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
5649 else g_Console_Add('centerprint <timeout> <text>');
5651 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5653 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5655 // Дополнительное время:
5656 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5658 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5659 [gGameSettings
.TimeLimit
div 3600,
5660 (gGameSettings
.TimeLimit
div 60) mod 60,
5661 gGameSettings
.TimeLimit
mod 60]));
5662 if g_Game_IsNet
then MH_SEND_GameSettings
;
5664 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5666 if (Length(P
) <= 1) then
5667 g_Console_Add('rcon_password <password>')
5669 MC_SEND_RCONPassword(P
[1]);
5671 else if cmd
= 'rcon' then
5673 if g_Game_IsClient
then
5675 if Length(P
) > 1 then
5678 for a
:= 1 to High(P
) do
5679 chstr
:= chstr
+ P
[a
] + ' ';
5681 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5683 if Length(chstr
) < 1 then
5685 g_Console_Add('rcon <command>');
5689 MC_SEND_RCONCommand(chstr
);
5691 else g_Console_Add('rcon <command>');
5694 else if cmd
= 'ready' then
5696 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5697 gLMSRespawnTime
:= gTime
+ 100;
5699 else if (cmd
= 'callvote') and g_Game_IsNet
then
5701 if Length(P
) > 1 then
5704 for a
:= 1 to High(P
) do begin
5705 if a
> 1 then chstr
:= chstr
+ ' ';
5706 chstr
:= chstr
+ P
[a
];
5709 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5711 if Length(chstr
) < 1 then
5713 g_Console_Add('callvote <command>');
5717 if g_Game_IsClient
then
5718 MC_SEND_Vote(True, chstr
)
5720 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5721 g_Console_Process('vote', True);
5724 g_Console_Add('callvote <command>');
5726 else if (cmd
= 'vote') and g_Game_IsNet
then
5728 if g_Game_IsClient
then
5730 else if gVoteInProgress
then
5732 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5733 a
:= Floor((NetClientCount
+1)/2.0) + 1
5735 a
:= Floor(NetClientCount
/2.0) + 1;
5740 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5741 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5747 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5748 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5756 procedure SystemCommands(P
: SSArray
);
5760 cmd
:= LowerCase(P
[0]);
5773 if Length(p
) = 2 then
5775 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
5777 gFrameTime
:= 1000 div gMaxFPS
5781 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
5785 if Length(p
) = 2 then
5787 gAskLanguage
:= true;
5788 gLanguage
:= LANGUAGE_ENGLISH
;
5789 case LowerCase(p
[1]) of
5792 gAskLanguage
:= false;
5793 gLanguage
:= LANGUAGE_ENGLISH
;
5797 gAskLanguage
:= false;
5798 gLanguage
:= LANGUAGE_RUSSIAN
;
5802 gAskLanguage
:= true;
5803 gLanguage
:= LANGUAGE_ENGLISH
;
5806 g_Language_Set(gLanguage
);
5810 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
5817 procedure g_TakeScreenShot(Filename
: string = '');
5818 var t
: TDateTime
; dir
, date
, name
: String;
5820 if e_NoGraphics
then
5823 dir
:= e_GetWriteableDir(ScreenshotDirs
);
5824 if Filename
= '' then
5827 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
5828 Filename
:= 'screenshot-' + date
;
5831 name
:= e_CatPath(dir
, Filename
+ '.png');
5832 if r_Render_WriteScreenShot(name
) then
5833 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
5835 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
5839 {$IFDEF ENABLE_MENU}
5840 procedure g_Game_InGameMenu(Show
: Boolean);
5842 if (g_ActiveWindow
= nil) and Show
then
5844 if gGameSettings
.GameType
= GT_SINGLE
then
5845 g_GUI_ShowWindow('GameSingleMenu')
5848 if g_Game_IsClient
then
5849 g_GUI_ShowWindow('GameClientMenu')
5851 if g_Game_IsNet
then
5852 g_GUI_ShowWindow('GameServerMenu')
5854 g_GUI_ShowWindow('GameCustomMenu');
5856 g_Sound_PlayEx('MENU_OPEN');
5858 // Пауза при меню только в одиночной игре:
5859 if (not g_Game_IsNet
) then
5863 if (g_ActiveWindow
<> nil) and (not Show
) then
5865 // Пауза при меню только в одиночной игре:
5866 if (not g_Game_IsNet
) then
5867 g_Game_Pause(False);
5872 procedure g_Game_Pause (Enable
: Boolean);
5876 if not gGameOn
then exit
;
5878 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
5881 gPauseMain
:= Enable
;
5883 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
5886 procedure g_Game_HolmesPause (Enable
: Boolean);
5890 if not gGameOn
then exit
;
5891 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
5894 gPauseHolmes
:= Enable
;
5896 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
5899 procedure g_Game_PauseAllSounds(Enable
: Boolean);
5904 if gTriggers
<> nil then
5905 for i
:= 0 to High(gTriggers
) do
5906 with gTriggers
[i
] do
5907 if (TriggerType
= TRIGGER_SOUND
) and
5909 Sound
.IsPlaying() then
5911 Sound
.Pause(Enable
);
5915 if gPlayers
<> nil then
5916 for i
:= 0 to High(gPlayers
) do
5917 if gPlayers
[i
] <> nil then
5918 gPlayers
[i
].PauseSounds(Enable
);
5921 if gMusic
<> nil then
5922 gMusic
.Pause(Enable
);
5925 procedure g_Game_StopAllSounds(all
: Boolean);
5929 if gTriggers
<> nil then
5930 for i
:= 0 to High(gTriggers
) do
5931 with gTriggers
[i
] do
5932 if (TriggerType
= TRIGGER_SOUND
) and
5936 if gMusic
<> nil then
5943 procedure g_Game_UpdateTriggerSounds
;
5946 if gTriggers
<> nil then
5947 for i
:= 0 to High(gTriggers
) do
5948 with gTriggers
[i
] do
5949 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
5950 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
5953 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
5956 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
5961 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
5966 if gSpectMode
<> SPECT_PLAYERS
then
5968 if gSpectPID1
= UID
then
5973 if gSpectViewTwo
and (gSpectPID2
= UID
) then
5980 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
5985 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
5990 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
5995 if gSpectMode
<> SPECT_PLAYERS
then
5997 Pl
:= g_Player_Get(gSpectPID1
);
5998 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6003 if gSpectViewTwo
then
6005 Pl
:= g_Player_Get(gSpectPID2
);
6006 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6014 procedure g_Game_Message (Msg
: string; Time
: Word);
6017 MessageTime
:= Time
;
6020 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6022 punct
: Array[0..13] of String =
6023 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6029 function IsPunctuation(S
: String): Boolean;
6034 if Length(S
) <> 1 then
6036 for i
:= Low(punct
) to High(punct
) do
6037 if S
= punct
[i
] then
6043 function FilterPunctuation(S
: String): String;
6047 for i
:= Low(punct
) to High(punct
) do
6048 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6054 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6056 // remove player name
6057 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6058 // for FullWord check
6059 Text := toLowerCase1251(' ' + Text + ' ');
6060 fpText
:= FilterPunctuation(Text);
6062 for i
:= 0 to Length(gChatSounds
) - 1 do
6065 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6067 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6068 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6070 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6076 gChatSounds
[i
].Sound
.Play();
6082 g_Sound_PlayEx('SOUND_GAME_RADIO');
6085 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6094 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6098 if goodsnd
[a
].IsPlaying() then
6101 goodsnd
[Random(4)].Play();
6104 procedure g_Game_Announce_KillCombo(Param
: Integer);
6111 UID
:= Param
and $FFFF;
6116 Pl
:= g_Player_Get(UID
);
6125 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6129 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6133 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6137 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6145 if not g_Game_IsWatchedPlayer(UID
) then
6148 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6152 if killsnd
[n
].IsPlaying() then
6157 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6165 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6169 if hahasnd
[a
].IsPlaying() then
6172 hahasnd
[Random(3)].Play();
6175 procedure g_Game_StartVote(Command
, Initiator
: string);
6179 if not gVotesEnabled
then Exit
;
6180 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6181 if gVoteInProgress
or gVotePassed
then
6183 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6184 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6187 gVoteInProgress
:= True;
6188 gVotePassed
:= False;
6189 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6192 gVoteCommand
:= Command
;
6194 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6195 Need
:= Floor((NetClientCount
+1)/2.0)+1
6197 Need
:= Floor(NetClientCount
/2.0)+1;
6198 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6199 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6202 procedure g_Game_CheckVote
;
6206 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6207 if not gVoteInProgress
then Exit
;
6209 if (gTime
>= gVoteTimer
) then
6211 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6212 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6214 Need
:= Floor(NetClientCount
/2.0) + 1;
6215 if gVoteCount
>= Need
then
6217 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6218 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6219 gVotePassed
:= True;
6220 gVoteCmdTimer
:= gTime
+ 5000;
6224 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6225 MH_SEND_VoteEvent(NET_VE_FAILED
);
6227 if NetClients
<> nil then
6228 for I
:= Low(NetClients
) to High(NetClients
) do
6229 if NetClients
[i
].Used
then
6230 NetClients
[i
].Voted
:= False;
6231 gVoteInProgress
:= False;
6237 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6238 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6240 Need
:= Floor(NetClientCount
/2.0) + 1;
6241 if gVoteCount
>= Need
then
6243 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6244 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6245 gVoteInProgress
:= False;
6246 gVotePassed
:= True;
6247 gVoteCmdTimer
:= gTime
+ 5000;
6250 if NetClients
<> nil then
6251 for I
:= Low(NetClients
) to High(NetClients
) do
6252 if NetClients
[i
].Used
then
6253 NetClients
[i
].Voted
:= False;
6258 procedure g_Game_LoadMapList(FileName
: string);
6266 if not FileExists(FileName
) then Exit
;
6268 AssignFile(ListFile
, FileName
);
6270 while not EOF(ListFile
) do
6272 ReadLn(ListFile
, s
);
6275 if s
= '' then Continue
;
6277 SetLength(MapList
, Length(MapList
)+1);
6278 MapList
[High(MapList
)] := s
;
6280 CloseFile(ListFile
);
6283 procedure g_Game_SetDebugMode();
6286 // Читы (даже в своей игре):
6290 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6294 if Length(LoadingStat
.Msgs
) = 0 then
6300 begin // Переходим на следующую строку или скроллируем:
6301 if NextMsg
= Length(Msgs
) then
6303 for i
:= 0 to High(Msgs
)-1 do
6304 Msgs
[i
] := Msgs
[i
+1];
6312 Msgs
[NextMsg
-1] := Text;
6316 PBarWasHere
:= false;
6319 {$IFDEF ENABLE_MENU}
6320 g_ActiveWindow
:= nil;
6323 ProcessLoading(true);
6326 procedure g_Game_StepLoading(Value
: Integer = -1);
6337 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6345 procedure g_Game_ClearLoading();
6354 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6355 if len
< 1 then len
:= 1;
6356 SetLength(Msgs
, len
);
6357 for len
:= Low(Msgs
) to High(Msgs
) do
6360 PBarWasHere
:= false;
6364 procedure Parse_Params(var pars
: TParamStrValues
);
6371 while i
<= ParamCount
do
6374 if (s
[1] = '-') and (Length(s
) > 1) then
6376 if (s
[2] = '-') and (Length(s
) > 2) then
6377 begin // Одиночный параметр
6378 SetLength(pars
, Length(pars
) + 1);
6379 with pars
[High(pars
)] do
6381 Name
:= LowerCase(s
);
6386 if (i
< ParamCount
) then
6387 begin // Параметр со значением
6389 SetLength(pars
, Length(pars
) + 1);
6390 with pars
[High(pars
)] do
6392 Name
:= LowerCase(s
);
6393 Value
:= LowerCase(ParamStr(i
));
6402 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6407 for i
:= 0 to High(pars
) do
6408 if pars
[i
].Name
= aName
then
6410 Result
:= pars
[i
].Value
;
6415 procedure g_Game_Process_Params();
6417 pars
: TParamStrValues
;
6420 LimT
, LimS
: Integer;
6431 s
:= Find_Param_Value(pars
, '--debug');
6434 g_Game_SetDebugMode();
6435 s
:= Find_Param_Value(pars
, '--netdump');
6440 // Connect when game loads
6441 ip
:= Find_Param_Value(pars
, '-connect');
6445 s
:= Find_Param_Value(pars
, '-port');
6446 if (s
= '') or not TryStrToInt(s
, Port
) then
6449 s
:= Find_Param_Value(pars
, '-pw');
6451 g_Game_StartClient(ip
, Port
, s
);
6455 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6458 gDefaultMegawadStart
:= s
;
6461 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6462 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6464 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6467 // Start map when game loads:
6468 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6469 if isWadPath(map
) then
6472 s
:= Find_Param_Value(pars
, '-gm');
6473 GMode
:= g_Game_TextToMode(s
);
6474 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6475 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6478 s
:= Find_Param_Value(pars
, '-limt');
6479 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6485 s
:= Find_Param_Value(pars
, '-lims');
6486 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6492 s
:= Find_Param_Value(pars
, '-lives');
6493 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6499 s
:= Find_Param_Value(pars
, '-opt');
6503 Opt
:= StrToIntDef(s
, 0);
6506 s
:= Find_Param_Value(pars
, '--close');
6510 // Override map to test:
6511 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6514 if e_IsValidResourceName(s
) then
6515 e_FindResource(AllMapDirs
, s
);
6516 gTestMap
:= ExpandFileName(s
);
6519 // Delete test map after play:
6520 s
:= Find_Param_Value(pars
, '--testdelete');
6523 //gMapToDelete := MapsDir + map;
6524 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6528 // Delete temporary WAD after play:
6529 s
:= Find_Param_Value(pars
, '--tempdelete');
6530 if (s
<> '') and (gTestMap
<> '') then
6532 gMapToDelete
:= gTestMap
;
6533 gTempDelete
:= True;
6536 // Number of players:
6537 s
:= Find_Param_Value(pars
, '-pl');
6539 n
:= DEFAULT_PLAYERS
6541 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6544 s
:= Find_Param_Value(pars
, '-port');
6545 if (s
= '') or not TryStrToInt(s
, Port
) then
6546 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6548 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6551 // Execute script when game loads:
6552 s
:= Find_Param_Value(pars
, '-exec');
6555 // if not isWadPath(s) then
6556 // s := GameDir + '/' + s;
6561 if IOResult
<> 0 then
6563 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6564 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6568 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6569 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6574 if IOResult
<> 0 then
6576 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6577 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6581 if Pos('#', s
) <> 1 then // script comment
6582 g_Console_Process(s
, True);
6593 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6594 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6595 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6596 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6598 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6599 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6600 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6601 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6604 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6605 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6608 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6609 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6611 {$IFDEF ENABLE_HOLMES}
6612 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6615 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6617 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6618 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6620 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6621 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6623 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6624 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6625 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6626 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
6627 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6628 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6629 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6630 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6631 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');