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
;
130 {$IFDEF ENABLE_RENDER}
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}
457 {$IFDEF ENABLE_SHELLS}
460 {$IFDEF ENABLE_CORPSES}
463 {$IFDEF ENABLE_RENDER}
466 {$IFDEF ENABLE_SYSTEM}
470 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
471 g_playermodel
, g_options
, Math
,
472 g_triggers
, g_monsters
, e_sound
, CONFIG
,
473 g_language
, g_net
, g_phys
,
474 ENet
, e_msg
, g_netmsg
, g_netmaster
,
478 charbuff
: packed array [0..15] of AnsiChar = (
479 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
482 function Translit (const S
: AnsiString): AnsiString;
487 for i
:= 1 to Length(Result
) do
490 #
$C9: Result
[i
] := 'Q';
491 #
$D6: Result
[i
] := 'W';
492 #
$D3: Result
[i
] := 'E';
493 #
$CA: Result
[i
] := 'R';
494 #
$C5: Result
[i
] := 'T';
495 #
$CD: Result
[i
] := 'Y';
496 #
$C3: Result
[i
] := 'U';
497 #
$D8: Result
[i
] := 'I';
498 #
$D9: Result
[i
] := 'O';
499 #
$C7: Result
[i
] := 'P';
500 #
$D5: Result
[i
] := '['; //Chr(219);
501 #
$DA: Result
[i
] := ']'; //Chr(221);
502 #
$D4: Result
[i
] := 'A';
503 #
$DB: Result
[i
] := 'S';
504 #
$C2: Result
[i
] := 'D';
505 #
$C0: Result
[i
] := 'F';
506 #
$CF: Result
[i
] := 'G';
507 #
$D0: Result
[i
] := 'H';
508 #
$CE: Result
[i
] := 'J';
509 #
$CB: Result
[i
] := 'K';
510 #
$C4: Result
[i
] := 'L';
511 #
$C6: Result
[i
] := ';'; //Chr(186);
512 #
$DD: Result
[i
] := #39; //Chr(222);
513 #
$DF: Result
[i
] := 'Z';
514 #
$D7: Result
[i
] := 'X';
515 #
$D1: Result
[i
] := 'C';
516 #
$CC: Result
[i
] := 'V';
517 #
$C8: Result
[i
] := 'B';
518 #
$D2: Result
[i
] := 'N';
519 #
$DC: Result
[i
] := 'M';
520 #
$C1: Result
[i
] := ','; //Chr(188);
521 #
$DE: Result
[i
] := '.'; //Chr(190);
527 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
532 ls2
:= Translit(CheatRus
[ct
]);
533 if length(ls1
) = 0 then ls1
:= '~';
534 if length(ls2
) = 0 then ls2
:= '~';
536 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
537 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
538 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
539 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
541 if ct = I_GAME_CHEAT_JETPACK then
543 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
544 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
545 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
546 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
547 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
548 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
564 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
565 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
566 or g_Game_IsNet then Exit;
568 if not gGameOn
then exit
;
569 if not conIsCheatsEnabled
then exit
;
571 s
:= 'SOUND_GAME_RADIO';
574 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
576 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
577 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
581 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
583 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
584 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
588 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
590 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
591 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
595 if CheckCheat(I_GAME_CHEAT_DEATH
) then
597 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
598 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
599 s
:= 'SOUND_MONSTER_HAHA';
603 if CheckCheat(I_GAME_CHEAT_DOORS
) then
605 g_Triggers_OpenAll();
609 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
611 if gTriggers
<> nil then
612 for a
:= 0 to High(gTriggers
) do
613 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
615 gExitByTrigger
:= True;
616 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
617 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
623 s2
:= Copy(charbuff
, 15, 2);
624 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
626 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
634 if CheckCheat(I_GAME_CHEAT_FLY
) then
640 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
642 VEL_JUMP
:= 30-VEL_JUMP
;
646 if CheckCheat(I_GAME_CHEAT_SPEED
) then
648 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
652 if CheckCheat(I_GAME_CHEAT_SUIT
) then
654 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
655 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
659 if CheckCheat(I_GAME_CHEAT_AIR
) then
661 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
662 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
666 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
668 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
669 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
673 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
675 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
676 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
680 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
682 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
683 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
687 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
689 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
690 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
694 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
696 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
697 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
700 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
702 gAimLine
:= not gAimLine
;
705 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
707 gShowMap
:= not gShowMap
;
718 procedure KeyPress (K
: Word);
719 var Msg
: g_gui
.TMessage
;
724 if (g_ActiveWindow
<> nil) then
726 Msg
.Msg
:= WM_KEYDOWN
;
727 Msg
.WParam
:= VK_ESCAPE
;
728 g_ActiveWindow
.OnMessage(Msg
);
729 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
731 else if (gState
<> STATE_FOLD
) then
733 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
735 g_Game_InGameMenu(True);
737 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
739 if (gState
<> STATE_MENU
) then
741 if (NetMode
<> NET_NONE
) then
743 g_Game_StopAllSounds(True);
745 gState
:= STATE_MENU
;
749 g_GUI_ShowWindow('MainMenu');
750 g_Sound_PlayEx('MENU_OPEN');
755 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
756 begin // <F2> .. <F6> � <F12>
757 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
759 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
760 if (not g_Game_IsNet
) then g_Game_Pause(True);
762 IK_F2
: g_Menu_Show_SaveMenu();
763 IK_F3
: g_Menu_Show_LoadMenu();
764 IK_F4
: g_Menu_Show_GameSetGame();
765 IK_F5
: g_Menu_Show_OptionsVideo();
766 IK_F6
: g_Menu_Show_OptionsSound();
767 IK_F7
: g_Menu_Show_EndGameMenu();
768 IK_F10
: g_Menu_Show_QuitGameMenu();
775 gJustChatted
:= False;
776 if gConsoleShow
or gChatShow
then
778 g_Console_Control(K
);
780 else if (g_ActiveWindow
<> nil) then
782 Msg
.Msg
:= WM_KEYDOWN
;
784 g_ActiveWindow
.OnMessage(Msg
);
786 else if (gState
= STATE_MENU
) then
788 g_GUI_ShowWindow('MainMenu');
789 g_Sound_PlayEx('MENU_OPEN');
795 procedure KeyPress (K
: Word);
797 gJustChatted
:= False;
798 if gConsoleShow
or gChatShow
then
800 g_Console_Control(K
);
806 procedure CharPress (C
: AnsiChar);
808 var Msg
: g_gui
.TMessage
;
812 if gConsoleShow
or gChatShow
then
817 else if g_ActiveWindow
<> nil then
820 Msg
.WParam
:= Ord(C
);
821 g_ActiveWindow
.OnMessage(Msg
);
828 charbuff
[a
] := charbuff
[a
+ 1];
830 charbuff
[15] := upcase1251(C
);
837 // ////////////////////////////////////////////////////////////////////////// //
838 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
840 procedure g_ResetDynlights ();
844 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
846 for idx
:= 0 to g_dynLightCount
-1 do
848 if g_dynLights
[idx
].exploCount
= -666 then
855 Inc(g_dynLights
[idx
].exploCount
);
856 if (g_dynLights
[idx
].exploCount
< 10) then
858 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
859 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
860 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
861 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
866 g_dynLightCount
:= lnum
;
869 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
871 if not gwin_has_stencil
then exit
;
872 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
873 g_dynLights
[g_dynLightCount
].x
:= x
;
874 g_dynLights
[g_dynLightCount
].y
:= y
;
875 g_dynLights
[g_dynLightCount
].radius
:= radius
;
876 g_dynLights
[g_dynLightCount
].r
:= r
;
877 g_dynLights
[g_dynLightCount
].g
:= g
;
878 g_dynLights
[g_dynLightCount
].b
:= b
;
879 g_dynLights
[g_dynLightCount
].a
:= a
;
880 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
881 Inc(g_dynLightCount
);
884 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
886 if not gwin_has_stencil
then exit
;
887 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
888 g_dynLights
[g_dynLightCount
].x
:= x
;
889 g_dynLights
[g_dynLightCount
].y
:= y
;
890 g_dynLights
[g_dynLightCount
].radius
:= 0;
891 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
892 g_dynLights
[g_dynLightCount
].r
:= r
;
893 g_dynLights
[g_dynLightCount
].g
:= g
;
894 g_dynLights
[g_dynLightCount
].b
:= b
;
895 g_dynLights
[g_dynLightCount
].a
:= 0;
896 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
897 Inc(g_dynLightCount
);
900 // ////////////////////////////////////////////////////////////////////////// //
901 function conIsCheatsEnabled (): Boolean; inline;
904 if g_Game_IsNet
then exit
;
905 if not gDebugMode
then
907 //if not gCheats then exit;
908 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
909 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
914 // ////////////////////////////////////////////////////////////////////////// //
916 TParamStrValue
= record
921 TParamStrValues
= Array of TParamStrValue
;
924 INTER_ACTION_TEXT
= 1;
925 INTER_ACTION_PIC
= 2;
926 INTER_ACTION_MUSIC
= 3;
931 DataLoaded
: Boolean = False;
933 MapList
: SSArray
= nil;
934 MapIndex
: Integer = -1;
935 InterReadyTime
: Integer = -1;
936 StatDate
: string = '';
951 function Compare(a
, b
: TPlayerStat
): Integer;
953 if a
.Spectator
then Result
:= 1
954 else if b
.Spectator
then Result
:= -1
955 else if a
.Frags
< b
.Frags
then Result
:= 1
956 else if a
.Frags
> b
.Frags
then Result
:= -1
957 else if a
.Deaths
< b
.Deaths
then Result
:= -1
958 else if a
.Deaths
> b
.Deaths
then Result
:= 1
959 else if a
.Kills
< b
.Kills
then Result
:= -1
963 procedure SortGameStat(var stat
: TPlayerStatArray
);
968 if stat
= nil then Exit
;
970 for I
:= High(stat
) downto Low(stat
) do
971 for J
:= Low(stat
) to High(stat
) - 1 do
972 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
975 stat
[J
] := stat
[J
+ 1];
980 // saves a shitty CSV containing the game stats passed to it
981 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
984 dir
, fname
, map
, mode
, etime
: String;
988 dir
:= e_GetWriteableDir(StatsDirs
);
989 // stats are placed in stats/yy/mm/dd/*.csv
990 fname
:= e_CatPath(dir
, Path
);
991 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
992 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
993 AssignFile(s
, fname
);
996 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
997 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
998 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
999 mode
:= g_Game_ModeToText(Stat
.GameMode
);
1000 etime
:= Format('%d:%.2d:%.2d', [
1001 Stat
.GameTime
div 1000 div 3600,
1002 (Stat
.GameTime
div 1000 div 60) mod 60,
1003 Stat
.GameTime
div 1000 mod 60
1005 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
1006 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
1012 gGameSettings
.TimeLimit
,
1013 gGameSettings
.GoalLimit
,
1014 gGameSettings
.Options
,
1016 Length(Stat
.PlayerStat
)
1018 // line 2: game specific shit
1019 // if it's a team game: red score, blue score
1020 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1021 // otherwise nothing
1022 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1024 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
1025 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1027 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1028 // lines 3-...: team, player name, frags, deaths
1029 WriteLn(s
, 'team,name,frags,deaths');
1030 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1031 with Stat
.PlayerStat
[I
] do
1032 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1034 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1037 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1042 function g_Game_ModeToText(Mode
: Byte): string;
1046 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1047 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1048 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1049 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1050 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1054 function g_Game_TextToMode(Mode
: string): Byte;
1057 Mode
:= UpperCase(Mode
);
1058 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1063 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1068 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1073 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1078 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1080 Result
:= GM_SINGLE
;
1085 function g_Game_IsNet(): Boolean;
1087 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1090 function g_Game_IsServer(): Boolean;
1092 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1095 function g_Game_IsClient(): Boolean;
1097 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1100 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1107 Result
.name
:= ExtractFileName(WAD
);
1108 Result
.description
:= '';
1109 Result
.author
:= '';
1111 w
:= TWADFile
.Create();
1114 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1120 cfg
:= TConfig
.CreateMem(p
, len
);
1121 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1122 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1123 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1124 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1130 procedure g_Game_FreeWAD
;
1133 g_Sound_Delete('MUSIC_endmus');
1134 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1135 gGameSettings
.WAD
:= '';
1138 procedure g_Game_LoadWAD(WAD
: string);
1147 gGameSettings
.WAD
:= WAD
;
1148 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1151 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1153 w
:= TWADFile
.Create();
1156 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1162 cfg
:= TConfig
.CreateMem(p
, len
);
1165 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1166 if MegaWAD
.endpic
<> '' then
1167 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1169 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1170 if MegaWAD
.endmus
<> '' then
1172 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1173 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1181 {procedure start_trigger(t: string);
1185 function next_trigger(): Boolean;
1189 procedure DisableCheats();
1195 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1196 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1197 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1198 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1200 {$IF DEFINED(D2F_DEBUG)}
1201 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1202 gAimLine
:= g_dbg_aimline_on
;
1206 procedure g_Game_ExecuteEvent(Name
: String);
1212 if gEvents
= nil then
1214 for a
:= 0 to High(gEvents
) do
1215 if gEvents
[a
].Name
= Name
then
1217 if gEvents
[a
].Command
<> '' then
1218 g_Console_Process(gEvents
[a
].Command
, True);
1223 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1228 if gDelayedEvents
<> nil then
1229 for a
:= 0 to High(gDelayedEvents
) do
1230 if not gDelayedEvents
[a
].Pending
then
1237 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1238 n
:= High(gDelayedEvents
);
1240 gDelayedEvents
[n
].Pending
:= True;
1241 gDelayedEvents
[n
].DEType
:= DEType
;
1242 gDelayedEvents
[n
].DENum
:= Num
;
1243 gDelayedEvents
[n
].DEStr
:= Str
;
1244 if DEType
= DE_GLOBEVENT
then
1245 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1247 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1251 procedure EndGame();
1257 if g_Game_IsNet
and g_Game_IsServer
then
1258 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1261 gPauseMain
:= false;
1262 gPauseHolmes
:= false;
1265 g_Game_StopAllSounds(False);
1270 EndingGameCounter
:= 0;
1272 {$IFDEF ENABLE_MENU}
1273 g_ActiveWindow
:= nil;
1276 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1277 gLMSRespawnTime
:= 0;
1280 EXIT_SIMPLE
: // Выход через меню или конец теста
1284 begin // Это был тест
1288 begin // Выход в главное меню
1289 {$IFDEF DISABLE_MENU}
1290 gState
:= STATE_MENU
; // ???
1292 gMusic
.SetByName('MUSIC_MENU');
1294 if gState
<> STATE_SLIST
then
1296 g_GUI_ShowWindow('MainMenu');
1297 gState
:= STATE_MENU
;
1301 // Обновляем список серверов
1302 slReturnPressed
:= True;
1303 if g_Net_Slist_Fetch(slCurrent
) then
1305 if slCurrent
= nil then
1306 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1309 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1310 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1313 g_Game_ExecuteEvent('ongameend');
1317 EXIT_RESTART
: // Начать уровень сначала
1319 if not g_Game_IsClient
then g_Game_Restart();
1322 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1324 // Статистика Своей игры:
1325 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1327 CustomStat
.GameTime
:= gTime
;
1328 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1329 CustomStat
.MapName
:= gMapInfo
.Name
;
1330 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1331 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1332 CustomStat
.TeamStat
:= gTeamStat
;
1334 CustomStat
.PlayerStat
:= nil;
1336 // Статистика игроков:
1337 if gPlayers
<> nil then
1339 for a
:= 0 to High(gPlayers
) do
1340 if gPlayers
[a
] <> nil then
1342 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1343 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1346 Name
:= gPlayers
[a
].Name
;
1347 Frags
:= gPlayers
[a
].Frags
;
1348 Deaths
:= gPlayers
[a
].Death
;
1349 Kills
:= gPlayers
[a
].Kills
;
1350 Team
:= gPlayers
[a
].Team
;
1351 Color
:= gPlayers
[a
].Model
.Color
;
1352 Spectator
:= gPlayers
[a
].FSpectator
;
1356 SortGameStat(CustomStat
.PlayerStat
);
1358 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1361 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1362 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1363 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1364 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1366 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1369 StatShotDone
:= False;
1372 g_Game_ExecuteEvent('onmapend');
1373 if not g_Game_IsClient
then g_Player_ResetReady
;
1374 gInterReadyCount
:= 0;
1376 // Затухающий экран:
1377 EndingGameCounter
:= 255;
1378 gState
:= STATE_FOLD
;
1380 if gDefInterTime
< 0 then
1381 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1383 gInterEndTime
:= gDefInterTime
* 1000;
1386 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1388 // Статистика Одиночной игры:
1389 SingleStat
.GameTime
:= gTime
;
1390 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1391 SingleStat
.TotalSecrets
:= gSecretsCount
;
1392 // Статистика первого игрока:
1393 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1394 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1395 // Статистика второго игрока (если есть):
1396 if SingleStat
.TwoPlayers
then
1398 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1399 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1402 g_Game_ExecuteEvent('onmapend');
1405 if gNextMap
<> '' then
1407 gMusic
.SetByName('MUSIC_INTERMUS');
1409 gState
:= STATE_INTERSINGLE
;
1412 g_Game_ExecuteEvent('oninter');
1414 else // Больше нет карт
1416 // Затухающий экран:
1417 EndingGameCounter
:= 255;
1418 gState
:= STATE_FOLD
;
1423 // Окончание обработано:
1424 if gExit
<> EXIT_QUIT
then
1428 procedure g_Game_Init();
1432 gTempDelete
:= False;
1434 sfsGCDisable(); // temporary disable removing of temporary volumes
1437 g_Game_ClearLoading();
1438 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1439 g_Game_SetLoadingText('', 0, False);
1441 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1444 gPauseMain
:= false;
1445 gPauseHolmes
:= false;
1448 {e_MouseInfo.Accel := 1.0;}
1450 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1453 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1454 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1455 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1456 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1457 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1459 gMusic
:= TMusic
.Create();
1460 gMusic
.SetByName('MUSIC_MENU');
1463 gGameSettings
.WarmupTime
:= 30;
1465 gState
:= STATE_MENU
;
1467 SetLength(gEvents
, 6);
1468 gEvents
[0].Name
:= 'ongamestart';
1469 gEvents
[1].Name
:= 'ongameend';
1470 gEvents
[2].Name
:= 'onmapstart';
1471 gEvents
[3].Name
:= 'onmapend';
1472 gEvents
[4].Name
:= 'oninter';
1473 gEvents
[5].Name
:= 'onwadend';
1475 sfsGCEnable(); // enable releasing unused volumes
1479 procedure g_Game_Free(freeTextures
: Boolean=true);
1481 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1482 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1484 g_Map_Free(freeTextures
);
1487 {$IFDEF ENABLE_GIBS}
1490 {$IFDEF ENALBE_SHELLS}
1493 {$IFDEF ENABLE_CORPSES}
1494 g_Corpses_RemoveAll
;
1497 gGameSettings
.GameType
:= GT_NONE
;
1498 if gGameSettings
.GameMode
= GM_SINGLE
then
1499 gGameSettings
.GameMode
:= GM_DM
;
1500 gSwitchGameMode
:= gGameSettings
.GameMode
;
1503 gExitByTrigger
:= False;
1506 function IsActivePlayer(p
: TPlayer
): Boolean;
1511 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1514 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1520 if gPlayers
= nil then
1524 for a
:= Low(gPlayers
) to High(gPlayers
) do
1525 if IsActivePlayer(gPlayers
[a
]) then
1527 SetLength(ids
, Length(ids
) + 1);
1528 ids
[High(ids
)] := gPlayers
[a
].UID
;
1529 if gPlayers
[a
].UID
= Skip
then
1532 if Length(ids
) = 0 then
1537 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1540 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1546 if gPlayers
= nil then
1550 for a
:= Low(gPlayers
) to High(gPlayers
) do
1551 if IsActivePlayer(gPlayers
[a
]) then
1553 SetLength(ids
, Length(ids
) + 1);
1554 ids
[High(ids
)] := gPlayers
[a
].UID
;
1555 if gPlayers
[a
].UID
= Skip
then
1558 if Length(ids
) = 0 then
1561 Result
:= ids
[Length(ids
) - 1]
1563 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1566 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1572 if gPlayers
= nil then
1576 for a
:= Low(gPlayers
) to High(gPlayers
) do
1577 if IsActivePlayer(gPlayers
[a
]) then
1579 SetLength(ids
, Length(ids
) + 1);
1580 ids
[High(ids
)] := gPlayers
[a
].UID
;
1581 if gPlayers
[a
].UID
= Skip
then
1584 if Length(ids
) = 0 then
1586 if Length(ids
) = 1 then
1591 Result
:= ids
[Random(Length(ids
))];
1593 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1595 Result
:= ids
[Random(Length(ids
))];
1600 function GetRandomSpectMode(Current
: Byte): Byte;
1607 0: Result
:= SPECT_STATS
;
1608 1: Result
:= SPECT_MAPVIEW
;
1609 2: Result
:= SPECT_MAPVIEW
;
1610 3: Result
:= SPECT_PLAYERS
;
1611 4: Result
:= SPECT_PLAYERS
;
1612 5: Result
:= SPECT_PLAYERS
;
1613 6: Result
:= SPECT_PLAYERS
;
1615 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1619 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1625 if (plr
= nil) then exit
;
1626 if (p
= 2) then time
:= 1000 else time
:= 1;
1627 strafeDir
:= MoveButton
shr 4;
1628 MoveButton
:= MoveButton
and $0F;
1630 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1631 MoveButton
:= 1 // Нажата только "Влево"
1632 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1633 MoveButton
:= 2 // Нажата только "Вправо"
1634 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1635 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1637 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1638 if MoveButton
= 1 then
1639 plr
.PressKey(KEY_LEFT
, time
)
1640 else if MoveButton
= 2 then
1641 plr
.PressKey(KEY_RIGHT
, time
);
1643 // if we have "strafe" key, turn off old strafe mechanics
1644 if gPlayerAction
[p
, ACTION_STRAFE
] then
1646 // new strafe mechanics
1647 if (strafeDir
= 0) then
1648 strafeDir
:= MoveButton
; // start strafing
1649 // now set direction according to strafe (reversed)
1650 if (strafeDir
= 2) then
1651 plr
.SetDirection(TDirection
.D_LEFT
)
1652 else if (strafeDir
= 1) then
1653 plr
.SetDirection(TDirection
.D_RIGHT
)
1657 strafeDir
:= 0; // not strafing anymore
1658 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1659 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1660 plr
.SetDirection(TDirection
.D_LEFT
)
1661 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1662 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1663 plr
.SetDirection(TDirection
.D_RIGHT
)
1664 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1665 else if MoveButton
<> 0 then
1666 plr
.SetDirection(TDirection(MoveButton
-1))
1669 // fix movebutton state
1670 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1672 // Остальные клавиши:
1673 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1674 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1675 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1676 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1677 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1678 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1679 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1681 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1682 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1684 for i
:= WP_FIRST
to WP_LAST
do
1686 if gSelectWeapon
[p
, i
] then
1688 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1689 gSelectWeapon
[p
, i
] := False
1693 {$IFDEF ENABLE_MENU}
1694 // HACK: add dynlight here
1695 if gwin_k8_enable_light_experiments
then
1697 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1699 g_playerLight
:= true;
1701 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1703 g_playerLight
:= false;
1707 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1711 // HACK: don't have a "key was pressed" function
1712 procedure InterReady();
1714 if InterReadyTime
> gTime
then Exit
;
1715 InterReadyTime
:= gTime
+ 3000;
1716 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1719 procedure g_Game_PreUpdate();
1721 // these are in separate PreUpdate functions because they can interact during Update()
1722 // and are synced over the net
1723 // we don't care that much about corpses and gibs
1724 g_Player_PreUpdate();
1725 g_Monsters_PreUpdate();
1726 g_Items_PreUpdate();
1727 g_Weapon_PreUpdate();
1730 procedure g_Game_Update();
1732 {$IFDEF ENABLE_MENU}
1733 Msg
: g_gui
.TMessage
;
1740 function sendMonsPos (mon
: TMonster
): Boolean;
1742 result
:= false; // don't stop
1743 // this will also reset "need-send" flag
1744 if mon
.gncNeedSend
then
1746 MH_SEND_MonsterPos(mon
.UID
);
1748 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1750 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1752 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1754 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1758 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1760 result
:= false; // don't stop
1761 // this will also reset "need-send" flag
1762 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1766 reliableUpdate
: Boolean;
1771 // Пора выключать игру:
1772 if gExit
= EXIT_QUIT
then
1774 // Игра закончилась - обрабатываем:
1778 if gExit
= EXIT_QUIT
then
1782 // Читаем клавиатуру и джойстик, если окно активно
1783 // no need to, as we'll do it in event handler
1785 // Обновляем консоль (движение и сообщения):
1788 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1790 gExit
:= EXIT_SIMPLE
;
1795 // process master server communications
1796 g_Net_Slist_Pulse();
1799 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1800 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1801 STATE_INTERTEXT
, // Текст между уровнями
1802 STATE_INTERPIC
: // Картинка между уровнями
1804 if g_Game_IsNet
and g_Game_IsServer
then
1806 gInterTime
:= gInterTime
+ GAME_TICK
;
1807 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1808 if a
<> gServInterTime
then
1810 gServInterTime
:= a
;
1811 MH_SEND_TimeSync(gServInterTime
);
1815 if (not g_Game_IsClient
) and
1819 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1820 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1821 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1822 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1824 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1825 {$IFDEF ENABLE_MENU}
1826 and (g_ActiveWindow
= nil)
1829 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1832 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1833 g_Game_StopAllSounds(True);
1835 if gMapOnce
then // Это был тест
1836 gExit
:= EXIT_SIMPLE
1838 if gNextMap
<> '' then // Переходим на следующую карту
1839 g_Game_ChangeMap(gNextMap
)
1840 else // Следующей карты нет
1842 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1844 // Выход в главное меню:
1846 {$IFDEF ENABLE_MENU}
1847 g_GUI_ShowWindow('MainMenu');
1848 gMusic
.SetByName('MUSIC_MENU');
1851 gState
:= STATE_MENU
;
1854 // Финальная картинка:
1855 g_Game_ExecuteEvent('onwadend');
1857 if not gMusic
.SetByName('MUSIC_endmus') then
1858 gMusic
.SetByName('MUSIC_STDENDMUS');
1860 gState
:= STATE_ENDPIC
;
1862 g_Game_ExecuteEvent('ongameend');
1867 else if g_Game_IsClient
and
1870 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1871 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1872 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1873 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1875 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1876 {$IFDEF ENABLE_MENU}
1877 and (g_ActiveWindow
= nil)
1886 if gState
= STATE_INTERTEXT
then
1887 if InterText
.counter
> 0 then
1888 InterText
.counter
:= InterText
.counter
- 1;
1891 STATE_FOLD
: // Затухание экрана
1893 if EndingGameCounter
= 0 then
1895 // Закончился уровень в Своей игре:
1896 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1898 InterReadyTime
:= -1;
1899 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1901 g_Game_ExecuteEvent('onwadend');
1902 if not gMusic
.SetByName('MUSIC_endmus') then
1903 gMusic
.SetByName('MUSIC_STDENDMUS');
1906 gMusic
.SetByName('MUSIC_ROUNDMUS');
1909 gState
:= STATE_INTERCUSTOM
;
1912 else // Закончилась последняя карта в Одиночной игре
1914 gMusic
.SetByName('MUSIC_INTERMUS');
1916 gState
:= STATE_INTERSINGLE
;
1919 g_Game_ExecuteEvent('oninter');
1922 DecMin(EndingGameCounter
, 6, 0);
1925 STATE_ENDPIC
: // Картинка окончания мегаВада
1927 if gMapOnce
then // Это был тест
1929 gExit
:= EXIT_SIMPLE
;
1935 g_Serverlist_Control(slCurrent
, slTable
);
1938 // Статистика по Tab:
1940 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1943 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1945 // Время += 28 миллисекунд:
1946 gTime
:= gTime
+ GAME_TICK
;
1948 // Сообщение посередине экрана:
1949 if MessageTime
= 0 then
1951 if MessageTime
> 0 then
1952 MessageTime
:= MessageTime
- 1;
1954 if (g_Game_IsServer
) then
1956 // Был задан лимит времени:
1957 if (gGameSettings
.TimeLimit
> 0) then
1958 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1959 begin // Он прошел => конец уровня
1964 // Надо респавнить игроков в LMS:
1965 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1966 g_Game_RestartRound(gLMSSoftSpawn
);
1968 // Проверим результат голосования, если время прошло
1969 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1971 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1973 g_Console_Process(gVoteCommand
);
1975 gVotePassed
:= False;
1978 // Замеряем время захвата флагов
1979 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1980 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1981 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1982 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1984 // Был задан лимит побед:
1985 if (gGameSettings
.GoalLimit
> 0) then
1989 if gGameSettings
.GameMode
= GM_DM
then
1990 begin // В DM ищем игрока с max фрагами
1991 for i
:= 0 to High(gPlayers
) do
1992 if gPlayers
[i
] <> nil then
1993 if gPlayers
[i
].Frags
> b
then
1994 b
:= gPlayers
[i
].Frags
;
1997 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1998 begin // В CTF/TDM выбираем команду с наибольшим счетом
1999 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
2002 // Лимит побед набран => конец уровня:
2003 if b
>= gGameSettings
.GoalLimit
then
2010 // Обрабатываем клавиши игроков:
2011 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2012 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2013 {$IFDEF DISABLE_MENU}
2014 if (not gConsoleShow
) and (not gChatShow
) then
2016 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2019 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2020 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2021 end // if not console
2024 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2026 // process weapon switch queue
2030 if (gPlayer1
= nil) and (gPlayer2
= nil)
2031 and (not gConsoleShow
) and (not gChatShow
)
2032 {$IFDEF ENABLE_MENU}
2033 and (g_ActiveWindow
= nil)
2037 if not gSpectKeyPress
then
2039 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2041 // switch spect mode
2043 SPECT_NONE
: ; // not spectator
2045 SPECT_MAPVIEW
: Inc(gSpectMode
);
2046 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2048 gSpectKeyPress
:= True;
2050 if (gSpectMode
= SPECT_MAPVIEW
)
2051 and (not gSpectAuto
) then
2053 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2054 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2055 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2056 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2057 if gPlayerAction
[0, ACTION_LOOKUP
] then
2058 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2059 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2060 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2061 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2064 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2065 gSpectKeyPress
:= True;
2067 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2070 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2071 gSpectKeyPress
:= True;
2074 if (gSpectMode
= SPECT_PLAYERS
)
2075 and (not gSpectAuto
) then
2077 if gPlayerAction
[0, ACTION_LOOKUP
] then
2080 gSpectViewTwo
:= True;
2081 gSpectKeyPress
:= True;
2083 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2085 // remove second view
2086 gSpectViewTwo
:= False;
2087 gSpectKeyPress
:= True;
2089 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2091 // prev player (view 1)
2092 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2093 gSpectKeyPress
:= True;
2095 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2097 // next player (view 1)
2098 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2099 gSpectKeyPress
:= True;
2101 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2103 // prev player (view 2)
2104 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2105 gSpectKeyPress
:= True;
2107 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2109 // next player (view 2)
2110 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2111 gSpectKeyPress
:= True;
2114 if gPlayerAction
[0, ACTION_ATTACK
] then
2116 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2119 gSpectAutoNext
:= 0;
2120 gSpectViewTwo
:= False;
2121 gSpectKeyPress
:= True;
2126 gSpectMode
:= SPECT_STATS
;
2127 gSpectAuto
:= False;
2128 gSpectKeyPress
:= True;
2133 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2134 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2135 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2136 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2137 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2138 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2139 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2140 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2141 gSpectKeyPress
:= False;
2145 if gSpectMode
= SPECT_MAPVIEW
then
2147 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2149 gSpectAutoNext
:= gTime
2152 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2154 gSpectAutoNext
:= gTime
2158 if gSpectAutoNext
<= gTime
then
2160 if gSpectAutoNext
> 0 then
2162 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2166 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2167 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2168 gSpectAutoStepX
:= Random(9) - 4;
2169 gSpectAutoStepY
:= Random(9) - 4;
2170 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2171 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2172 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2173 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2174 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2175 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2179 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2184 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2185 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2186 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2192 // Обновляем все остальное:
2195 g_Triggers_Update();
2197 g_Monsters_Update();
2201 g_Player_UpdateAll();
2202 {$IFDEF ENABLE_GIBS}
2205 {$IFDEF ENABLE_CORPSES}
2208 {$IFDEF ENABLE_SHELLS}
2212 // server: send newly spawned monsters unconditionally
2213 if (gGameSettings
.GameType
= GT_SERVER
) then
2215 if (Length(gMonstersSpawned
) > 0) then
2217 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2218 SetLength(gMonstersSpawned
, 0);
2222 if (gSoundTriggerTime
> 8) then
2224 g_Game_UpdateTriggerSounds();
2225 gSoundTriggerTime
:= 0;
2229 Inc(gSoundTriggerTime
);
2232 if (NetMode
= NET_SERVER
) then
2234 Inc(NetTimeToUpdate
);
2235 Inc(NetTimeToReliable
);
2237 // send monster updates
2238 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2240 // send all monsters (periodic sync)
2241 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2243 for I
:= 0 to High(gPlayers
) do
2245 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2248 g_Mons_ForEach(sendMonsPos
);
2250 if reliableUpdate
then
2252 NetTimeToReliable
:= 0;
2253 NetTimeToUpdate
:= NetUpdateRate
;
2257 NetTimeToUpdate
:= 0;
2262 // send only mosters with some unexpected changes
2263 g_Mons_ForEach(sendMonsPosUnexpected
);
2266 // send unexpected platform changes
2267 g_Map_NetSendInterestingPanels();
2269 g_Net_Slist_ServerUpdate();
2271 if NetUseMaster then
2273 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2275 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2277 NetTimeToMaster := gTime + NetMasterRate;
2282 else if (NetMode
= NET_CLIENT
) then
2284 MC_SEND_PlayerPos();
2286 end; // if gameOn ...
2288 // Активно окно интерфейса - передаем клавиши ему:
2289 {$IFDEF ENABLE_MENU}
2290 if g_ActiveWindow
<> nil then
2292 w
:= e_GetFirstKeyPressed();
2294 if (w
<> IK_INVALID
) then
2296 Msg
.Msg
:= MESSAGE_DIKEY
;
2298 g_ActiveWindow
.OnMessage(Msg
);
2301 // Если оно от этого не закрылось, то обновляем:
2302 if g_ActiveWindow
<> nil then
2303 g_ActiveWindow
.Update();
2305 // Нужно сменить разрешение:
2306 if gResolutionChange
then
2309 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2312 gResolutionChange
:= False;
2313 g_ActiveWindow
:= nil;
2316 // Нужно сменить язык:
2317 if gLanguageChange
then
2319 //e_WriteLog('Read language file', MSG_NOTIFY);
2320 //g_Language_Load(DataDir + gLanguage + '.txt');
2321 g_Language_Set(gLanguage
);
2323 gLanguageChange
:= False;
2327 // Горячая клавиша для вызова меню выхода из игры (F10):
2328 if e_KeyPressed(IK_F10
) and
2330 (not gConsoleShow
) and
2331 (g_ActiveWindow
= nil) then
2337 Time
:= GetTickCount64() {div 1000};
2339 // Обработка отложенных событий:
2340 if gDelayedEvents
<> nil then
2341 for a
:= 0 to High(gDelayedEvents
) do
2342 if gDelayedEvents
[a
].Pending
and
2344 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2345 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2348 case gDelayedEvents
[a
].DEType
of
2350 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2353 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2357 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2358 if g_Game_IsNet
and g_Game_IsServer
then
2359 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2363 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2365 gDelayedEvents
[a
].Pending
:= False;
2368 // Каждую секунду обновляем счетчик обновлений:
2369 UPSCounter
:= UPSCounter
+ 1;
2370 if Time
- UPSTime
>= 1000 then
2379 g_Weapon_AddDynLights();
2380 g_Items_AddDynLights();
2384 procedure g_Game_LoadChatSounds(Resource
: string);
2387 FileName
, Snd
: string;
2389 len
, cnt
, tags
, i
, j
: Integer;
2392 FileName
:= g_ExtractWadName(Resource
);
2394 WAD
:= TWADFile
.Create();
2395 WAD
.ReadFile(FileName
);
2397 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2404 cfg
:= TConfig
.CreateMem(p
, len
);
2405 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2407 SetLength(gChatSounds
, cnt
);
2408 for i
:= 0 to Length(gChatSounds
) - 1 do
2410 gChatSounds
[i
].Sound
:= nil;
2411 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2412 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2413 if (Snd
= '') or (Tags
<= 0) then
2415 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2416 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2417 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2418 SetLength(gChatSounds
[i
].Tags
, tags
);
2419 for j
:= 0 to tags
- 1 do
2420 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2421 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2428 procedure g_Game_FreeChatSounds();
2432 for i
:= 0 to Length(gChatSounds
) - 1 do
2434 gChatSounds
[i
].Sound
.Free();
2435 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2437 SetLength(gChatSounds
, 0);
2441 procedure g_Game_LoadData();
2443 if DataLoaded
then Exit
;
2445 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2447 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2448 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2449 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2450 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2451 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2452 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2453 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2454 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2455 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2456 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2457 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2458 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2459 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2460 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2461 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2462 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2463 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2464 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2465 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2466 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2467 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2468 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2469 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2470 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2471 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2472 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2473 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2474 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2475 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2476 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2477 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2478 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2480 goodsnd
[0] := TPlayableSound
.Create();
2481 goodsnd
[1] := TPlayableSound
.Create();
2482 goodsnd
[2] := TPlayableSound
.Create();
2483 goodsnd
[3] := TPlayableSound
.Create();
2485 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2486 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2487 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2488 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2490 killsnd
[0] := TPlayableSound
.Create();
2491 killsnd
[1] := TPlayableSound
.Create();
2492 killsnd
[2] := TPlayableSound
.Create();
2493 killsnd
[3] := TPlayableSound
.Create();
2495 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2496 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2497 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2498 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2500 hahasnd
[0] := TPlayableSound
.Create();
2501 hahasnd
[1] := TPlayableSound
.Create();
2502 hahasnd
[2] := TPlayableSound
.Create();
2504 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2505 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2506 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2508 sound_get_flag
[0] := TPlayableSound
.Create();
2509 sound_get_flag
[1] := TPlayableSound
.Create();
2510 sound_lost_flag
[0] := TPlayableSound
.Create();
2511 sound_lost_flag
[1] := TPlayableSound
.Create();
2512 sound_ret_flag
[0] := TPlayableSound
.Create();
2513 sound_ret_flag
[1] := TPlayableSound
.Create();
2514 sound_cap_flag
[0] := TPlayableSound
.Create();
2515 sound_cap_flag
[1] := TPlayableSound
.Create();
2517 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2518 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2519 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2520 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2521 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2522 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2523 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2524 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2526 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2528 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2531 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2532 g_Weapon_LoadData();
2534 g_Monsters_LoadData();
2539 procedure g_Game_Quit();
2541 g_Game_StopAllSounds(True);
2544 g_PlayerModel_FreeData();
2546 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2549 if NetInitDone
then g_Net_Free
;
2551 // remove map after test
2552 if gMapToDelete
<> '' then
2553 g_Game_DeleteTestMap();
2557 {$IFDEF ENABLE_SYSTEM}
2562 procedure g_Game_FreeData();
2564 if not DataLoaded
then Exit
;
2567 g_Weapon_FreeData();
2568 g_Monsters_FreeData();
2570 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2572 g_Sound_Delete('SOUND_GAME_TELEPORT');
2573 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2574 g_Sound_Delete('SOUND_GAME_SECRET');
2575 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2576 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2577 g_Sound_Delete('SOUND_GAME_BULK1');
2578 g_Sound_Delete('SOUND_GAME_BULK2');
2579 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2580 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2581 g_Sound_Delete('SOUND_GAME_BURNING');
2582 g_Sound_Delete('SOUND_GAME_SWITCH1');
2583 g_Sound_Delete('SOUND_GAME_SWITCH0');
2590 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2591 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2592 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2593 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2600 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2601 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2602 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2603 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2609 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2610 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2611 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2613 sound_get_flag
[0].Free();
2614 sound_get_flag
[1].Free();
2615 sound_lost_flag
[0].Free();
2616 sound_lost_flag
[1].Free();
2617 sound_ret_flag
[0].Free();
2618 sound_ret_flag
[1].Free();
2619 sound_cap_flag
[0].Free();
2620 sound_cap_flag
[1].Free();
2622 g_Sound_Delete('SOUND_CTF_GET1');
2623 g_Sound_Delete('SOUND_CTF_GET2');
2624 g_Sound_Delete('SOUND_CTF_LOST1');
2625 g_Sound_Delete('SOUND_CTF_LOST2');
2626 g_Sound_Delete('SOUND_CTF_RETURN1');
2627 g_Sound_Delete('SOUND_CTF_RETURN2');
2628 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2629 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2631 g_Game_FreeChatSounds();
2633 DataLoaded
:= False;
2636 procedure g_FatalError(Text: String);
2638 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2639 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2641 gExit
:= EXIT_SIMPLE
;
2642 if gGameOn
then EndGame
;
2645 procedure g_SimpleError(Text: String);
2647 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2648 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2651 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2653 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2654 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2657 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2660 if gPlayer1
= nil then
2662 if g_Game_IsClient
then
2664 if NetPlrUID1
> -1 then
2665 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2669 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2670 Team
:= gPlayer1Settings
.Team
;
2672 // Создание первого игрока:
2673 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2674 gPlayer1Settings
.Color
,
2676 if gPlayer1
= nil then
2677 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2680 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2681 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2682 if g_Game_IsServer
and g_Game_IsNet
then
2683 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2684 gPlayer1
.Respawn(False, True);
2685 g_Net_Slist_ServerPlayerComes();
2690 if gPlayer2
= nil then
2692 if g_Game_IsClient
then
2694 if NetPlrUID2
> -1 then
2695 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2699 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2700 Team
:= gPlayer2Settings
.Team
;
2702 // Создание второго игрока:
2703 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2704 gPlayer2Settings
.Color
,
2706 if gPlayer2
= nil then
2707 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2710 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2711 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2712 if g_Game_IsServer
and g_Game_IsNet
then
2713 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2714 gPlayer2
.Respawn(False, True);
2715 g_Net_Slist_ServerPlayerComes();
2722 procedure g_Game_RemovePlayer();
2726 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2727 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2732 if g_Game_IsServer
then
2735 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2736 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2737 g_Player_Remove(Pl
.UID
);
2738 g_Net_Slist_ServerPlayerLeaves();
2742 gSpectLatchPID2
:= Pl
.UID
;
2750 if g_Game_IsServer
then
2753 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2754 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2755 g_Player_Remove(Pl
.UID
);
2756 g_Net_Slist_ServerPlayerLeaves();
2759 gSpectLatchPID1
:= Pl
.UID
;
2761 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2765 g_Net_Slist_ServerPlayerLeaves();
2768 procedure g_Game_Spectate();
2770 g_Game_RemovePlayer();
2771 if gPlayer1
<> nil then
2772 g_Game_RemovePlayer();
2775 procedure g_Game_SpectateCenterView();
2777 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2778 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2781 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2788 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2790 g_Game_ClearLoading();
2793 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2796 gGameSettings
.GameType
:= GT_SINGLE
;
2797 gGameSettings
.MaxLives
:= 0;
2798 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2799 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2800 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2801 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2802 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2803 gSwitchGameMode
:= GM_SINGLE
;
2805 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2806 gLMSRespawnTime
:= 0;
2807 gSpectLatchPID1
:= 0;
2808 gSpectLatchPID2
:= 0;
2810 g_Game_ExecuteEvent('ongamestart');
2812 // Создание первого игрока:
2813 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2814 gPlayer1Settings
.Color
,
2815 gPlayer1Settings
.Team
, False));
2816 if gPlayer1
= nil then
2818 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2822 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2825 // Создание второго игрока, если есть:
2828 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2829 gPlayer2Settings
.Color
,
2830 gPlayer2Settings
.Team
, False));
2831 if gPlayer2
= nil then
2833 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2837 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2841 // Загрузка и запуск карты:
2842 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2844 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2845 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2849 // Настройки игроков и ботов:
2853 for i
:= nPl
+1 to nPlayers
do
2854 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2857 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2858 TimeLimit
, GoalLimit
: Word;
2860 Options
: LongWord; nPlayers
: Byte);
2866 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2868 g_Game_ClearLoading();
2871 gGameSettings
.GameType
:= GT_CUSTOM
;
2872 gGameSettings
.GameMode
:= GameMode
;
2873 gSwitchGameMode
:= GameMode
;
2874 gGameSettings
.TimeLimit
:= TimeLimit
;
2875 gGameSettings
.GoalLimit
:= GoalLimit
;
2876 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2877 gGameSettings
.Options
:= Options
;
2879 gCoopTotalMonstersKilled
:= 0;
2880 gCoopTotalSecretsFound
:= 0;
2881 gCoopTotalMonsters
:= 0;
2882 gCoopTotalSecrets
:= 0;
2886 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2887 gLMSRespawnTime
:= 0;
2888 gSpectLatchPID1
:= 0;
2889 gSpectLatchPID2
:= 0;
2891 g_Game_ExecuteEvent('ongamestart');
2893 // Режим наблюдателя:
2894 if nPlayers
= 0 then
2901 if nPlayers
>= 1 then
2903 // Создание первого игрока:
2904 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2905 gPlayer1Settings
.Color
,
2906 gPlayer1Settings
.Team
, False));
2907 if gPlayer1
= nil then
2909 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2913 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2917 if nPlayers
>= 2 then
2919 // Создание второго игрока:
2920 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2921 gPlayer2Settings
.Color
,
2922 gPlayer2Settings
.Team
, False));
2923 if gPlayer2
= nil then
2925 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2929 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2933 // Загрузка и запуск карты:
2934 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
2936 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2940 // Нет точек появления:
2941 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2942 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2943 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2944 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2945 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2947 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2951 // Настройки игроков и ботов:
2955 for i
:= nPl
+1 to nPlayers
do
2956 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2959 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
2960 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
2961 Options
: LongWord; nPlayers
: Byte;
2962 IPAddr
: LongWord; Port
: Word);
2965 g_Net_Slist_ServerClosed();
2967 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
2969 g_Game_ClearLoading();
2972 gGameSettings
.GameType
:= GT_SERVER
;
2973 gGameSettings
.GameMode
:= GameMode
;
2974 gSwitchGameMode
:= GameMode
;
2975 gGameSettings
.TimeLimit
:= TimeLimit
;
2976 gGameSettings
.GoalLimit
:= GoalLimit
;
2977 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2978 gGameSettings
.Options
:= Options
;
2980 gCoopTotalMonstersKilled
:= 0;
2981 gCoopTotalSecretsFound
:= 0;
2982 gCoopTotalMonsters
:= 0;
2983 gCoopTotalSecrets
:= 0;
2987 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2988 gLMSRespawnTime
:= 0;
2989 gSpectLatchPID1
:= 0;
2990 gSpectLatchPID2
:= 0;
2992 g_Game_ExecuteEvent('ongamestart');
2994 // Режим наблюдателя:
2995 if nPlayers
= 0 then
3001 if nPlayers
>= 1 then
3003 // Создание первого игрока:
3004 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3005 gPlayer1Settings
.Color
,
3006 gPlayer1Settings
.Team
, False));
3007 if gPlayer1
= nil then
3009 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3013 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3016 if nPlayers
>= 2 then
3018 // Создание второго игрока:
3019 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3020 gPlayer2Settings
.Color
,
3021 gPlayer2Settings
.Team
, False));
3022 if gPlayer2
= nil then
3024 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3028 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3031 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3032 if NetForwardPorts
then
3033 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3036 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3038 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3042 g_Net_Slist_Set(NetMasterList
);
3044 g_Net_Slist_ServerStarted();
3046 // Загрузка и запуск карты:
3047 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3049 g_Net_Slist_ServerClosed();
3050 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3054 // Нет точек появления:
3055 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3056 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3057 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3058 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3059 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3061 g_Net_Slist_ServerClosed();
3062 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3066 // Настройки игроков и ботов:
3069 g_Net_Slist_ServerMapStarted();
3070 NetState
:= NET_STATE_GAME
;
3073 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3088 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3089 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3091 g_Game_ClearLoading();
3094 gGameSettings
.GameType
:= GT_CLIENT
;
3096 gCoopTotalMonstersKilled
:= 0;
3097 gCoopTotalSecretsFound
:= 0;
3098 gCoopTotalMonsters
:= 0;
3099 gCoopTotalSecrets
:= 0;
3103 g_Game_ExecuteEvent('ongamestart');
3105 NetState
:= NET_STATE_AUTH
;
3107 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3109 // create (or update) map/resource databases
3110 g_Res_CreateDatabases(true);
3112 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3113 gLMSRespawnTime
:= 0;
3114 gSpectLatchPID1
:= 0;
3115 gSpectLatchPID2
:= 0;
3118 if not g_Net_Connect(Addr
, Port
) then
3120 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3121 NetState
:= NET_STATE_NONE
;
3125 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3127 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3132 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3133 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3134 // thank you, enet. let's ignore failures altogether then.
3135 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3137 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3139 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
3141 // ignore all download packets, they're processed by separate code
3142 enet_packet_destroy(NetEvent
.packet
);
3145 Ptr
:= NetEvent
.packet
^.data
;
3146 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3148 enet_packet_destroy(NetEvent
.packet
);
3152 InMsg
.ReadLongWord(); // skip size
3153 MID
:= InMsg
.ReadByte();
3155 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3157 NetMyID
:= InMsg
.ReadByte();
3158 NetPlrUID1
:= InMsg
.ReadWord();
3160 WadName
:= InMsg
.ReadString();
3161 Map
:= InMsg
.ReadString();
3163 gWADHash
:= InMsg
.ReadMD5();
3165 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3166 gSwitchGameMode
:= gGameSettings
.GameMode
;
3167 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
3168 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3169 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3170 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3171 T
:= InMsg
.ReadLongWord();
3173 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3174 //if newResPath = '' then
3176 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3177 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3178 if newResPath
= '' then
3180 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3181 enet_packet_destroy(NetEvent
.packet
);
3182 NetState
:= NET_STATE_NONE
;
3185 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3187 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3190 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3191 gPlayer1Settings
.Color
,
3192 gPlayer1Settings
.Team
, False));
3194 if gPlayer1
= nil then
3196 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3198 enet_packet_destroy(NetEvent
.packet
);
3199 NetState
:= NET_STATE_NONE
;
3203 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3204 gPlayer1
.UID
:= NetPlrUID1
;
3205 gPlayer1
.Reset(True);
3207 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3209 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3211 enet_packet_destroy(NetEvent
.packet
);
3212 NetState
:= NET_STATE_NONE
;
3220 enet_packet_destroy(NetEvent
.packet
);
3224 enet_packet_destroy(NetEvent
.packet
);
3228 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3231 if (NetEvent
.data
<= NET_DISC_MAX
) then
3232 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3233 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3240 ProcessLoading(true);
3242 if g_Net_UserRequestExit() then
3251 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3252 NetState
:= NET_STATE_NONE
;
3257 NetState
:= NET_STATE_GAME
;
3258 MC_SEND_FullStateRequest
;
3259 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3263 lastAsMegaWad
: Boolean = false;
3265 procedure g_Game_ChangeMap(const MapPath
: String);
3269 g_Game_ClearLoading();
3271 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3272 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3273 if gExitByTrigger
then
3276 gExitByTrigger
:= False;
3278 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3279 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3282 procedure g_Game_Restart();
3286 if g_Game_IsClient
then
3288 map
:= g_ExtractFileName(gMapInfo
.Map
);
3289 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3293 g_Game_ClearLoading();
3294 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3297 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3299 NewWAD
, ResName
: String;
3303 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3305 {$IFDEF ENABLE_GIBS}
3308 {$IFDEF ENALBE_SHELLS}
3311 {$IFDEF ENABLE_CORPSES}
3312 g_Corpses_RemoveAll
;
3315 if (not g_Game_IsClient
) and
3316 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3317 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3319 if gSwitchGameMode
= GM_CTF
then
3320 gGameSettings
.MaxLives
:= 0;
3321 gGameSettings
.GameMode
:= gSwitchGameMode
;
3324 gSwitchGameMode
:= gGameSettings
.GameMode
;
3326 g_Player_ResetTeams();
3328 lastAsMegaWad
:= asMegawad
;
3329 if isWadPath(Map
) then
3331 NewWAD
:= g_ExtractWadName(Map
);
3332 ResName
:= g_ExtractFileName(Map
);
3333 if g_Game_IsServer
then
3335 nws
:= findDiskWad(NewWAD
);
3336 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3339 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3340 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3344 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3345 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3347 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3348 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3350 if (length(nws
) = 0) then
3352 ResName
:= ''; // failed
3357 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3358 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3359 g_Game_LoadWAD(NewWAD
);
3364 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3365 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3370 NewWAD
:= gGameSettings
.WAD
;
3376 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3378 if (ResName
<> '') and (NewWAD
<> '') then
3380 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3381 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3382 {$IFDEF ENABLE_RENDER}
3383 r_Render_LoadTextures
;
3388 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3390 gState
:= STATE_NONE
;
3391 {$IFDEF ENABLE_MENU}
3392 g_ActiveWindow
:= nil;
3397 wNeedTimeReset
:= True;
3399 if gGameSettings
.GameMode
= GM_CTF
then
3401 g_Map_ResetFlag(FLAG_RED
);
3402 g_Map_ResetFlag(FLAG_BLUE
);
3403 // CTF, а флагов нет:
3404 if not g_Map_HaveFlagPoints() then
3405 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3410 gState
:= STATE_MENU
;
3415 gPauseMain
:= false;
3416 gPauseHolmes
:= false;
3417 NetTimeToUpdate
:= 1;
3418 NetTimeToReliable
:= 0;
3419 NetTimeToMaster
:= NetMasterRate
;
3420 gSpectLatchPID1
:= 0;
3421 gSpectLatchPID2
:= 0;
3422 gMissionFailed
:= False;
3425 gCoopMonstersKilled
:= 0;
3426 gCoopSecretsFound
:= 0;
3428 gVoteInProgress
:= False;
3429 gVotePassed
:= False;
3435 if not gGameOn
then Exit
;
3437 g_Game_SpectateCenterView();
3439 if g_Game_IsServer
then
3441 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3443 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3444 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3445 gLMSSoftSpawn
:= True;
3446 if g_Game_IsNet
then
3447 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3451 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3452 gLMSRespawnTime
:= 0;
3456 if NetMode
= NET_SERVER
then
3458 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3461 g_Net_Slist_ServerMapStarted();
3463 if NetClients
<> nil then
3464 for I
:= 0 to High(NetClients
) do
3465 if NetClients
[I
].Used
then
3467 NetClients
[I
].Voted
:= False;
3468 if NetClients
[I
].RequestedFullUpdate
then
3470 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3471 NetClients
[I
].RequestedFullUpdate
:= False;
3475 g_Net_UnbanNonPermHosts();
3480 gCoopTotalMonstersKilled
:= 0;
3481 gCoopTotalSecretsFound
:= 0;
3482 gCoopTotalMonsters
:= 0;
3483 gCoopTotalSecrets
:= 0;
3487 g_Game_ExecuteEvent('onmapstart');
3490 procedure SetFirstLevel
;
3494 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3495 if MapList
= nil then
3498 SortSArray(MapList
);
3499 gNextMap
:= MapList
[Low(MapList
)];
3504 procedure g_Game_ExitLevel(const Map
: AnsiString);
3508 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3509 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3510 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3511 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3513 // Вышли в выход в Одиночной игре:
3514 if gGameSettings
.GameType
= GT_SINGLE
then
3515 gExit
:= EXIT_ENDLEVELSINGLE
3516 else // Вышли в выход в Своей игре
3518 gExit
:= EXIT_ENDLEVELCUSTOM
;
3519 if gGameSettings
.GameMode
= GM_COOP
then
3520 g_Player_RememberAll
;
3522 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3525 if gGameSettings
.GameMode
= GM_COOP
then
3528 gStatsPressed
:= True;
3529 gNextMap
:= 'MAP01';
3531 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3534 if g_Game_IsNet
then
3536 MH_SEND_GameStats();
3537 MH_SEND_CoopStats();
3543 procedure g_Game_RestartLevel();
3547 if gGameSettings
.GameMode
= GM_SINGLE
then
3552 gExit
:= EXIT_ENDLEVELCUSTOM
;
3553 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3557 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3559 gWAD
{, xwad}: String;
3562 if not g_Game_IsClient
then Exit
;
3563 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3565 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3570 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3574 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3577 g_Game_LoadWAD(NewWAD
);
3581 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3582 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3585 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3586 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3590 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3594 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3595 g_Game_LoadWAD(NewWAD);
3599 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3601 i
, n
, nb
, nr
: Integer;
3603 if not g_Game_IsServer
then Exit
;
3604 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3605 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3606 gLMSRespawnTime
:= 0;
3609 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3611 gMissionFailed
:= True;
3612 g_Game_RestartLevel
;
3616 n
:= 0; nb
:= 0; nr
:= 0;
3617 for i
:= Low(gPlayers
) to High(gPlayers
) do
3618 if (gPlayers
[i
] <> nil) and
3619 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3620 (gPlayers
[i
] is TBot
)) then
3623 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3624 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3627 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3629 // wait a second until the fuckers finally decide to join
3630 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3631 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3632 gLMSSoftSpawn
:= NoMapRestart
;
3633 if g_Game_IsNet
then
3634 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3638 {$IFDEF ENABLE_GIBS}
3641 {$IFDEF ENALBE_SHELLS}
3644 {$IFDEF ENABLE_CORPSES}
3645 g_Corpses_RemoveAll
;
3648 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3649 if g_Game_IsNet
then
3650 MH_SEND_GameEvent(NET_EV_LMS_START
);
3652 for i
:= Low(gPlayers
) to High(gPlayers
) do
3654 if gPlayers
[i
] = nil then continue
;
3655 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3656 // don't touch normal spectators
3657 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3659 gPlayers
[i
].FNoRespawn
:= True;
3660 gPlayers
[i
].Lives
:= 0;
3661 if g_Game_IsNet
then
3662 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3665 gPlayers
[i
].FNoRespawn
:= False;
3666 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3667 gPlayers
[i
].Respawn(False, True);
3668 if gGameSettings
.GameMode
= GM_COOP
then
3670 gPlayers
[i
].Frags
:= 0;
3671 gPlayers
[i
].RecallState
;
3673 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3674 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3675 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3676 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3679 g_Items_RestartRound();
3681 gLMSSoftSpawn
:= False;
3684 function g_Game_GetFirstMap(WAD
: String): String;
3688 MapList
:= g_Map_GetMapsList(WAD
);
3689 if MapList
= nil then
3692 SortSArray(MapList
);
3693 Result
:= MapList
[Low(MapList
)];
3695 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3701 function g_Game_GetNextMap(): String;
3708 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3709 if MapList
= nil then
3712 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3714 SortSArray(MapList
);
3716 for I
:= Low(MapList
) to High(MapList
) do
3717 if Map
= MapList
[I
] then
3723 if MapIndex
<> -255 then
3725 if MapIndex
= High(MapList
) then
3726 Result
:= MapList
[Low(MapList
)]
3728 Result
:= MapList
[MapIndex
+ 1];
3730 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3736 procedure g_Game_NextLevel();
3738 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3739 gExit
:= EXIT_ENDLEVELCUSTOM
3742 gExit
:= EXIT_ENDLEVELSINGLE
;
3746 if gNextMap
<> '' then Exit
;
3747 gNextMap
:= g_Game_GetNextMap();
3750 function g_Game_IsTestMap(): Boolean;
3752 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3755 procedure g_Game_DeleteTestMap();
3758 //MapName: AnsiString;
3766 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3767 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3768 if (a
= 0) then exit
;
3770 // Выделяем имя wad-файла и имя карты
3771 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3772 Delete(gMapToDelete
, 1, a
+5);
3773 gMapToDelete
:= UpperCase(gMapToDelete
);
3775 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3778 // Имя карты не стандартное тестовое:
3779 if MapName <> TEST_MAP_NAME then
3782 if not gTempDelete then
3784 time := g_GetFileTime(WadName);
3785 WAD := TWADFile.Create();
3788 if not WAD.ReadFile(WadName) then
3789 begin // Нет такого WAD-файла
3794 // Составляем список карт и ищем нужную:
3796 MapList := WAD.GetResourcesList('');
3798 if MapList <> nil then
3799 for a := 0 to High(MapList) do
3800 if MapList[a] = MapName then
3802 // Удаляем и сохраняем:
3803 WAD.RemoveResource('', MapName);
3804 WAD.SaveTo(WadName);
3809 g_SetFileTime(WadName, time);
3812 if gTempDelete
then DeleteFile(WadName
);
3815 procedure GameCVars(P
: SSArray
);
3818 stat
: TPlayerStatArray
;
3821 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3825 if Length(P
) > 1 then
3830 gsGameFlags
:= gsGameFlags
or Flag
3832 gsGameFlags
:= gsGameFlags
and (not Flag
);
3834 if g_Game_IsServer
then
3837 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3839 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3840 if g_Game_IsNet
then MH_SEND_GameSettings
;
3844 if LongBool(gsGameFlags
and Flag
) then
3845 g_Console_Add(_lc
[OnMsg
])
3847 g_Console_Add(_lc
[OffMsg
]);
3849 if OnMapChange
and g_Game_IsServer
then
3850 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3855 cmd
:= LowerCase(P
[0]);
3857 if cmd
= 'g_gamemode' then
3859 if (Length(P
) > 1) then
3861 a
:= g_Game_TextToMode(P
[1]);
3862 if a
= GM_SINGLE
then a
:= GM_COOP
;
3863 gsGameMode
:= g_Game_ModeToText(a
);
3864 if g_Game_IsServer
then
3866 gSwitchGameMode
:= a
;
3867 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3868 (gState
= STATE_INTERSINGLE
) then
3869 gSwitchGameMode
:= GM_SINGLE
;
3871 gGameSettings
.GameMode
:= gSwitchGameMode
;
3875 if gSwitchGameMode
= gGameSettings
.GameMode
then
3876 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3877 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3879 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3880 [g_Game_ModeToText(gGameSettings
.GameMode
),
3881 g_Game_ModeToText(gSwitchGameMode
)]));
3883 else if cmd
= 'g_friendlyfire' then
3885 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3887 else if cmd
= 'g_friendly_absorb_damage' then
3889 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3891 else if cmd
= 'g_friendly_hit_trace' then
3893 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3895 else if cmd
= 'g_friendly_hit_projectile' then
3897 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3899 else if cmd
= 'g_weaponstay' then
3901 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3903 else if cmd
= 'g_allow_exit' then
3905 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3907 else if cmd
= 'g_allow_monsters' then
3909 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3911 else if cmd
= 'g_bot_vsplayers' then
3913 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3915 else if cmd
= 'g_bot_vsmonsters' then
3917 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3919 else if cmd
= 'g_dm_keys' then
3921 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
3923 else if cmd
= 'g_gameflags' then
3925 if Length(P
) > 1 then
3927 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
3928 if g_Game_IsServer
then
3930 gGameSettings
.Options
:= gsGameFlags
;
3931 if g_Game_IsNet
then MH_SEND_GameSettings
;
3935 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
3937 else if cmd
= 'g_warmup_time' then
3939 if Length(P
) > 1 then
3941 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
3942 if g_Game_IsServer
then
3944 gGameSettings
.WarmupTime
:= gsWarmupTime
;
3945 // extend warmup if it's already going
3946 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
3948 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
3949 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3951 if g_Game_IsNet
then MH_SEND_GameSettings
;
3955 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
3956 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3958 else if cmd
= 'g_spawn_invul' then
3960 if Length(P
) > 1 then
3962 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
3963 if g_Game_IsServer
then
3965 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
3966 if g_Game_IsNet
then MH_SEND_GameSettings
;
3970 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
3972 else if cmd
= 'g_item_respawn_time' then
3974 if Length(P
) > 1 then
3976 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
3977 if g_Game_IsServer
then
3979 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
3980 if g_Game_IsNet
then MH_SEND_GameSettings
;
3984 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
3985 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3987 else if cmd
= 'sv_intertime' then
3989 if (Length(P
) > 1) then
3990 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
3992 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
3994 else if cmd
= 'g_max_particles' then
3996 if Length(p
) = 2 then
3999 a
:= Max(0, StrToInt(p
[1]));
4003 else if Length(p
) = 1 then
4006 e_LogWritefln('%s', [g_GFX_GetMax()])
4008 e_LogWritefln('%s', [0])
4013 e_LogWritefln('usage: %s <n>', [cmd
])
4016 else if cmd
= 'g_max_shells' then
4018 if Length(p
) = 2 then
4020 {$IFDEF ENABLE_SHELLS}
4021 a
:= Max(0, StrToInt(p
[1]));
4025 else if Length(p
) = 1 then
4027 {$IFDEF ENABLE_SHELLS}
4028 e_LogWritefln('%s', [g_Shells_GetMax()])
4030 e_LogWritefln('%s', [0])
4035 e_LogWritefln('usage: %s <n>', [cmd
])
4038 else if cmd
= 'g_max_gibs' then
4040 if Length(p
) = 2 then
4042 {$IFDEF ENABLE_GIBS}
4043 a
:= Max(0, StrToInt(p
[1]));
4047 else if Length(p
) = 1 then
4049 {$IFDEF ENABLE_GIBS}
4050 e_LogWritefln('%s', [g_Gibs_GetMax()])
4052 e_LogWritefln('%s', [0])
4057 e_LogWritefln('usage: %s <n>', [cmd
])
4060 else if cmd
= 'g_max_corpses' then
4062 if Length(p
) = 2 then
4064 {$IFDEF ENABLE_CORPSES}
4065 a
:= Max(0, StrToInt(p
[1]));
4069 else if Length(p
) = 1 then
4071 {$IFDEF ENABLE_CORPSES}
4072 e_LogWritefln('%s', [g_Corpses_GetMax()])
4074 e_LogWritefln('%s', [0])
4079 e_LogWritefln('usage: %s <n>', [cmd
])
4082 else if cmd
= 'g_scorelimit' then
4084 if Length(P
) > 1 then
4086 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
4088 if g_Game_IsServer
then
4091 if gGameSettings
.GameMode
= GM_DM
then
4093 stat
:= g_Player_GetStats();
4095 for a
:= 0 to High(stat
) do
4096 if stat
[a
].Frags
> b
then
4100 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4102 // if someone has a higher score, set it to that instead
4103 gsGoalLimit
:= max(gsGoalLimit
, b
);
4104 gGameSettings
.GoalLimit
:= gsGoalLimit
;
4106 if g_Game_IsNet
then MH_SEND_GameSettings
;
4110 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
4112 else if cmd
= 'g_timelimit' then
4114 if Length(P
) > 1 then
4116 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4117 if g_Game_IsServer
then
4119 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4120 if g_Game_IsNet
then MH_SEND_GameSettings
;
4123 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4124 [gsTimeLimit
div 3600,
4125 (gsTimeLimit
div 60) mod 60,
4126 gsTimeLimit
mod 60]));
4128 else if cmd
= 'g_maxlives' then
4130 if Length(P
) > 1 then
4132 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4133 if g_Game_IsServer
then
4135 gGameSettings
.MaxLives
:= gsMaxLives
;
4136 if g_Game_IsNet
then MH_SEND_GameSettings
;
4140 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4144 procedure PlayerSettingsCVars(P
: SSArray
);
4149 function ParseTeam(s
: string): Byte;
4153 'red', '1': result
:= TEAM_RED
;
4154 'blue', '2': result
:= TEAM_BLUE
;
4155 else result
:= TEAM_NONE
;
4159 cmd
:= LowerCase(P
[0]);
4163 if (Length(P
) > 1) then
4165 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4166 if g_Game_IsClient
then
4167 MC_SEND_PlayerSettings
4168 else if gGameOn
and (gPlayer1
<> nil) then
4170 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4171 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4177 if (Length(P
) > 1) then
4179 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4180 if g_Game_IsClient
then
4181 MC_SEND_PlayerSettings
4182 else if gGameOn
and (gPlayer2
<> nil) then
4184 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4185 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4191 if Length(P
) > 3 then
4193 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4194 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4195 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4196 if g_Game_IsClient
then
4197 MC_SEND_PlayerSettings
4198 else if gGameOn
and (gPlayer1
<> nil) then
4200 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4201 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4207 if Length(P
) > 3 then
4209 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4210 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4211 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4212 if g_Game_IsClient
then
4213 MC_SEND_PlayerSettings
4214 else if gGameOn
and (gPlayer2
<> nil) then
4216 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4217 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4223 if (Length(P
) > 1) then
4225 gPlayer1Settings
.Model
:= P
[1];
4226 if g_Game_IsClient
then
4227 MC_SEND_PlayerSettings
4228 else if gGameOn
and (gPlayer1
<> nil) then
4230 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4231 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4232 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4238 if (Length(P
) > 1) then
4240 gPlayer2Settings
.Model
:= P
[1];
4241 if g_Game_IsClient
then
4242 MC_SEND_PlayerSettings
4243 else if gGameOn
and (gPlayer2
<> nil) then
4245 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4246 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4247 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4253 // TODO: switch teams if in game or store this separately
4254 if (Length(P
) > 1) then
4256 team
:= ParseTeam(P
[1]);
4257 if team
= TEAM_NONE
then
4258 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4259 else if not gGameOn
and not g_Game_IsNet
then
4260 gPlayer1Settings
.Team
:= team
4262 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4267 // TODO: switch teams if in game or store this separately
4268 if (Length(P
) > 1) then
4270 team
:= ParseTeam(P
[1]);
4271 if team
= TEAM_NONE
then
4272 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4273 else if not gGameOn
and not g_Game_IsNet
then
4274 gPlayer2Settings
.Team
:= team
4276 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4282 procedure PrintHeapStats();
4286 hs
:= GetFPCHeapStatus();
4287 e_LogWriteLn ('v===== heap status =====v');
4288 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4289 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4290 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4291 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4292 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4293 e_LogWriteLn ('^=======================^');
4296 procedure DebugCommands(P
: SSArray
);
4303 // Команды отладочного режима:
4304 if {gDebugMode}conIsCheatsEnabled
then
4306 cmd
:= LowerCase(P
[0]);
4307 if cmd
= 'd_window' then
4309 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4310 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4312 else if cmd
= 'd_sounds' then
4314 if (Length(P
) > 1) and
4315 ((P
[1] = '1') or (P
[1] = '0')) then
4316 g_Debug_Sounds
:= (P
[1][1] = '1');
4318 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4320 else if cmd
= 'd_frames' then
4322 if (Length(P
) > 1) and
4323 ((P
[1] = '1') or (P
[1] = '0')) then
4324 g_Debug_Frames
:= (P
[1][1] = '1');
4326 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4328 else if cmd
= 'd_winmsg' then
4330 if (Length(P
) > 1) and
4331 ((P
[1] = '1') or (P
[1] = '0')) then
4332 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4334 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4336 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4338 if (Length(P
) > 1) and
4339 ((P
[1] = '1') or (P
[1] = '0')) then
4340 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4342 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4344 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4346 if Length(P
) > 1 then
4348 '0': g_debug_BotAIOff
:= 0;
4349 '1': g_debug_BotAIOff
:= 1;
4350 '2': g_debug_BotAIOff
:= 2;
4351 '3': g_debug_BotAIOff
:= 3;
4354 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4356 else if cmd
= 'd_monster' then
4358 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4359 if Length(P
) < 2 then
4361 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4362 g_Console_Add('ID | Name');
4363 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4364 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4365 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4368 a
:= StrToIntDef(P
[1], 0);
4369 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4370 a
:= g_Mons_TypeIdByName(P
[1]);
4372 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4373 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4376 with gPlayer1
.Obj
do
4378 mon
:= g_Monsters_Create(a
,
4379 X
+ Rect
.X
+ (Rect
.Width
div 2),
4380 Y
+ Rect
.Y
+ Rect
.Height
,
4381 gPlayer1
.Direction
, True);
4383 if (Length(P
) > 2) and (mon
<> nil) then
4385 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4386 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4387 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4388 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4389 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4390 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4391 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4392 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4393 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4398 else if (cmd
= 'd_health') then
4400 if (Length(P
) > 1) and
4401 ((P
[1] = '1') or (P
[1] = '0')) then
4402 g_debug_HealthBar
:= (P
[1][1] = '1');
4404 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4406 else if (cmd
= 'd_player') then
4408 if (Length(P
) > 1) and
4409 ((P
[1] = '1') or (P
[1] = '0')) then
4410 g_debug_Player
:= (P
[1][1] = '1');
4412 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4414 else if (cmd
= 'd_mem') then
4420 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4424 procedure GameCheats(P
: SSArray
);
4430 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4432 g_Console_Add('not available');
4438 g_Console_Add('where is the player?!');
4441 cmd
:= LowerCase(P
[0]);
4445 plr
.GodMode
:= not plr
.GodMode
;
4446 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4449 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4450 if cmd
= 'give' then
4452 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4453 for f
:= 1 to High(P
) do
4455 cmd
:= LowerCase(P
[f
]);
4456 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4457 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4458 if cmd
= 'exit' then
4460 if gTriggers
<> nil then
4462 for a
:= 0 to High(gTriggers
) do
4464 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4466 g_Console_Add('player left the map');
4467 gExitByTrigger
:= True;
4468 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4469 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4477 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4478 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4479 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4480 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4481 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4483 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4484 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4486 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4487 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;
4489 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4490 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4492 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4493 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4495 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4496 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4498 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4499 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4500 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4502 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4503 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4504 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4505 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;
4506 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4507 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4509 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;
4510 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;
4511 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;
4512 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;
4513 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;
4514 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;
4516 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4517 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;
4519 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;
4520 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;
4522 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4524 if cmd
= 'ammo' then
4526 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4527 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4528 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4529 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4530 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4531 g_Console_Add('player got some ammo');
4535 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4536 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4538 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4539 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4541 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4542 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4544 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4545 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4547 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4549 if cmd
= 'weapons' then
4551 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4552 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4553 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4554 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4555 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4556 plr
.GiveItem(ITEM_WEAPON_BFG
);
4557 g_Console_Add('player got weapons');
4561 if cmd
= 'keys' then
4563 plr
.GiveItem(ITEM_KEY_RED
);
4564 plr
.GiveItem(ITEM_KEY_GREEN
);
4565 plr
.GiveItem(ITEM_KEY_BLUE
);
4566 g_Console_Add('player got all keys');
4570 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4575 if cmd
= 'open' then
4577 g_Console_Add('player activated sesame');
4578 g_Triggers_OpenAll();
4585 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4589 if cmd
= 'noclip' then
4592 g_Console_Add('wall hardeness adjusted');
4596 if cmd
= 'notarget' then
4598 plr
.NoTarget
:= not plr
.NoTarget
;
4599 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4603 if cmd
= 'noreload' then
4605 plr
.NoReload
:= not plr
.NoReload
;
4606 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4610 if cmd
= 'speedy' then
4612 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4613 g_Console_Add('speed adjusted');
4617 if cmd
= 'jumpy' then
4619 VEL_JUMP
:= 30-VEL_JUMP
;
4620 g_Console_Add('jump height adjusted');
4624 if cmd
= 'automap' then
4626 gShowMap
:= not gShowMap
;
4627 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4631 if cmd
= 'aimline' then
4633 gAimLine
:= not gAimLine
;
4634 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4639 procedure GameCommands(P
: SSArray
);
4645 pl
: pTNetClient
= nil;
4653 cmd
:= LowerCase(P
[0]);
4655 if cmd
= 'pause' then
4657 {$IFDEF ENABLE_MENU}
4658 if (g_ActiveWindow
= nil) then
4659 g_Game_Pause(not gPauseMain
);
4661 g_Game_Pause(not gPauseMain
);
4664 else if cmd
= 'endgame' then
4665 gExit
:= EXIT_SIMPLE
4666 else if cmd
= 'restart' then
4668 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4670 if g_Game_IsClient
then
4672 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4677 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4679 else if cmd
= 'kick' then
4681 if g_Game_IsServer
then
4683 if Length(P
) < 2 then
4685 g_Console_Add('kick <name>');
4690 g_Console_Add('kick <name>');
4694 if g_Game_IsNet
then
4695 pl
:= g_Net_Client_ByName(P
[1]);
4698 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4699 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4700 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4701 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4702 g_Net_Slist_ServerPlayerLeaves();
4703 end else if gPlayers
<> nil then
4704 for a
:= Low(gPlayers
) to High(gPlayers
) do
4705 if gPlayers
[a
] <> nil then
4706 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4708 // Не отключать основных игроков в сингле
4709 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4711 gPlayers
[a
].Lives
:= 0;
4712 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4713 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4714 g_Player_Remove(gPlayers
[a
].UID
);
4715 g_Net_Slist_ServerPlayerLeaves();
4716 // Если не перемешать, при добавлении новых ботов появятся старые
4720 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4722 else if cmd
= 'kick_id' then
4724 if g_Game_IsServer
and g_Game_IsNet
then
4726 if Length(P
) < 2 then
4728 g_Console_Add('kick_id <client ID>');
4733 g_Console_Add('kick_id <client ID>');
4737 a
:= StrToIntDef(P
[1], 0);
4738 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4740 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4742 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4743 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
4744 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4745 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4746 g_Net_Slist_ServerPlayerLeaves();
4750 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4752 else if cmd
= 'kick_pid' then
4754 if g_Game_IsServer
and g_Game_IsNet
then
4756 if Length(P
) < 2 then
4758 g_Console_Add('kick_pid <player ID>');
4763 g_Console_Add('kick_pid <player ID>');
4767 a
:= StrToIntDef(P
[1], 0);
4768 pl
:= g_Net_Client_ByPlayer(a
);
4769 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4771 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4772 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4773 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4774 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4775 g_Net_Slist_ServerPlayerLeaves();
4778 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4780 else if cmd
= 'ban' then
4782 if g_Game_IsServer
and g_Game_IsNet
then
4784 if Length(P
) < 2 then
4786 g_Console_Add('ban <name>');
4791 g_Console_Add('ban <name>');
4795 pl
:= g_Net_Client_ByName(P
[1]);
4798 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4799 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4800 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4801 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4802 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4803 g_Net_Slist_ServerPlayerLeaves();
4805 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4807 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4809 else if cmd
= 'ban_id' then
4811 if g_Game_IsServer
and g_Game_IsNet
then
4813 if Length(P
) < 2 then
4815 g_Console_Add('ban_id <client ID>');
4820 g_Console_Add('ban_id <client ID>');
4824 a
:= StrToIntDef(P
[1], 0);
4825 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4826 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4828 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4829 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
4830 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
4831 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4832 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4833 g_Net_Slist_ServerPlayerLeaves();
4836 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4838 else if cmd
= 'ban_pid' then
4840 if g_Game_IsServer
and g_Game_IsNet
then
4842 if Length(P
) < 2 then
4844 g_Console_Add('ban_pid <player ID>');
4849 g_Console_Add('ban_pid <player ID>');
4853 a
:= StrToIntDef(P
[1], 0);
4854 pl
:= g_Net_Client_ByPlayer(a
);
4855 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4857 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4858 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4859 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4860 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4861 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4862 g_Net_Slist_ServerPlayerLeaves();
4865 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4867 else if cmd
= 'permban' then
4869 if g_Game_IsServer
and g_Game_IsNet
then
4871 if Length(P
) < 2 then
4873 g_Console_Add('permban <name>');
4878 g_Console_Add('permban <name>');
4882 pl
:= g_Net_Client_ByName(P
[1]);
4885 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4886 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4887 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
4888 g_Net_SaveBanList();
4889 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4890 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4891 g_Net_Slist_ServerPlayerLeaves();
4893 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4895 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4897 else if cmd
= 'permban_id' then
4899 if g_Game_IsServer
and g_Game_IsNet
then
4901 if Length(P
) < 2 then
4903 g_Console_Add('permban_id <client ID>');
4908 g_Console_Add('permban_id <client ID>');
4912 a
:= StrToIntDef(P
[1], 0);
4913 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4914 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4916 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4917 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
4918 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
4919 g_Net_SaveBanList();
4920 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4921 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4922 g_Net_Slist_ServerPlayerLeaves();
4925 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4927 else if cmd
= 'permban_pid' then
4929 if g_Game_IsServer
and g_Game_IsNet
then
4931 if Length(P
) < 2 then
4933 g_Console_Add('permban_pid <player ID>');
4938 g_Console_Add('permban_pid <player ID>');
4942 a
:= StrToIntDef(P
[1], 0);
4943 pl
:= g_Net_Client_ByPlayer(a
);
4944 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4946 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4947 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4948 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
4949 g_Net_SaveBanList();
4950 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4951 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4952 g_Net_Slist_ServerPlayerLeaves();
4955 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4957 else if cmd
= 'permban_ip' then
4959 if g_Game_IsServer
and g_Game_IsNet
then
4961 if Length(P
) < 2 then
4963 g_Console_Add('permban_ip <IP address>');
4968 g_Console_Add('permban_ip <IP address>');
4972 g_Net_BanHost(P
[1]);
4973 g_Net_SaveBanList();
4974 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
4976 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4978 else if cmd
= 'unban' then
4980 if g_Game_IsServer
and g_Game_IsNet
then
4982 if Length(P
) < 2 then
4984 g_Console_Add('unban <IP Address>');
4989 g_Console_Add('unban <IP Address>');
4993 if g_Net_UnbanHost(P
[1]) then
4995 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
4996 g_Net_SaveBanList();
4998 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5000 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5002 else if cmd
= 'clientlist' then
5004 if g_Game_IsServer
and g_Game_IsNet
then
5007 if NetClients
<> nil then
5008 for a
:= Low(NetClients
) to High(NetClients
) do
5009 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5011 plr
:= g_Player_Get(NetClients
[a
].Player
);
5012 if plr
= nil then continue
;
5014 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5015 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5018 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5020 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5022 else if cmd
= 'connect' then
5024 if (NetMode
= NET_NONE
) then
5026 if Length(P
) < 2 then
5028 g_Console_Add('connect <IP> [port] [password]');
5033 g_Console_Add('connect <IP> [port] [password]');
5037 if Length(P
) > 2 then
5038 prt
:= StrToIntDef(P
[2], 25666)
5042 if Length(P
) > 3 then
5047 g_Game_StartClient(P
[1], prt
, pw
);
5050 else if cmd
= 'disconnect' then
5052 if (NetMode
= NET_CLIENT
) then
5055 else if cmd
= 'reconnect' then
5057 if (NetMode
= NET_SERVER
) then
5060 if (NetMode
= NET_CLIENT
) then
5063 gExit
:= EXIT_SIMPLE
;
5067 //TODO: Use last successful password to reconnect, instead of ''
5068 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5070 else if (cmd
= 'addbot') or
5071 (cmd
= 'bot_add') then
5073 if Length(P
) > 2 then
5074 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5075 else if Length(P
) > 1 then
5076 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5078 g_Bot_Add(TEAM_NONE
, 2);
5080 else if cmd
= 'bot_addlist' then
5082 if Length(P
) > 1 then
5084 if Length(P
) = 2 then
5085 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5086 else if Length(P
) = 3 then
5087 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5089 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5092 else if cmd
= 'bot_removeall' then
5094 else if cmd
= 'chat' then
5096 if g_Game_IsNet
then
5098 if Length(P
) > 1 then
5100 for a
:= 1 to High(P
) do
5101 chstr
:= chstr
+ P
[a
] + ' ';
5103 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5105 if Length(chstr
) < 1 then
5107 g_Console_Add('chat <text>');
5111 chstr
:= b_Text_Format(chstr
);
5112 if g_Game_IsClient
then
5113 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5115 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5118 g_Console_Add('chat <text>');
5120 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5122 else if cmd
= 'teamchat' then
5124 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5126 if Length(P
) > 1 then
5128 for a
:= 1 to High(P
) do
5129 chstr
:= chstr
+ P
[a
] + ' ';
5131 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5133 if Length(chstr
) < 1 then
5135 g_Console_Add('teamchat <text>');
5139 chstr
:= b_Text_Format(chstr
);
5140 if g_Game_IsClient
then
5141 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5143 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5144 gPlayer1Settings
.Team
);
5147 g_Console_Add('teamchat <text>');
5149 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5151 else if cmd
= 'game' then
5153 if gGameSettings
.GameType
<> GT_NONE
then
5155 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5158 if Length(P
) = 1 then
5160 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5163 // game not started yet, load fist map from some wad
5165 s
:= addWadExtension(P
[1]);
5166 found
:= e_FindResource(AllMapDirs
, s
);
5170 P
[1] := ExpandFileName(P
[1]);
5171 // if map not choosed then set first map
5172 if Length(P
) < 3 then
5175 P
[2] := g_Game_GetFirstMap(P
[1]);
5178 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5180 if g_Map_Exist(s
) then
5184 with gGameSettings
do
5186 Options
:= gsGameFlags
;
5187 GameMode
:= g_Game_TextToMode(gsGameMode
);
5188 if gSwitchGameMode
<> GM_NONE
then
5189 GameMode
:= gSwitchGameMode
;
5190 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5191 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5193 if Length(P
) >= 4 then
5194 b
:= StrToIntDef(P
[3], 1);
5195 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5196 GoalLimit
, MaxLives
, Options
, b
);
5201 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5203 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5205 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5207 else if cmd
= 'host' then
5209 if gGameSettings
.GameType
<> GT_NONE
then
5211 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5214 if Length(P
) < 4 then
5216 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5219 if not StrToIp(P
[1], listen
) then
5221 prt
:= StrToIntDef(P
[2], 25666);
5223 s
:= addWadExtension(P
[3]);
5224 found
:= e_FindResource(AllMapDirs
, s
);
5228 // get first map in wad, if not specified
5229 if Length(P
) < 5 then
5232 P
[4] := g_Game_GetFirstMap(P
[1]);
5234 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5235 if g_Map_Exist(s
) then
5239 with gGameSettings
do
5241 Options
:= gsGameFlags
;
5242 GameMode
:= g_Game_TextToMode(gsGameMode
);
5243 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5244 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5245 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5247 if Length(P
) >= 6 then
5248 b
:= StrToIntDef(P
[5], 0);
5249 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
5255 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5257 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5262 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5265 else if cmd
= 'map' then
5267 if Length(P
) = 1 then
5269 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5271 g_Console_Add(cmd
+ ' <MAP>');
5272 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5276 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5281 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5283 if Length(P
) < 3 then
5285 // first param is map or wad
5286 s
:= UpperCase(P
[1]);
5287 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5289 gExitByTrigger
:= False;
5292 // already in game, finish current map
5294 gExit
:= EXIT_ENDLEVELCUSTOM
;
5298 // intermission, so change map immediately
5305 found
:= e_FindResource(AllMapDirs
, s
);
5307 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5310 // no such map, found wad
5313 P
[1] := ExpandFileName(pw
);
5314 P
[2] := g_Game_GetFirstMap(P
[1]);
5315 s
:= P
[1] + ':\' + P
[2];
5316 if g_Map_Exist(s
) then
5318 gExitByTrigger
:= False;
5321 // already in game, finish current map
5323 gExit
:= EXIT_ENDLEVELCUSTOM
5327 // intermission, so change map immediately
5334 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5336 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5341 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5347 s
:= addWadExtension(P
[1]);
5348 found
:= e_FindResource(AllMapDirs
, s
);
5352 P
[2] := UpperCase(P
[2]);
5353 s
:= P
[1] + ':\' + P
[2];
5354 if g_Map_Exist(s
) then
5356 gExitByTrigger
:= False;
5360 gExit
:= EXIT_ENDLEVELCUSTOM
5369 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5374 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5380 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5384 else if cmd
= 'nextmap' then
5386 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5388 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5393 if Length(P
) = 1 then
5395 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5397 g_Console_Add(cmd
+ ' <MAP>');
5398 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5403 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5409 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5411 if Length(P
) < 3 then
5413 // first param is map or wad
5414 s
:= UpperCase(P
[1]);
5415 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5418 gExitByTrigger
:= False;
5424 // no such map, found wad
5425 pw
:= addWadExtension(P
[1]);
5426 found
:= e_FindResource(MapDirs
, pw
);
5428 found
:= e_FindResource(WadDirs
, pw
);
5430 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5433 // map not specified, select first map
5435 P
[2] := g_Game_GetFirstMap(P
[1]);
5436 s
:= P
[1] + ':\' + P
[2];
5437 if g_Map_Exist(s
) then
5439 gExitByTrigger
:= False;
5446 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5448 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5453 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5459 // specified two params wad + map
5460 pw
:= addWadExtension(P
[1]);
5461 found
:= e_FindResource(MapDirs
, pw
);
5463 found
:= e_FindResource(MapDirs
, pw
);
5467 P
[2] := UpperCase(P
[2]);
5468 s
:= P
[1] + ':\' + P
[2];
5469 if g_Map_Exist(s
) then
5471 gExitByTrigger
:= False;
5477 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5482 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5488 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5493 if gNextMap
= '' then
5494 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5496 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5500 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5504 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5508 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5510 gExitByTrigger
:= False;
5511 // next map not specified, try to find trigger EXIT
5512 if (gNextMap
= '') and (gTriggers
<> nil) then
5514 for a
:= 0 to High(gTriggers
) do
5516 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5518 gExitByTrigger
:= True;
5519 //gNextMap := gTriggers[a].Data.MapName;
5520 gNextMap
:= gTriggers
[a
].tgcMap
;
5525 if gNextMap
= '' then
5526 gNextMap
:= g_Game_GetNextMap();
5527 if not isWadPath(gNextMap
) then
5528 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5531 if g_Map_Exist(s
) then
5532 gExit
:= EXIT_ENDLEVELCUSTOM
5534 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5538 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5542 else if (cmd
= 'event') then
5544 if (Length(P
) <= 1) then
5546 for a
:= 0 to High(gEvents
) do
5547 if gEvents
[a
].Command
= '' then
5548 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5550 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5553 if (Length(P
) = 2) then
5555 for a
:= 0 to High(gEvents
) do
5556 if gEvents
[a
].Name
= P
[1] then
5557 if gEvents
[a
].Command
= '' then
5558 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5560 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5563 for a
:= 0 to High(gEvents
) do
5564 if gEvents
[a
].Name
= P
[1] then
5566 gEvents
[a
].Command
:= '';
5567 for b
:= 2 to High(P
) do
5568 if Pos(' ', P
[b
]) = 0 then
5569 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5571 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5572 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5576 else if cmd
= 'suicide' then
5580 if g_Game_IsClient
then
5581 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5584 if gPlayer1
<> nil then
5585 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5586 if gPlayer2
<> nil then
5587 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5591 else if cmd
= 'screenshot' then
5593 {$IFDEF ENABLE_RENDER}
5597 else if cmd
= 'weapon' then
5599 if Length(p
) = 2 then
5601 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
5602 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5603 gSelectWeapon
[0, a
] := True
5606 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5608 if Length(p
) = 2 then
5610 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
5611 b
:= ord(cmd
[2]) - ord('1');
5612 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5613 gSelectWeapon
[b
, a
] := True
5616 // Команды Своей игры:
5617 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5619 if cmd
= 'bot_addred' then
5621 if Length(P
) > 1 then
5622 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5624 g_Bot_Add(TEAM_RED
, 2);
5626 else if cmd
= 'bot_addblue' then
5628 if Length(P
) > 1 then
5629 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5631 g_Bot_Add(TEAM_BLUE
, 2);
5633 else if cmd
= 'spectate' then
5639 else if cmd
= 'say' then
5641 if g_Game_IsServer
and g_Game_IsNet
then
5643 if Length(P
) > 1 then
5646 for a
:= 1 to High(P
) do
5647 chstr
:= chstr
+ P
[a
] + ' ';
5649 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5651 if Length(chstr
) < 1 then
5653 g_Console_Add('say <text>');
5657 chstr
:= b_Text_Format(chstr
);
5658 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5660 else g_Console_Add('say <text>');
5662 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5664 else if cmd
= 'tell' then
5666 if g_Game_IsServer
and g_Game_IsNet
then
5668 if (Length(P
) > 2) and (P
[1] <> '') then
5671 for a
:= 2 to High(P
) do
5672 chstr
:= chstr
+ P
[a
] + ' ';
5674 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5676 if Length(chstr
) < 1 then
5678 g_Console_Add('tell <playername> <text>');
5682 pl
:= g_Net_Client_ByName(P
[1]);
5684 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5686 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5688 else g_Console_Add('tell <playername> <text>');
5690 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5692 else if cmd
= 'centerprint' then
5694 if (Length(P
) > 2) and (P
[1] <> '') then
5697 for a
:= 2 to High(P
) do
5698 chstr
:= chstr
+ P
[a
] + ' ';
5700 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5702 if Length(chstr
) < 1 then
5704 g_Console_Add('centerprint <timeout> <text>');
5708 a
:= StrToIntDef(P
[1], 100);
5709 chstr
:= b_Text_Format(chstr
);
5710 g_Game_Message(chstr
, a
);
5711 if g_Game_IsNet
and g_Game_IsServer
then
5712 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
5714 else g_Console_Add('centerprint <timeout> <text>');
5716 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5718 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5720 // Дополнительное время:
5721 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5723 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5724 [gGameSettings
.TimeLimit
div 3600,
5725 (gGameSettings
.TimeLimit
div 60) mod 60,
5726 gGameSettings
.TimeLimit
mod 60]));
5727 if g_Game_IsNet
then MH_SEND_GameSettings
;
5729 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5731 if (Length(P
) <= 1) then
5732 g_Console_Add('rcon_password <password>')
5734 MC_SEND_RCONPassword(P
[1]);
5736 else if cmd
= 'rcon' then
5738 if g_Game_IsClient
then
5740 if Length(P
) > 1 then
5743 for a
:= 1 to High(P
) do
5744 chstr
:= chstr
+ P
[a
] + ' ';
5746 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5748 if Length(chstr
) < 1 then
5750 g_Console_Add('rcon <command>');
5754 MC_SEND_RCONCommand(chstr
);
5756 else g_Console_Add('rcon <command>');
5759 else if cmd
= 'ready' then
5761 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5762 gLMSRespawnTime
:= gTime
+ 100;
5764 else if (cmd
= 'callvote') and g_Game_IsNet
then
5766 if Length(P
) > 1 then
5769 for a
:= 1 to High(P
) do begin
5770 if a
> 1 then chstr
:= chstr
+ ' ';
5771 chstr
:= chstr
+ P
[a
];
5774 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5776 if Length(chstr
) < 1 then
5778 g_Console_Add('callvote <command>');
5782 if g_Game_IsClient
then
5783 MC_SEND_Vote(True, chstr
)
5785 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5786 g_Console_Process('vote', True);
5789 g_Console_Add('callvote <command>');
5791 else if (cmd
= 'vote') and g_Game_IsNet
then
5793 if g_Game_IsClient
then
5795 else if gVoteInProgress
then
5797 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5798 a
:= Floor((NetClientCount
+1)/2.0) + 1
5800 a
:= Floor(NetClientCount
/2.0) + 1;
5805 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5806 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5812 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5813 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5821 procedure SystemCommands(P
: SSArray
);
5825 cmd
:= LowerCase(P
[0]);
5832 {$IFDEF ENABLE_RENDER}
5838 if Length(p
) = 2 then
5840 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
5842 gFrameTime
:= 1000 div gMaxFPS
5846 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
5850 if Length(p
) = 2 then
5852 gAskLanguage
:= true;
5853 gLanguage
:= LANGUAGE_ENGLISH
;
5854 case LowerCase(p
[1]) of
5857 gAskLanguage
:= false;
5858 gLanguage
:= LANGUAGE_ENGLISH
;
5862 gAskLanguage
:= false;
5863 gLanguage
:= LANGUAGE_RUSSIAN
;
5867 gAskLanguage
:= true;
5868 gLanguage
:= LANGUAGE_ENGLISH
;
5871 g_Language_Set(gLanguage
);
5875 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
5881 {$IFDEF ENABLE_RENDER}
5882 procedure g_TakeScreenShot(Filename
: string = '');
5883 var t
: TDateTime
; dir
, date
, name
: String;
5885 if e_NoGraphics
then
5888 dir
:= e_GetWriteableDir(ScreenshotDirs
);
5889 if Filename
= '' then
5892 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
5893 Filename
:= 'screenshot-' + date
;
5896 name
:= e_CatPath(dir
, Filename
+ '.png');
5897 if r_Render_WriteScreenShot(name
) then
5898 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
5900 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
5904 {$IFDEF ENABLE_MENU}
5905 procedure g_Game_InGameMenu(Show
: Boolean);
5907 if (g_ActiveWindow
= nil) and Show
then
5909 if gGameSettings
.GameType
= GT_SINGLE
then
5910 g_GUI_ShowWindow('GameSingleMenu')
5913 if g_Game_IsClient
then
5914 g_GUI_ShowWindow('GameClientMenu')
5916 if g_Game_IsNet
then
5917 g_GUI_ShowWindow('GameServerMenu')
5919 g_GUI_ShowWindow('GameCustomMenu');
5921 g_Sound_PlayEx('MENU_OPEN');
5923 // Пауза при меню только в одиночной игре:
5924 if (not g_Game_IsNet
) then
5928 if (g_ActiveWindow
<> nil) and (not Show
) then
5930 // Пауза при меню только в одиночной игре:
5931 if (not g_Game_IsNet
) then
5932 g_Game_Pause(False);
5937 procedure g_Game_Pause (Enable
: Boolean);
5941 if not gGameOn
then exit
;
5943 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
5946 gPauseMain
:= Enable
;
5948 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
5951 procedure g_Game_HolmesPause (Enable
: Boolean);
5955 if not gGameOn
then exit
;
5956 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
5959 gPauseHolmes
:= Enable
;
5961 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
5964 procedure g_Game_PauseAllSounds(Enable
: Boolean);
5969 if gTriggers
<> nil then
5970 for i
:= 0 to High(gTriggers
) do
5971 with gTriggers
[i
] do
5972 if (TriggerType
= TRIGGER_SOUND
) and
5974 Sound
.IsPlaying() then
5976 Sound
.Pause(Enable
);
5980 if gPlayers
<> nil then
5981 for i
:= 0 to High(gPlayers
) do
5982 if gPlayers
[i
] <> nil then
5983 gPlayers
[i
].PauseSounds(Enable
);
5986 if gMusic
<> nil then
5987 gMusic
.Pause(Enable
);
5990 procedure g_Game_StopAllSounds(all
: Boolean);
5994 if gTriggers
<> nil then
5995 for i
:= 0 to High(gTriggers
) do
5996 with gTriggers
[i
] do
5997 if (TriggerType
= TRIGGER_SOUND
) and
6001 if gMusic
<> nil then
6008 procedure g_Game_UpdateTriggerSounds
;
6011 if gTriggers
<> nil then
6012 for i
:= 0 to High(gTriggers
) do
6013 with gTriggers
[i
] do
6014 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6015 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6018 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6021 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6026 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6031 if gSpectMode
<> SPECT_PLAYERS
then
6033 if gSpectPID1
= UID
then
6038 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6045 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6050 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6055 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6060 if gSpectMode
<> SPECT_PLAYERS
then
6062 Pl
:= g_Player_Get(gSpectPID1
);
6063 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6068 if gSpectViewTwo
then
6070 Pl
:= g_Player_Get(gSpectPID2
);
6071 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6079 procedure g_Game_Message (Msg
: string; Time
: Word);
6082 MessageTime
:= Time
;
6085 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6087 punct
: Array[0..13] of String =
6088 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6094 function IsPunctuation(S
: String): Boolean;
6099 if Length(S
) <> 1 then
6101 for i
:= Low(punct
) to High(punct
) do
6102 if S
= punct
[i
] then
6108 function FilterPunctuation(S
: String): String;
6112 for i
:= Low(punct
) to High(punct
) do
6113 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6119 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6121 // remove player name
6122 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6123 // for FullWord check
6124 Text := toLowerCase1251(' ' + Text + ' ');
6125 fpText
:= FilterPunctuation(Text);
6127 for i
:= 0 to Length(gChatSounds
) - 1 do
6130 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6132 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6133 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6135 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6141 gChatSounds
[i
].Sound
.Play();
6147 g_Sound_PlayEx('SOUND_GAME_RADIO');
6150 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6159 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6163 if goodsnd
[a
].IsPlaying() then
6166 goodsnd
[Random(4)].Play();
6169 procedure g_Game_Announce_KillCombo(Param
: Integer);
6176 UID
:= Param
and $FFFF;
6181 Pl
:= g_Player_Get(UID
);
6190 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6194 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6198 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6202 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6210 if not g_Game_IsWatchedPlayer(UID
) then
6213 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6217 if killsnd
[n
].IsPlaying() then
6222 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6230 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6234 if hahasnd
[a
].IsPlaying() then
6237 hahasnd
[Random(3)].Play();
6240 procedure g_Game_StartVote(Command
, Initiator
: string);
6244 if not gVotesEnabled
then Exit
;
6245 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6246 if gVoteInProgress
or gVotePassed
then
6248 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6249 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6252 gVoteInProgress
:= True;
6253 gVotePassed
:= False;
6254 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6257 gVoteCommand
:= Command
;
6259 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6260 Need
:= Floor((NetClientCount
+1)/2.0)+1
6262 Need
:= Floor(NetClientCount
/2.0)+1;
6263 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6264 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6267 procedure g_Game_CheckVote
;
6271 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6272 if not gVoteInProgress
then Exit
;
6274 if (gTime
>= gVoteTimer
) then
6276 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6277 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6279 Need
:= Floor(NetClientCount
/2.0) + 1;
6280 if gVoteCount
>= Need
then
6282 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6283 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6284 gVotePassed
:= True;
6285 gVoteCmdTimer
:= gTime
+ 5000;
6289 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6290 MH_SEND_VoteEvent(NET_VE_FAILED
);
6292 if NetClients
<> nil then
6293 for I
:= Low(NetClients
) to High(NetClients
) do
6294 if NetClients
[i
].Used
then
6295 NetClients
[i
].Voted
:= False;
6296 gVoteInProgress
:= False;
6302 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6303 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6305 Need
:= Floor(NetClientCount
/2.0) + 1;
6306 if gVoteCount
>= Need
then
6308 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6309 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6310 gVoteInProgress
:= False;
6311 gVotePassed
:= True;
6312 gVoteCmdTimer
:= gTime
+ 5000;
6315 if NetClients
<> nil then
6316 for I
:= Low(NetClients
) to High(NetClients
) do
6317 if NetClients
[i
].Used
then
6318 NetClients
[i
].Voted
:= False;
6323 procedure g_Game_LoadMapList(FileName
: string);
6331 if not FileExists(FileName
) then Exit
;
6333 AssignFile(ListFile
, FileName
);
6335 while not EOF(ListFile
) do
6337 ReadLn(ListFile
, s
);
6340 if s
= '' then Continue
;
6342 SetLength(MapList
, Length(MapList
)+1);
6343 MapList
[High(MapList
)] := s
;
6345 CloseFile(ListFile
);
6348 procedure g_Game_SetDebugMode();
6351 // Читы (даже в своей игре):
6355 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6359 if Length(LoadingStat
.Msgs
) = 0 then
6365 begin // Переходим на следующую строку или скроллируем:
6366 if NextMsg
= Length(Msgs
) then
6368 for i
:= 0 to High(Msgs
)-1 do
6369 Msgs
[i
] := Msgs
[i
+1];
6377 Msgs
[NextMsg
-1] := Text;
6381 PBarWasHere
:= false;
6384 {$IFDEF ENABLE_MENU}
6385 g_ActiveWindow
:= nil;
6388 ProcessLoading(true);
6391 procedure g_Game_StepLoading(Value
: Integer = -1);
6402 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6410 procedure g_Game_ClearLoading();
6419 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6420 if len
< 1 then len
:= 1;
6421 SetLength(Msgs
, len
);
6422 for len
:= Low(Msgs
) to High(Msgs
) do
6425 PBarWasHere
:= false;
6429 procedure Parse_Params(var pars
: TParamStrValues
);
6436 while i
<= ParamCount
do
6439 if (s
[1] = '-') and (Length(s
) > 1) then
6441 if (s
[2] = '-') and (Length(s
) > 2) then
6442 begin // Одиночный параметр
6443 SetLength(pars
, Length(pars
) + 1);
6444 with pars
[High(pars
)] do
6446 Name
:= LowerCase(s
);
6451 if (i
< ParamCount
) then
6452 begin // Параметр со значением
6454 SetLength(pars
, Length(pars
) + 1);
6455 with pars
[High(pars
)] do
6457 Name
:= LowerCase(s
);
6458 Value
:= LowerCase(ParamStr(i
));
6467 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6472 for i
:= 0 to High(pars
) do
6473 if pars
[i
].Name
= aName
then
6475 Result
:= pars
[i
].Value
;
6480 procedure g_Game_Process_Params();
6482 pars
: TParamStrValues
;
6485 LimT
, LimS
: Integer;
6496 s
:= Find_Param_Value(pars
, '--debug');
6499 g_Game_SetDebugMode();
6500 s
:= Find_Param_Value(pars
, '--netdump');
6505 // Connect when game loads
6506 ip
:= Find_Param_Value(pars
, '-connect');
6510 s
:= Find_Param_Value(pars
, '-port');
6511 if (s
= '') or not TryStrToInt(s
, Port
) then
6514 s
:= Find_Param_Value(pars
, '-pw');
6516 g_Game_StartClient(ip
, Port
, s
);
6520 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6523 gDefaultMegawadStart
:= s
;
6526 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6527 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6529 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6532 // Start map when game loads:
6533 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6534 if isWadPath(map
) then
6537 s
:= Find_Param_Value(pars
, '-gm');
6538 GMode
:= g_Game_TextToMode(s
);
6539 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6540 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6543 s
:= Find_Param_Value(pars
, '-limt');
6544 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6550 s
:= Find_Param_Value(pars
, '-lims');
6551 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6557 s
:= Find_Param_Value(pars
, '-lives');
6558 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6564 s
:= Find_Param_Value(pars
, '-opt');
6568 Opt
:= StrToIntDef(s
, 0);
6571 s
:= Find_Param_Value(pars
, '--close');
6575 // Override map to test:
6576 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6579 if e_IsValidResourceName(s
) then
6580 e_FindResource(AllMapDirs
, s
);
6581 gTestMap
:= ExpandFileName(s
);
6584 // Delete test map after play:
6585 s
:= Find_Param_Value(pars
, '--testdelete');
6588 //gMapToDelete := MapsDir + map;
6589 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6593 // Delete temporary WAD after play:
6594 s
:= Find_Param_Value(pars
, '--tempdelete');
6595 if (s
<> '') and (gTestMap
<> '') then
6597 gMapToDelete
:= gTestMap
;
6598 gTempDelete
:= True;
6601 // Number of players:
6602 s
:= Find_Param_Value(pars
, '-pl');
6604 n
:= DEFAULT_PLAYERS
6606 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6609 s
:= Find_Param_Value(pars
, '-port');
6610 if (s
= '') or not TryStrToInt(s
, Port
) then
6611 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6613 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6616 // Execute script when game loads:
6617 s
:= Find_Param_Value(pars
, '-exec');
6620 // if not isWadPath(s) then
6621 // s := GameDir + '/' + s;
6626 if IOResult
<> 0 then
6628 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6629 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6633 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6634 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6639 if IOResult
<> 0 then
6641 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6642 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6646 if Pos('#', s
) <> 1 then // script comment
6647 g_Console_Process(s
, True);
6658 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6659 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6660 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6661 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6663 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6664 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6665 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6666 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6669 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6670 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6673 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6674 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6676 {$IFDEF ENABLE_HOLMES}
6677 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6680 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6682 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6683 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6685 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6686 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6688 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6689 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6690 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6691 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
6692 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6693 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6694 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6695 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6696 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');