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);
157 {$IFDEF ENABLE_SYSTEM}
158 procedure CharPress (C
: AnsiChar);
161 procedure KeyPress (K
: Word);
163 { procedure SetWinPause(Enable: Boolean); }
168 LOADING_SHOW_STEP
= 100;
169 LOADING_INTERLINE
= 20;
187 EXIT_ENDLEVELSINGLE
= 4;
188 EXIT_ENDLEVELCUSTOM
= 5;
190 GAME_OPTION_RESERVED
= 1;
191 GAME_OPTION_TEAMDAMAGE
= 2;
192 GAME_OPTION_ALLOWEXIT
= 4;
193 GAME_OPTION_WEAPONSTAY
= 8;
194 GAME_OPTION_MONSTERS
= 16;
195 GAME_OPTION_BOTVSPLAYER
= 32;
196 GAME_OPTION_BOTVSMONSTER
= 64;
197 GAME_OPTION_DMKEYS
= 128;
198 GAME_OPTION_TEAMHITTRACE
= 256;
199 GAME_OPTION_TEAMHITPROJECTILE
= 512;
200 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
205 STATE_INTERCUSTOM
= 3;
206 STATE_INTERSINGLE
= 4;
212 LMS_RESPAWN_NONE
= 0;
213 LMS_RESPAWN_WARMUP
= 1;
214 LMS_RESPAWN_FINAL
= 2;
231 CONFIG_FILENAME
= 'Doom2DF.cfg';
233 TEST_MAP_NAME
= '$$$_TEST_$$$';
235 STD_PLAYER_MODEL
= 'Doomer';
243 STATFILE_VERSION
= $03;
246 gGameSettings
: TGameSettings
;
247 gPlayer1Settings
: TPlayerSettings
;
248 gPlayer2Settings
: TPlayerSettings
;
250 gPlayerScreenSize
: TDFPoint
;
251 gPlayer1ScreenCoord
: TDFPoint
;
252 gPlayer2ScreenCoord
: TDFPoint
;
253 gPlayer1
: TPlayer
= nil;
254 gPlayer2
: TPlayer
= nil;
255 gPlayerDrawn
: TPlayer
= nil;
257 gLerpFactor
: Single = 1.0;
258 gSwitchGameMode
: Byte = GM_DM
;
259 gHearPoint1
, gHearPoint2
: THearPoint
;
260 gSoundEffectsDF
: Boolean = False;
261 gSoundTriggerTime
: Word = 0;
262 gAnnouncer
: Integer = ANNOUNCE_NONE
;
263 goodsnd
: array[0..3] of TPlayableSound
;
264 killsnd
: array[0..3] of TPlayableSound
;
265 hahasnd
: array[0..2] of TPlayableSound
;
266 sound_get_flag
: array[0..1] of TPlayableSound
;
267 sound_lost_flag
: array[0..1] of TPlayableSound
;
268 sound_ret_flag
: array[0..1] of TPlayableSound
;
269 sound_cap_flag
: array[0..1] of TPlayableSound
;
270 gBodyKillEvent
: Integer = -1;
271 gDefInterTime
: ShortInt = -1;
272 gInterEndTime
: LongWord = 0;
273 gInterTime
: LongWord = 0;
274 gServInterTime
: Byte = 0;
275 gGameStartTime
: LongWord = 0;
276 gTotalMonsters
: Integer = 0;
277 gPauseMain
: Boolean = false;
278 gPauseHolmes
: Boolean = false;
279 gShowTime
: Boolean = False;
280 gShowFPS
: Boolean = False;
281 gShowGoals
: Boolean = True;
282 gShowStat
: Boolean = True;
283 gShowPIDs
: Boolean = False;
284 gShowKillMsg
: Boolean = True;
285 gShowLives
: Boolean = True;
286 gShowPing
: Boolean = False;
287 gShowMap
: Boolean = False;
289 gState
: Byte = STATE_NONE
;
291 sWidth
, sHeight
: Word;
292 gSpectMode
: Byte = SPECT_NONE
;
293 gSpectHUD
: Boolean = True;
294 gSpectKeyPress
: Boolean = False;
295 gSpectX
: Integer = 0;
296 gSpectY
: Integer = 0;
297 gSpectStep
: Byte = 8;
298 gSpectViewTwo
: Boolean = False;
299 gSpectPID1
: Integer = -1;
300 gSpectPID2
: Integer = -1;
301 gSpectAuto
: Boolean = False;
302 gSpectAutoNext
: LongWord;
303 gSpectAutoStepX
: Integer;
304 gSpectAutoStepY
: Integer;
305 gMusic
: TMusic
= nil;
306 gLoadGameMode
: Boolean;
307 gCheats
: Boolean = False;
308 gMapOnce
: Boolean = False;
309 gMapToDelete
: String;
310 gTempDelete
: Boolean = False;
311 gLastMap
: Boolean = False;
314 gResolutionChange
: Boolean = False;
315 gRC_Width
, gRC_Height
: Integer;
316 gRC_FullScreen
, gRC_Maximized
: Boolean;
317 gLanguageChange
: Boolean = False;
318 gDebugMode
: Boolean = False;
319 g_debug_Sounds
: Boolean = False;
320 g_debug_Frames
: Boolean = False;
321 g_debug_WinMsgs
: Boolean = False;
322 g_debug_MonsterOff
: Boolean = False;
323 g_debug_BotAIOff
: Byte = 0;
324 g_debug_HealthBar
: Boolean = False;
325 g_Debug_Player
: Boolean = False;
326 gCoopMonstersKilled
: Word = 0;
327 gCoopSecretsFound
: Word = 0;
328 gCoopTotalMonstersKilled
: Word = 0;
329 gCoopTotalSecretsFound
: Word = 0;
330 gCoopTotalMonsters
: Word = 0;
331 gCoopTotalSecrets
: Word = 0;
332 gStatsOff
: Boolean = False;
333 gStatsPressed
: Boolean = False;
334 gExitByTrigger
: Boolean = False;
335 gNextMap
: String = '';
336 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
337 gLMSRespawnTime
: Cardinal = 0;
338 gLMSSoftSpawn
: Boolean = False;
339 gMissionFailed
: Boolean = False;
340 gVoteInProgress
: Boolean = False;
341 gVotePassed
: Boolean = False;
342 gVoteCommand
: string = '';
343 gVoteTimer
: Cardinal = 0;
344 gVoteCmdTimer
: Cardinal = 0;
345 gVoteCount
: Integer = 0;
346 gVoteTimeout
: Cardinal = 30;
347 gVoted
: Boolean = False;
348 gVotesEnabled
: Boolean = True;
349 gEvents
: Array of TGameEvent
;
350 gDelayedEvents
: Array of TDelayedEvent
;
351 gUseChatSounds
: Boolean = True;
352 gChatSounds
: Array of TChatSound
;
353 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
354 gInterReadyCount
: Integer = 0;
356 g_dbg_ignore_bounds
: Boolean = false;
357 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
358 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
360 // move button values:
361 // bits 0-1: l/r state:
362 // 0: neither left, nor right pressed
365 // bits 4-5: l/r state when strafe was pressed
366 P1MoveButton
: Byte = 0;
367 P2MoveButton
: Byte = 0;
369 g_profile_frame_update
: Boolean = false;
370 g_profile_frame_draw
: Boolean = false;
371 g_profile_collision
: Boolean = false;
372 g_profile_los
: Boolean = false;
373 g_profile_history_size
: Integer = 1000;
375 g_rlayer_back
: Boolean = true;
376 g_rlayer_step
: Boolean = true;
377 g_rlayer_wall
: Boolean = true;
378 g_rlayer_door
: Boolean = true;
379 g_rlayer_acid1
: Boolean = true;
380 g_rlayer_acid2
: Boolean = true;
381 g_rlayer_water
: Boolean = true;
382 g_rlayer_fore
: Boolean = true;
384 wNeedTimeReset
: Boolean = false;
386 procedure g_ResetDynlights ();
387 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
388 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
390 function conIsCheatsEnabled (): Boolean; inline;
391 function gPause (): Boolean; inline;
393 type (* private state *)
394 TEndCustomGameStat
= record
395 PlayerStat
: TPlayerStatArray
;
399 Map
, MapName
: String;
402 TEndSingleGameStat
= record
403 PlayerStat
: Array [0..1] of record
409 TotalSecrets
: Integer;
412 TLoadingStat
= record
416 Msgs
: Array of String;
418 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
422 x
, y
, radius
: Integer;
425 exploRadius
: Integer;
428 var (* private state *)
429 CustomStat
: TEndCustomGameStat
;
430 StatShotDone
: Boolean;
431 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
432 SingleStat
: TEndSingleGameStat
;
433 LoadingStat
: TLoadingStat
;
436 EndingGameCounter
: Byte;
438 g_playerLight
: Boolean;
439 g_dynLights
: array of TDynLight
= nil;
440 g_dynLightCount
: Integer = 0;
441 EndPicPath
: AnsiString; // full path, used by render
446 {$IFDEF ENABLE_HOLMES}
458 {$IFDEF ENABLE_SHELLS}
461 {$IFDEF ENABLE_CORPSES}
464 {$IFDEF ENABLE_RENDER}
467 {$IFDEF ENABLE_SYSTEM}
471 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
472 g_playermodel
, g_options
, Math
,
473 g_triggers
, g_monsters
, e_sound
, CONFIG
,
474 g_language
, g_net
, g_phys
,
475 ENet
, e_msg
, g_netmsg
, g_netmaster
,
479 charbuff
: packed array [0..15] of AnsiChar = (
480 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
483 function Translit (const S
: AnsiString): AnsiString;
488 for i
:= 1 to Length(Result
) do
491 #
$C9: Result
[i
] := 'Q';
492 #
$D6: Result
[i
] := 'W';
493 #
$D3: Result
[i
] := 'E';
494 #
$CA: Result
[i
] := 'R';
495 #
$C5: Result
[i
] := 'T';
496 #
$CD: Result
[i
] := 'Y';
497 #
$C3: Result
[i
] := 'U';
498 #
$D8: Result
[i
] := 'I';
499 #
$D9: Result
[i
] := 'O';
500 #
$C7: Result
[i
] := 'P';
501 #
$D5: Result
[i
] := '['; //Chr(219);
502 #
$DA: Result
[i
] := ']'; //Chr(221);
503 #
$D4: Result
[i
] := 'A';
504 #
$DB: Result
[i
] := 'S';
505 #
$C2: Result
[i
] := 'D';
506 #
$C0: Result
[i
] := 'F';
507 #
$CF: Result
[i
] := 'G';
508 #
$D0: Result
[i
] := 'H';
509 #
$CE: Result
[i
] := 'J';
510 #
$CB: Result
[i
] := 'K';
511 #
$C4: Result
[i
] := 'L';
512 #
$C6: Result
[i
] := ';'; //Chr(186);
513 #
$DD: Result
[i
] := #39; //Chr(222);
514 #
$DF: Result
[i
] := 'Z';
515 #
$D7: Result
[i
] := 'X';
516 #
$D1: Result
[i
] := 'C';
517 #
$CC: Result
[i
] := 'V';
518 #
$C8: Result
[i
] := 'B';
519 #
$D2: Result
[i
] := 'N';
520 #
$DC: Result
[i
] := 'M';
521 #
$C1: Result
[i
] := ','; //Chr(188);
522 #
$DE: Result
[i
] := '.'; //Chr(190);
528 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
533 ls2
:= Translit(CheatRus
[ct
]);
534 if length(ls1
) = 0 then ls1
:= '~';
535 if length(ls2
) = 0 then ls2
:= '~';
537 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
538 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
539 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
540 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
542 if ct = I_GAME_CHEAT_JETPACK then
544 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
545 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
546 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
547 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
548 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
549 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
565 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
566 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
567 or g_Game_IsNet then Exit;
569 if not gGameOn
then exit
;
570 if not conIsCheatsEnabled
then exit
;
572 s
:= 'SOUND_GAME_RADIO';
575 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
577 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
578 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
582 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
584 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
585 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
589 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
591 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
592 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
596 if CheckCheat(I_GAME_CHEAT_DEATH
) then
598 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
599 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
600 s
:= 'SOUND_MONSTER_HAHA';
604 if CheckCheat(I_GAME_CHEAT_DOORS
) then
606 g_Triggers_OpenAll();
610 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
612 if gTriggers
<> nil then
613 for a
:= 0 to High(gTriggers
) do
614 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
616 gExitByTrigger
:= True;
617 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
618 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
624 s2
:= Copy(charbuff
, 15, 2);
625 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
627 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
635 if CheckCheat(I_GAME_CHEAT_FLY
) then
641 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
643 VEL_JUMP
:= 30-VEL_JUMP
;
647 if CheckCheat(I_GAME_CHEAT_SPEED
) then
649 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
653 if CheckCheat(I_GAME_CHEAT_SUIT
) then
655 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
656 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
660 if CheckCheat(I_GAME_CHEAT_AIR
) then
662 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
663 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
667 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
669 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
670 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
674 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
676 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
677 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
681 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
683 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
684 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
688 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
690 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
691 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
695 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
697 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
698 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
701 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
703 gAimLine
:= not gAimLine
;
706 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
708 gShowMap
:= not gShowMap
;
719 procedure KeyPress (K
: Word);
720 var Msg
: g_gui
.TMessage
;
725 if (g_ActiveWindow
<> nil) then
727 Msg
.Msg
:= WM_KEYDOWN
;
728 Msg
.WParam
:= VK_ESCAPE
;
729 g_ActiveWindow
.OnMessage(Msg
);
730 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
732 else if (gState
<> STATE_FOLD
) then
734 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
736 g_Game_InGameMenu(True);
738 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
740 if (gState
<> STATE_MENU
) then
742 if (NetMode
<> NET_NONE
) then
744 g_Game_StopAllSounds(True);
746 gState
:= STATE_MENU
;
750 g_GUI_ShowWindow('MainMenu');
751 g_Sound_PlayEx('MENU_OPEN');
756 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
757 begin // <F2> .. <F6> � <F12>
758 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
760 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
761 if (not g_Game_IsNet
) then g_Game_Pause(True);
763 IK_F2
: g_Menu_Show_SaveMenu();
764 IK_F3
: g_Menu_Show_LoadMenu();
765 IK_F4
: g_Menu_Show_GameSetGame();
766 IK_F5
: g_Menu_Show_OptionsVideo();
767 IK_F6
: g_Menu_Show_OptionsSound();
768 IK_F7
: g_Menu_Show_EndGameMenu();
769 IK_F10
: g_Menu_Show_QuitGameMenu();
776 gJustChatted
:= False;
777 if gConsoleShow
or gChatShow
then
779 g_Console_Control(K
);
781 else if (g_ActiveWindow
<> nil) then
783 Msg
.Msg
:= WM_KEYDOWN
;
785 g_ActiveWindow
.OnMessage(Msg
);
787 else if (gState
= STATE_MENU
) then
789 g_GUI_ShowWindow('MainMenu');
790 g_Sound_PlayEx('MENU_OPEN');
796 procedure KeyPress (K
: Word);
798 gJustChatted
:= False;
799 if gConsoleShow
or gChatShow
then
801 g_Console_Control(K
);
806 {$IFDEF ENABLE_SYSTEM}
807 procedure CharPress (C
: AnsiChar);
809 var Msg
: g_gui
.TMessage
;
813 if gConsoleShow
or gChatShow
then
818 else if g_ActiveWindow
<> nil then
821 Msg
.WParam
:= Ord(C
);
822 g_ActiveWindow
.OnMessage(Msg
);
829 charbuff
[a
] := charbuff
[a
+ 1];
831 charbuff
[15] := upcase1251(C
);
838 // ////////////////////////////////////////////////////////////////////////// //
839 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
841 procedure g_ResetDynlights ();
845 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
847 for idx
:= 0 to g_dynLightCount
-1 do
849 if g_dynLights
[idx
].exploCount
= -666 then
856 Inc(g_dynLights
[idx
].exploCount
);
857 if (g_dynLights
[idx
].exploCount
< 10) then
859 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
860 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
861 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
862 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
867 g_dynLightCount
:= lnum
;
870 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
872 if not gwin_has_stencil
then exit
;
873 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
874 g_dynLights
[g_dynLightCount
].x
:= x
;
875 g_dynLights
[g_dynLightCount
].y
:= y
;
876 g_dynLights
[g_dynLightCount
].radius
:= radius
;
877 g_dynLights
[g_dynLightCount
].r
:= r
;
878 g_dynLights
[g_dynLightCount
].g
:= g
;
879 g_dynLights
[g_dynLightCount
].b
:= b
;
880 g_dynLights
[g_dynLightCount
].a
:= a
;
881 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
882 Inc(g_dynLightCount
);
885 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
887 if not gwin_has_stencil
then exit
;
888 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
889 g_dynLights
[g_dynLightCount
].x
:= x
;
890 g_dynLights
[g_dynLightCount
].y
:= y
;
891 g_dynLights
[g_dynLightCount
].radius
:= 0;
892 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
893 g_dynLights
[g_dynLightCount
].r
:= r
;
894 g_dynLights
[g_dynLightCount
].g
:= g
;
895 g_dynLights
[g_dynLightCount
].b
:= b
;
896 g_dynLights
[g_dynLightCount
].a
:= 0;
897 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
898 Inc(g_dynLightCount
);
901 // ////////////////////////////////////////////////////////////////////////// //
902 function conIsCheatsEnabled (): Boolean; inline;
905 if g_Game_IsNet
then exit
;
906 if not gDebugMode
then
908 //if not gCheats then exit;
909 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
910 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
915 // ////////////////////////////////////////////////////////////////////////// //
917 TParamStrValue
= record
922 TParamStrValues
= Array of TParamStrValue
;
925 INTER_ACTION_TEXT
= 1;
926 INTER_ACTION_PIC
= 2;
927 INTER_ACTION_MUSIC
= 3;
932 DataLoaded
: Boolean = False;
934 MapList
: SSArray
= nil;
935 MapIndex
: Integer = -1;
936 InterReadyTime
: Integer = -1;
937 StatDate
: string = '';
952 function Compare(a
, b
: TPlayerStat
): Integer;
954 if a
.Spectator
then Result
:= 1
955 else if b
.Spectator
then Result
:= -1
956 else if a
.Frags
< b
.Frags
then Result
:= 1
957 else if a
.Frags
> b
.Frags
then Result
:= -1
958 else if a
.Deaths
< b
.Deaths
then Result
:= -1
959 else if a
.Deaths
> b
.Deaths
then Result
:= 1
960 else if a
.Kills
< b
.Kills
then Result
:= -1
964 procedure SortGameStat(var stat
: TPlayerStatArray
);
969 if stat
= nil then Exit
;
971 for I
:= High(stat
) downto Low(stat
) do
972 for J
:= Low(stat
) to High(stat
) - 1 do
973 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
976 stat
[J
] := stat
[J
+ 1];
981 // saves a shitty CSV containing the game stats passed to it
982 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
985 dir
, fname
, map
, mode
, etime
: String;
989 dir
:= e_GetWriteableDir(StatsDirs
);
990 // stats are placed in stats/yy/mm/dd/*.csv
991 fname
:= e_CatPath(dir
, Path
);
992 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
993 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
994 AssignFile(s
, fname
);
997 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
998 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
999 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
1000 mode
:= g_Game_ModeToText(Stat
.GameMode
);
1001 etime
:= Format('%d:%.2d:%.2d', [
1002 Stat
.GameTime
div 1000 div 3600,
1003 (Stat
.GameTime
div 1000 div 60) mod 60,
1004 Stat
.GameTime
div 1000 mod 60
1006 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
1007 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
1013 gGameSettings
.TimeLimit
,
1014 gGameSettings
.GoalLimit
,
1015 gGameSettings
.Options
,
1017 Length(Stat
.PlayerStat
)
1019 // line 2: game specific shit
1020 // if it's a team game: red score, blue score
1021 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1022 // otherwise nothing
1023 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1025 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
1026 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1028 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1029 // lines 3-...: team, player name, frags, deaths
1030 WriteLn(s
, 'team,name,frags,deaths');
1031 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1032 with Stat
.PlayerStat
[I
] do
1033 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1035 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1038 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1043 function g_Game_ModeToText(Mode
: Byte): string;
1047 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1048 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1049 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1050 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1051 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1055 function g_Game_TextToMode(Mode
: string): Byte;
1058 Mode
:= UpperCase(Mode
);
1059 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1064 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1069 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1074 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1079 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1081 Result
:= GM_SINGLE
;
1086 function g_Game_IsNet(): Boolean;
1088 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1091 function g_Game_IsServer(): Boolean;
1093 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1096 function g_Game_IsClient(): Boolean;
1098 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1101 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1108 Result
.name
:= ExtractFileName(WAD
);
1109 Result
.description
:= '';
1110 Result
.author
:= '';
1112 w
:= TWADFile
.Create();
1115 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1121 cfg
:= TConfig
.CreateMem(p
, len
);
1122 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1123 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1124 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1125 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1131 procedure g_Game_FreeWAD
;
1134 g_Sound_Delete('MUSIC_endmus');
1135 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1136 gGameSettings
.WAD
:= '';
1139 procedure g_Game_LoadWAD(WAD
: string);
1148 gGameSettings
.WAD
:= WAD
;
1149 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1152 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1154 w
:= TWADFile
.Create();
1157 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1163 cfg
:= TConfig
.CreateMem(p
, len
);
1166 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1167 if MegaWAD
.endpic
<> '' then
1168 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1170 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1171 if MegaWAD
.endmus
<> '' then
1173 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1174 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1182 {procedure start_trigger(t: string);
1186 function next_trigger(): Boolean;
1190 procedure DisableCheats();
1196 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1197 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1198 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1199 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1201 {$IF DEFINED(D2F_DEBUG)}
1202 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1203 gAimLine
:= g_dbg_aimline_on
;
1207 procedure g_Game_ExecuteEvent(Name
: String);
1213 if gEvents
= nil then
1215 for a
:= 0 to High(gEvents
) do
1216 if gEvents
[a
].Name
= Name
then
1218 if gEvents
[a
].Command
<> '' then
1219 g_Console_Process(gEvents
[a
].Command
, True);
1224 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1229 if gDelayedEvents
<> nil then
1230 for a
:= 0 to High(gDelayedEvents
) do
1231 if not gDelayedEvents
[a
].Pending
then
1238 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1239 n
:= High(gDelayedEvents
);
1241 gDelayedEvents
[n
].Pending
:= True;
1242 gDelayedEvents
[n
].DEType
:= DEType
;
1243 gDelayedEvents
[n
].DENum
:= Num
;
1244 gDelayedEvents
[n
].DEStr
:= Str
;
1245 if DEType
= DE_GLOBEVENT
then
1246 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1248 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1252 procedure EndGame();
1258 if g_Game_IsNet
and g_Game_IsServer
then
1259 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1262 gPauseMain
:= false;
1263 gPauseHolmes
:= false;
1266 g_Game_StopAllSounds(False);
1271 EndingGameCounter
:= 0;
1273 {$IFDEF ENABLE_MENU}
1274 g_ActiveWindow
:= nil;
1277 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1278 gLMSRespawnTime
:= 0;
1281 EXIT_SIMPLE
: // Выход через меню или конец теста
1285 begin // Это был тест
1289 begin // Выход в главное меню
1290 {$IFDEF DISABLE_MENU}
1291 gState
:= STATE_MENU
; // ???
1293 gMusic
.SetByName('MUSIC_MENU');
1295 if gState
<> STATE_SLIST
then
1297 g_GUI_ShowWindow('MainMenu');
1298 gState
:= STATE_MENU
;
1302 // Обновляем список серверов
1303 slReturnPressed
:= True;
1304 if g_Net_Slist_Fetch(slCurrent
) then
1306 if slCurrent
= nil then
1307 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1310 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1311 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1314 g_Game_ExecuteEvent('ongameend');
1318 EXIT_RESTART
: // Начать уровень сначала
1320 if not g_Game_IsClient
then g_Game_Restart();
1323 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1325 // Статистика Своей игры:
1326 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1328 CustomStat
.GameTime
:= gTime
;
1329 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1330 CustomStat
.MapName
:= gMapInfo
.Name
;
1331 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1332 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1333 CustomStat
.TeamStat
:= gTeamStat
;
1335 CustomStat
.PlayerStat
:= nil;
1337 // Статистика игроков:
1338 if gPlayers
<> nil then
1340 for a
:= 0 to High(gPlayers
) do
1341 if gPlayers
[a
] <> nil then
1343 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1344 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1347 Name
:= gPlayers
[a
].Name
;
1348 Frags
:= gPlayers
[a
].Frags
;
1349 Deaths
:= gPlayers
[a
].Death
;
1350 Kills
:= gPlayers
[a
].Kills
;
1351 Team
:= gPlayers
[a
].Team
;
1352 Color
:= gPlayers
[a
].Model
.Color
;
1353 Spectator
:= gPlayers
[a
].FSpectator
;
1357 SortGameStat(CustomStat
.PlayerStat
);
1359 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1362 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1363 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1364 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1365 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1367 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1370 StatShotDone
:= False;
1373 g_Game_ExecuteEvent('onmapend');
1374 if not g_Game_IsClient
then g_Player_ResetReady
;
1375 gInterReadyCount
:= 0;
1377 // Затухающий экран:
1378 EndingGameCounter
:= 255;
1379 gState
:= STATE_FOLD
;
1381 if gDefInterTime
< 0 then
1382 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1384 gInterEndTime
:= gDefInterTime
* 1000;
1387 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1389 // Статистика Одиночной игры:
1390 SingleStat
.GameTime
:= gTime
;
1391 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1392 SingleStat
.TotalSecrets
:= gSecretsCount
;
1393 // Статистика первого игрока:
1394 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1395 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1396 // Статистика второго игрока (если есть):
1397 if SingleStat
.TwoPlayers
then
1399 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1400 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1403 g_Game_ExecuteEvent('onmapend');
1406 if gNextMap
<> '' then
1408 gMusic
.SetByName('MUSIC_INTERMUS');
1410 gState
:= STATE_INTERSINGLE
;
1413 g_Game_ExecuteEvent('oninter');
1415 else // Больше нет карт
1417 // Затухающий экран:
1418 EndingGameCounter
:= 255;
1419 gState
:= STATE_FOLD
;
1424 // Окончание обработано:
1425 if gExit
<> EXIT_QUIT
then
1429 procedure g_Game_Init();
1433 gTempDelete
:= False;
1435 sfsGCDisable(); // temporary disable removing of temporary volumes
1438 g_Game_ClearLoading();
1439 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1440 g_Game_SetLoadingText('', 0, False);
1442 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1445 gPauseMain
:= false;
1446 gPauseHolmes
:= false;
1449 {e_MouseInfo.Accel := 1.0;}
1451 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1454 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1455 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1456 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1457 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1458 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1460 gMusic
:= TMusic
.Create();
1461 gMusic
.SetByName('MUSIC_MENU');
1464 gGameSettings
.WarmupTime
:= 30;
1466 gState
:= STATE_MENU
;
1468 SetLength(gEvents
, 6);
1469 gEvents
[0].Name
:= 'ongamestart';
1470 gEvents
[1].Name
:= 'ongameend';
1471 gEvents
[2].Name
:= 'onmapstart';
1472 gEvents
[3].Name
:= 'onmapend';
1473 gEvents
[4].Name
:= 'oninter';
1474 gEvents
[5].Name
:= 'onwadend';
1476 sfsGCEnable(); // enable releasing unused volumes
1480 procedure g_Game_Free(freeTextures
: Boolean=true);
1482 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1483 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1485 g_Map_Free(freeTextures
);
1488 {$IFDEF ENABLE_GIBS}
1491 {$IFDEF ENALBE_SHELLS}
1494 {$IFDEF ENABLE_CORPSES}
1495 g_Corpses_RemoveAll
;
1498 gGameSettings
.GameType
:= GT_NONE
;
1499 if gGameSettings
.GameMode
= GM_SINGLE
then
1500 gGameSettings
.GameMode
:= GM_DM
;
1501 gSwitchGameMode
:= gGameSettings
.GameMode
;
1504 gExitByTrigger
:= False;
1507 function IsActivePlayer(p
: TPlayer
): Boolean;
1512 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1515 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1521 if gPlayers
= nil then
1525 for a
:= Low(gPlayers
) to High(gPlayers
) do
1526 if IsActivePlayer(gPlayers
[a
]) then
1528 SetLength(ids
, Length(ids
) + 1);
1529 ids
[High(ids
)] := gPlayers
[a
].UID
;
1530 if gPlayers
[a
].UID
= Skip
then
1533 if Length(ids
) = 0 then
1538 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1541 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1547 if gPlayers
= nil then
1551 for a
:= Low(gPlayers
) to High(gPlayers
) do
1552 if IsActivePlayer(gPlayers
[a
]) then
1554 SetLength(ids
, Length(ids
) + 1);
1555 ids
[High(ids
)] := gPlayers
[a
].UID
;
1556 if gPlayers
[a
].UID
= Skip
then
1559 if Length(ids
) = 0 then
1562 Result
:= ids
[Length(ids
) - 1]
1564 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1567 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1573 if gPlayers
= nil then
1577 for a
:= Low(gPlayers
) to High(gPlayers
) do
1578 if IsActivePlayer(gPlayers
[a
]) then
1580 SetLength(ids
, Length(ids
) + 1);
1581 ids
[High(ids
)] := gPlayers
[a
].UID
;
1582 if gPlayers
[a
].UID
= Skip
then
1585 if Length(ids
) = 0 then
1587 if Length(ids
) = 1 then
1592 Result
:= ids
[Random(Length(ids
))];
1594 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1596 Result
:= ids
[Random(Length(ids
))];
1601 function GetRandomSpectMode(Current
: Byte): Byte;
1608 0: Result
:= SPECT_STATS
;
1609 1: Result
:= SPECT_MAPVIEW
;
1610 2: Result
:= SPECT_MAPVIEW
;
1611 3: Result
:= SPECT_PLAYERS
;
1612 4: Result
:= SPECT_PLAYERS
;
1613 5: Result
:= SPECT_PLAYERS
;
1614 6: Result
:= SPECT_PLAYERS
;
1616 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1620 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1626 if (plr
= nil) then exit
;
1627 if (p
= 2) then time
:= 1000 else time
:= 1;
1628 strafeDir
:= MoveButton
shr 4;
1629 MoveButton
:= MoveButton
and $0F;
1631 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1632 MoveButton
:= 1 // Нажата только "Влево"
1633 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1634 MoveButton
:= 2 // Нажата только "Вправо"
1635 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1636 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1638 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1639 if MoveButton
= 1 then
1640 plr
.PressKey(KEY_LEFT
, time
)
1641 else if MoveButton
= 2 then
1642 plr
.PressKey(KEY_RIGHT
, time
);
1644 // if we have "strafe" key, turn off old strafe mechanics
1645 if gPlayerAction
[p
, ACTION_STRAFE
] then
1647 // new strafe mechanics
1648 if (strafeDir
= 0) then
1649 strafeDir
:= MoveButton
; // start strafing
1650 // now set direction according to strafe (reversed)
1651 if (strafeDir
= 2) then
1652 plr
.SetDirection(TDirection
.D_LEFT
)
1653 else if (strafeDir
= 1) then
1654 plr
.SetDirection(TDirection
.D_RIGHT
)
1658 strafeDir
:= 0; // not strafing anymore
1659 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1660 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1661 plr
.SetDirection(TDirection
.D_LEFT
)
1662 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1663 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1664 plr
.SetDirection(TDirection
.D_RIGHT
)
1665 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1666 else if MoveButton
<> 0 then
1667 plr
.SetDirection(TDirection(MoveButton
-1))
1670 // fix movebutton state
1671 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1673 // Остальные клавиши:
1674 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1675 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1676 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1677 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1678 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1679 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1680 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1682 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1683 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1685 for i
:= WP_FIRST
to WP_LAST
do
1687 if gSelectWeapon
[p
, i
] then
1689 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1690 gSelectWeapon
[p
, i
] := False
1694 {$IFDEF ENABLE_MENU}
1695 // HACK: add dynlight here
1696 if gwin_k8_enable_light_experiments
then
1698 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1700 g_playerLight
:= true;
1702 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1704 g_playerLight
:= false;
1708 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1712 // HACK: don't have a "key was pressed" function
1713 procedure InterReady();
1715 if InterReadyTime
> gTime
then Exit
;
1716 InterReadyTime
:= gTime
+ 3000;
1717 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1720 procedure g_Game_PreUpdate();
1722 // these are in separate PreUpdate functions because they can interact during Update()
1723 // and are synced over the net
1724 // we don't care that much about corpses and gibs
1725 g_Player_PreUpdate();
1726 g_Monsters_PreUpdate();
1727 g_Items_PreUpdate();
1728 g_Weapon_PreUpdate();
1731 procedure g_Game_Update();
1733 {$IFDEF ENABLE_MENU}
1734 Msg
: g_gui
.TMessage
;
1741 function sendMonsPos (mon
: TMonster
): Boolean;
1743 result
:= false; // don't stop
1744 // this will also reset "need-send" flag
1745 if mon
.gncNeedSend
then
1747 MH_SEND_MonsterPos(mon
.UID
);
1749 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1751 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1753 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1755 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1759 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1761 result
:= false; // don't stop
1762 // this will also reset "need-send" flag
1763 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1767 reliableUpdate
: Boolean;
1772 // Пора выключать игру:
1773 if gExit
= EXIT_QUIT
then
1775 // Игра закончилась - обрабатываем:
1779 if gExit
= EXIT_QUIT
then
1783 // Читаем клавиатуру и джойстик, если окно активно
1784 // no need to, as we'll do it in event handler
1786 // Обновляем консоль (движение и сообщения):
1789 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1791 gExit
:= EXIT_SIMPLE
;
1796 // process master server communications
1797 g_Net_Slist_Pulse();
1800 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1801 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1802 STATE_INTERTEXT
, // Текст между уровнями
1803 STATE_INTERPIC
: // Картинка между уровнями
1805 if g_Game_IsNet
and g_Game_IsServer
then
1807 gInterTime
:= gInterTime
+ GAME_TICK
;
1808 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1809 if a
<> gServInterTime
then
1811 gServInterTime
:= a
;
1812 MH_SEND_TimeSync(gServInterTime
);
1816 if (not g_Game_IsClient
) and
1820 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1821 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1822 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1823 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1825 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1826 {$IFDEF ENABLE_MENU}
1827 and (g_ActiveWindow
= nil)
1830 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1833 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1834 g_Game_StopAllSounds(True);
1836 if gMapOnce
then // Это был тест
1837 gExit
:= EXIT_SIMPLE
1839 if gNextMap
<> '' then // Переходим на следующую карту
1840 g_Game_ChangeMap(gNextMap
)
1841 else // Следующей карты нет
1843 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1845 // Выход в главное меню:
1847 {$IFDEF ENABLE_MENU}
1848 g_GUI_ShowWindow('MainMenu');
1849 gMusic
.SetByName('MUSIC_MENU');
1852 gState
:= STATE_MENU
;
1855 // Финальная картинка:
1856 g_Game_ExecuteEvent('onwadend');
1858 if not gMusic
.SetByName('MUSIC_endmus') then
1859 gMusic
.SetByName('MUSIC_STDENDMUS');
1861 gState
:= STATE_ENDPIC
;
1863 g_Game_ExecuteEvent('ongameend');
1868 else if g_Game_IsClient
and
1871 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1872 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1873 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1874 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1876 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1877 {$IFDEF ENABLE_MENU}
1878 and (g_ActiveWindow
= nil)
1887 if gState
= STATE_INTERTEXT
then
1888 if InterText
.counter
> 0 then
1889 InterText
.counter
:= InterText
.counter
- 1;
1892 STATE_FOLD
: // Затухание экрана
1894 if EndingGameCounter
= 0 then
1896 // Закончился уровень в Своей игре:
1897 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1899 InterReadyTime
:= -1;
1900 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1902 g_Game_ExecuteEvent('onwadend');
1903 if not gMusic
.SetByName('MUSIC_endmus') then
1904 gMusic
.SetByName('MUSIC_STDENDMUS');
1907 gMusic
.SetByName('MUSIC_ROUNDMUS');
1910 gState
:= STATE_INTERCUSTOM
;
1913 else // Закончилась последняя карта в Одиночной игре
1915 gMusic
.SetByName('MUSIC_INTERMUS');
1917 gState
:= STATE_INTERSINGLE
;
1920 g_Game_ExecuteEvent('oninter');
1923 DecMin(EndingGameCounter
, 6, 0);
1926 STATE_ENDPIC
: // Картинка окончания мегаВада
1928 if gMapOnce
then // Это был тест
1930 gExit
:= EXIT_SIMPLE
;
1936 g_Serverlist_Control(slCurrent
, slTable
);
1939 // Статистика по Tab:
1941 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1944 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1946 // Время += 28 миллисекунд:
1947 gTime
:= gTime
+ GAME_TICK
;
1949 // Сообщение посередине экрана:
1950 if MessageTime
= 0 then
1952 if MessageTime
> 0 then
1953 MessageTime
:= MessageTime
- 1;
1955 if (g_Game_IsServer
) then
1957 // Был задан лимит времени:
1958 if (gGameSettings
.TimeLimit
> 0) then
1959 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1960 begin // Он прошел => конец уровня
1965 // Надо респавнить игроков в LMS:
1966 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1967 g_Game_RestartRound(gLMSSoftSpawn
);
1969 // Проверим результат голосования, если время прошло
1970 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1972 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1974 g_Console_Process(gVoteCommand
);
1976 gVotePassed
:= False;
1979 // Замеряем время захвата флагов
1980 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1981 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1982 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1983 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1985 // Был задан лимит побед:
1986 if (gGameSettings
.GoalLimit
> 0) then
1990 if gGameSettings
.GameMode
= GM_DM
then
1991 begin // В DM ищем игрока с max фрагами
1992 for i
:= 0 to High(gPlayers
) do
1993 if gPlayers
[i
] <> nil then
1994 if gPlayers
[i
].Frags
> b
then
1995 b
:= gPlayers
[i
].Frags
;
1998 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1999 begin // В CTF/TDM выбираем команду с наибольшим счетом
2000 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
2003 // Лимит побед набран => конец уровня:
2004 if b
>= gGameSettings
.GoalLimit
then
2011 // Обрабатываем клавиши игроков:
2012 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2013 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2014 {$IFDEF DISABLE_MENU}
2015 if (not gConsoleShow
) and (not gChatShow
) then
2017 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2020 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2021 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2022 end // if not console
2025 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2027 // process weapon switch queue
2031 if (gPlayer1
= nil) and (gPlayer2
= nil)
2032 and (not gConsoleShow
) and (not gChatShow
)
2033 {$IFDEF ENABLE_MENU}
2034 and (g_ActiveWindow
= nil)
2038 if not gSpectKeyPress
then
2040 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2042 // switch spect mode
2044 SPECT_NONE
: ; // not spectator
2046 SPECT_MAPVIEW
: Inc(gSpectMode
);
2047 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2049 gSpectKeyPress
:= True;
2051 if (gSpectMode
= SPECT_MAPVIEW
)
2052 and (not gSpectAuto
) then
2054 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2055 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2056 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2057 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2058 if gPlayerAction
[0, ACTION_LOOKUP
] then
2059 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2060 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2061 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2062 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2065 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2066 gSpectKeyPress
:= True;
2068 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2071 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2072 gSpectKeyPress
:= True;
2075 if (gSpectMode
= SPECT_PLAYERS
)
2076 and (not gSpectAuto
) then
2078 if gPlayerAction
[0, ACTION_LOOKUP
] then
2081 gSpectViewTwo
:= True;
2082 gSpectKeyPress
:= True;
2084 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2086 // remove second view
2087 gSpectViewTwo
:= False;
2088 gSpectKeyPress
:= True;
2090 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2092 // prev player (view 1)
2093 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2094 gSpectKeyPress
:= True;
2096 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2098 // next player (view 1)
2099 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2100 gSpectKeyPress
:= True;
2102 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2104 // prev player (view 2)
2105 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2106 gSpectKeyPress
:= True;
2108 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2110 // next player (view 2)
2111 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2112 gSpectKeyPress
:= True;
2115 if gPlayerAction
[0, ACTION_ATTACK
] then
2117 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2120 gSpectAutoNext
:= 0;
2121 gSpectViewTwo
:= False;
2122 gSpectKeyPress
:= True;
2127 gSpectMode
:= SPECT_STATS
;
2128 gSpectAuto
:= False;
2129 gSpectKeyPress
:= True;
2134 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2135 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2136 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2137 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2138 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2139 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2140 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2141 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2142 gSpectKeyPress
:= False;
2146 if gSpectMode
= SPECT_MAPVIEW
then
2148 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2150 gSpectAutoNext
:= gTime
2153 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2155 gSpectAutoNext
:= gTime
2159 if gSpectAutoNext
<= gTime
then
2161 if gSpectAutoNext
> 0 then
2163 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2167 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2168 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2169 gSpectAutoStepX
:= Random(9) - 4;
2170 gSpectAutoStepY
:= Random(9) - 4;
2171 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2172 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2173 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2174 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2175 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2176 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2180 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2185 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2186 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2187 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2193 // Обновляем все остальное:
2196 g_Triggers_Update();
2198 g_Monsters_Update();
2202 g_Player_UpdateAll();
2203 {$IFDEF ENABLE_GIBS}
2206 {$IFDEF ENABLE_CORPSES}
2209 {$IFDEF ENABLE_SHELLS}
2213 // server: send newly spawned monsters unconditionally
2214 if (gGameSettings
.GameType
= GT_SERVER
) then
2216 if (Length(gMonstersSpawned
) > 0) then
2218 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2219 SetLength(gMonstersSpawned
, 0);
2223 if (gSoundTriggerTime
> 8) then
2225 g_Game_UpdateTriggerSounds();
2226 gSoundTriggerTime
:= 0;
2230 Inc(gSoundTriggerTime
);
2233 if (NetMode
= NET_SERVER
) then
2235 Inc(NetTimeToUpdate
);
2236 Inc(NetTimeToReliable
);
2238 // send monster updates
2239 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2241 // send all monsters (periodic sync)
2242 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2244 for I
:= 0 to High(gPlayers
) do
2246 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2249 g_Mons_ForEach(sendMonsPos
);
2251 if reliableUpdate
then
2253 NetTimeToReliable
:= 0;
2254 NetTimeToUpdate
:= NetUpdateRate
;
2258 NetTimeToUpdate
:= 0;
2263 // send only mosters with some unexpected changes
2264 g_Mons_ForEach(sendMonsPosUnexpected
);
2267 // send unexpected platform changes
2268 g_Map_NetSendInterestingPanels();
2270 g_Net_Slist_ServerUpdate();
2272 if NetUseMaster then
2274 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2276 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2278 NetTimeToMaster := gTime + NetMasterRate;
2283 else if (NetMode
= NET_CLIENT
) then
2285 MC_SEND_PlayerPos();
2287 end; // if gameOn ...
2289 // Активно окно интерфейса - передаем клавиши ему:
2290 {$IFDEF ENABLE_MENU}
2291 if g_ActiveWindow
<> nil then
2293 w
:= e_GetFirstKeyPressed();
2295 if (w
<> IK_INVALID
) then
2297 Msg
.Msg
:= MESSAGE_DIKEY
;
2299 g_ActiveWindow
.OnMessage(Msg
);
2302 // Если оно от этого не закрылось, то обновляем:
2303 if g_ActiveWindow
<> nil then
2304 g_ActiveWindow
.Update();
2306 // Нужно сменить разрешение:
2307 if gResolutionChange
then
2309 {$IFDEF ENABLE_RENDER}
2310 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2313 gResolutionChange
:= False;
2314 g_ActiveWindow
:= nil;
2317 // Нужно сменить язык:
2318 if gLanguageChange
then
2320 //e_WriteLog('Read language file', MSG_NOTIFY);
2321 //g_Language_Load(DataDir + gLanguage + '.txt');
2322 g_Language_Set(gLanguage
);
2324 gLanguageChange
:= False;
2328 // Горячая клавиша для вызова меню выхода из игры (F10):
2329 if e_KeyPressed(IK_F10
) and
2331 (not gConsoleShow
) and
2332 (g_ActiveWindow
= nil) then
2338 Time
:= GetTickCount64() {div 1000};
2340 // Обработка отложенных событий:
2341 if gDelayedEvents
<> nil then
2342 for a
:= 0 to High(gDelayedEvents
) do
2343 if gDelayedEvents
[a
].Pending
and
2345 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2346 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2349 case gDelayedEvents
[a
].DEType
of
2351 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2354 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2358 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2359 if g_Game_IsNet
and g_Game_IsServer
then
2360 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2364 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2366 gDelayedEvents
[a
].Pending
:= False;
2369 // Каждую секунду обновляем счетчик обновлений:
2370 UPSCounter
:= UPSCounter
+ 1;
2371 if Time
- UPSTime
>= 1000 then
2380 g_Weapon_AddDynLights();
2381 g_Items_AddDynLights();
2385 procedure g_Game_LoadChatSounds(Resource
: string);
2388 FileName
, Snd
: string;
2390 len
, cnt
, tags
, i
, j
: Integer;
2393 FileName
:= g_ExtractWadName(Resource
);
2395 WAD
:= TWADFile
.Create();
2396 WAD
.ReadFile(FileName
);
2398 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2405 cfg
:= TConfig
.CreateMem(p
, len
);
2406 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2408 SetLength(gChatSounds
, cnt
);
2409 for i
:= 0 to Length(gChatSounds
) - 1 do
2411 gChatSounds
[i
].Sound
:= nil;
2412 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2413 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2414 if (Snd
= '') or (Tags
<= 0) then
2416 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2417 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2418 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2419 SetLength(gChatSounds
[i
].Tags
, tags
);
2420 for j
:= 0 to tags
- 1 do
2421 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2422 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2429 procedure g_Game_FreeChatSounds();
2433 for i
:= 0 to Length(gChatSounds
) - 1 do
2435 gChatSounds
[i
].Sound
.Free();
2436 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2438 SetLength(gChatSounds
, 0);
2442 procedure g_Game_LoadData();
2444 if DataLoaded
then Exit
;
2446 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2448 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2449 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2450 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2451 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2452 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2453 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2454 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2455 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2456 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2457 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2458 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2459 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2460 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2461 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2462 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2463 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2464 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2465 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2466 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2467 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2468 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2469 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2470 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2471 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2472 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2473 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2474 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2475 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2476 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2477 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2478 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2479 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2481 goodsnd
[0] := TPlayableSound
.Create();
2482 goodsnd
[1] := TPlayableSound
.Create();
2483 goodsnd
[2] := TPlayableSound
.Create();
2484 goodsnd
[3] := TPlayableSound
.Create();
2486 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2487 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2488 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2489 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2491 killsnd
[0] := TPlayableSound
.Create();
2492 killsnd
[1] := TPlayableSound
.Create();
2493 killsnd
[2] := TPlayableSound
.Create();
2494 killsnd
[3] := TPlayableSound
.Create();
2496 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2497 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2498 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2499 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2501 hahasnd
[0] := TPlayableSound
.Create();
2502 hahasnd
[1] := TPlayableSound
.Create();
2503 hahasnd
[2] := TPlayableSound
.Create();
2505 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2506 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2507 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2509 sound_get_flag
[0] := TPlayableSound
.Create();
2510 sound_get_flag
[1] := TPlayableSound
.Create();
2511 sound_lost_flag
[0] := TPlayableSound
.Create();
2512 sound_lost_flag
[1] := TPlayableSound
.Create();
2513 sound_ret_flag
[0] := TPlayableSound
.Create();
2514 sound_ret_flag
[1] := TPlayableSound
.Create();
2515 sound_cap_flag
[0] := TPlayableSound
.Create();
2516 sound_cap_flag
[1] := TPlayableSound
.Create();
2518 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2519 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2520 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2521 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2522 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2523 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2524 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2525 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2527 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2529 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2532 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2533 g_Weapon_LoadData();
2535 g_Monsters_LoadData();
2540 procedure g_Game_Quit();
2542 g_Game_StopAllSounds(True);
2545 g_PlayerModel_FreeData();
2546 {$IFDEF ENABLE_MENU}
2547 // g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2550 if NetInitDone
then g_Net_Free
;
2552 // remove map after test
2553 if gMapToDelete
<> '' then
2554 g_Game_DeleteTestMap();
2558 {$IFDEF ENABLE_SYSTEM}
2563 procedure g_Game_FreeData();
2565 if not DataLoaded
then Exit
;
2568 g_Weapon_FreeData();
2569 g_Monsters_FreeData();
2571 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2573 g_Sound_Delete('SOUND_GAME_TELEPORT');
2574 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2575 g_Sound_Delete('SOUND_GAME_SECRET');
2576 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2577 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2578 g_Sound_Delete('SOUND_GAME_BULK1');
2579 g_Sound_Delete('SOUND_GAME_BULK2');
2580 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2581 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2582 g_Sound_Delete('SOUND_GAME_BURNING');
2583 g_Sound_Delete('SOUND_GAME_SWITCH1');
2584 g_Sound_Delete('SOUND_GAME_SWITCH0');
2591 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2592 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2593 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2594 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2601 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2602 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2603 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2604 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2610 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2611 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2612 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2614 sound_get_flag
[0].Free();
2615 sound_get_flag
[1].Free();
2616 sound_lost_flag
[0].Free();
2617 sound_lost_flag
[1].Free();
2618 sound_ret_flag
[0].Free();
2619 sound_ret_flag
[1].Free();
2620 sound_cap_flag
[0].Free();
2621 sound_cap_flag
[1].Free();
2623 g_Sound_Delete('SOUND_CTF_GET1');
2624 g_Sound_Delete('SOUND_CTF_GET2');
2625 g_Sound_Delete('SOUND_CTF_LOST1');
2626 g_Sound_Delete('SOUND_CTF_LOST2');
2627 g_Sound_Delete('SOUND_CTF_RETURN1');
2628 g_Sound_Delete('SOUND_CTF_RETURN2');
2629 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2630 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2632 g_Game_FreeChatSounds();
2634 DataLoaded
:= False;
2637 procedure g_FatalError(Text: String);
2639 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2640 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2642 gExit
:= EXIT_SIMPLE
;
2643 if gGameOn
then EndGame
;
2646 procedure g_SimpleError(Text: String);
2648 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2649 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2652 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2654 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2655 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2658 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2661 if gPlayer1
= nil then
2663 if g_Game_IsClient
then
2665 if NetPlrUID1
> -1 then
2666 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2670 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2671 Team
:= gPlayer1Settings
.Team
;
2673 // Создание первого игрока:
2674 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2675 gPlayer1Settings
.Color
,
2677 if gPlayer1
= nil then
2678 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2681 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2682 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2683 if g_Game_IsServer
and g_Game_IsNet
then
2684 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2685 gPlayer1
.Respawn(False, True);
2686 g_Net_Slist_ServerPlayerComes();
2691 if gPlayer2
= nil then
2693 if g_Game_IsClient
then
2695 if NetPlrUID2
> -1 then
2696 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2700 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2701 Team
:= gPlayer2Settings
.Team
;
2703 // Создание второго игрока:
2704 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2705 gPlayer2Settings
.Color
,
2707 if gPlayer2
= nil then
2708 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2711 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2712 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2713 if g_Game_IsServer
and g_Game_IsNet
then
2714 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2715 gPlayer2
.Respawn(False, True);
2716 g_Net_Slist_ServerPlayerComes();
2723 procedure g_Game_RemovePlayer();
2727 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2728 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2733 if g_Game_IsServer
then
2736 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2737 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2738 g_Player_Remove(Pl
.UID
);
2739 g_Net_Slist_ServerPlayerLeaves();
2743 gSpectLatchPID2
:= Pl
.UID
;
2751 if g_Game_IsServer
then
2754 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2755 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2756 g_Player_Remove(Pl
.UID
);
2757 g_Net_Slist_ServerPlayerLeaves();
2760 gSpectLatchPID1
:= Pl
.UID
;
2762 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2766 g_Net_Slist_ServerPlayerLeaves();
2769 procedure g_Game_Spectate();
2771 g_Game_RemovePlayer();
2772 if gPlayer1
<> nil then
2773 g_Game_RemovePlayer();
2776 procedure g_Game_SpectateCenterView();
2778 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2779 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2782 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2789 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2791 g_Game_ClearLoading();
2794 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2797 gGameSettings
.GameType
:= GT_SINGLE
;
2798 gGameSettings
.MaxLives
:= 0;
2799 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2800 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2801 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2802 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2803 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2804 gSwitchGameMode
:= GM_SINGLE
;
2806 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2807 gLMSRespawnTime
:= 0;
2808 gSpectLatchPID1
:= 0;
2809 gSpectLatchPID2
:= 0;
2811 g_Game_ExecuteEvent('ongamestart');
2813 // Создание первого игрока:
2814 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2815 gPlayer1Settings
.Color
,
2816 gPlayer1Settings
.Team
, False));
2817 if gPlayer1
= nil then
2819 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2823 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2826 // Создание второго игрока, если есть:
2829 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2830 gPlayer2Settings
.Color
,
2831 gPlayer2Settings
.Team
, False));
2832 if gPlayer2
= nil then
2834 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2838 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2842 // Загрузка и запуск карты:
2843 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2845 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2846 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2850 // Настройки игроков и ботов:
2854 for i
:= nPl
+1 to nPlayers
do
2855 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2858 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2859 TimeLimit
, GoalLimit
: Word;
2861 Options
: LongWord; nPlayers
: Byte);
2867 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2869 g_Game_ClearLoading();
2872 gGameSettings
.GameType
:= GT_CUSTOM
;
2873 gGameSettings
.GameMode
:= GameMode
;
2874 gSwitchGameMode
:= GameMode
;
2875 gGameSettings
.TimeLimit
:= TimeLimit
;
2876 gGameSettings
.GoalLimit
:= GoalLimit
;
2877 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2878 gGameSettings
.Options
:= Options
;
2880 gCoopTotalMonstersKilled
:= 0;
2881 gCoopTotalSecretsFound
:= 0;
2882 gCoopTotalMonsters
:= 0;
2883 gCoopTotalSecrets
:= 0;
2887 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2888 gLMSRespawnTime
:= 0;
2889 gSpectLatchPID1
:= 0;
2890 gSpectLatchPID2
:= 0;
2892 g_Game_ExecuteEvent('ongamestart');
2894 // Режим наблюдателя:
2895 if nPlayers
= 0 then
2902 if nPlayers
>= 1 then
2904 // Создание первого игрока:
2905 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2906 gPlayer1Settings
.Color
,
2907 gPlayer1Settings
.Team
, False));
2908 if gPlayer1
= nil then
2910 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2914 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2918 if nPlayers
>= 2 then
2920 // Создание второго игрока:
2921 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2922 gPlayer2Settings
.Color
,
2923 gPlayer2Settings
.Team
, False));
2924 if gPlayer2
= nil then
2926 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2930 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2934 // Загрузка и запуск карты:
2935 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
2937 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2941 // Нет точек появления:
2942 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2943 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2944 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2945 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2946 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2948 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2952 // Настройки игроков и ботов:
2956 for i
:= nPl
+1 to nPlayers
do
2957 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2960 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
2961 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
2962 Options
: LongWord; nPlayers
: Byte;
2963 IPAddr
: LongWord; Port
: Word);
2966 g_Net_Slist_ServerClosed();
2968 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
2970 g_Game_ClearLoading();
2973 gGameSettings
.GameType
:= GT_SERVER
;
2974 gGameSettings
.GameMode
:= GameMode
;
2975 gSwitchGameMode
:= GameMode
;
2976 gGameSettings
.TimeLimit
:= TimeLimit
;
2977 gGameSettings
.GoalLimit
:= GoalLimit
;
2978 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2979 gGameSettings
.Options
:= Options
;
2981 gCoopTotalMonstersKilled
:= 0;
2982 gCoopTotalSecretsFound
:= 0;
2983 gCoopTotalMonsters
:= 0;
2984 gCoopTotalSecrets
:= 0;
2988 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2989 gLMSRespawnTime
:= 0;
2990 gSpectLatchPID1
:= 0;
2991 gSpectLatchPID2
:= 0;
2993 g_Game_ExecuteEvent('ongamestart');
2995 // Режим наблюдателя:
2996 if nPlayers
= 0 then
3002 if nPlayers
>= 1 then
3004 // Создание первого игрока:
3005 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3006 gPlayer1Settings
.Color
,
3007 gPlayer1Settings
.Team
, False));
3008 if gPlayer1
= nil then
3010 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3014 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3017 if nPlayers
>= 2 then
3019 // Создание второго игрока:
3020 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3021 gPlayer2Settings
.Color
,
3022 gPlayer2Settings
.Team
, False));
3023 if gPlayer2
= nil then
3025 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3029 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3032 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3033 if NetForwardPorts
then
3034 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3037 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3039 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3043 g_Net_Slist_Set(NetMasterList
);
3045 g_Net_Slist_ServerStarted();
3047 // Загрузка и запуск карты:
3048 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3050 g_Net_Slist_ServerClosed();
3051 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3055 // Нет точек появления:
3056 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3057 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3058 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3059 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3060 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3062 g_Net_Slist_ServerClosed();
3063 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3067 // Настройки игроков и ботов:
3070 g_Net_Slist_ServerMapStarted();
3071 NetState
:= NET_STATE_GAME
;
3074 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3089 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3090 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3092 g_Game_ClearLoading();
3095 gGameSettings
.GameType
:= GT_CLIENT
;
3097 gCoopTotalMonstersKilled
:= 0;
3098 gCoopTotalSecretsFound
:= 0;
3099 gCoopTotalMonsters
:= 0;
3100 gCoopTotalSecrets
:= 0;
3104 g_Game_ExecuteEvent('ongamestart');
3106 NetState
:= NET_STATE_AUTH
;
3108 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3110 // create (or update) map/resource databases
3111 g_Res_CreateDatabases(true);
3113 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3114 gLMSRespawnTime
:= 0;
3115 gSpectLatchPID1
:= 0;
3116 gSpectLatchPID2
:= 0;
3119 if not g_Net_Connect(Addr
, Port
) then
3121 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3122 NetState
:= NET_STATE_NONE
;
3126 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3128 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3133 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3134 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3135 // thank you, enet. let's ignore failures altogether then.
3136 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3138 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3140 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
3142 // ignore all download packets, they're processed by separate code
3143 enet_packet_destroy(NetEvent
.packet
);
3146 Ptr
:= NetEvent
.packet
^.data
;
3147 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3149 enet_packet_destroy(NetEvent
.packet
);
3153 InMsg
.ReadLongWord(); // skip size
3154 MID
:= InMsg
.ReadByte();
3156 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3158 NetMyID
:= InMsg
.ReadByte();
3159 NetPlrUID1
:= InMsg
.ReadWord();
3161 WadName
:= InMsg
.ReadString();
3162 Map
:= InMsg
.ReadString();
3164 gWADHash
:= InMsg
.ReadMD5();
3166 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3167 gSwitchGameMode
:= gGameSettings
.GameMode
;
3168 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
3169 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3170 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3171 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3172 T
:= InMsg
.ReadLongWord();
3174 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3175 //if newResPath = '' then
3177 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3178 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3179 if newResPath
= '' then
3181 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3182 enet_packet_destroy(NetEvent
.packet
);
3183 NetState
:= NET_STATE_NONE
;
3186 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3188 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3191 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3192 gPlayer1Settings
.Color
,
3193 gPlayer1Settings
.Team
, False));
3195 if gPlayer1
= nil then
3197 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3199 enet_packet_destroy(NetEvent
.packet
);
3200 NetState
:= NET_STATE_NONE
;
3204 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3205 gPlayer1
.UID
:= NetPlrUID1
;
3206 gPlayer1
.Reset(True);
3208 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3210 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3212 enet_packet_destroy(NetEvent
.packet
);
3213 NetState
:= NET_STATE_NONE
;
3221 enet_packet_destroy(NetEvent
.packet
);
3225 enet_packet_destroy(NetEvent
.packet
);
3229 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3232 if (NetEvent
.data
<= NET_DISC_MAX
) then
3233 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3234 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3241 ProcessLoading(true);
3243 if g_Net_UserRequestExit() then
3252 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3253 NetState
:= NET_STATE_NONE
;
3258 NetState
:= NET_STATE_GAME
;
3259 MC_SEND_FullStateRequest
;
3260 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3264 lastAsMegaWad
: Boolean = false;
3266 procedure g_Game_ChangeMap(const MapPath
: String);
3270 g_Game_ClearLoading();
3272 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3273 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3274 if gExitByTrigger
then
3277 gExitByTrigger
:= False;
3279 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3280 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3283 procedure g_Game_Restart();
3287 if g_Game_IsClient
then
3289 map
:= g_ExtractFileName(gMapInfo
.Map
);
3290 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3294 g_Game_ClearLoading();
3295 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3298 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3300 NewWAD
, ResName
: String;
3304 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3306 {$IFDEF ENABLE_GIBS}
3309 {$IFDEF ENALBE_SHELLS}
3312 {$IFDEF ENABLE_CORPSES}
3313 g_Corpses_RemoveAll
;
3316 if (not g_Game_IsClient
) and
3317 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3318 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3320 if gSwitchGameMode
= GM_CTF
then
3321 gGameSettings
.MaxLives
:= 0;
3322 gGameSettings
.GameMode
:= gSwitchGameMode
;
3325 gSwitchGameMode
:= gGameSettings
.GameMode
;
3327 g_Player_ResetTeams();
3329 lastAsMegaWad
:= asMegawad
;
3330 if isWadPath(Map
) then
3332 NewWAD
:= g_ExtractWadName(Map
);
3333 ResName
:= g_ExtractFileName(Map
);
3334 if g_Game_IsServer
then
3336 nws
:= findDiskWad(NewWAD
);
3337 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3340 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3341 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3345 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3346 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3348 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3349 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3351 if (length(nws
) = 0) then
3353 ResName
:= ''; // failed
3358 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3359 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3360 g_Game_LoadWAD(NewWAD
);
3365 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3366 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3371 NewWAD
:= gGameSettings
.WAD
;
3377 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3379 if (ResName
<> '') and (NewWAD
<> '') then
3381 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3382 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3383 {$IFDEF ENABLE_RENDER}
3384 r_Render_LoadTextures
;
3389 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3391 gState
:= STATE_NONE
;
3392 {$IFDEF ENABLE_MENU}
3393 g_ActiveWindow
:= nil;
3398 wNeedTimeReset
:= True;
3400 if gGameSettings
.GameMode
= GM_CTF
then
3402 g_Map_ResetFlag(FLAG_RED
);
3403 g_Map_ResetFlag(FLAG_BLUE
);
3404 // CTF, а флагов нет:
3405 if not g_Map_HaveFlagPoints() then
3406 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3411 gState
:= STATE_MENU
;
3416 gPauseMain
:= false;
3417 gPauseHolmes
:= false;
3418 NetTimeToUpdate
:= 1;
3419 NetTimeToReliable
:= 0;
3420 NetTimeToMaster
:= NetMasterRate
;
3421 gSpectLatchPID1
:= 0;
3422 gSpectLatchPID2
:= 0;
3423 gMissionFailed
:= False;
3426 gCoopMonstersKilled
:= 0;
3427 gCoopSecretsFound
:= 0;
3429 gVoteInProgress
:= False;
3430 gVotePassed
:= False;
3436 if not gGameOn
then Exit
;
3438 g_Game_SpectateCenterView();
3440 if g_Game_IsServer
then
3442 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3444 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3445 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3446 gLMSSoftSpawn
:= True;
3447 if g_Game_IsNet
then
3448 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3452 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3453 gLMSRespawnTime
:= 0;
3457 if NetMode
= NET_SERVER
then
3459 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3462 g_Net_Slist_ServerMapStarted();
3464 if NetClients
<> nil then
3465 for I
:= 0 to High(NetClients
) do
3466 if NetClients
[I
].Used
then
3468 NetClients
[I
].Voted
:= False;
3469 if NetClients
[I
].RequestedFullUpdate
then
3471 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3472 NetClients
[I
].RequestedFullUpdate
:= False;
3476 g_Net_UnbanNonPermHosts();
3481 gCoopTotalMonstersKilled
:= 0;
3482 gCoopTotalSecretsFound
:= 0;
3483 gCoopTotalMonsters
:= 0;
3484 gCoopTotalSecrets
:= 0;
3488 g_Game_ExecuteEvent('onmapstart');
3491 procedure SetFirstLevel
;
3495 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3496 if MapList
= nil then
3499 SortSArray(MapList
);
3500 gNextMap
:= MapList
[Low(MapList
)];
3505 procedure g_Game_ExitLevel(const Map
: AnsiString);
3509 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3510 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3511 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3512 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3514 // Вышли в выход в Одиночной игре:
3515 if gGameSettings
.GameType
= GT_SINGLE
then
3516 gExit
:= EXIT_ENDLEVELSINGLE
3517 else // Вышли в выход в Своей игре
3519 gExit
:= EXIT_ENDLEVELCUSTOM
;
3520 if gGameSettings
.GameMode
= GM_COOP
then
3521 g_Player_RememberAll
;
3523 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3526 if gGameSettings
.GameMode
= GM_COOP
then
3529 gStatsPressed
:= True;
3530 gNextMap
:= 'MAP01';
3532 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3535 if g_Game_IsNet
then
3537 MH_SEND_GameStats();
3538 MH_SEND_CoopStats();
3544 procedure g_Game_RestartLevel();
3548 if gGameSettings
.GameMode
= GM_SINGLE
then
3553 gExit
:= EXIT_ENDLEVELCUSTOM
;
3554 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3558 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3560 gWAD
{, xwad}: String;
3563 if not g_Game_IsClient
then Exit
;
3564 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3566 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3571 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3575 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3578 g_Game_LoadWAD(NewWAD
);
3582 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3583 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3586 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3587 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3591 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3595 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3596 g_Game_LoadWAD(NewWAD);
3600 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3602 i
, n
, nb
, nr
: Integer;
3604 if not g_Game_IsServer
then Exit
;
3605 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3606 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3607 gLMSRespawnTime
:= 0;
3610 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3612 gMissionFailed
:= True;
3613 g_Game_RestartLevel
;
3617 n
:= 0; nb
:= 0; nr
:= 0;
3618 for i
:= Low(gPlayers
) to High(gPlayers
) do
3619 if (gPlayers
[i
] <> nil) and
3620 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3621 (gPlayers
[i
] is TBot
)) then
3624 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3625 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3628 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3630 // wait a second until the fuckers finally decide to join
3631 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3632 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3633 gLMSSoftSpawn
:= NoMapRestart
;
3634 if g_Game_IsNet
then
3635 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3639 {$IFDEF ENABLE_GIBS}
3642 {$IFDEF ENALBE_SHELLS}
3645 {$IFDEF ENABLE_CORPSES}
3646 g_Corpses_RemoveAll
;
3649 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3650 if g_Game_IsNet
then
3651 MH_SEND_GameEvent(NET_EV_LMS_START
);
3653 for i
:= Low(gPlayers
) to High(gPlayers
) do
3655 if gPlayers
[i
] = nil then continue
;
3656 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3657 // don't touch normal spectators
3658 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3660 gPlayers
[i
].FNoRespawn
:= True;
3661 gPlayers
[i
].Lives
:= 0;
3662 if g_Game_IsNet
then
3663 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3666 gPlayers
[i
].FNoRespawn
:= False;
3667 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3668 gPlayers
[i
].Respawn(False, True);
3669 if gGameSettings
.GameMode
= GM_COOP
then
3671 gPlayers
[i
].Frags
:= 0;
3672 gPlayers
[i
].RecallState
;
3674 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3675 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3676 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3677 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3680 g_Items_RestartRound();
3682 gLMSSoftSpawn
:= False;
3685 function g_Game_GetFirstMap(WAD
: String): String;
3689 MapList
:= g_Map_GetMapsList(WAD
);
3690 if MapList
= nil then
3693 SortSArray(MapList
);
3694 Result
:= MapList
[Low(MapList
)];
3696 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3702 function g_Game_GetNextMap(): String;
3709 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3710 if MapList
= nil then
3713 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3715 SortSArray(MapList
);
3717 for I
:= Low(MapList
) to High(MapList
) do
3718 if Map
= MapList
[I
] then
3724 if MapIndex
<> -255 then
3726 if MapIndex
= High(MapList
) then
3727 Result
:= MapList
[Low(MapList
)]
3729 Result
:= MapList
[MapIndex
+ 1];
3731 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3737 procedure g_Game_NextLevel();
3739 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3740 gExit
:= EXIT_ENDLEVELCUSTOM
3743 gExit
:= EXIT_ENDLEVELSINGLE
;
3747 if gNextMap
<> '' then Exit
;
3748 gNextMap
:= g_Game_GetNextMap();
3751 function g_Game_IsTestMap(): Boolean;
3753 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3756 procedure g_Game_DeleteTestMap();
3759 //MapName: AnsiString;
3767 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3768 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3769 if (a
= 0) then exit
;
3771 // Выделяем имя wad-файла и имя карты
3772 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3773 Delete(gMapToDelete
, 1, a
+5);
3774 gMapToDelete
:= UpperCase(gMapToDelete
);
3776 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3779 // Имя карты не стандартное тестовое:
3780 if MapName <> TEST_MAP_NAME then
3783 if not gTempDelete then
3785 time := g_GetFileTime(WadName);
3786 WAD := TWADFile.Create();
3789 if not WAD.ReadFile(WadName) then
3790 begin // Нет такого WAD-файла
3795 // Составляем список карт и ищем нужную:
3797 MapList := WAD.GetResourcesList('');
3799 if MapList <> nil then
3800 for a := 0 to High(MapList) do
3801 if MapList[a] = MapName then
3803 // Удаляем и сохраняем:
3804 WAD.RemoveResource('', MapName);
3805 WAD.SaveTo(WadName);
3810 g_SetFileTime(WadName, time);
3813 if gTempDelete
then DeleteFile(WadName
);
3816 procedure GameCVars(P
: SSArray
);
3819 stat
: TPlayerStatArray
;
3822 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3826 if Length(P
) > 1 then
3831 gsGameFlags
:= gsGameFlags
or Flag
3833 gsGameFlags
:= gsGameFlags
and (not Flag
);
3835 if g_Game_IsServer
then
3838 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3840 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3841 if g_Game_IsNet
then MH_SEND_GameSettings
;
3845 if LongBool(gsGameFlags
and Flag
) then
3846 g_Console_Add(_lc
[OnMsg
])
3848 g_Console_Add(_lc
[OffMsg
]);
3850 if OnMapChange
and g_Game_IsServer
then
3851 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3856 cmd
:= LowerCase(P
[0]);
3858 if cmd
= 'g_gamemode' then
3860 if (Length(P
) > 1) then
3862 a
:= g_Game_TextToMode(P
[1]);
3863 if a
= GM_SINGLE
then a
:= GM_COOP
;
3864 gsGameMode
:= g_Game_ModeToText(a
);
3865 if g_Game_IsServer
then
3867 gSwitchGameMode
:= a
;
3868 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3869 (gState
= STATE_INTERSINGLE
) then
3870 gSwitchGameMode
:= GM_SINGLE
;
3872 gGameSettings
.GameMode
:= gSwitchGameMode
;
3876 if gSwitchGameMode
= gGameSettings
.GameMode
then
3877 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3878 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3880 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3881 [g_Game_ModeToText(gGameSettings
.GameMode
),
3882 g_Game_ModeToText(gSwitchGameMode
)]));
3884 else if cmd
= 'g_friendlyfire' then
3886 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3888 else if cmd
= 'g_friendly_absorb_damage' then
3890 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3892 else if cmd
= 'g_friendly_hit_trace' then
3894 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3896 else if cmd
= 'g_friendly_hit_projectile' then
3898 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3900 else if cmd
= 'g_weaponstay' then
3902 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3904 else if cmd
= 'g_allow_exit' then
3906 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3908 else if cmd
= 'g_allow_monsters' then
3910 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3912 else if cmd
= 'g_bot_vsplayers' then
3914 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3916 else if cmd
= 'g_bot_vsmonsters' then
3918 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3920 else if cmd
= 'g_dm_keys' then
3922 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
3924 else if cmd
= 'g_gameflags' then
3926 if Length(P
) > 1 then
3928 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
3929 if g_Game_IsServer
then
3931 gGameSettings
.Options
:= gsGameFlags
;
3932 if g_Game_IsNet
then MH_SEND_GameSettings
;
3936 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
3938 else if cmd
= 'g_warmup_time' then
3940 if Length(P
) > 1 then
3942 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
3943 if g_Game_IsServer
then
3945 gGameSettings
.WarmupTime
:= gsWarmupTime
;
3946 // extend warmup if it's already going
3947 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
3949 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
3950 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3952 if g_Game_IsNet
then MH_SEND_GameSettings
;
3956 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
3957 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3959 else if cmd
= 'g_spawn_invul' then
3961 if Length(P
) > 1 then
3963 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
3964 if g_Game_IsServer
then
3966 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
3967 if g_Game_IsNet
then MH_SEND_GameSettings
;
3971 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
3973 else if cmd
= 'g_item_respawn_time' then
3975 if Length(P
) > 1 then
3977 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
3978 if g_Game_IsServer
then
3980 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
3981 if g_Game_IsNet
then MH_SEND_GameSettings
;
3985 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
3986 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3988 else if cmd
= 'sv_intertime' then
3990 if (Length(P
) > 1) then
3991 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
3993 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
3995 else if cmd
= 'g_max_particles' then
3997 if Length(p
) = 2 then
4000 a
:= Max(0, StrToInt(p
[1]));
4004 else if Length(p
) = 1 then
4007 e_LogWritefln('%s', [g_GFX_GetMax()])
4009 e_LogWritefln('%s', [0])
4014 e_LogWritefln('usage: %s <n>', [cmd
])
4017 else if cmd
= 'g_max_shells' then
4019 if Length(p
) = 2 then
4021 {$IFDEF ENABLE_SHELLS}
4022 a
:= Max(0, StrToInt(p
[1]));
4026 else if Length(p
) = 1 then
4028 {$IFDEF ENABLE_SHELLS}
4029 e_LogWritefln('%s', [g_Shells_GetMax()])
4031 e_LogWritefln('%s', [0])
4036 e_LogWritefln('usage: %s <n>', [cmd
])
4039 else if cmd
= 'g_max_gibs' then
4041 if Length(p
) = 2 then
4043 {$IFDEF ENABLE_GIBS}
4044 a
:= Max(0, StrToInt(p
[1]));
4048 else if Length(p
) = 1 then
4050 {$IFDEF ENABLE_GIBS}
4051 e_LogWritefln('%s', [g_Gibs_GetMax()])
4053 e_LogWritefln('%s', [0])
4058 e_LogWritefln('usage: %s <n>', [cmd
])
4061 else if cmd
= 'g_max_corpses' then
4063 if Length(p
) = 2 then
4065 {$IFDEF ENABLE_CORPSES}
4066 a
:= Max(0, StrToInt(p
[1]));
4070 else if Length(p
) = 1 then
4072 {$IFDEF ENABLE_CORPSES}
4073 e_LogWritefln('%s', [g_Corpses_GetMax()])
4075 e_LogWritefln('%s', [0])
4080 e_LogWritefln('usage: %s <n>', [cmd
])
4083 else if cmd
= 'g_scorelimit' then
4085 if Length(P
) > 1 then
4087 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
4089 if g_Game_IsServer
then
4092 if gGameSettings
.GameMode
= GM_DM
then
4094 stat
:= g_Player_GetStats();
4096 for a
:= 0 to High(stat
) do
4097 if stat
[a
].Frags
> b
then
4101 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4103 // if someone has a higher score, set it to that instead
4104 gsGoalLimit
:= max(gsGoalLimit
, b
);
4105 gGameSettings
.GoalLimit
:= gsGoalLimit
;
4107 if g_Game_IsNet
then MH_SEND_GameSettings
;
4111 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
4113 else if cmd
= 'g_timelimit' then
4115 if Length(P
) > 1 then
4117 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4118 if g_Game_IsServer
then
4120 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4121 if g_Game_IsNet
then MH_SEND_GameSettings
;
4124 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4125 [gsTimeLimit
div 3600,
4126 (gsTimeLimit
div 60) mod 60,
4127 gsTimeLimit
mod 60]));
4129 else if cmd
= 'g_maxlives' then
4131 if Length(P
) > 1 then
4133 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4134 if g_Game_IsServer
then
4136 gGameSettings
.MaxLives
:= gsMaxLives
;
4137 if g_Game_IsNet
then MH_SEND_GameSettings
;
4141 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4145 procedure PlayerSettingsCVars(P
: SSArray
);
4150 function ParseTeam(s
: string): Byte;
4154 'red', '1': result
:= TEAM_RED
;
4155 'blue', '2': result
:= TEAM_BLUE
;
4156 else result
:= TEAM_NONE
;
4160 cmd
:= LowerCase(P
[0]);
4164 if (Length(P
) > 1) then
4166 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4167 if g_Game_IsClient
then
4168 MC_SEND_PlayerSettings
4169 else if gGameOn
and (gPlayer1
<> nil) then
4171 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4172 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4178 if (Length(P
) > 1) then
4180 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4181 if g_Game_IsClient
then
4182 MC_SEND_PlayerSettings
4183 else if gGameOn
and (gPlayer2
<> nil) then
4185 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4186 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4192 if Length(P
) > 3 then
4194 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4195 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4196 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4197 if g_Game_IsClient
then
4198 MC_SEND_PlayerSettings
4199 else if gGameOn
and (gPlayer1
<> nil) then
4201 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4202 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4208 if Length(P
) > 3 then
4210 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4211 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4212 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4213 if g_Game_IsClient
then
4214 MC_SEND_PlayerSettings
4215 else if gGameOn
and (gPlayer2
<> nil) then
4217 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4218 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4224 if (Length(P
) > 1) then
4226 gPlayer1Settings
.Model
:= P
[1];
4227 if g_Game_IsClient
then
4228 MC_SEND_PlayerSettings
4229 else if gGameOn
and (gPlayer1
<> nil) then
4231 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4232 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4233 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4239 if (Length(P
) > 1) then
4241 gPlayer2Settings
.Model
:= P
[1];
4242 if g_Game_IsClient
then
4243 MC_SEND_PlayerSettings
4244 else if gGameOn
and (gPlayer2
<> nil) then
4246 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4247 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4248 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4254 // TODO: switch teams if in game or store this separately
4255 if (Length(P
) > 1) then
4257 team
:= ParseTeam(P
[1]);
4258 if team
= TEAM_NONE
then
4259 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4260 else if not gGameOn
and not g_Game_IsNet
then
4261 gPlayer1Settings
.Team
:= team
4263 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4268 // TODO: switch teams if in game or store this separately
4269 if (Length(P
) > 1) then
4271 team
:= ParseTeam(P
[1]);
4272 if team
= TEAM_NONE
then
4273 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4274 else if not gGameOn
and not g_Game_IsNet
then
4275 gPlayer2Settings
.Team
:= team
4277 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4283 procedure PrintHeapStats();
4287 hs
:= GetFPCHeapStatus();
4288 e_LogWriteLn ('v===== heap status =====v');
4289 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4290 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4291 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4292 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4293 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4294 e_LogWriteLn ('^=======================^');
4297 procedure DebugCommands(P
: SSArray
);
4304 // Команды отладочного режима:
4305 if {gDebugMode}conIsCheatsEnabled
then
4307 cmd
:= LowerCase(P
[0]);
4308 if cmd
= 'd_window' then
4310 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4311 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4313 else if cmd
= 'd_sounds' then
4315 if (Length(P
) > 1) and
4316 ((P
[1] = '1') or (P
[1] = '0')) then
4317 g_Debug_Sounds
:= (P
[1][1] = '1');
4319 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4321 else if cmd
= 'd_frames' then
4323 if (Length(P
) > 1) and
4324 ((P
[1] = '1') or (P
[1] = '0')) then
4325 g_Debug_Frames
:= (P
[1][1] = '1');
4327 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4329 else if cmd
= 'd_winmsg' then
4331 if (Length(P
) > 1) and
4332 ((P
[1] = '1') or (P
[1] = '0')) then
4333 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4335 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4337 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4339 if (Length(P
) > 1) and
4340 ((P
[1] = '1') or (P
[1] = '0')) then
4341 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4343 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4345 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4347 if Length(P
) > 1 then
4349 '0': g_debug_BotAIOff
:= 0;
4350 '1': g_debug_BotAIOff
:= 1;
4351 '2': g_debug_BotAIOff
:= 2;
4352 '3': g_debug_BotAIOff
:= 3;
4355 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4357 else if cmd
= 'd_monster' then
4359 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4360 if Length(P
) < 2 then
4362 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4363 g_Console_Add('ID | Name');
4364 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4365 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4366 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4369 a
:= StrToIntDef(P
[1], 0);
4370 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4371 a
:= g_Mons_TypeIdByName(P
[1]);
4373 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4374 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4377 with gPlayer1
.Obj
do
4379 mon
:= g_Monsters_Create(a
,
4380 X
+ Rect
.X
+ (Rect
.Width
div 2),
4381 Y
+ Rect
.Y
+ Rect
.Height
,
4382 gPlayer1
.Direction
, True);
4384 if (Length(P
) > 2) and (mon
<> nil) then
4386 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4387 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4388 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4389 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4390 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4391 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4392 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4393 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4394 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4399 else if (cmd
= 'd_health') then
4401 if (Length(P
) > 1) and
4402 ((P
[1] = '1') or (P
[1] = '0')) then
4403 g_debug_HealthBar
:= (P
[1][1] = '1');
4405 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4407 else if (cmd
= 'd_player') then
4409 if (Length(P
) > 1) and
4410 ((P
[1] = '1') or (P
[1] = '0')) then
4411 g_debug_Player
:= (P
[1][1] = '1');
4413 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4415 else if (cmd
= 'd_mem') then
4421 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4425 procedure GameCheats(P
: SSArray
);
4431 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4433 g_Console_Add('not available');
4439 g_Console_Add('where is the player?!');
4442 cmd
:= LowerCase(P
[0]);
4446 plr
.GodMode
:= not plr
.GodMode
;
4447 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4450 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4451 if cmd
= 'give' then
4453 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4454 for f
:= 1 to High(P
) do
4456 cmd
:= LowerCase(P
[f
]);
4457 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4458 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4459 if cmd
= 'exit' then
4461 if gTriggers
<> nil then
4463 for a
:= 0 to High(gTriggers
) do
4465 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4467 g_Console_Add('player left the map');
4468 gExitByTrigger
:= True;
4469 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4470 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4478 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4479 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4480 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4481 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4482 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4484 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4485 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4487 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4488 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;
4490 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4491 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4493 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4494 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4496 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4497 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4499 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4500 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4501 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4503 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4504 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4505 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4506 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;
4507 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4508 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4510 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;
4511 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;
4512 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;
4513 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;
4514 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;
4515 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;
4517 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4518 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;
4520 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;
4521 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;
4523 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4525 if cmd
= 'ammo' then
4527 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4528 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4529 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4530 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4531 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4532 g_Console_Add('player got some ammo');
4536 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4537 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4539 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4540 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4542 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4543 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4545 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4546 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4548 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4550 if cmd
= 'weapons' then
4552 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4553 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4554 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4555 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4556 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4557 plr
.GiveItem(ITEM_WEAPON_BFG
);
4558 g_Console_Add('player got weapons');
4562 if cmd
= 'keys' then
4564 plr
.GiveItem(ITEM_KEY_RED
);
4565 plr
.GiveItem(ITEM_KEY_GREEN
);
4566 plr
.GiveItem(ITEM_KEY_BLUE
);
4567 g_Console_Add('player got all keys');
4571 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4576 if cmd
= 'open' then
4578 g_Console_Add('player activated sesame');
4579 g_Triggers_OpenAll();
4586 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4590 if cmd
= 'noclip' then
4593 g_Console_Add('wall hardeness adjusted');
4597 if cmd
= 'notarget' then
4599 plr
.NoTarget
:= not plr
.NoTarget
;
4600 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4604 if cmd
= 'noreload' then
4606 plr
.NoReload
:= not plr
.NoReload
;
4607 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4611 if cmd
= 'speedy' then
4613 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4614 g_Console_Add('speed adjusted');
4618 if cmd
= 'jumpy' then
4620 VEL_JUMP
:= 30-VEL_JUMP
;
4621 g_Console_Add('jump height adjusted');
4625 if cmd
= 'automap' then
4627 gShowMap
:= not gShowMap
;
4628 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4632 if cmd
= 'aimline' then
4634 gAimLine
:= not gAimLine
;
4635 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4640 procedure GameCommands(P
: SSArray
);
4646 pl
: pTNetClient
= nil;
4654 cmd
:= LowerCase(P
[0]);
4656 if cmd
= 'pause' then
4658 {$IFDEF ENABLE_MENU}
4659 if (g_ActiveWindow
= nil) then
4660 g_Game_Pause(not gPauseMain
);
4662 g_Game_Pause(not gPauseMain
);
4665 else if cmd
= 'endgame' then
4666 gExit
:= EXIT_SIMPLE
4667 else if cmd
= 'restart' then
4669 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4671 if g_Game_IsClient
then
4673 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4678 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4680 else if cmd
= 'kick' then
4682 if g_Game_IsServer
then
4684 if Length(P
) < 2 then
4686 g_Console_Add('kick <name>');
4691 g_Console_Add('kick <name>');
4695 if g_Game_IsNet
then
4696 pl
:= g_Net_Client_ByName(P
[1]);
4699 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4700 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4701 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4702 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4703 g_Net_Slist_ServerPlayerLeaves();
4704 end else if gPlayers
<> nil then
4705 for a
:= Low(gPlayers
) to High(gPlayers
) do
4706 if gPlayers
[a
] <> nil then
4707 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4709 // Не отключать основных игроков в сингле
4710 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4712 gPlayers
[a
].Lives
:= 0;
4713 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4714 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4715 g_Player_Remove(gPlayers
[a
].UID
);
4716 g_Net_Slist_ServerPlayerLeaves();
4717 // Если не перемешать, при добавлении новых ботов появятся старые
4721 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4723 else if cmd
= 'kick_id' then
4725 if g_Game_IsServer
and g_Game_IsNet
then
4727 if Length(P
) < 2 then
4729 g_Console_Add('kick_id <client ID>');
4734 g_Console_Add('kick_id <client ID>');
4738 a
:= StrToIntDef(P
[1], 0);
4739 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4741 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4743 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4744 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
4745 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4746 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4747 g_Net_Slist_ServerPlayerLeaves();
4751 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4753 else if cmd
= 'kick_pid' then
4755 if g_Game_IsServer
and g_Game_IsNet
then
4757 if Length(P
) < 2 then
4759 g_Console_Add('kick_pid <player ID>');
4764 g_Console_Add('kick_pid <player ID>');
4768 a
:= StrToIntDef(P
[1], 0);
4769 pl
:= g_Net_Client_ByPlayer(a
);
4770 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4772 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4773 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4774 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4775 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4776 g_Net_Slist_ServerPlayerLeaves();
4779 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4781 else if cmd
= 'ban' then
4783 if g_Game_IsServer
and g_Game_IsNet
then
4785 if Length(P
) < 2 then
4787 g_Console_Add('ban <name>');
4792 g_Console_Add('ban <name>');
4796 pl
:= g_Net_Client_ByName(P
[1]);
4799 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4800 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4801 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4802 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4803 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4804 g_Net_Slist_ServerPlayerLeaves();
4806 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4808 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4810 else if cmd
= 'ban_id' then
4812 if g_Game_IsServer
and g_Game_IsNet
then
4814 if Length(P
) < 2 then
4816 g_Console_Add('ban_id <client ID>');
4821 g_Console_Add('ban_id <client ID>');
4825 a
:= StrToIntDef(P
[1], 0);
4826 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4827 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4829 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4830 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
4831 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
4832 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4833 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4834 g_Net_Slist_ServerPlayerLeaves();
4837 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4839 else if cmd
= 'ban_pid' then
4841 if g_Game_IsServer
and g_Game_IsNet
then
4843 if Length(P
) < 2 then
4845 g_Console_Add('ban_pid <player ID>');
4850 g_Console_Add('ban_pid <player ID>');
4854 a
:= StrToIntDef(P
[1], 0);
4855 pl
:= g_Net_Client_ByPlayer(a
);
4856 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4858 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4859 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4860 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4861 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4862 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4863 g_Net_Slist_ServerPlayerLeaves();
4866 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4868 else if cmd
= 'permban' then
4870 if g_Game_IsServer
and g_Game_IsNet
then
4872 if Length(P
) < 2 then
4874 g_Console_Add('permban <name>');
4879 g_Console_Add('permban <name>');
4883 pl
:= g_Net_Client_ByName(P
[1]);
4886 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4887 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4888 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
4889 g_Net_SaveBanList();
4890 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4891 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4892 g_Net_Slist_ServerPlayerLeaves();
4894 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4896 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4898 else if cmd
= 'permban_id' then
4900 if g_Game_IsServer
and g_Game_IsNet
then
4902 if Length(P
) < 2 then
4904 g_Console_Add('permban_id <client ID>');
4909 g_Console_Add('permban_id <client ID>');
4913 a
:= StrToIntDef(P
[1], 0);
4914 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4915 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4917 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4918 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
4919 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
4920 g_Net_SaveBanList();
4921 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4922 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4923 g_Net_Slist_ServerPlayerLeaves();
4926 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4928 else if cmd
= 'permban_pid' then
4930 if g_Game_IsServer
and g_Game_IsNet
then
4932 if Length(P
) < 2 then
4934 g_Console_Add('permban_pid <player ID>');
4939 g_Console_Add('permban_pid <player ID>');
4943 a
:= StrToIntDef(P
[1], 0);
4944 pl
:= g_Net_Client_ByPlayer(a
);
4945 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4947 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4948 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4949 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
4950 g_Net_SaveBanList();
4951 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4952 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4953 g_Net_Slist_ServerPlayerLeaves();
4956 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4958 else if cmd
= 'permban_ip' then
4960 if g_Game_IsServer
and g_Game_IsNet
then
4962 if Length(P
) < 2 then
4964 g_Console_Add('permban_ip <IP address>');
4969 g_Console_Add('permban_ip <IP address>');
4973 g_Net_BanHost(P
[1]);
4974 g_Net_SaveBanList();
4975 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
4977 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4979 else if cmd
= 'unban' then
4981 if g_Game_IsServer
and g_Game_IsNet
then
4983 if Length(P
) < 2 then
4985 g_Console_Add('unban <IP Address>');
4990 g_Console_Add('unban <IP Address>');
4994 if g_Net_UnbanHost(P
[1]) then
4996 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
4997 g_Net_SaveBanList();
4999 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5001 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5003 else if cmd
= 'clientlist' then
5005 if g_Game_IsServer
and g_Game_IsNet
then
5008 if NetClients
<> nil then
5009 for a
:= Low(NetClients
) to High(NetClients
) do
5010 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5012 plr
:= g_Player_Get(NetClients
[a
].Player
);
5013 if plr
= nil then continue
;
5015 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5016 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5019 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5021 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5023 else if cmd
= 'connect' then
5025 if (NetMode
= NET_NONE
) then
5027 if Length(P
) < 2 then
5029 g_Console_Add('connect <IP> [port] [password]');
5034 g_Console_Add('connect <IP> [port] [password]');
5038 if Length(P
) > 2 then
5039 prt
:= StrToIntDef(P
[2], 25666)
5043 if Length(P
) > 3 then
5048 g_Game_StartClient(P
[1], prt
, pw
);
5051 else if cmd
= 'disconnect' then
5053 if (NetMode
= NET_CLIENT
) then
5056 else if cmd
= 'reconnect' then
5058 if (NetMode
= NET_SERVER
) then
5061 if (NetMode
= NET_CLIENT
) then
5064 gExit
:= EXIT_SIMPLE
;
5068 //TODO: Use last successful password to reconnect, instead of ''
5069 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5071 else if (cmd
= 'addbot') or
5072 (cmd
= 'bot_add') then
5074 if Length(P
) > 2 then
5075 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5076 else if Length(P
) > 1 then
5077 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5079 g_Bot_Add(TEAM_NONE
, 2);
5081 else if cmd
= 'bot_addlist' then
5083 if Length(P
) > 1 then
5085 if Length(P
) = 2 then
5086 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5087 else if Length(P
) = 3 then
5088 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5090 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5093 else if cmd
= 'bot_removeall' then
5095 else if cmd
= 'chat' then
5097 if g_Game_IsNet
then
5099 if Length(P
) > 1 then
5101 for a
:= 1 to High(P
) do
5102 chstr
:= chstr
+ P
[a
] + ' ';
5104 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5106 if Length(chstr
) < 1 then
5108 g_Console_Add('chat <text>');
5112 chstr
:= b_Text_Format(chstr
);
5113 if g_Game_IsClient
then
5114 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5116 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5119 g_Console_Add('chat <text>');
5121 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5123 else if cmd
= 'teamchat' then
5125 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5127 if Length(P
) > 1 then
5129 for a
:= 1 to High(P
) do
5130 chstr
:= chstr
+ P
[a
] + ' ';
5132 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5134 if Length(chstr
) < 1 then
5136 g_Console_Add('teamchat <text>');
5140 chstr
:= b_Text_Format(chstr
);
5141 if g_Game_IsClient
then
5142 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5144 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5145 gPlayer1Settings
.Team
);
5148 g_Console_Add('teamchat <text>');
5150 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5152 else if cmd
= 'game' then
5154 if gGameSettings
.GameType
<> GT_NONE
then
5156 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5159 if Length(P
) = 1 then
5161 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5164 // game not started yet, load fist map from some wad
5166 s
:= addWadExtension(P
[1]);
5167 found
:= e_FindResource(AllMapDirs
, s
);
5171 P
[1] := ExpandFileName(P
[1]);
5172 // if map not choosed then set first map
5173 if Length(P
) < 3 then
5176 P
[2] := g_Game_GetFirstMap(P
[1]);
5179 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5181 if g_Map_Exist(s
) then
5185 with gGameSettings
do
5187 Options
:= gsGameFlags
;
5188 GameMode
:= g_Game_TextToMode(gsGameMode
);
5189 if gSwitchGameMode
<> GM_NONE
then
5190 GameMode
:= gSwitchGameMode
;
5191 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5192 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5194 if Length(P
) >= 4 then
5195 b
:= StrToIntDef(P
[3], 1);
5196 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5197 GoalLimit
, MaxLives
, Options
, b
);
5202 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5204 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5206 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5208 else if cmd
= 'host' then
5210 if gGameSettings
.GameType
<> GT_NONE
then
5212 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5215 if Length(P
) < 4 then
5217 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5220 if not StrToIp(P
[1], listen
) then
5222 prt
:= StrToIntDef(P
[2], 25666);
5224 s
:= addWadExtension(P
[3]);
5225 found
:= e_FindResource(AllMapDirs
, s
);
5229 // get first map in wad, if not specified
5230 if Length(P
) < 5 then
5233 P
[4] := g_Game_GetFirstMap(P
[1]);
5235 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5236 if g_Map_Exist(s
) then
5240 with gGameSettings
do
5242 Options
:= gsGameFlags
;
5243 GameMode
:= g_Game_TextToMode(gsGameMode
);
5244 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5245 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5246 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5248 if Length(P
) >= 6 then
5249 b
:= StrToIntDef(P
[5], 0);
5250 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
5256 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5258 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5263 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5266 else if cmd
= 'map' then
5268 if Length(P
) = 1 then
5270 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5272 g_Console_Add(cmd
+ ' <MAP>');
5273 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5277 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5282 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5284 if Length(P
) < 3 then
5286 // first param is map or wad
5287 s
:= UpperCase(P
[1]);
5288 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5290 gExitByTrigger
:= False;
5293 // already in game, finish current map
5295 gExit
:= EXIT_ENDLEVELCUSTOM
;
5299 // intermission, so change map immediately
5306 found
:= e_FindResource(AllMapDirs
, s
);
5308 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5311 // no such map, found wad
5314 P
[1] := ExpandFileName(pw
);
5315 P
[2] := g_Game_GetFirstMap(P
[1]);
5316 s
:= P
[1] + ':\' + P
[2];
5317 if g_Map_Exist(s
) then
5319 gExitByTrigger
:= False;
5322 // already in game, finish current map
5324 gExit
:= EXIT_ENDLEVELCUSTOM
5328 // intermission, so change map immediately
5335 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5337 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5342 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5348 s
:= addWadExtension(P
[1]);
5349 found
:= e_FindResource(AllMapDirs
, s
);
5353 P
[2] := UpperCase(P
[2]);
5354 s
:= P
[1] + ':\' + P
[2];
5355 if g_Map_Exist(s
) then
5357 gExitByTrigger
:= False;
5361 gExit
:= EXIT_ENDLEVELCUSTOM
5370 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5375 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5381 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5385 else if cmd
= 'nextmap' then
5387 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5389 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5394 if Length(P
) = 1 then
5396 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5398 g_Console_Add(cmd
+ ' <MAP>');
5399 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5404 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5410 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5412 if Length(P
) < 3 then
5414 // first param is map or wad
5415 s
:= UpperCase(P
[1]);
5416 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5419 gExitByTrigger
:= False;
5425 // no such map, found wad
5426 pw
:= addWadExtension(P
[1]);
5427 found
:= e_FindResource(MapDirs
, pw
);
5429 found
:= e_FindResource(WadDirs
, pw
);
5431 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5434 // map not specified, select first map
5436 P
[2] := g_Game_GetFirstMap(P
[1]);
5437 s
:= P
[1] + ':\' + P
[2];
5438 if g_Map_Exist(s
) then
5440 gExitByTrigger
:= False;
5447 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5449 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5454 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5460 // specified two params wad + map
5461 pw
:= addWadExtension(P
[1]);
5462 found
:= e_FindResource(MapDirs
, pw
);
5464 found
:= e_FindResource(MapDirs
, pw
);
5468 P
[2] := UpperCase(P
[2]);
5469 s
:= P
[1] + ':\' + P
[2];
5470 if g_Map_Exist(s
) then
5472 gExitByTrigger
:= False;
5478 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5483 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5489 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5494 if gNextMap
= '' then
5495 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5497 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5501 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5505 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5509 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5511 gExitByTrigger
:= False;
5512 // next map not specified, try to find trigger EXIT
5513 if (gNextMap
= '') and (gTriggers
<> nil) then
5515 for a
:= 0 to High(gTriggers
) do
5517 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5519 gExitByTrigger
:= True;
5520 //gNextMap := gTriggers[a].Data.MapName;
5521 gNextMap
:= gTriggers
[a
].tgcMap
;
5526 if gNextMap
= '' then
5527 gNextMap
:= g_Game_GetNextMap();
5528 if not isWadPath(gNextMap
) then
5529 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5532 if g_Map_Exist(s
) then
5533 gExit
:= EXIT_ENDLEVELCUSTOM
5535 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5539 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5543 else if (cmd
= 'event') then
5545 if (Length(P
) <= 1) then
5547 for a
:= 0 to High(gEvents
) do
5548 if gEvents
[a
].Command
= '' then
5549 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5551 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5554 if (Length(P
) = 2) then
5556 for a
:= 0 to High(gEvents
) do
5557 if gEvents
[a
].Name
= P
[1] then
5558 if gEvents
[a
].Command
= '' then
5559 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5561 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5564 for a
:= 0 to High(gEvents
) do
5565 if gEvents
[a
].Name
= P
[1] then
5567 gEvents
[a
].Command
:= '';
5568 for b
:= 2 to High(P
) do
5569 if Pos(' ', P
[b
]) = 0 then
5570 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5572 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5573 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5577 else if cmd
= 'suicide' then
5581 if g_Game_IsClient
then
5582 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5585 if gPlayer1
<> nil then
5586 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5587 if gPlayer2
<> nil then
5588 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5592 else if cmd
= 'screenshot' then
5594 {$IFDEF ENABLE_RENDER}
5598 else if cmd
= 'weapon' then
5600 if Length(p
) = 2 then
5602 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
5603 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5604 gSelectWeapon
[0, a
] := True
5607 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5609 if Length(p
) = 2 then
5611 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
5612 b
:= ord(cmd
[2]) - ord('1');
5613 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5614 gSelectWeapon
[b
, a
] := True
5617 // Команды Своей игры:
5618 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5620 if cmd
= 'bot_addred' then
5622 if Length(P
) > 1 then
5623 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5625 g_Bot_Add(TEAM_RED
, 2);
5627 else if cmd
= 'bot_addblue' then
5629 if Length(P
) > 1 then
5630 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5632 g_Bot_Add(TEAM_BLUE
, 2);
5634 else if cmd
= 'spectate' then
5640 else if cmd
= 'say' then
5642 if g_Game_IsServer
and g_Game_IsNet
then
5644 if Length(P
) > 1 then
5647 for a
:= 1 to High(P
) do
5648 chstr
:= chstr
+ P
[a
] + ' ';
5650 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5652 if Length(chstr
) < 1 then
5654 g_Console_Add('say <text>');
5658 chstr
:= b_Text_Format(chstr
);
5659 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5661 else g_Console_Add('say <text>');
5663 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5665 else if cmd
= 'tell' then
5667 if g_Game_IsServer
and g_Game_IsNet
then
5669 if (Length(P
) > 2) and (P
[1] <> '') then
5672 for a
:= 2 to High(P
) do
5673 chstr
:= chstr
+ P
[a
] + ' ';
5675 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5677 if Length(chstr
) < 1 then
5679 g_Console_Add('tell <playername> <text>');
5683 pl
:= g_Net_Client_ByName(P
[1]);
5685 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5687 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5689 else g_Console_Add('tell <playername> <text>');
5691 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5693 else if cmd
= 'centerprint' then
5695 if (Length(P
) > 2) and (P
[1] <> '') then
5698 for a
:= 2 to High(P
) do
5699 chstr
:= chstr
+ P
[a
] + ' ';
5701 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5703 if Length(chstr
) < 1 then
5705 g_Console_Add('centerprint <timeout> <text>');
5709 a
:= StrToIntDef(P
[1], 100);
5710 chstr
:= b_Text_Format(chstr
);
5711 g_Game_Message(chstr
, a
);
5712 if g_Game_IsNet
and g_Game_IsServer
then
5713 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
5715 else g_Console_Add('centerprint <timeout> <text>');
5717 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5719 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5721 // Дополнительное время:
5722 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5724 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5725 [gGameSettings
.TimeLimit
div 3600,
5726 (gGameSettings
.TimeLimit
div 60) mod 60,
5727 gGameSettings
.TimeLimit
mod 60]));
5728 if g_Game_IsNet
then MH_SEND_GameSettings
;
5730 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5732 if (Length(P
) <= 1) then
5733 g_Console_Add('rcon_password <password>')
5735 MC_SEND_RCONPassword(P
[1]);
5737 else if cmd
= 'rcon' then
5739 if g_Game_IsClient
then
5741 if Length(P
) > 1 then
5744 for a
:= 1 to High(P
) do
5745 chstr
:= chstr
+ P
[a
] + ' ';
5747 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5749 if Length(chstr
) < 1 then
5751 g_Console_Add('rcon <command>');
5755 MC_SEND_RCONCommand(chstr
);
5757 else g_Console_Add('rcon <command>');
5760 else if cmd
= 'ready' then
5762 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5763 gLMSRespawnTime
:= gTime
+ 100;
5765 else if (cmd
= 'callvote') and g_Game_IsNet
then
5767 if Length(P
) > 1 then
5770 for a
:= 1 to High(P
) do begin
5771 if a
> 1 then chstr
:= chstr
+ ' ';
5772 chstr
:= chstr
+ P
[a
];
5775 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5777 if Length(chstr
) < 1 then
5779 g_Console_Add('callvote <command>');
5783 if g_Game_IsClient
then
5784 MC_SEND_Vote(True, chstr
)
5786 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5787 g_Console_Process('vote', True);
5790 g_Console_Add('callvote <command>');
5792 else if (cmd
= 'vote') and g_Game_IsNet
then
5794 if g_Game_IsClient
then
5796 else if gVoteInProgress
then
5798 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5799 a
:= Floor((NetClientCount
+1)/2.0) + 1
5801 a
:= Floor(NetClientCount
/2.0) + 1;
5806 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5807 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5813 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5814 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5822 procedure SystemCommands(P
: SSArray
);
5826 cmd
:= LowerCase(P
[0]);
5833 {$IFDEF ENABLE_RENDER}
5839 if Length(p
) = 2 then
5841 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
5843 gFrameTime
:= 1000 div gMaxFPS
5847 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
5851 if Length(p
) = 2 then
5853 gAskLanguage
:= true;
5854 gLanguage
:= LANGUAGE_ENGLISH
;
5855 case LowerCase(p
[1]) of
5858 gAskLanguage
:= false;
5859 gLanguage
:= LANGUAGE_ENGLISH
;
5863 gAskLanguage
:= false;
5864 gLanguage
:= LANGUAGE_RUSSIAN
;
5868 gAskLanguage
:= true;
5869 gLanguage
:= LANGUAGE_ENGLISH
;
5872 g_Language_Set(gLanguage
);
5876 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
5882 {$IFDEF ENABLE_RENDER}
5883 procedure g_TakeScreenShot(Filename
: string = '');
5884 var t
: TDateTime
; dir
, date
, name
: String;
5886 if e_NoGraphics
then
5889 dir
:= e_GetWriteableDir(ScreenshotDirs
);
5890 if Filename
= '' then
5893 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
5894 Filename
:= 'screenshot-' + date
;
5897 name
:= e_CatPath(dir
, Filename
+ '.png');
5898 if r_Render_WriteScreenShot(name
) then
5899 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
5901 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
5905 {$IFDEF ENABLE_MENU}
5906 procedure g_Game_InGameMenu(Show
: Boolean);
5908 if (g_ActiveWindow
= nil) and Show
then
5910 if gGameSettings
.GameType
= GT_SINGLE
then
5911 g_GUI_ShowWindow('GameSingleMenu')
5914 if g_Game_IsClient
then
5915 g_GUI_ShowWindow('GameClientMenu')
5917 if g_Game_IsNet
then
5918 g_GUI_ShowWindow('GameServerMenu')
5920 g_GUI_ShowWindow('GameCustomMenu');
5922 g_Sound_PlayEx('MENU_OPEN');
5924 // Пауза при меню только в одиночной игре:
5925 if (not g_Game_IsNet
) then
5929 if (g_ActiveWindow
<> nil) and (not Show
) then
5931 // Пауза при меню только в одиночной игре:
5932 if (not g_Game_IsNet
) then
5933 g_Game_Pause(False);
5938 procedure g_Game_Pause (Enable
: Boolean);
5942 if not gGameOn
then exit
;
5944 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
5947 gPauseMain
:= Enable
;
5949 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
5952 procedure g_Game_HolmesPause (Enable
: Boolean);
5956 if not gGameOn
then exit
;
5957 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
5960 gPauseHolmes
:= Enable
;
5962 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
5965 procedure g_Game_PauseAllSounds(Enable
: Boolean);
5970 if gTriggers
<> nil then
5971 for i
:= 0 to High(gTriggers
) do
5972 with gTriggers
[i
] do
5973 if (TriggerType
= TRIGGER_SOUND
) and
5975 Sound
.IsPlaying() then
5977 Sound
.Pause(Enable
);
5981 if gPlayers
<> nil then
5982 for i
:= 0 to High(gPlayers
) do
5983 if gPlayers
[i
] <> nil then
5984 gPlayers
[i
].PauseSounds(Enable
);
5987 if gMusic
<> nil then
5988 gMusic
.Pause(Enable
);
5991 procedure g_Game_StopAllSounds(all
: Boolean);
5995 if gTriggers
<> nil then
5996 for i
:= 0 to High(gTriggers
) do
5997 with gTriggers
[i
] do
5998 if (TriggerType
= TRIGGER_SOUND
) and
6002 if gMusic
<> nil then
6009 procedure g_Game_UpdateTriggerSounds
;
6012 if gTriggers
<> nil then
6013 for i
:= 0 to High(gTriggers
) do
6014 with gTriggers
[i
] do
6015 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6016 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6019 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6022 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6027 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6032 if gSpectMode
<> SPECT_PLAYERS
then
6034 if gSpectPID1
= UID
then
6039 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6046 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6051 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6056 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6061 if gSpectMode
<> SPECT_PLAYERS
then
6063 Pl
:= g_Player_Get(gSpectPID1
);
6064 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6069 if gSpectViewTwo
then
6071 Pl
:= g_Player_Get(gSpectPID2
);
6072 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6080 procedure g_Game_Message (Msg
: string; Time
: Word);
6083 MessageTime
:= Time
;
6086 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6088 punct
: Array[0..13] of String =
6089 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6095 function IsPunctuation(S
: String): Boolean;
6100 if Length(S
) <> 1 then
6102 for i
:= Low(punct
) to High(punct
) do
6103 if S
= punct
[i
] then
6109 function FilterPunctuation(S
: String): String;
6113 for i
:= Low(punct
) to High(punct
) do
6114 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6120 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6122 // remove player name
6123 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6124 // for FullWord check
6125 Text := toLowerCase1251(' ' + Text + ' ');
6126 fpText
:= FilterPunctuation(Text);
6128 for i
:= 0 to Length(gChatSounds
) - 1 do
6131 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6133 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6134 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6136 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6142 gChatSounds
[i
].Sound
.Play();
6148 g_Sound_PlayEx('SOUND_GAME_RADIO');
6151 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6160 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6164 if goodsnd
[a
].IsPlaying() then
6167 goodsnd
[Random(4)].Play();
6170 procedure g_Game_Announce_KillCombo(Param
: Integer);
6177 UID
:= Param
and $FFFF;
6182 Pl
:= g_Player_Get(UID
);
6191 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6195 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6199 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6203 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6211 if not g_Game_IsWatchedPlayer(UID
) then
6214 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6218 if killsnd
[n
].IsPlaying() then
6223 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6231 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6235 if hahasnd
[a
].IsPlaying() then
6238 hahasnd
[Random(3)].Play();
6241 procedure g_Game_StartVote(Command
, Initiator
: string);
6245 if not gVotesEnabled
then Exit
;
6246 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6247 if gVoteInProgress
or gVotePassed
then
6249 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6250 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6253 gVoteInProgress
:= True;
6254 gVotePassed
:= False;
6255 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6258 gVoteCommand
:= Command
;
6260 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6261 Need
:= Floor((NetClientCount
+1)/2.0)+1
6263 Need
:= Floor(NetClientCount
/2.0)+1;
6264 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6265 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6268 procedure g_Game_CheckVote
;
6272 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6273 if not gVoteInProgress
then Exit
;
6275 if (gTime
>= gVoteTimer
) then
6277 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6278 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6280 Need
:= Floor(NetClientCount
/2.0) + 1;
6281 if gVoteCount
>= Need
then
6283 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6284 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6285 gVotePassed
:= True;
6286 gVoteCmdTimer
:= gTime
+ 5000;
6290 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6291 MH_SEND_VoteEvent(NET_VE_FAILED
);
6293 if NetClients
<> nil then
6294 for I
:= Low(NetClients
) to High(NetClients
) do
6295 if NetClients
[i
].Used
then
6296 NetClients
[i
].Voted
:= False;
6297 gVoteInProgress
:= False;
6303 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6304 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6306 Need
:= Floor(NetClientCount
/2.0) + 1;
6307 if gVoteCount
>= Need
then
6309 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6310 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6311 gVoteInProgress
:= False;
6312 gVotePassed
:= True;
6313 gVoteCmdTimer
:= gTime
+ 5000;
6316 if NetClients
<> nil then
6317 for I
:= Low(NetClients
) to High(NetClients
) do
6318 if NetClients
[i
].Used
then
6319 NetClients
[i
].Voted
:= False;
6324 procedure g_Game_LoadMapList(FileName
: string);
6332 if not FileExists(FileName
) then Exit
;
6334 AssignFile(ListFile
, FileName
);
6336 while not EOF(ListFile
) do
6338 ReadLn(ListFile
, s
);
6341 if s
= '' then Continue
;
6343 SetLength(MapList
, Length(MapList
)+1);
6344 MapList
[High(MapList
)] := s
;
6346 CloseFile(ListFile
);
6349 procedure g_Game_SetDebugMode();
6352 // Читы (даже в своей игре):
6356 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6360 if Length(LoadingStat
.Msgs
) = 0 then
6366 begin // Переходим на следующую строку или скроллируем:
6367 if NextMsg
= Length(Msgs
) then
6369 for i
:= 0 to High(Msgs
)-1 do
6370 Msgs
[i
] := Msgs
[i
+1];
6378 Msgs
[NextMsg
-1] := Text;
6382 PBarWasHere
:= false;
6385 {$IFDEF ENABLE_MENU}
6386 g_ActiveWindow
:= nil;
6389 ProcessLoading(true);
6392 procedure g_Game_StepLoading(Value
: Integer = -1);
6403 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6411 procedure g_Game_ClearLoading();
6420 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6421 if len
< 1 then len
:= 1;
6422 SetLength(Msgs
, len
);
6423 for len
:= Low(Msgs
) to High(Msgs
) do
6426 PBarWasHere
:= false;
6430 procedure Parse_Params(var pars
: TParamStrValues
);
6437 while i
<= ParamCount
do
6440 if (s
[1] = '-') and (Length(s
) > 1) then
6442 if (s
[2] = '-') and (Length(s
) > 2) then
6443 begin // Одиночный параметр
6444 SetLength(pars
, Length(pars
) + 1);
6445 with pars
[High(pars
)] do
6447 Name
:= LowerCase(s
);
6452 if (i
< ParamCount
) then
6453 begin // Параметр со значением
6455 SetLength(pars
, Length(pars
) + 1);
6456 with pars
[High(pars
)] do
6458 Name
:= LowerCase(s
);
6459 Value
:= LowerCase(ParamStr(i
));
6468 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6473 for i
:= 0 to High(pars
) do
6474 if pars
[i
].Name
= aName
then
6476 Result
:= pars
[i
].Value
;
6481 procedure g_Game_Process_Params();
6483 pars
: TParamStrValues
;
6486 LimT
, LimS
: Integer;
6497 s
:= Find_Param_Value(pars
, '--debug');
6500 g_Game_SetDebugMode();
6501 s
:= Find_Param_Value(pars
, '--netdump');
6506 // Connect when game loads
6507 ip
:= Find_Param_Value(pars
, '-connect');
6511 s
:= Find_Param_Value(pars
, '-port');
6512 if (s
= '') or not TryStrToInt(s
, Port
) then
6515 s
:= Find_Param_Value(pars
, '-pw');
6517 g_Game_StartClient(ip
, Port
, s
);
6521 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6524 gDefaultMegawadStart
:= s
;
6527 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6528 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6530 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6533 // Start map when game loads:
6534 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6535 if isWadPath(map
) then
6538 s
:= Find_Param_Value(pars
, '-gm');
6539 GMode
:= g_Game_TextToMode(s
);
6540 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6541 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6544 s
:= Find_Param_Value(pars
, '-limt');
6545 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6551 s
:= Find_Param_Value(pars
, '-lims');
6552 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6558 s
:= Find_Param_Value(pars
, '-lives');
6559 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6565 s
:= Find_Param_Value(pars
, '-opt');
6569 Opt
:= StrToIntDef(s
, 0);
6572 s
:= Find_Param_Value(pars
, '--close');
6576 // Override map to test:
6577 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6580 if e_IsValidResourceName(s
) then
6581 e_FindResource(AllMapDirs
, s
);
6582 gTestMap
:= ExpandFileName(s
);
6585 // Delete test map after play:
6586 s
:= Find_Param_Value(pars
, '--testdelete');
6589 //gMapToDelete := MapsDir + map;
6590 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6594 // Delete temporary WAD after play:
6595 s
:= Find_Param_Value(pars
, '--tempdelete');
6596 if (s
<> '') and (gTestMap
<> '') then
6598 gMapToDelete
:= gTestMap
;
6599 gTempDelete
:= True;
6602 // Number of players:
6603 s
:= Find_Param_Value(pars
, '-pl');
6605 n
:= DEFAULT_PLAYERS
6607 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6610 s
:= Find_Param_Value(pars
, '-port');
6611 if (s
= '') or not TryStrToInt(s
, Port
) then
6612 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6614 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6617 // Execute script when game loads:
6618 s
:= Find_Param_Value(pars
, '-exec');
6621 // if not isWadPath(s) then
6622 // s := GameDir + '/' + s;
6627 if IOResult
<> 0 then
6629 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6630 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6634 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6635 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6640 if IOResult
<> 0 then
6642 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6643 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6647 if Pos('#', s
) <> 1 then // script comment
6648 g_Console_Process(s
, True);
6659 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6660 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6661 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6662 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6664 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6665 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6666 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6667 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6670 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6671 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6674 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6675 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6677 {$IFDEF ENABLE_HOLMES}
6678 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6681 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6683 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6684 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6686 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6687 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6689 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6690 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6691 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6692 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
6693 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6694 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6695 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6696 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6697 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');