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
68 // ones below are sent only to the server
70 WeaponPreferences
: Array[WP_FIRST
..WP_LAST
+1] of Byte;
87 function g_Game_IsNet(): Boolean;
88 function g_Game_IsServer(): Boolean;
89 function g_Game_IsClient(): Boolean;
90 procedure g_Game_Init();
91 procedure g_Game_Free (freeTextures
: Boolean=true);
92 procedure g_Game_LoadData();
93 procedure g_Game_FreeData();
94 procedure g_Game_Update();
95 procedure g_Game_PreUpdate();
96 procedure g_Game_Quit();
97 function g_Game_ModeToText(Mode
: Byte): string;
98 function g_Game_TextToMode(Mode
: string): Byte;
99 procedure g_Game_ExecuteEvent(Name
: String);
100 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
101 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
102 procedure g_Game_RemovePlayer();
103 procedure g_Game_Spectate();
104 procedure g_Game_SpectateCenterView();
105 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
106 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
107 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
108 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
109 procedure g_Game_Restart();
110 procedure g_Game_RestartLevel();
111 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
112 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
113 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
114 procedure g_Game_ChangeMap(const MapPath
: String);
115 procedure g_Game_ExitLevel(const Map
: AnsiString);
116 function g_Game_GetFirstMap(WAD
: String): String;
117 function g_Game_GetNextMap(): String;
118 procedure g_Game_NextLevel();
119 procedure g_Game_Pause(Enable
: Boolean);
120 procedure g_Game_HolmesPause(Enable
: Boolean);
121 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
122 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
123 procedure g_Game_Message(Msg
: String; Time
: Word);
124 procedure g_Game_LoadMapList(FileName
: String);
125 procedure g_Game_PauseAllSounds(Enable
: Boolean);
126 procedure g_Game_StopAllSounds(all
: Boolean);
127 procedure g_Game_UpdateTriggerSounds();
128 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
129 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
130 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
131 procedure g_Game_Announce_KillCombo(Param
: Integer);
132 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
133 procedure g_Game_StartVote(Command
, Initiator
: string);
134 procedure g_Game_CheckVote
;
136 procedure g_TakeScreenShot(Filename
: string = '');
138 procedure g_FatalError(Text: String);
139 procedure g_SimpleError(Text: String);
140 function g_Game_IsTestMap(): Boolean;
141 procedure g_Game_DeleteTestMap();
142 procedure GameCVars(P
: SSArray
);
143 procedure PlayerSettingsCVars(P
: SSArray
);
144 procedure SystemCommands(P
: SSArray
);
145 procedure GameCommands(P
: SSArray
);
146 procedure GameCheats(P
: SSArray
);
147 procedure DebugCommands(P
: SSArray
);
148 procedure g_Game_Process_Params
;
149 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
150 procedure g_Game_StepLoading(Value
: Integer = -1);
151 procedure g_Game_ClearLoading();
152 procedure g_Game_SetDebugMode();
154 function IsActivePlayer(p
: TPlayer
): Boolean;
155 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
156 procedure SortGameStat(var stat
: TPlayerStatArray
);
160 procedure g_Game_InGameMenu(Show
: Boolean);
163 procedure CharPress (C
: AnsiChar);
165 procedure KeyPress (K
: Word);
167 { procedure SetWinPause(Enable: Boolean); }
172 LOADING_SHOW_STEP
= 100;
173 LOADING_INTERLINE
= 20;
191 EXIT_ENDLEVELSINGLE
= 4;
192 EXIT_ENDLEVELCUSTOM
= 5;
194 GAME_OPTION_RESERVED
= 1;
195 GAME_OPTION_TEAMDAMAGE
= 2;
196 GAME_OPTION_ALLOWEXIT
= 4;
197 GAME_OPTION_WEAPONSTAY
= 8;
198 GAME_OPTION_MONSTERS
= 16;
199 GAME_OPTION_BOTVSPLAYER
= 32;
200 GAME_OPTION_BOTVSMONSTER
= 64;
201 GAME_OPTION_DMKEYS
= 128;
202 GAME_OPTION_TEAMHITTRACE
= 256;
203 GAME_OPTION_TEAMHITPROJECTILE
= 512;
204 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
205 GAME_OPTION_ALLOWDROPFLAG
= 2048;
206 GAME_OPTION_THROWFLAG
= 4096;
211 STATE_INTERCUSTOM
= 3;
212 STATE_INTERSINGLE
= 4;
218 LMS_RESPAWN_NONE
= 0;
219 LMS_RESPAWN_WARMUP
= 1;
220 LMS_RESPAWN_FINAL
= 2;
237 CONFIG_FILENAME
= 'Doom2DF.cfg';
239 TEST_MAP_NAME
= '$$$_TEST_$$$';
241 STD_PLAYER_MODEL
= 'Doomer';
249 STATFILE_VERSION
= $03;
252 gGameSettings
: TGameSettings
;
253 gPlayer1Settings
: TPlayerSettings
;
254 gPlayer2Settings
: TPlayerSettings
;
256 gPlayerScreenSize
: TDFPoint
;
257 gPlayer1ScreenCoord
: TDFPoint
;
258 gPlayer2ScreenCoord
: TDFPoint
;
259 gPlayer1
: TPlayer
= nil;
260 gPlayer2
: TPlayer
= nil;
261 gPlayerDrawn
: TPlayer
= nil;
263 gLerpFactor
: Single = 1.0;
264 gSwitchGameMode
: Byte = GM_DM
;
265 gHearPoint1
, gHearPoint2
: THearPoint
;
266 gSoundEffectsDF
: Boolean = False;
267 gSoundTriggerTime
: Word = 0;
268 gAnnouncer
: Integer = ANNOUNCE_NONE
;
269 goodsnd
: array[0..3] of TPlayableSound
;
270 killsnd
: array[0..3] of TPlayableSound
;
271 hahasnd
: array[0..2] of TPlayableSound
;
272 sound_get_flag
: array[0..1] of TPlayableSound
;
273 sound_lost_flag
: array[0..1] of TPlayableSound
;
274 sound_ret_flag
: array[0..1] of TPlayableSound
;
275 sound_cap_flag
: array[0..1] of TPlayableSound
;
276 gBodyKillEvent
: Integer = -1;
277 gDefInterTime
: ShortInt = -1;
278 gInterEndTime
: LongWord = 0;
279 gInterTime
: LongWord = 0;
280 gServInterTime
: Byte = 0;
281 gGameStartTime
: LongWord = 0;
282 gTotalMonsters
: Integer = 0;
283 gPauseMain
: Boolean = false;
284 gPauseHolmes
: Boolean = false;
285 gShowTime
: Boolean = False;
286 gShowFPS
: Boolean = False;
287 gShowScore
: Boolean = True;
288 gShowStat
: Boolean = True;
289 gShowPIDs
: Boolean = False;
290 gShowKillMsg
: Boolean = True;
291 gShowLives
: Boolean = True;
292 gShowPing
: Boolean = False;
293 gShowMap
: Boolean = False;
295 gState
: Byte = STATE_NONE
;
297 sWidth
, sHeight
: Word;
298 gSpectMode
: Byte = SPECT_NONE
;
299 gSpectHUD
: Boolean = True;
300 gSpectKeyPress
: Boolean = False;
301 gSpectX
: Integer = 0;
302 gSpectY
: Integer = 0;
303 gSpectStep
: Byte = 8;
304 gSpectViewTwo
: Boolean = False;
305 gSpectPID1
: Integer = -1;
306 gSpectPID2
: Integer = -1;
307 gSpectAuto
: Boolean = False;
308 gSpectAutoNext
: LongWord;
309 gSpectAutoStepX
: Integer;
310 gSpectAutoStepY
: Integer;
311 gMusic
: TMusic
= nil;
312 gLoadGameMode
: Boolean;
313 gCheats
: Boolean = False;
314 gMapOnce
: Boolean = False;
315 gMapToDelete
: String;
316 gTempDelete
: Boolean = False;
317 gLastMap
: Boolean = False;
320 gResolutionChange
: Boolean = False;
321 gRC_Width
, gRC_Height
: Integer;
322 gRC_FullScreen
, gRC_Maximized
: Boolean;
323 gLanguageChange
: Boolean = False;
324 gDebugMode
: Boolean = False;
325 g_debug_Sounds
: Boolean = False;
326 g_debug_Frames
: Boolean = False;
327 g_debug_WinMsgs
: Boolean = False;
328 g_debug_MonsterOff
: Boolean = False;
329 g_debug_BotAIOff
: Byte = 0;
330 g_debug_HealthBar
: Boolean = False;
331 g_Debug_Player
: Boolean = False;
332 gCoopMonstersKilled
: Word = 0;
333 gCoopSecretsFound
: Word = 0;
334 gCoopTotalMonstersKilled
: Word = 0;
335 gCoopTotalSecretsFound
: Word = 0;
336 gCoopTotalMonsters
: Word = 0;
337 gCoopTotalSecrets
: Word = 0;
338 gStatsOff
: Boolean = False;
339 gStatsPressed
: Boolean = False;
340 gExitByTrigger
: Boolean = False;
341 gNextMap
: String = '';
342 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
343 gLMSRespawnTime
: Cardinal = 0;
344 gLMSSoftSpawn
: Boolean = False;
345 gMissionFailed
: Boolean = False;
346 gVoteInProgress
: Boolean = False;
347 gVotePassed
: Boolean = False;
348 gVoteCommand
: string = '';
349 gVoteTimer
: Cardinal = 0;
350 gVoteCmdTimer
: Cardinal = 0;
351 gVoteCount
: Integer = 0;
352 gVoteTimeout
: Cardinal = 30;
353 gVoted
: Boolean = False;
354 gVotesEnabled
: Boolean = True;
355 gEvents
: Array of TGameEvent
;
356 gDelayedEvents
: Array of TDelayedEvent
;
357 gUseChatSounds
: Boolean = True;
358 gChatSounds
: Array of TChatSound
;
359 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
360 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
361 gInterReadyCount
: Integer = 0;
362 gMaxBots
: Integer = 127;
364 g_dbg_ignore_bounds
: Boolean = false;
365 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
366 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
368 // move button values:
369 // bits 0-1: l/r state:
370 // 0: neither left, nor right pressed
373 // bits 4-5: l/r state when strafe was pressed
374 P1MoveButton
: Byte = 0;
375 P2MoveButton
: Byte = 0;
377 g_profile_frame_update
: Boolean = false;
378 g_profile_frame_draw
: Boolean = false;
379 g_profile_collision
: Boolean = false;
380 g_profile_los
: Boolean = false;
381 g_profile_history_size
: Integer = 1000;
383 g_rlayer_back
: Boolean = true;
384 g_rlayer_step
: Boolean = true;
385 g_rlayer_wall
: Boolean = true;
386 g_rlayer_door
: Boolean = true;
387 g_rlayer_acid1
: Boolean = true;
388 g_rlayer_acid2
: Boolean = true;
389 g_rlayer_water
: Boolean = true;
390 g_rlayer_fore
: Boolean = true;
392 wNeedTimeReset
: Boolean = false;
394 procedure g_ResetDynlights ();
395 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
396 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
398 function conIsCheatsEnabled (): Boolean; inline;
399 function gPause (): Boolean; inline;
401 type (* private state *)
402 TEndCustomGameStat
= record
403 PlayerStat
: TPlayerStatArray
;
407 Map
, MapName
: String;
410 TEndSingleGameStat
= record
411 PlayerStat
: Array [0..1] of record
417 TotalSecrets
: Integer;
420 TLoadingStat
= record
424 Msgs
: Array of String;
426 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
430 x
, y
, radius
: Integer;
433 exploRadius
: Integer;
436 var (* private state *)
437 CustomStat
: TEndCustomGameStat
;
438 StatShotDone
: Boolean;
439 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
440 SingleStat
: TEndSingleGameStat
;
441 LoadingStat
: TLoadingStat
;
444 EndingGameCounter
: Byte;
446 g_playerLight
: Boolean;
447 g_dynLights
: array of TDynLight
= nil;
448 g_dynLightCount
: Integer = 0;
449 EndPicPath
: AnsiString; // full path, used by render
454 {$IFDEF ENABLE_HOLMES}
467 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
468 g_playermodel
, g_options
, Math
,
469 g_triggers
, g_monsters
, e_sound
, CONFIG
,
470 g_language
, g_net
, g_phys
,
471 ENet
, e_msg
, g_netmsg
, g_netmaster
,
475 charbuff
: packed array [0..15] of AnsiChar = (
476 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
479 function Translit (const S
: AnsiString): AnsiString;
484 for i
:= 1 to Length(Result
) do
487 #
$C9: Result
[i
] := 'Q';
488 #
$D6: Result
[i
] := 'W';
489 #
$D3: Result
[i
] := 'E';
490 #
$CA: Result
[i
] := 'R';
491 #
$C5: Result
[i
] := 'T';
492 #
$CD: Result
[i
] := 'Y';
493 #
$C3: Result
[i
] := 'U';
494 #
$D8: Result
[i
] := 'I';
495 #
$D9: Result
[i
] := 'O';
496 #
$C7: Result
[i
] := 'P';
497 #
$D5: Result
[i
] := '['; //Chr(219);
498 #
$DA: Result
[i
] := ']'; //Chr(221);
499 #
$D4: Result
[i
] := 'A';
500 #
$DB: Result
[i
] := 'S';
501 #
$C2: Result
[i
] := 'D';
502 #
$C0: Result
[i
] := 'F';
503 #
$CF: Result
[i
] := 'G';
504 #
$D0: Result
[i
] := 'H';
505 #
$CE: Result
[i
] := 'J';
506 #
$CB: Result
[i
] := 'K';
507 #
$C4: Result
[i
] := 'L';
508 #
$C6: Result
[i
] := ';'; //Chr(186);
509 #
$DD: Result
[i
] := #39; //Chr(222);
510 #
$DF: Result
[i
] := 'Z';
511 #
$D7: Result
[i
] := 'X';
512 #
$D1: Result
[i
] := 'C';
513 #
$CC: Result
[i
] := 'V';
514 #
$C8: Result
[i
] := 'B';
515 #
$D2: Result
[i
] := 'N';
516 #
$DC: Result
[i
] := 'M';
517 #
$C1: Result
[i
] := ','; //Chr(188);
518 #
$DE: Result
[i
] := '.'; //Chr(190);
524 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
529 ls2
:= Translit(CheatRus
[ct
]);
530 if length(ls1
) = 0 then ls1
:= '~';
531 if length(ls2
) = 0 then ls2
:= '~';
533 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
534 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
535 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
536 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
538 if ct = I_GAME_CHEAT_JETPACK then
540 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
541 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
542 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
543 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
544 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
545 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
561 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
562 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
563 or g_Game_IsNet then Exit;
565 if not gGameOn
then exit
;
566 if not conIsCheatsEnabled
then exit
;
568 s
:= 'SOUND_GAME_RADIO';
571 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
573 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
574 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
578 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
580 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
581 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
585 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
587 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
588 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
592 if CheckCheat(I_GAME_CHEAT_DEATH
) then
594 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
595 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
596 s
:= 'SOUND_MONSTER_HAHA';
600 if CheckCheat(I_GAME_CHEAT_DOORS
) then
602 g_Triggers_OpenAll();
606 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
608 if gTriggers
<> nil then
609 for a
:= 0 to High(gTriggers
) do
610 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
612 gExitByTrigger
:= True;
613 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
614 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
620 s2
:= Copy(charbuff
, 15, 2);
621 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
623 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
631 if CheckCheat(I_GAME_CHEAT_FLY
) then
637 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
639 VEL_JUMP
:= 30-VEL_JUMP
;
643 if CheckCheat(I_GAME_CHEAT_SPEED
) then
645 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
649 if CheckCheat(I_GAME_CHEAT_SUIT
) then
651 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
652 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
656 if CheckCheat(I_GAME_CHEAT_AIR
) then
658 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
659 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
663 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
665 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
666 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
670 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
672 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
673 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
677 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
679 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
680 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
684 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
686 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
687 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
691 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
693 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
694 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
697 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
699 gAimLine
:= not gAimLine
;
702 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
704 gShowMap
:= not gShowMap
;
715 procedure KeyPress (K
: Word);
716 var Msg
: g_gui
.TMessage
;
721 if (g_ActiveWindow
<> nil) then
723 Msg
.Msg
:= WM_KEYDOWN
;
724 Msg
.WParam
:= VK_ESCAPE
;
725 g_ActiveWindow
.OnMessage(Msg
);
726 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
728 else if (gState
<> STATE_FOLD
) then
730 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
732 g_Game_InGameMenu(True);
734 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
736 if (gState
<> STATE_MENU
) then
738 if (NetMode
<> NET_NONE
) then
740 g_Game_StopAllSounds(True);
742 gState
:= STATE_MENU
;
746 g_GUI_ShowWindow('MainMenu');
747 g_Sound_PlayEx('MENU_OPEN');
752 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
753 begin // <F2> .. <F6> � <F12>
754 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
756 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
757 if (not g_Game_IsNet
) then g_Game_Pause(True);
759 IK_F2
: g_Menu_Show_SaveMenu();
760 IK_F3
: g_Menu_Show_LoadMenu();
761 IK_F4
: g_Menu_Show_GameSetGame();
762 IK_F5
: g_Menu_Show_OptionsVideo();
763 IK_F6
: g_Menu_Show_OptionsSound();
764 IK_F7
: g_Menu_Show_EndGameMenu();
765 IK_F10
: g_Menu_Show_QuitGameMenu();
772 gJustChatted
:= False;
773 if gConsoleShow
or gChatShow
then
775 g_Console_Control(K
);
777 else if (g_ActiveWindow
<> nil) then
779 Msg
.Msg
:= WM_KEYDOWN
;
781 g_ActiveWindow
.OnMessage(Msg
);
783 else if (gState
= STATE_MENU
) then
785 g_GUI_ShowWindow('MainMenu');
786 g_Sound_PlayEx('MENU_OPEN');
792 procedure KeyPress (K
: Word);
794 gJustChatted
:= False;
795 if gConsoleShow
or gChatShow
then
797 g_Console_Control(K
);
803 procedure CharPress (C
: AnsiChar);
805 var Msg
: g_gui
.TMessage
;
809 if gConsoleShow
or gChatShow
then
814 else if g_ActiveWindow
<> nil then
817 Msg
.WParam
:= Ord(C
);
818 g_ActiveWindow
.OnMessage(Msg
);
825 charbuff
[a
] := charbuff
[a
+ 1];
827 charbuff
[15] := upcase1251(C
);
834 // ////////////////////////////////////////////////////////////////////////// //
835 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
837 procedure g_ResetDynlights ();
841 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
843 for idx
:= 0 to g_dynLightCount
-1 do
845 if g_dynLights
[idx
].exploCount
= -666 then
852 Inc(g_dynLights
[idx
].exploCount
);
853 if (g_dynLights
[idx
].exploCount
< 10) then
855 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
856 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
857 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
858 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
863 g_dynLightCount
:= lnum
;
866 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
868 if not gwin_has_stencil
then exit
;
869 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
870 g_dynLights
[g_dynLightCount
].x
:= x
;
871 g_dynLights
[g_dynLightCount
].y
:= y
;
872 g_dynLights
[g_dynLightCount
].radius
:= radius
;
873 g_dynLights
[g_dynLightCount
].r
:= r
;
874 g_dynLights
[g_dynLightCount
].g
:= g
;
875 g_dynLights
[g_dynLightCount
].b
:= b
;
876 g_dynLights
[g_dynLightCount
].a
:= a
;
877 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
878 Inc(g_dynLightCount
);
881 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
883 if not gwin_has_stencil
then exit
;
884 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
885 g_dynLights
[g_dynLightCount
].x
:= x
;
886 g_dynLights
[g_dynLightCount
].y
:= y
;
887 g_dynLights
[g_dynLightCount
].radius
:= 0;
888 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
889 g_dynLights
[g_dynLightCount
].r
:= r
;
890 g_dynLights
[g_dynLightCount
].g
:= g
;
891 g_dynLights
[g_dynLightCount
].b
:= b
;
892 g_dynLights
[g_dynLightCount
].a
:= 0;
893 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
894 Inc(g_dynLightCount
);
897 // ////////////////////////////////////////////////////////////////////////// //
898 function conIsCheatsEnabled (): Boolean; inline;
901 if g_Game_IsNet
then exit
;
902 if not gDebugMode
then
904 //if not gCheats then exit;
905 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
906 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
911 // ////////////////////////////////////////////////////////////////////////// //
913 TParamStrValue
= record
918 TParamStrValues
= Array of TParamStrValue
;
921 INTER_ACTION_TEXT
= 1;
922 INTER_ACTION_PIC
= 2;
923 INTER_ACTION_MUSIC
= 3;
928 DataLoaded
: Boolean = False;
930 MapList
: SSArray
= nil;
931 MapIndex
: Integer = -1;
932 InterReadyTime
: Integer = -1;
933 StatDate
: string = '';
948 function Compare(a
, b
: TPlayerStat
): Integer;
950 if a
.Spectator
then Result
:= 1
951 else if b
.Spectator
then Result
:= -1
952 else if a
.Frags
< b
.Frags
then Result
:= 1
953 else if a
.Frags
> b
.Frags
then Result
:= -1
954 else if a
.Deaths
< b
.Deaths
then Result
:= -1
955 else if a
.Deaths
> b
.Deaths
then Result
:= 1
956 else if a
.Kills
< b
.Kills
then Result
:= -1
960 procedure SortGameStat(var stat
: TPlayerStatArray
);
965 if stat
= nil then Exit
;
967 for I
:= High(stat
) downto Low(stat
) do
968 for J
:= Low(stat
) to High(stat
) - 1 do
969 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
972 stat
[J
] := stat
[J
+ 1];
977 // saves a shitty CSV containing the game stats passed to it
978 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
981 dir
, fname
, map
, mode
, etime
: String;
985 dir
:= e_GetWriteableDir(StatsDirs
);
986 // stats are placed in stats/yy/mm/dd/*.csv
987 fname
:= e_CatPath(dir
, Path
);
988 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
989 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
990 AssignFile(s
, fname
);
992 SetTextCodePage(s
, CP_UTF8
);
994 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
995 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
996 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
997 mode
:= g_Game_ModeToText(Stat
.GameMode
);
998 etime
:= Format('%d:%.2d:%.2d', [
999 Stat
.GameTime
div 1000 div 3600,
1000 (Stat
.GameTime
div 1000 div 60) mod 60,
1001 Stat
.GameTime
div 1000 mod 60
1003 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
1004 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
1010 gGameSettings
.TimeLimit
,
1011 gGameSettings
.ScoreLimit
,
1012 gGameSettings
.Options
,
1014 Length(Stat
.PlayerStat
)
1016 // line 2: game specific shit
1017 // if it's a team game: red score, blue score
1018 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1019 // otherwise nothing
1020 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1022 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
1023 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1025 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1026 // lines 3-...: team, player name, frags, deaths
1027 WriteLn(s
, 'team,name,frags,deaths');
1028 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1029 with Stat
.PlayerStat
[I
] do
1030 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1032 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1035 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1040 procedure ClearDebugCvars();
1042 g_debug_Sounds
:= False;
1043 g_debug_Frames
:= False;
1044 g_debug_WinMsgs
:= False;
1045 g_debug_MonsterOff
:= False;
1046 g_debug_BotAIOff
:= 0;
1047 g_debug_HealthBar
:= False;
1048 g_Debug_Player
:= False;
1051 function g_Game_ModeToText(Mode
: Byte): string;
1055 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1056 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1057 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1058 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1059 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1063 function g_Game_TextToMode(Mode
: string): Byte;
1066 Mode
:= UpperCase(Mode
);
1067 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1072 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1077 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1082 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1087 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1089 Result
:= GM_SINGLE
;
1094 function g_Game_IsNet(): Boolean;
1096 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1099 function g_Game_IsServer(): Boolean;
1101 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1104 function g_Game_IsClient(): Boolean;
1106 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1109 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1116 Result
.name
:= ExtractFileName(WAD
);
1117 Result
.description
:= '';
1118 Result
.author
:= '';
1120 w
:= TWADFile
.Create();
1123 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1129 cfg
:= TConfig
.CreateMem(p
, len
);
1130 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1131 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1132 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1133 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1139 procedure g_Game_FreeWAD
;
1142 g_Sound_Delete('MUSIC_endmus');
1143 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1144 gGameSettings
.WAD
:= '';
1147 procedure g_Game_LoadWAD(WAD
: string);
1156 gGameSettings
.WAD
:= WAD
;
1157 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1160 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1162 w
:= TWADFile
.Create();
1165 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1171 cfg
:= TConfig
.CreateMem(p
, len
);
1174 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1175 if MegaWAD
.endpic
<> '' then
1176 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1178 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1179 if MegaWAD
.endmus
<> '' then
1181 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1182 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1190 {procedure start_trigger(t: string);
1194 function next_trigger(): Boolean;
1198 procedure DisableCheats();
1204 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1205 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1206 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1207 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1209 {$IF DEFINED(D2F_DEBUG)}
1210 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1211 gAimLine
:= g_dbg_aimline_on
;
1215 procedure g_Game_ExecuteEvent(Name
: String);
1221 if gEvents
= nil then
1223 for a
:= 0 to High(gEvents
) do
1224 if gEvents
[a
].Name
= Name
then
1226 if gEvents
[a
].Command
<> '' then
1227 g_Console_Process(gEvents
[a
].Command
, True);
1232 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1237 if gDelayedEvents
<> nil then
1238 for a
:= 0 to High(gDelayedEvents
) do
1239 if not gDelayedEvents
[a
].Pending
then
1246 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1247 n
:= High(gDelayedEvents
);
1249 gDelayedEvents
[n
].Pending
:= True;
1250 gDelayedEvents
[n
].DEType
:= DEType
;
1251 gDelayedEvents
[n
].DENum
:= Num
;
1252 gDelayedEvents
[n
].DEStr
:= Str
;
1253 if DEType
= DE_GLOBEVENT
then
1254 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1256 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1260 procedure EndGame();
1266 if g_Game_IsNet
and g_Game_IsServer
then
1267 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1270 gPauseMain
:= false;
1271 gPauseHolmes
:= false;
1274 g_Game_StopAllSounds(False);
1279 EndingGameCounter
:= 0;
1281 {$IFDEF ENABLE_MENU}
1282 g_ActiveWindow
:= nil;
1285 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1286 gLMSRespawnTime
:= 0;
1289 EXIT_SIMPLE
: // Выход через меню или конец теста
1293 begin // Это был тест
1297 begin // Выход в главное меню
1298 {$IFDEF DISABLE_MENU}
1299 gState
:= STATE_MENU
; // ???
1301 gMusic
.SetByName('MUSIC_MENU');
1303 if gState
<> STATE_SLIST
then
1305 g_GUI_ShowWindow('MainMenu');
1306 gState
:= STATE_MENU
;
1310 // Обновляем список серверов
1311 slReturnPressed
:= True;
1312 if g_Net_Slist_Fetch(slCurrent
) then
1314 if slCurrent
= nil then
1315 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1318 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1319 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1322 g_Game_ExecuteEvent('ongameend');
1326 EXIT_RESTART
: // Начать уровень сначала
1328 if not g_Game_IsClient
then g_Game_Restart();
1331 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1333 // Статистика Своей игры:
1334 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1336 CustomStat
.GameTime
:= gTime
;
1337 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1338 CustomStat
.MapName
:= gMapInfo
.Name
;
1339 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1340 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1341 CustomStat
.TeamStat
:= gTeamStat
;
1343 CustomStat
.PlayerStat
:= nil;
1345 // Статистика игроков:
1346 if gPlayers
<> nil then
1348 for a
:= 0 to High(gPlayers
) do
1349 if gPlayers
[a
] <> nil then
1351 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1352 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1355 Name
:= gPlayers
[a
].Name
;
1356 Frags
:= gPlayers
[a
].Frags
;
1357 Deaths
:= gPlayers
[a
].Death
;
1358 Kills
:= gPlayers
[a
].Kills
;
1359 Team
:= gPlayers
[a
].Team
;
1360 Color
:= gPlayers
[a
].Model
.Color
;
1361 Spectator
:= gPlayers
[a
].FSpectator
;
1365 SortGameStat(CustomStat
.PlayerStat
);
1367 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1370 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1371 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1372 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1373 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1375 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1378 StatShotDone
:= False;
1381 g_Game_ExecuteEvent('onmapend');
1382 if not g_Game_IsClient
then g_Player_ResetReady
;
1383 gInterReadyCount
:= 0;
1385 // Затухающий экран:
1386 EndingGameCounter
:= 255;
1387 gState
:= STATE_FOLD
;
1389 if gDefInterTime
< 0 then
1390 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1392 gInterEndTime
:= gDefInterTime
* 1000;
1395 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1397 // Статистика Одиночной игры:
1398 SingleStat
.GameTime
:= gTime
;
1399 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1400 SingleStat
.TotalSecrets
:= gSecretsCount
;
1401 // Статистика первого игрока:
1402 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1403 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1404 // Статистика второго игрока (если есть):
1405 if SingleStat
.TwoPlayers
then
1407 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1408 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1411 g_Game_ExecuteEvent('onmapend');
1414 if gNextMap
<> '' then
1416 gMusic
.SetByName('MUSIC_INTERMUS');
1418 gState
:= STATE_INTERSINGLE
;
1421 g_Game_ExecuteEvent('oninter');
1423 else // Больше нет карт
1425 // Затухающий экран:
1426 EndingGameCounter
:= 255;
1427 gState
:= STATE_FOLD
;
1432 // Окончание обработано:
1433 if gExit
<> EXIT_QUIT
then
1437 procedure g_Game_Init();
1441 gTempDelete
:= False;
1443 sfsGCDisable(); // temporary disable removing of temporary volumes
1446 g_Game_ClearLoading();
1447 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1448 g_Game_SetLoadingText('', 0, False);
1450 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1453 gPauseMain
:= false;
1454 gPauseHolmes
:= false;
1457 {e_MouseInfo.Accel := 1.0;}
1459 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1462 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1463 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1464 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1465 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1466 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1468 gMusic
:= TMusic
.Create();
1469 gMusic
.SetByName('MUSIC_MENU');
1472 gGameSettings
.WarmupTime
:= 30;
1474 gState
:= STATE_MENU
;
1476 SetLength(gEvents
, 6);
1477 gEvents
[0].Name
:= 'ongamestart';
1478 gEvents
[1].Name
:= 'ongameend';
1479 gEvents
[2].Name
:= 'onmapstart';
1480 gEvents
[3].Name
:= 'onmapend';
1481 gEvents
[4].Name
:= 'oninter';
1482 gEvents
[5].Name
:= 'onwadend';
1484 sfsGCEnable(); // enable releasing unused volumes
1488 procedure g_Game_Free(freeTextures
: Boolean=true);
1490 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1491 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1493 g_Map_Free(freeTextures
);
1495 g_Player_RemoveAllCorpses();
1497 gGameSettings
.GameType
:= GT_NONE
;
1498 if gGameSettings
.GameMode
= GM_SINGLE
then
1499 gGameSettings
.GameMode
:= GM_DM
;
1500 gSwitchGameMode
:= gGameSettings
.GameMode
;
1503 gExitByTrigger
:= False;
1506 function IsActivePlayer(p
: TPlayer
): Boolean;
1511 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1514 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1520 if gPlayers
= nil then
1524 for a
:= Low(gPlayers
) to High(gPlayers
) do
1525 if IsActivePlayer(gPlayers
[a
]) then
1527 SetLength(ids
, Length(ids
) + 1);
1528 ids
[High(ids
)] := gPlayers
[a
].UID
;
1529 if gPlayers
[a
].UID
= Skip
then
1532 if Length(ids
) = 0 then
1537 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1540 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1546 if gPlayers
= nil then
1550 for a
:= Low(gPlayers
) to High(gPlayers
) do
1551 if IsActivePlayer(gPlayers
[a
]) then
1553 SetLength(ids
, Length(ids
) + 1);
1554 ids
[High(ids
)] := gPlayers
[a
].UID
;
1555 if gPlayers
[a
].UID
= Skip
then
1558 if Length(ids
) = 0 then
1561 Result
:= ids
[Length(ids
) - 1]
1563 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1566 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1572 if gPlayers
= nil then
1576 for a
:= Low(gPlayers
) to High(gPlayers
) do
1577 if IsActivePlayer(gPlayers
[a
]) then
1579 SetLength(ids
, Length(ids
) + 1);
1580 ids
[High(ids
)] := gPlayers
[a
].UID
;
1581 if gPlayers
[a
].UID
= Skip
then
1584 if Length(ids
) = 0 then
1586 if Length(ids
) = 1 then
1591 Result
:= ids
[Random(Length(ids
))];
1593 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1595 Result
:= ids
[Random(Length(ids
))];
1600 function GetRandomSpectMode(Current
: Byte): Byte;
1607 0: Result
:= SPECT_STATS
;
1608 1: Result
:= SPECT_MAPVIEW
;
1609 2: Result
:= SPECT_MAPVIEW
;
1610 3: Result
:= SPECT_PLAYERS
;
1611 4: Result
:= SPECT_PLAYERS
;
1612 5: Result
:= SPECT_PLAYERS
;
1613 6: Result
:= SPECT_PLAYERS
;
1615 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1619 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1625 if (plr
= nil) then exit
;
1626 if (p
= 2) then time
:= 1000 else time
:= 1;
1627 strafeDir
:= MoveButton
shr 4;
1628 MoveButton
:= MoveButton
and $0F;
1630 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1631 MoveButton
:= 1 // Нажата только "Влево"
1632 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1633 MoveButton
:= 2 // Нажата только "Вправо"
1634 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1635 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1637 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1638 if MoveButton
= 1 then
1639 plr
.PressKey(KEY_LEFT
, time
)
1640 else if MoveButton
= 2 then
1641 plr
.PressKey(KEY_RIGHT
, time
);
1643 // if we have "strafe" key, turn off old strafe mechanics
1644 if gPlayerAction
[p
, ACTION_STRAFE
] then
1646 // new strafe mechanics
1647 if (strafeDir
= 0) then
1648 strafeDir
:= MoveButton
; // start strafing
1649 // now set direction according to strafe (reversed)
1650 if (strafeDir
= 2) then
1651 plr
.SetDirection(TDirection
.D_LEFT
)
1652 else if (strafeDir
= 1) then
1653 plr
.SetDirection(TDirection
.D_RIGHT
)
1657 strafeDir
:= 0; // not strafing anymore
1658 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1659 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1660 plr
.SetDirection(TDirection
.D_LEFT
)
1661 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1662 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1663 plr
.SetDirection(TDirection
.D_RIGHT
)
1664 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1665 else if MoveButton
<> 0 then
1666 plr
.SetDirection(TDirection(MoveButton
-1))
1669 // fix movebutton state
1670 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1672 // Остальные клавиши:
1673 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1674 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1675 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1676 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1677 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1679 for i
:= WP_FACT
to WP_LACT
do
1681 if gWeaponAction
[p
, i
] then
1683 plr
.ProcessWeaponAction(i
);
1684 gWeaponAction
[p
, i
] := False
1688 for i
:= WP_FIRST
to WP_LAST
do
1690 if gSelectWeapon
[p
, i
] then
1692 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1693 gSelectWeapon
[p
, i
] := False
1697 {$IFDEF ENABLE_MENU}
1698 // HACK: add dynlight here
1699 if gwin_k8_enable_light_experiments
then
1701 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1703 g_playerLight
:= true;
1705 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1707 g_playerLight
:= false;
1711 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1715 // HACK: don't have a "key was pressed" function
1716 procedure InterReady();
1718 if InterReadyTime
> gTime
then Exit
;
1719 InterReadyTime
:= gTime
+ 3000;
1720 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1723 procedure g_Game_PreUpdate();
1725 // these are in separate PreUpdate functions because they can interact during Update()
1726 // and are synced over the net
1727 // we don't care that much about corpses and gibs
1728 g_Player_PreUpdate();
1729 g_Monsters_PreUpdate();
1730 g_Items_PreUpdate();
1731 g_Weapon_PreUpdate();
1734 procedure g_Game_Update();
1736 {$IFDEF ENABLE_MENU}
1737 Msg
: g_gui
.TMessage
;
1744 function sendMonsPos (mon
: TMonster
): Boolean;
1746 result
:= false; // don't stop
1747 // this will also reset "need-send" flag
1748 if mon
.gncNeedSend
then
1750 MH_SEND_MonsterPos(mon
.UID
);
1752 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1754 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1756 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1758 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1762 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1764 result
:= false; // don't stop
1765 // this will also reset "need-send" flag
1766 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1769 function sendItemPos (it
: PItem
): Boolean;
1771 result
:= false; // don't stop
1774 MH_SEND_ItemPos(it
.myId
);
1775 it
.needSend
:= False;
1780 reliableUpdate
: Boolean;
1785 // Пора выключать игру:
1786 if gExit
= EXIT_QUIT
then
1788 // Игра закончилась - обрабатываем:
1792 if gExit
= EXIT_QUIT
then
1796 // Читаем клавиатуру и джойстик, если окно активно
1797 // no need to, as we'll do it in event handler
1799 // Обновляем консоль (движение и сообщения):
1802 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1804 gExit
:= EXIT_SIMPLE
;
1809 // process master server communications
1810 g_Net_Slist_Pulse();
1813 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1814 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1815 STATE_INTERTEXT
, // Текст между уровнями
1816 STATE_INTERPIC
: // Картинка между уровнями
1818 if g_Game_IsNet
and g_Game_IsServer
then
1820 gInterTime
:= gInterTime
+ GAME_TICK
;
1821 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1822 if a
<> gServInterTime
then
1824 gServInterTime
:= a
;
1825 MH_SEND_TimeSync(gServInterTime
);
1829 if (not g_Game_IsClient
) and
1833 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1834 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1835 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1836 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1838 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1839 {$IFDEF ENABLE_MENU}
1840 and (g_ActiveWindow
= nil)
1843 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1846 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1847 g_Game_StopAllSounds(True);
1849 if gMapOnce
then // Это был тест
1850 gExit
:= EXIT_SIMPLE
1852 if gNextMap
<> '' then // Переходим на следующую карту
1853 g_Game_ChangeMap(gNextMap
)
1854 else // Следующей карты нет
1856 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1858 // Выход в главное меню:
1860 {$IFDEF ENABLE_MENU}
1861 g_GUI_ShowWindow('MainMenu');
1862 gMusic
.SetByName('MUSIC_MENU');
1865 gState
:= STATE_MENU
;
1868 // Финальная картинка:
1869 g_Game_ExecuteEvent('onwadend');
1871 if not gMusic
.SetByName('MUSIC_endmus') then
1872 gMusic
.SetByName('MUSIC_STDENDMUS');
1874 gState
:= STATE_ENDPIC
;
1876 g_Game_ExecuteEvent('ongameend');
1881 else if g_Game_IsClient
and
1884 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1885 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1886 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1887 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1889 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1890 {$IFDEF ENABLE_MENU}
1891 and (g_ActiveWindow
= nil)
1900 if gState
= STATE_INTERTEXT
then
1901 if InterText
.counter
> 0 then
1902 InterText
.counter
:= InterText
.counter
- 1;
1905 STATE_FOLD
: // Затухание экрана
1907 if EndingGameCounter
= 0 then
1909 // Закончился уровень в Своей игре:
1910 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1912 gState
:= STATE_INTERCUSTOM
;
1913 InterReadyTime
:= -1;
1914 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1916 g_Game_ExecuteEvent('onwadend');
1917 if not gMusic
.SetByName('MUSIC_endmus') then
1918 gMusic
.SetByName('MUSIC_STDENDMUS');
1921 gMusic
.SetByName('MUSIC_ROUNDMUS');
1925 else // Закончилась последняя карта в Одиночной игре
1927 gMusic
.SetByName('MUSIC_INTERMUS');
1929 gState
:= STATE_INTERSINGLE
;
1932 g_Game_ExecuteEvent('oninter');
1935 DecMin(EndingGameCounter
, 6, 0);
1938 STATE_ENDPIC
: // Картинка окончания мегаВада
1940 if gMapOnce
then // Это был тест
1942 gExit
:= EXIT_SIMPLE
;
1948 g_Serverlist_Control(slCurrent
, slTable
);
1951 // Статистика по Tab:
1953 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1956 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1958 // Время += 28 миллисекунд:
1959 gTime
:= gTime
+ GAME_TICK
;
1961 // Сообщение посередине экрана:
1962 if MessageTime
= 0 then
1964 if MessageTime
> 0 then
1965 MessageTime
:= MessageTime
- 1;
1967 if (g_Game_IsServer
) then
1969 // Был задан лимит времени:
1970 if (gGameSettings
.TimeLimit
> 0) then
1971 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1972 begin // Он прошел => конец уровня
1977 // Надо респавнить игроков в LMS:
1978 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1979 g_Game_RestartRound(gLMSSoftSpawn
);
1981 // Проверим результат голосования, если время прошло
1982 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1984 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1986 g_Console_Process(gVoteCommand
);
1988 gVotePassed
:= False;
1991 // Замеряем время захвата флагов
1992 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1993 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1994 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1995 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1997 // Был задан лимит побед:
1998 if (gGameSettings
.ScoreLimit
> 0) then
2002 if gGameSettings
.GameMode
= GM_DM
then
2003 begin // В DM ищем игрока с max фрагами
2004 for i
:= 0 to High(gPlayers
) do
2005 if gPlayers
[i
] <> nil then
2006 if gPlayers
[i
].Frags
> b
then
2007 b
:= gPlayers
[i
].Frags
;
2010 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2011 begin // В CTF/TDM выбираем команду с наибольшим счетом
2012 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2015 // Лимит побед набран => конец уровня:
2016 if b
>= gGameSettings
.ScoreLimit
then
2023 // Обрабатываем клавиши игроков:
2024 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2025 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2026 {$IFDEF DISABLE_MENU}
2027 if (not gConsoleShow
) and (not gChatShow
) then
2029 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2032 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2033 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2034 end // if not console
2037 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2039 // process weapon switch queue
2043 if (gPlayer1
= nil) and (gPlayer2
= nil)
2044 and (not gConsoleShow
) and (not gChatShow
)
2045 {$IFDEF ENABLE_MENU}
2046 and (g_ActiveWindow
= nil)
2050 if not gSpectKeyPress
then
2052 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2054 // switch spect mode
2056 SPECT_NONE
: ; // not spectator
2058 SPECT_MAPVIEW
: Inc(gSpectMode
);
2059 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2061 gSpectKeyPress
:= True;
2063 if (gSpectMode
= SPECT_MAPVIEW
)
2064 and (not gSpectAuto
) then
2066 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2067 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2068 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2069 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2070 if gPlayerAction
[0, ACTION_LOOKUP
] then
2071 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2072 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2073 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2074 if gWeaponAction
[0, WP_PREV
] then
2077 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2078 gWeaponAction
[0, WP_PREV
] := False;
2080 if gWeaponAction
[0, WP_NEXT
] then
2083 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2084 gWeaponAction
[0, WP_NEXT
] := False;
2087 if (gSpectMode
= SPECT_PLAYERS
)
2088 and (not gSpectAuto
) then
2090 if gPlayerAction
[0, ACTION_LOOKUP
] then
2093 gSpectViewTwo
:= True;
2094 gSpectKeyPress
:= True;
2096 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2098 // remove second view
2099 gSpectViewTwo
:= False;
2100 gSpectKeyPress
:= True;
2102 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2104 // prev player (view 1)
2105 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2106 gSpectKeyPress
:= True;
2108 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2110 // next player (view 1)
2111 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2112 gSpectKeyPress
:= True;
2114 if gWeaponAction
[0, WP_PREV
] then
2116 // prev player (view 2)
2117 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2118 gWeaponAction
[0, WP_PREV
] := False;
2120 if gWeaponAction
[0, WP_NEXT
] then
2122 // next player (view 2)
2123 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2124 gWeaponAction
[0, WP_NEXT
] := False;
2127 if gPlayerAction
[0, ACTION_ATTACK
] then
2129 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2132 gSpectAutoNext
:= 0;
2133 gSpectViewTwo
:= False;
2134 gSpectKeyPress
:= True;
2139 gSpectMode
:= SPECT_STATS
;
2140 gSpectAuto
:= False;
2141 gSpectKeyPress
:= True;
2146 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2147 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2148 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2149 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2150 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2151 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2152 gSpectKeyPress
:= False;
2156 if gSpectMode
= SPECT_MAPVIEW
then
2158 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2160 gSpectAutoNext
:= gTime
2163 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2165 gSpectAutoNext
:= gTime
2169 if gSpectAutoNext
<= gTime
then
2171 if gSpectAutoNext
> 0 then
2173 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2177 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2178 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2179 gSpectAutoStepX
:= Random(9) - 4;
2180 gSpectAutoStepY
:= Random(9) - 4;
2181 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2182 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2183 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2184 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2185 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2186 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2190 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2195 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2196 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2197 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2203 // Обновляем все остальное:
2206 g_Triggers_Update();
2208 g_Monsters_Update();
2212 g_Player_UpdateAll();
2213 g_Player_UpdatePhysicalObjects();
2215 // server: send newly spawned monsters unconditionally
2216 if (gGameSettings
.GameType
= GT_SERVER
) then
2218 if (Length(gMonstersSpawned
) > 0) then
2220 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2221 SetLength(gMonstersSpawned
, 0);
2225 if (gSoundTriggerTime
> 8) then
2227 g_Game_UpdateTriggerSounds();
2228 gSoundTriggerTime
:= 0;
2232 Inc(gSoundTriggerTime
);
2235 if (NetMode
= NET_SERVER
) then
2237 Inc(NetTimeToUpdate
);
2238 Inc(NetTimeToReliable
);
2240 // send monster updates
2241 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2243 // send all monsters (periodic sync)
2244 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2246 for I
:= 0 to High(gPlayers
) do
2248 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2251 g_Mons_ForEach(sendMonsPos
);
2253 // update flags that aren't stationary
2254 if gGameSettings
.GameMode
= GM_CTF
then
2255 for I
:= FLAG_RED
to FLAG_BLUE
do
2256 if gFlags
[I
].NeedSend
then
2258 gFlags
[I
].NeedSend
:= False;
2262 // update items that aren't stationary
2263 g_Items_ForEachAlive(sendItemPos
);
2265 if reliableUpdate
then
2267 NetTimeToReliable
:= 0;
2268 NetTimeToUpdate
:= NetUpdateRate
;
2272 NetTimeToUpdate
:= 0;
2277 // send only mosters with some unexpected changes
2278 g_Mons_ForEach(sendMonsPosUnexpected
);
2281 // send unexpected platform changes
2282 g_Map_NetSendInterestingPanels();
2284 g_Net_Slist_ServerUpdate();
2286 if NetUseMaster then
2288 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2290 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2292 NetTimeToMaster := gTime + NetMasterRate;
2297 else if (NetMode
= NET_CLIENT
) then
2299 MC_SEND_PlayerPos();
2301 end; // if gameOn ...
2303 // Активно окно интерфейса - передаем клавиши ему:
2304 {$IFDEF ENABLE_MENU}
2305 if g_ActiveWindow
<> nil then
2307 w
:= e_GetFirstKeyPressed();
2309 if (w
<> IK_INVALID
) then
2311 Msg
.Msg
:= MESSAGE_DIKEY
;
2313 g_ActiveWindow
.OnMessage(Msg
);
2316 // Если оно от этого не закрылось, то обновляем:
2317 if g_ActiveWindow
<> nil then
2318 g_ActiveWindow
.Update();
2320 // Нужно сменить разрешение:
2321 if gResolutionChange
then
2324 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2327 gResolutionChange
:= False;
2328 g_ActiveWindow
:= nil;
2331 // Нужно сменить язык:
2332 if gLanguageChange
then
2334 //e_WriteLog('Read language file', MSG_NOTIFY);
2335 //g_Language_Load(DataDir + gLanguage + '.txt');
2336 g_Language_Set(gLanguage
);
2338 gLanguageChange
:= False;
2342 // Горячая клавиша для вызова меню выхода из игры (F10):
2343 if e_KeyPressed(IK_F10
) and
2345 (not gConsoleShow
) and
2346 (g_ActiveWindow
= nil) then
2352 Time
:= GetTickCount64() {div 1000};
2354 // Обработка отложенных событий:
2355 if gDelayedEvents
<> nil then
2356 for a
:= 0 to High(gDelayedEvents
) do
2357 if gDelayedEvents
[a
].Pending
and
2359 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2360 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2363 case gDelayedEvents
[a
].DEType
of
2365 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2368 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2372 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2373 if g_Game_IsNet
and g_Game_IsServer
then
2374 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2378 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2380 gDelayedEvents
[a
].Pending
:= False;
2383 // Каждую секунду обновляем счетчик обновлений:
2384 UPSCounter
:= UPSCounter
+ 1;
2385 if Time
- UPSTime
>= 1000 then
2394 g_Weapon_AddDynLights();
2395 g_Items_AddDynLights();
2399 procedure g_Game_LoadChatSounds(Resource
: string);
2402 FileName
, Snd
: string;
2404 len
, cnt
, tags
, i
, j
: Integer;
2407 FileName
:= g_ExtractWadName(Resource
);
2409 WAD
:= TWADFile
.Create();
2410 WAD
.ReadFile(FileName
);
2412 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2419 cfg
:= TConfig
.CreateMem(p
, len
);
2420 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2422 SetLength(gChatSounds
, cnt
);
2423 for i
:= 0 to Length(gChatSounds
) - 1 do
2425 gChatSounds
[i
].Sound
:= nil;
2426 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2427 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2428 if (Snd
= '') or (Tags
<= 0) then
2430 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2431 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2432 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2433 SetLength(gChatSounds
[i
].Tags
, tags
);
2434 for j
:= 0 to tags
- 1 do
2435 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2436 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2443 procedure g_Game_FreeChatSounds();
2447 for i
:= 0 to Length(gChatSounds
) - 1 do
2449 gChatSounds
[i
].Sound
.Free();
2450 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2452 SetLength(gChatSounds
, 0);
2456 procedure g_Game_LoadData();
2458 if DataLoaded
then Exit
;
2460 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2462 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2463 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2464 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2465 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2466 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2467 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2468 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2469 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2470 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2471 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2472 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2473 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2474 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2475 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2476 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2477 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2478 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2479 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2480 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2481 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2482 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2483 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2484 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2485 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2486 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2487 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2488 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2489 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2490 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2491 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2492 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2493 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2495 goodsnd
[0] := TPlayableSound
.Create();
2496 goodsnd
[1] := TPlayableSound
.Create();
2497 goodsnd
[2] := TPlayableSound
.Create();
2498 goodsnd
[3] := TPlayableSound
.Create();
2500 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2501 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2502 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2503 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2505 killsnd
[0] := TPlayableSound
.Create();
2506 killsnd
[1] := TPlayableSound
.Create();
2507 killsnd
[2] := TPlayableSound
.Create();
2508 killsnd
[3] := TPlayableSound
.Create();
2510 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2511 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2512 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2513 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2515 hahasnd
[0] := TPlayableSound
.Create();
2516 hahasnd
[1] := TPlayableSound
.Create();
2517 hahasnd
[2] := TPlayableSound
.Create();
2519 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2520 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2521 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2523 sound_get_flag
[0] := TPlayableSound
.Create();
2524 sound_get_flag
[1] := TPlayableSound
.Create();
2525 sound_lost_flag
[0] := TPlayableSound
.Create();
2526 sound_lost_flag
[1] := TPlayableSound
.Create();
2527 sound_ret_flag
[0] := TPlayableSound
.Create();
2528 sound_ret_flag
[1] := TPlayableSound
.Create();
2529 sound_cap_flag
[0] := TPlayableSound
.Create();
2530 sound_cap_flag
[1] := TPlayableSound
.Create();
2532 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2533 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2534 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2535 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2536 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2537 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2538 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2539 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2541 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2543 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2546 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2547 g_Weapon_LoadData();
2549 g_Monsters_LoadData();
2554 procedure g_Game_Quit();
2556 g_Game_StopAllSounds(True);
2559 g_PlayerModel_FreeData();
2561 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2564 if NetInitDone
then g_Net_Free
;
2566 // remove map after test
2567 if gMapToDelete
<> '' then
2568 g_Game_DeleteTestMap();
2577 procedure g_Game_FreeData();
2579 if not DataLoaded
then Exit
;
2582 g_Weapon_FreeData();
2583 g_Monsters_FreeData();
2585 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2587 g_Sound_Delete('SOUND_GAME_TELEPORT');
2588 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2589 g_Sound_Delete('SOUND_GAME_SECRET');
2590 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2591 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2592 g_Sound_Delete('SOUND_GAME_BULK1');
2593 g_Sound_Delete('SOUND_GAME_BULK2');
2594 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2595 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2596 g_Sound_Delete('SOUND_GAME_BURNING');
2597 g_Sound_Delete('SOUND_GAME_SWITCH1');
2598 g_Sound_Delete('SOUND_GAME_SWITCH0');
2605 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2606 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2607 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2608 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2615 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2616 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2617 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2618 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2624 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2625 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2626 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2628 sound_get_flag
[0].Free();
2629 sound_get_flag
[1].Free();
2630 sound_lost_flag
[0].Free();
2631 sound_lost_flag
[1].Free();
2632 sound_ret_flag
[0].Free();
2633 sound_ret_flag
[1].Free();
2634 sound_cap_flag
[0].Free();
2635 sound_cap_flag
[1].Free();
2637 g_Sound_Delete('SOUND_CTF_GET1');
2638 g_Sound_Delete('SOUND_CTF_GET2');
2639 g_Sound_Delete('SOUND_CTF_LOST1');
2640 g_Sound_Delete('SOUND_CTF_LOST2');
2641 g_Sound_Delete('SOUND_CTF_RETURN1');
2642 g_Sound_Delete('SOUND_CTF_RETURN2');
2643 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2644 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2646 g_Game_FreeChatSounds();
2648 DataLoaded
:= False;
2651 procedure g_FatalError(Text: String);
2653 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2654 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2656 gExit
:= EXIT_SIMPLE
;
2657 if gGameOn
then EndGame
;
2660 procedure g_SimpleError(Text: String);
2662 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2663 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2666 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2668 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2669 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2672 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2675 if gPlayer1
= nil then
2677 if g_Game_IsClient
then
2679 if NetPlrUID1
> -1 then
2680 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2684 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2685 Team
:= gPlayer1Settings
.Team
;
2687 // Создание первого игрока:
2688 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2689 gPlayer1Settings
.Color
,
2691 if gPlayer1
= nil then
2692 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2695 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2696 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2697 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2698 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2699 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2700 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2701 if g_Game_IsServer
and g_Game_IsNet
then
2702 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2703 gPlayer1
.Respawn(False, True);
2704 g_Net_Slist_ServerPlayerComes();
2709 if gPlayer2
= nil then
2711 if g_Game_IsClient
then
2713 if NetPlrUID2
> -1 then
2714 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2718 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2719 Team
:= gPlayer2Settings
.Team
;
2721 // Создание второго игрока:
2722 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2723 gPlayer2Settings
.Color
,
2725 if gPlayer2
= nil then
2726 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2729 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2730 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2731 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2732 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2733 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2734 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2735 if g_Game_IsServer
and g_Game_IsNet
then
2736 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2737 gPlayer2
.Respawn(False, True);
2738 g_Net_Slist_ServerPlayerComes();
2745 procedure g_Game_RemovePlayer();
2749 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2750 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2755 if g_Game_IsServer
then
2758 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2759 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2760 g_Player_Remove(Pl
.UID
);
2761 g_Net_Slist_ServerPlayerLeaves();
2765 gSpectLatchPID2
:= Pl
.UID
;
2773 if g_Game_IsServer
then
2776 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2777 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2778 g_Player_Remove(Pl
.UID
);
2779 g_Net_Slist_ServerPlayerLeaves();
2782 gSpectLatchPID1
:= Pl
.UID
;
2784 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2788 g_Net_Slist_ServerPlayerLeaves();
2791 procedure g_Game_Spectate();
2793 g_Game_RemovePlayer();
2794 if gPlayer1
<> nil then
2795 g_Game_RemovePlayer();
2798 procedure g_Game_SpectateCenterView();
2800 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2801 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2804 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2811 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2813 g_Game_ClearLoading();
2816 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2819 gGameSettings
.GameType
:= GT_SINGLE
;
2820 gGameSettings
.MaxLives
:= 0;
2821 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2822 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2823 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2824 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2825 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2826 gSwitchGameMode
:= GM_SINGLE
;
2828 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2829 gLMSRespawnTime
:= 0;
2830 gSpectLatchPID1
:= 0;
2831 gSpectLatchPID2
:= 0;
2833 g_Game_ExecuteEvent('ongamestart');
2835 // Создание первого игрока:
2836 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2837 gPlayer1Settings
.Color
,
2838 gPlayer1Settings
.Team
, False));
2839 if gPlayer1
= nil then
2841 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2845 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2846 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2847 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2848 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2849 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2852 // Создание второго игрока, если есть:
2855 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2856 gPlayer2Settings
.Color
,
2857 gPlayer2Settings
.Team
, False));
2858 if gPlayer2
= nil then
2860 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2864 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2865 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2866 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2867 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2868 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2872 // Загрузка и запуск карты:
2873 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2875 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2876 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2880 // Настройки игроков и ботов:
2884 for i
:= nPl
+1 to nPlayers
do
2885 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2888 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2889 TimeLimit
, ScoreLimit
: Word;
2891 Options
: LongWord; nPlayers
: Byte);
2897 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2899 g_Game_ClearLoading();
2902 gGameSettings
.GameType
:= GT_CUSTOM
;
2903 gGameSettings
.GameMode
:= GameMode
;
2904 gSwitchGameMode
:= GameMode
;
2905 gGameSettings
.TimeLimit
:= TimeLimit
;
2906 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2907 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2908 gGameSettings
.Options
:= Options
;
2910 gCoopTotalMonstersKilled
:= 0;
2911 gCoopTotalSecretsFound
:= 0;
2912 gCoopTotalMonsters
:= 0;
2913 gCoopTotalSecrets
:= 0;
2917 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2918 gLMSRespawnTime
:= 0;
2919 gSpectLatchPID1
:= 0;
2920 gSpectLatchPID2
:= 0;
2922 g_Game_ExecuteEvent('ongamestart');
2924 // Режим наблюдателя:
2925 if nPlayers
= 0 then
2932 if nPlayers
>= 1 then
2934 // Создание первого игрока:
2935 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2936 gPlayer1Settings
.Color
,
2937 gPlayer1Settings
.Team
, False));
2938 if gPlayer1
= nil then
2940 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2944 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2945 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2946 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2947 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2948 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2952 if nPlayers
>= 2 then
2954 // Создание второго игрока:
2955 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2956 gPlayer2Settings
.Color
,
2957 gPlayer2Settings
.Team
, False));
2958 if gPlayer2
= nil then
2960 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2964 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2965 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2966 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2967 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2968 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2972 // Загрузка и запуск карты:
2973 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
2975 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2979 // Нет точек появления:
2980 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2981 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2982 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2983 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2984 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2986 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2990 // Настройки игроков и ботов:
2994 for i
:= nPl
+1 to nPlayers
do
2995 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2998 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
2999 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3000 Options
: LongWord; nPlayers
: Byte;
3001 IPAddr
: LongWord; Port
: Word);
3004 g_Net_Slist_ServerClosed();
3006 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3008 g_Game_ClearLoading();
3013 gGameSettings
.GameType
:= GT_SERVER
;
3014 gGameSettings
.GameMode
:= GameMode
;
3015 gSwitchGameMode
:= GameMode
;
3016 gGameSettings
.TimeLimit
:= TimeLimit
;
3017 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3018 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3019 gGameSettings
.Options
:= Options
;
3021 gCoopTotalMonstersKilled
:= 0;
3022 gCoopTotalSecretsFound
:= 0;
3023 gCoopTotalMonsters
:= 0;
3024 gCoopTotalSecrets
:= 0;
3028 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3029 gLMSRespawnTime
:= 0;
3030 gSpectLatchPID1
:= 0;
3031 gSpectLatchPID2
:= 0;
3033 g_Game_ExecuteEvent('ongamestart');
3035 // Режим наблюдателя:
3036 if nPlayers
= 0 then
3042 if nPlayers
>= 1 then
3044 // Создание первого игрока:
3045 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3046 gPlayer1Settings
.Color
,
3047 gPlayer1Settings
.Team
, False));
3048 if gPlayer1
= nil then
3050 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3054 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3055 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3056 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3057 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3058 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3061 if nPlayers
>= 2 then
3063 // Создание второго игрока:
3064 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3065 gPlayer2Settings
.Color
,
3066 gPlayer2Settings
.Team
, False));
3067 if gPlayer2
= nil then
3069 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3073 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3074 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3075 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3076 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3077 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3080 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3081 if NetForwardPorts
then
3082 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3085 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3087 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3091 g_Net_Slist_Set(NetMasterList
);
3093 g_Net_Slist_ServerStarted();
3095 // Загрузка и запуск карты:
3096 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3098 g_Net_Slist_ServerClosed();
3099 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3103 // Нет точек появления:
3104 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3105 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3106 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3107 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3108 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3110 g_Net_Slist_ServerClosed();
3111 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3115 // Настройки игроков и ботов:
3118 g_Net_Slist_ServerMapStarted();
3119 NetState
:= NET_STATE_GAME
;
3122 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3137 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3138 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3140 g_Game_ClearLoading();
3145 gGameSettings
.GameType
:= GT_CLIENT
;
3147 gCoopTotalMonstersKilled
:= 0;
3148 gCoopTotalSecretsFound
:= 0;
3149 gCoopTotalMonsters
:= 0;
3150 gCoopTotalSecrets
:= 0;
3154 g_Game_ExecuteEvent('ongamestart');
3156 NetState
:= NET_STATE_AUTH
;
3158 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3160 // create (or update) map/resource databases
3161 g_Res_CreateDatabases(true);
3163 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3164 gLMSRespawnTime
:= 0;
3165 gSpectLatchPID1
:= 0;
3166 gSpectLatchPID2
:= 0;
3169 if not g_Net_Connect(Addr
, Port
) then
3171 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3172 NetState
:= NET_STATE_NONE
;
3176 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3178 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3183 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3184 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3185 // thank you, enet. let's ignore failures altogether then.
3186 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3188 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3190 Ptr
:= NetEvent
.packet
^.data
;
3191 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3193 enet_packet_destroy(NetEvent
.packet
);
3197 InMsg
.ReadLongWord(); // skip size
3198 MID
:= InMsg
.ReadByte();
3200 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3202 NetMyID
:= InMsg
.ReadByte();
3203 NetPlrUID1
:= InMsg
.ReadWord();
3205 WadName
:= InMsg
.ReadString();
3206 Map
:= InMsg
.ReadString();
3208 gWADHash
:= InMsg
.ReadMD5();
3210 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3211 gSwitchGameMode
:= gGameSettings
.GameMode
;
3212 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3213 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3214 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3215 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3216 T
:= InMsg
.ReadLongWord();
3218 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3219 //if newResPath = '' then
3221 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3222 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3223 if newResPath
= '' then
3225 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3226 enet_packet_destroy(NetEvent
.packet
);
3227 NetState
:= NET_STATE_NONE
;
3230 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3232 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3235 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3236 gPlayer1Settings
.Color
,
3237 gPlayer1Settings
.Team
, False));
3239 if gPlayer1
= nil then
3241 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3243 enet_packet_destroy(NetEvent
.packet
);
3244 NetState
:= NET_STATE_NONE
;
3248 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3249 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3250 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3251 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3252 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3253 gPlayer1
.UID
:= NetPlrUID1
;
3254 gPlayer1
.Reset(True);
3256 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3258 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3260 enet_packet_destroy(NetEvent
.packet
);
3261 NetState
:= NET_STATE_NONE
;
3269 enet_packet_destroy(NetEvent
.packet
);
3273 enet_packet_destroy(NetEvent
.packet
);
3277 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3280 if (NetEvent
.data
<= NET_DISC_MAX
) then
3281 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3282 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3289 ProcessLoading(True);
3290 if g_Net_UserRequestExit() then
3299 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3300 NetState
:= NET_STATE_NONE
;
3305 NetState
:= NET_STATE_GAME
;
3306 MC_SEND_FullStateRequest
;
3307 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3311 lastAsMegaWad
: Boolean = false;
3313 procedure g_Game_ChangeMap(const MapPath
: String);
3317 g_Game_ClearLoading();
3319 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3320 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3321 if gExitByTrigger
then
3324 gExitByTrigger
:= False;
3326 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3327 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3330 procedure g_Game_Restart();
3334 if g_Game_IsClient
then
3336 map
:= g_ExtractFileName(gMapInfo
.Map
);
3337 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3341 g_Game_ClearLoading();
3342 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3345 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3347 NewWAD
, ResName
: String;
3351 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3352 g_Player_RemoveAllCorpses();
3354 if (not g_Game_IsClient
) and
3355 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3356 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3358 if gSwitchGameMode
= GM_CTF
then
3359 gGameSettings
.MaxLives
:= 0;
3360 gGameSettings
.GameMode
:= gSwitchGameMode
;
3363 gSwitchGameMode
:= gGameSettings
.GameMode
;
3365 g_Player_ResetTeams();
3367 lastAsMegaWad
:= asMegawad
;
3368 if isWadPath(Map
) then
3370 NewWAD
:= g_ExtractWadName(Map
);
3371 ResName
:= g_ExtractFileName(Map
);
3372 if g_Game_IsServer
then
3374 nws
:= findDiskWad(NewWAD
);
3375 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3378 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3379 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3383 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3384 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3386 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3387 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3389 if (length(nws
) = 0) then
3391 ResName
:= ''; // failed
3396 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3397 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3398 g_Game_LoadWAD(NewWAD
);
3403 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3404 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3409 NewWAD
:= gGameSettings
.WAD
;
3415 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3417 if (ResName
<> '') and (NewWAD
<> '') then
3419 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3420 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3422 r_Render_LoadTextures
;
3427 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3429 gState
:= STATE_NONE
;
3430 {$IFDEF ENABLE_MENU}
3431 g_ActiveWindow
:= nil;
3436 wNeedTimeReset
:= True;
3438 if gGameSettings
.GameMode
= GM_CTF
then
3440 g_Map_ResetFlag(FLAG_RED
);
3441 g_Map_ResetFlag(FLAG_BLUE
);
3442 // CTF, а флагов нет:
3443 if not g_Map_HaveFlagPoints() then
3444 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3449 gState
:= STATE_MENU
;
3454 gPauseMain
:= false;
3455 gPauseHolmes
:= false;
3456 NetTimeToUpdate
:= 1;
3457 NetTimeToReliable
:= 0;
3458 NetTimeToMaster
:= NetMasterRate
;
3459 gSpectLatchPID1
:= 0;
3460 gSpectLatchPID2
:= 0;
3461 gMissionFailed
:= False;
3464 gCoopMonstersKilled
:= 0;
3465 gCoopSecretsFound
:= 0;
3467 gVoteInProgress
:= False;
3468 gVotePassed
:= False;
3474 if not gGameOn
then Exit
;
3476 g_Game_SpectateCenterView();
3478 if g_Game_IsServer
then
3480 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3482 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3483 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3484 gLMSSoftSpawn
:= True;
3485 if g_Game_IsNet
then
3486 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3490 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3491 gLMSRespawnTime
:= 0;
3495 if NetMode
= NET_SERVER
then
3497 // reset full state flags
3498 if NetClients
<> nil then
3499 for I
:= 0 to High(NetClients
) do
3500 NetClients
[I
].FullUpdateSent
:= False;
3502 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3505 g_Net_Slist_ServerMapStarted();
3507 if NetClients
<> nil then
3508 for I
:= 0 to High(NetClients
) do
3509 if NetClients
[I
].Used
then
3511 NetClients
[I
].Voted
:= False;
3512 if NetClients
[I
].RequestedFullUpdate
then
3514 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3515 NetClients
[I
].RequestedFullUpdate
:= False;
3519 g_Net_UnbanNonPermHosts();
3524 gCoopTotalMonstersKilled
:= 0;
3525 gCoopTotalSecretsFound
:= 0;
3526 gCoopTotalMonsters
:= 0;
3527 gCoopTotalSecrets
:= 0;
3531 g_Game_ExecuteEvent('onmapstart');
3534 procedure SetFirstLevel
;
3538 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3539 if MapList
= nil then
3542 SortSArray(MapList
);
3543 gNextMap
:= MapList
[Low(MapList
)];
3548 procedure g_Game_ExitLevel(const Map
: AnsiString);
3552 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3553 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3554 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3555 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3557 // Вышли в выход в Одиночной игре:
3558 if gGameSettings
.GameType
= GT_SINGLE
then
3559 gExit
:= EXIT_ENDLEVELSINGLE
3560 else // Вышли в выход в Своей игре
3562 gExit
:= EXIT_ENDLEVELCUSTOM
;
3563 if gGameSettings
.GameMode
= GM_COOP
then
3564 g_Player_RememberAll
;
3566 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3569 if gGameSettings
.GameMode
= GM_COOP
then
3572 gStatsPressed
:= True;
3573 gNextMap
:= 'MAP01';
3575 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3578 if g_Game_IsNet
then
3580 MH_SEND_GameStats();
3581 MH_SEND_CoopStats();
3587 procedure g_Game_RestartLevel();
3591 if gGameSettings
.GameMode
= GM_SINGLE
then
3596 gExit
:= EXIT_ENDLEVELCUSTOM
;
3597 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3601 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3603 gWAD
{, xwad}: String;
3606 if not g_Game_IsClient
then Exit
;
3607 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3609 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3614 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3618 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3621 g_Game_LoadWAD(NewWAD
);
3625 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3626 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3629 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3630 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3634 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3638 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3639 g_Game_LoadWAD(NewWAD);
3643 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3645 i
, n
, nb
, nr
: Integer;
3647 if not g_Game_IsServer
then Exit
;
3648 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3649 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3650 gLMSRespawnTime
:= 0;
3653 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3655 gMissionFailed
:= True;
3656 g_Game_RestartLevel
;
3660 n
:= 0; nb
:= 0; nr
:= 0;
3661 for i
:= Low(gPlayers
) to High(gPlayers
) do
3662 if (gPlayers
[i
] <> nil) and
3663 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3664 (gPlayers
[i
] is TBot
)) then
3667 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3668 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3671 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3673 // wait a second until the fuckers finally decide to join
3674 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3675 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3676 gLMSSoftSpawn
:= NoMapRestart
;
3677 if g_Game_IsNet
then
3678 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3682 g_Player_RemoveAllCorpses
;
3683 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3684 if g_Game_IsNet
then
3685 MH_SEND_GameEvent(NET_EV_LMS_START
);
3687 for i
:= Low(gPlayers
) to High(gPlayers
) do
3689 if gPlayers
[i
] = nil then continue
;
3690 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3691 // don't touch normal spectators
3692 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3694 gPlayers
[i
].FNoRespawn
:= True;
3695 gPlayers
[i
].Lives
:= 0;
3696 if g_Game_IsNet
then
3697 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3700 gPlayers
[i
].FNoRespawn
:= False;
3701 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3702 gPlayers
[i
].Respawn(False, True);
3703 if gGameSettings
.GameMode
= GM_COOP
then
3705 gPlayers
[i
].Frags
:= 0;
3706 gPlayers
[i
].RecallState
;
3708 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3709 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3710 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3711 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3714 g_Items_RestartRound();
3716 gLMSSoftSpawn
:= False;
3719 function g_Game_GetFirstMap(WAD
: String): String;
3723 MapList
:= g_Map_GetMapsList(WAD
);
3724 if MapList
= nil then
3727 SortSArray(MapList
);
3728 Result
:= MapList
[Low(MapList
)];
3730 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3736 function g_Game_GetNextMap(): String;
3743 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3744 if MapList
= nil then
3747 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3749 SortSArray(MapList
);
3751 for I
:= Low(MapList
) to High(MapList
) do
3752 if Map
= MapList
[I
] then
3758 if MapIndex
<> -255 then
3760 if MapIndex
= High(MapList
) then
3761 Result
:= MapList
[Low(MapList
)]
3763 Result
:= MapList
[MapIndex
+ 1];
3765 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3771 procedure g_Game_NextLevel();
3773 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3774 gExit
:= EXIT_ENDLEVELCUSTOM
3777 gExit
:= EXIT_ENDLEVELSINGLE
;
3781 if gNextMap
<> '' then Exit
;
3782 gNextMap
:= g_Game_GetNextMap();
3785 function g_Game_IsTestMap(): Boolean;
3787 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3790 procedure g_Game_DeleteTestMap();
3793 //MapName: AnsiString;
3801 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3802 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3803 if (a
= 0) then exit
;
3805 // Выделяем имя wad-файла и имя карты
3806 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3807 Delete(gMapToDelete
, 1, a
+5);
3808 gMapToDelete
:= UpperCase(gMapToDelete
);
3810 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3813 // Имя карты не стандартное тестовое:
3814 if MapName <> TEST_MAP_NAME then
3817 if not gTempDelete then
3819 time := g_GetFileTime(WadName);
3820 WAD := TWADFile.Create();
3823 if not WAD.ReadFile(WadName) then
3824 begin // Нет такого WAD-файла
3829 // Составляем список карт и ищем нужную:
3831 MapList := WAD.GetResourcesList('');
3833 if MapList <> nil then
3834 for a := 0 to High(MapList) do
3835 if MapList[a] = MapName then
3837 // Удаляем и сохраняем:
3838 WAD.RemoveResource('', MapName);
3839 WAD.SaveTo(WadName);
3844 g_SetFileTime(WadName, time);
3847 if gTempDelete
then DeleteFile(WadName
);
3850 procedure GameCVars(P
: SSArray
);
3853 stat
: TPlayerStatArray
;
3856 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3860 if Length(P
) > 1 then
3865 gsGameFlags
:= gsGameFlags
or Flag
3867 gsGameFlags
:= gsGameFlags
and (not Flag
);
3869 if g_Game_IsServer
then
3872 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3874 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3875 if g_Game_IsNet
then MH_SEND_GameSettings
;
3879 if LongBool(gsGameFlags
and Flag
) then
3880 g_Console_Add(_lc
[OnMsg
])
3882 g_Console_Add(_lc
[OffMsg
]);
3884 if OnMapChange
and g_Game_IsServer
then
3885 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3890 cmd
:= LowerCase(P
[0]);
3892 if cmd
= 'g_gamemode' then
3894 if (Length(P
) > 1) then
3896 a
:= g_Game_TextToMode(P
[1]);
3897 if a
= GM_SINGLE
then a
:= GM_COOP
;
3898 gsGameMode
:= g_Game_ModeToText(a
);
3899 if g_Game_IsServer
then
3901 gSwitchGameMode
:= a
;
3902 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3903 (gState
= STATE_INTERSINGLE
) then
3904 gSwitchGameMode
:= GM_SINGLE
;
3906 gGameSettings
.GameMode
:= gSwitchGameMode
;
3910 if gSwitchGameMode
= gGameSettings
.GameMode
then
3911 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3912 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3914 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3915 [g_Game_ModeToText(gGameSettings
.GameMode
),
3916 g_Game_ModeToText(gSwitchGameMode
)]));
3918 else if cmd
= 'g_friendlyfire' then
3920 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3922 else if cmd
= 'g_friendly_absorb_damage' then
3924 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
3926 else if cmd
= 'g_friendly_hit_trace' then
3928 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
3930 else if cmd
= 'g_friendly_hit_projectile' then
3932 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
3934 else if cmd
= 'g_weaponstay' then
3936 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3938 else if cmd
= 'g_allow_exit' then
3940 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3942 else if cmd
= 'g_allow_monsters' then
3944 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3946 else if cmd
= 'g_allow_dropflag' then
3948 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
3950 else if cmd
= 'g_throw_flag' then
3952 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
3954 else if cmd
= 'g_bot_vsplayers' then
3956 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3958 else if cmd
= 'g_bot_vsmonsters' then
3960 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3962 else if cmd
= 'g_dm_keys' then
3964 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
3966 else if cmd
= 'g_gameflags' then
3968 if Length(P
) > 1 then
3970 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
3971 if g_Game_IsServer
then
3973 gGameSettings
.Options
:= gsGameFlags
;
3974 if g_Game_IsNet
then MH_SEND_GameSettings
;
3978 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
3980 else if cmd
= 'g_warmup_time' then
3982 if Length(P
) > 1 then
3984 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
3985 if g_Game_IsServer
then
3987 gGameSettings
.WarmupTime
:= gsWarmupTime
;
3988 // extend warmup if it's already going
3989 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
3991 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
3992 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3994 if g_Game_IsNet
then MH_SEND_GameSettings
;
3998 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
3999 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4001 else if cmd
= 'g_spawn_invul' then
4003 if Length(P
) > 1 then
4005 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4006 if g_Game_IsServer
then
4008 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4009 if g_Game_IsNet
then MH_SEND_GameSettings
;
4013 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4015 else if cmd
= 'g_item_respawn_time' then
4017 if Length(P
) > 1 then
4019 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4020 if g_Game_IsServer
then
4022 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4023 if g_Game_IsNet
then MH_SEND_GameSettings
;
4027 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4028 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4030 else if cmd
= 'sv_intertime' then
4032 if (Length(P
) > 1) then
4033 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4035 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4037 else if cmd
= 'g_max_particles' then
4039 if Length(p
) = 2 then
4042 a
:= Max(0, StrToIntDef(p
[1], 0));
4046 else if Length(p
) = 1 then
4049 e_LogWritefln('%s', [g_GFX_GetMax()])
4051 e_LogWritefln('%s', [0])
4056 e_LogWritefln('usage: %s <n>', [cmd
])
4059 else if cmd
= 'g_max_shells' then
4061 if Length(p
) = 2 then
4063 a
:= Max(0, StrToIntDef(p
[1], 0));
4066 else if Length(p
) = 1 then
4068 e_LogWritefln('%s', [g_Shells_GetMax()])
4072 e_LogWritefln('usage: %s <n>', [cmd
])
4075 else if cmd
= 'g_max_gibs' then
4077 if Length(p
) = 2 then
4079 a
:= Max(0, StrToIntDef(p
[1], 0));
4082 else if Length(p
) = 1 then
4084 e_LogWritefln('%s', [g_Gibs_GetMax()])
4088 e_LogWritefln('usage: %s <n>', [cmd
])
4091 else if cmd
= 'g_max_corpses' then
4093 if Length(p
) = 2 then
4095 a
:= Max(0, StrToIntDef(p
[1], 0));
4098 else if Length(p
) = 1 then
4100 e_LogWritefln('%s', [g_Corpses_GetMax()])
4104 e_LogWritefln('usage: %s <n>', [cmd
])
4107 else if cmd
= 'g_force_model' then
4109 if Length(p
) = 2 then
4111 a
:= StrToIntDef(p
[1], 0);
4112 g_Force_Model_Set(a
);
4113 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4115 for a
:= Low(gPlayers
) to High(gPlayers
) do
4117 if (gPlayers
[a
] <> nil) then
4119 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4121 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4123 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4127 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4129 for a
:= Low(gPlayers
) to High(gPlayers
) do
4131 if (gPlayers
[a
] <> nil) then
4133 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4135 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4137 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4143 else if cmd
= 'g_force_model_name' then
4145 if (Length(P
) > 1) then
4147 cmd
:= b_Text_Unformat(P
[1]);
4148 g_Forced_Model_SetName(cmd
);
4149 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4151 for a
:= Low(gPlayers
) to High(gPlayers
) do
4153 if (gPlayers
[a
] <> nil) then
4155 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4157 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4159 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4165 else if cmd
= 'g_scorelimit' then
4167 if Length(P
) > 1 then
4169 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4171 if g_Game_IsServer
then
4174 if gGameSettings
.GameMode
= GM_DM
then
4176 stat
:= g_Player_GetStats();
4178 for a
:= 0 to High(stat
) do
4179 if stat
[a
].Frags
> b
then
4183 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4185 // if someone has a higher score, set it to that instead
4186 gsScoreLimit
:= max(gsScoreLimit
, b
);
4187 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4189 if g_Game_IsNet
then MH_SEND_GameSettings
;
4193 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4195 else if cmd
= 'g_timelimit' then
4197 if Length(P
) > 1 then
4199 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4200 if g_Game_IsServer
then
4202 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4203 if g_Game_IsNet
then MH_SEND_GameSettings
;
4206 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4207 [gsTimeLimit
div 3600,
4208 (gsTimeLimit
div 60) mod 60,
4209 gsTimeLimit
mod 60]));
4211 else if cmd
= 'g_max_bots' then
4213 if Length(P
) > 1 then
4214 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4215 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4217 else if cmd
= 'g_maxlives' then
4219 if Length(P
) > 1 then
4221 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4222 if g_Game_IsServer
then
4224 gGameSettings
.MaxLives
:= gsMaxLives
;
4225 if g_Game_IsNet
then MH_SEND_GameSettings
;
4229 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4233 procedure PlayerSettingsCVars(P
: SSArray
);
4238 function ParseTeam(s
: string): Byte;
4242 'red', '1': result
:= TEAM_RED
;
4243 'blue', '2': result
:= TEAM_BLUE
;
4244 else result
:= TEAM_NONE
;
4248 cmd
:= LowerCase(P
[0]);
4252 if (Length(P
) > 1) then
4254 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4255 if g_Game_IsClient
then
4256 MC_SEND_PlayerSettings
4257 else if gGameOn
and (gPlayer1
<> nil) then
4259 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4260 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4266 if (Length(P
) > 1) then
4268 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4269 if g_Game_IsClient
then
4270 MC_SEND_PlayerSettings
4271 else if gGameOn
and (gPlayer2
<> nil) then
4273 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4274 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4280 if Length(P
) > 3 then
4282 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4283 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4284 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4285 if g_Game_IsClient
then
4286 MC_SEND_PlayerSettings
4287 else if gGameOn
and (gPlayer1
<> nil) then
4289 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4290 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4296 if Length(P
) > 3 then
4298 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4299 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4300 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4301 if g_Game_IsClient
then
4302 MC_SEND_PlayerSettings
4303 else if gGameOn
and (gPlayer2
<> nil) then
4305 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4306 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4312 if (Length(P
) > 1) then
4314 gPlayer1Settings
.Model
:= P
[1];
4315 if g_Game_IsClient
then
4316 MC_SEND_PlayerSettings
4317 else if gGameOn
and (gPlayer1
<> nil) then
4319 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4320 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4321 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4327 if (Length(P
) > 1) then
4329 gPlayer2Settings
.Model
:= P
[1];
4330 if g_Game_IsClient
then
4331 MC_SEND_PlayerSettings
4332 else if gGameOn
and (gPlayer2
<> nil) then
4334 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4335 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4336 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4342 // TODO: switch teams if in game or store this separately
4343 if (Length(P
) > 1) then
4345 team
:= ParseTeam(P
[1]);
4346 if team
= TEAM_NONE
then
4347 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4348 else if not gGameOn
and not g_Game_IsNet
then
4349 gPlayer1Settings
.Team
:= team
4351 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4356 // TODO: switch teams if in game or store this separately
4357 if (Length(P
) > 1) then
4359 team
:= ParseTeam(P
[1]);
4360 if team
= TEAM_NONE
then
4361 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4362 else if not gGameOn
and not g_Game_IsNet
then
4363 gPlayer2Settings
.Team
:= team
4365 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4370 if (Length(P
) = 2) then
4371 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4375 if (Length(P
) = 2) then
4376 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4380 if (Length(P
) = 2) then
4381 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4385 if (Length(P
) = 2) then
4386 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4390 if (Length(P
) = 2) then
4391 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4395 if (Length(P
) = 2) then
4396 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4398 'p1_priority_kastet':
4400 if (Length(P
) = 2) then
4401 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4403 'p2_priority_kastet':
4405 if (Length(P
) = 2) then
4406 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4410 if (Length(P
) = 2) then
4411 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4415 if (Length(P
) = 2) then
4416 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4418 'p1_priority_pistol':
4420 if (Length(P
) = 2) then
4421 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4423 'p2_priority_pistol':
4425 if (Length(P
) = 2) then
4426 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4428 'p1_priority_shotgun1':
4430 if (Length(P
) = 2) then
4431 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4433 'p2_priority_shotgun1':
4435 if (Length(P
) = 2) then
4436 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4438 'p1_priority_shotgun2':
4440 if (Length(P
) = 2) then
4441 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4443 'p2_priority_shotgun2':
4445 if (Length(P
) = 2) then
4446 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4448 'p1_priority_chaingun':
4450 if (Length(P
) = 2) then
4451 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4453 'p2_priority_chaingun':
4455 if (Length(P
) = 2) then
4456 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4458 'p1_priority_rocketlauncher':
4460 if (Length(P
) = 2) then
4461 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4463 'p2_priority_rocketlauncher':
4465 if (Length(P
) = 2) then
4466 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4468 'p1_priority_plasma':
4470 if (Length(P
) = 2) then
4471 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4473 'p2_priority_plasma':
4475 if (Length(P
) = 2) then
4476 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4480 if (Length(P
) = 2) then
4481 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4485 if (Length(P
) = 2) then
4486 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4488 'p1_priority_super':
4490 if (Length(P
) = 2) then
4491 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4493 'p2_priority_super':
4495 if (Length(P
) = 2) then
4496 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4498 'p1_priority_flamethrower':
4500 if (Length(P
) = 2) then
4501 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4503 'p2_priority_flamethrower':
4505 if (Length(P
) = 2) then
4506 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4508 'p1_priority_berserk':
4510 if (Length(P
) = 2) then
4511 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4513 'p2_priority_berserk':
4515 if (Length(P
) = 2) then
4516 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4521 procedure PrintHeapStats();
4525 hs
:= GetFPCHeapStatus();
4526 e_LogWriteLn ('v===== heap status =====v');
4527 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4528 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4529 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4530 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4531 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4532 e_LogWriteLn ('^=======================^');
4535 procedure DebugCommands(P
: SSArray
);
4542 // Команды отладочного режима:
4543 if {gDebugMode}conIsCheatsEnabled
then
4545 cmd
:= LowerCase(P
[0]);
4546 if cmd
= 'd_window' then
4548 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4549 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4551 else if cmd
= 'd_sounds' then
4553 if (Length(P
) > 1) and
4554 ((P
[1] = '1') or (P
[1] = '0')) then
4555 g_Debug_Sounds
:= (P
[1][1] = '1');
4557 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4559 else if cmd
= 'd_frames' then
4561 if (Length(P
) > 1) and
4562 ((P
[1] = '1') or (P
[1] = '0')) then
4563 g_Debug_Frames
:= (P
[1][1] = '1');
4565 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4567 else if cmd
= 'd_winmsg' then
4569 if (Length(P
) > 1) and
4570 ((P
[1] = '1') or (P
[1] = '0')) then
4571 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4573 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4575 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4577 if (Length(P
) > 1) and
4578 ((P
[1] = '1') or (P
[1] = '0')) then
4579 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4581 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4583 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4585 if Length(P
) > 1 then
4587 '0': g_debug_BotAIOff
:= 0;
4588 '1': g_debug_BotAIOff
:= 1;
4589 '2': g_debug_BotAIOff
:= 2;
4590 '3': g_debug_BotAIOff
:= 3;
4593 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4595 else if cmd
= 'd_monster' then
4597 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4598 if Length(P
) < 2 then
4600 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4601 g_Console_Add('ID | Name');
4602 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4603 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4604 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4607 a
:= StrToIntDef(P
[1], 0);
4608 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4609 a
:= g_Mons_TypeIdByName(P
[1]);
4611 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4612 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4615 with gPlayer1
.Obj
do
4617 mon
:= g_Monsters_Create(a
,
4618 X
+ Rect
.X
+ (Rect
.Width
div 2),
4619 Y
+ Rect
.Y
+ Rect
.Height
,
4620 gPlayer1
.Direction
, True);
4622 if (Length(P
) > 2) and (mon
<> nil) then
4624 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4625 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4626 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4627 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4628 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4629 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4630 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4631 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4632 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4637 else if (cmd
= 'd_health') then
4639 if (Length(P
) > 1) and
4640 ((P
[1] = '1') or (P
[1] = '0')) then
4641 g_debug_HealthBar
:= (P
[1][1] = '1');
4643 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4645 else if (cmd
= 'd_player') then
4647 if (Length(P
) > 1) and
4648 ((P
[1] = '1') or (P
[1] = '0')) then
4649 g_debug_Player
:= (P
[1][1] = '1');
4651 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4653 else if (cmd
= 'd_mem') then
4659 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4663 procedure GameCheats(P
: SSArray
);
4669 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4671 g_Console_Add('not available');
4677 g_Console_Add('where is the player?!');
4680 cmd
:= LowerCase(P
[0]);
4684 plr
.GodMode
:= not plr
.GodMode
;
4685 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4688 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4689 if cmd
= 'give' then
4691 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4692 for f
:= 1 to High(P
) do
4694 cmd
:= LowerCase(P
[f
]);
4695 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4696 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4697 if cmd
= 'exit' then
4699 if gTriggers
<> nil then
4701 for a
:= 0 to High(gTriggers
) do
4703 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4705 g_Console_Add('player left the map');
4706 gExitByTrigger
:= True;
4707 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4708 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4716 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4717 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4718 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4719 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4720 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4722 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4723 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4725 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4726 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;
4728 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4729 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4731 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4732 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4734 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4735 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4737 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4738 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4739 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4741 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4742 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4743 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4744 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;
4745 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4746 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4748 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;
4749 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;
4750 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;
4751 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;
4752 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;
4753 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;
4755 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4756 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;
4758 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;
4759 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;
4761 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4763 if cmd
= 'ammo' then
4765 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4766 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4767 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4768 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4769 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4770 g_Console_Add('player got some ammo');
4774 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4775 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4777 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4778 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4780 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4781 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4783 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4784 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4786 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4788 if cmd
= 'weapons' then
4790 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4791 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4792 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4793 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4794 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4795 plr
.GiveItem(ITEM_WEAPON_BFG
);
4796 g_Console_Add('player got weapons');
4800 if cmd
= 'keys' then
4802 plr
.GiveItem(ITEM_KEY_RED
);
4803 plr
.GiveItem(ITEM_KEY_GREEN
);
4804 plr
.GiveItem(ITEM_KEY_BLUE
);
4805 g_Console_Add('player got all keys');
4809 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4814 if cmd
= 'open' then
4816 g_Console_Add('player activated sesame');
4817 g_Triggers_OpenAll();
4824 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4828 if cmd
= 'noclip' then
4831 g_Console_Add('wall hardeness adjusted');
4835 if cmd
= 'notarget' then
4837 plr
.NoTarget
:= not plr
.NoTarget
;
4838 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4842 if cmd
= 'noreload' then
4844 plr
.NoReload
:= not plr
.NoReload
;
4845 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4849 if cmd
= 'speedy' then
4851 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4852 g_Console_Add('speed adjusted');
4856 if cmd
= 'jumpy' then
4858 VEL_JUMP
:= 30-VEL_JUMP
;
4859 g_Console_Add('jump height adjusted');
4863 if cmd
= 'automap' then
4865 gShowMap
:= not gShowMap
;
4866 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4870 if cmd
= 'aimline' then
4872 gAimLine
:= not gAimLine
;
4873 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4878 procedure GameCommands(P
: SSArray
);
4884 pl
: pTNetClient
= nil;
4892 cmd
:= LowerCase(P
[0]);
4894 if cmd
= 'pause' then
4896 {$IFDEF ENABLE_MENU}
4897 if (g_ActiveWindow
= nil) then
4898 g_Game_Pause(not gPauseMain
);
4900 g_Game_Pause(not gPauseMain
);
4903 else if cmd
= 'endgame' then
4904 gExit
:= EXIT_SIMPLE
4905 else if cmd
= 'restart' then
4907 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4909 if g_Game_IsClient
then
4911 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4916 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4918 else if cmd
= 'kick' then
4920 if g_Game_IsServer
then
4922 if Length(P
) < 2 then
4924 g_Console_Add('kick <name>');
4929 g_Console_Add('kick <name>');
4933 if g_Game_IsNet
then
4934 pl
:= g_Net_Client_ByName(P
[1]);
4937 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4938 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4939 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4940 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4941 g_Net_Slist_ServerPlayerLeaves();
4942 end else if gPlayers
<> nil then
4943 for a
:= Low(gPlayers
) to High(gPlayers
) do
4944 if gPlayers
[a
] <> nil then
4945 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4947 // Не отключать основных игроков в сингле
4948 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4950 gPlayers
[a
].Lives
:= 0;
4951 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4952 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4953 g_Player_Remove(gPlayers
[a
].UID
);
4954 g_Net_Slist_ServerPlayerLeaves();
4955 // Если не перемешать, при добавлении новых ботов появятся старые
4959 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4961 else if cmd
= 'kick_id' then
4963 if g_Game_IsServer
and g_Game_IsNet
then
4965 if Length(P
) < 2 then
4967 g_Console_Add('kick_id <client ID>');
4972 g_Console_Add('kick_id <client ID>');
4976 a
:= StrToIntDef(P
[1], 0);
4977 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4979 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4981 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4982 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
4983 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4984 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4985 g_Net_Slist_ServerPlayerLeaves();
4989 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4991 else if cmd
= 'kick_pid' then
4993 if g_Game_IsServer
and g_Game_IsNet
then
4995 if Length(P
) < 2 then
4997 g_Console_Add('kick_pid <player ID>');
5002 g_Console_Add('kick_pid <player ID>');
5006 a
:= StrToIntDef(P
[1], 0);
5007 pl
:= g_Net_Client_ByPlayer(a
);
5008 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5010 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5011 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5012 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5013 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5014 g_Net_Slist_ServerPlayerLeaves();
5017 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5019 else if cmd
= 'ban' then
5021 if g_Game_IsServer
and g_Game_IsNet
then
5023 if Length(P
) < 2 then
5025 g_Console_Add('ban <name>');
5030 g_Console_Add('ban <name>');
5034 pl
:= g_Net_Client_ByName(P
[1]);
5037 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5038 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5039 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5040 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5041 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5042 g_Net_Slist_ServerPlayerLeaves();
5044 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5046 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5048 else if cmd
= 'ban_id' then
5050 if g_Game_IsServer
and g_Game_IsNet
then
5052 if Length(P
) < 2 then
5054 g_Console_Add('ban_id <client ID>');
5059 g_Console_Add('ban_id <client ID>');
5063 a
:= StrToIntDef(P
[1], 0);
5064 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5065 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5067 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5068 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5069 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5070 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5071 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5072 g_Net_Slist_ServerPlayerLeaves();
5075 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5077 else if cmd
= 'ban_pid' then
5079 if g_Game_IsServer
and g_Game_IsNet
then
5081 if Length(P
) < 2 then
5083 g_Console_Add('ban_pid <player ID>');
5088 g_Console_Add('ban_pid <player ID>');
5092 a
:= StrToIntDef(P
[1], 0);
5093 pl
:= g_Net_Client_ByPlayer(a
);
5094 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5096 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5097 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5098 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5099 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5100 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5101 g_Net_Slist_ServerPlayerLeaves();
5104 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5106 else if cmd
= 'permban' then
5108 if g_Game_IsServer
and g_Game_IsNet
then
5110 if Length(P
) < 2 then
5112 g_Console_Add('permban <name>');
5117 g_Console_Add('permban <name>');
5121 pl
:= g_Net_Client_ByName(P
[1]);
5124 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5125 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5126 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5127 g_Net_SaveBanList();
5128 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5129 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5130 g_Net_Slist_ServerPlayerLeaves();
5132 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5134 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5136 else if cmd
= 'permban_id' then
5138 if g_Game_IsServer
and g_Game_IsNet
then
5140 if Length(P
) < 2 then
5142 g_Console_Add('permban_id <client ID>');
5147 g_Console_Add('permban_id <client ID>');
5151 a
:= StrToIntDef(P
[1], 0);
5152 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5153 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5155 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5156 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5157 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5158 g_Net_SaveBanList();
5159 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5160 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5161 g_Net_Slist_ServerPlayerLeaves();
5164 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5166 else if cmd
= 'permban_pid' then
5168 if g_Game_IsServer
and g_Game_IsNet
then
5170 if Length(P
) < 2 then
5172 g_Console_Add('permban_pid <player ID>');
5177 g_Console_Add('permban_pid <player ID>');
5181 a
:= StrToIntDef(P
[1], 0);
5182 pl
:= g_Net_Client_ByPlayer(a
);
5183 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5185 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5186 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5187 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5188 g_Net_SaveBanList();
5189 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5190 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5191 g_Net_Slist_ServerPlayerLeaves();
5194 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5196 else if cmd
= 'permban_ip' then
5198 if g_Game_IsServer
and g_Game_IsNet
then
5200 if Length(P
) < 2 then
5202 g_Console_Add('permban_ip <IP address>');
5207 g_Console_Add('permban_ip <IP address>');
5211 g_Net_BanHost(P
[1]);
5212 g_Net_SaveBanList();
5213 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5215 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5217 else if cmd
= 'unban' then
5219 if g_Game_IsServer
and g_Game_IsNet
then
5221 if Length(P
) < 2 then
5223 g_Console_Add('unban <IP Address>');
5228 g_Console_Add('unban <IP Address>');
5232 if g_Net_UnbanHost(P
[1]) then
5234 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5235 g_Net_SaveBanList();
5237 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5239 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5241 else if cmd
= 'clientlist' then
5243 if g_Game_IsServer
and g_Game_IsNet
then
5246 if NetClients
<> nil then
5247 for a
:= Low(NetClients
) to High(NetClients
) do
5248 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5250 plr
:= g_Player_Get(NetClients
[a
].Player
);
5251 if plr
= nil then continue
;
5253 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5254 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5257 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5259 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5261 else if cmd
= 'connect' then
5263 if (NetMode
= NET_NONE
) then
5265 if Length(P
) < 2 then
5267 g_Console_Add('connect <IP> [port] [password]');
5272 g_Console_Add('connect <IP> [port] [password]');
5276 if Length(P
) > 2 then
5277 prt
:= StrToIntDef(P
[2], 25666)
5281 if Length(P
) > 3 then
5286 g_Game_StartClient(P
[1], prt
, pw
);
5289 else if cmd
= 'disconnect' then
5291 if (NetMode
= NET_CLIENT
) then
5294 else if cmd
= 'reconnect' then
5296 if (NetMode
= NET_SERVER
) then
5299 if (NetMode
= NET_CLIENT
) then
5302 gExit
:= EXIT_SIMPLE
;
5306 //TODO: Use last successful password to reconnect, instead of ''
5307 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5309 else if (cmd
= 'addbot') or
5310 (cmd
= 'bot_add') then
5312 if Length(P
) > 2 then
5313 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5314 else if Length(P
) > 1 then
5315 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5317 g_Bot_Add(TEAM_NONE
, 2);
5319 else if cmd
= 'bot_addlist' then
5321 if Length(P
) > 1 then
5323 if Length(P
) = 2 then
5324 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5325 else if Length(P
) = 3 then
5326 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5328 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5331 else if cmd
= 'bot_removeall' then
5333 else if cmd
= 'chat' then
5335 if g_Game_IsNet
then
5337 if Length(P
) > 1 then
5339 for a
:= 1 to High(P
) do
5340 chstr
:= chstr
+ P
[a
] + ' ';
5342 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5344 if Length(chstr
) < 1 then
5346 g_Console_Add('chat <text>');
5350 chstr
:= b_Text_Format(chstr
);
5351 if g_Game_IsClient
then
5352 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5354 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5357 g_Console_Add('chat <text>');
5359 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5361 else if cmd
= 'teamchat' then
5363 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5365 if Length(P
) > 1 then
5367 for a
:= 1 to High(P
) do
5368 chstr
:= chstr
+ P
[a
] + ' ';
5370 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5372 if Length(chstr
) < 1 then
5374 g_Console_Add('teamchat <text>');
5378 chstr
:= b_Text_Format(chstr
);
5379 if g_Game_IsClient
then
5380 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5382 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5383 gPlayer1Settings
.Team
);
5386 g_Console_Add('teamchat <text>');
5388 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5390 else if (cmd
= 'an') or (cmd
= 'announce') then
5392 if g_Game_IsNet
then
5394 if Length(P
) > 1 then
5396 for a
:= 1 to High(P
) do
5397 chstr
:= chstr
+ P
[a
] + ' ';
5399 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5401 if Length(chstr
) < 1 then
5403 g_Console_Add('announce <text>');
5407 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5408 if g_Game_IsClient
then
5409 MC_SEND_RCONCommand(chstr
)
5411 g_Console_Process(chstr
, True);
5414 g_Console_Add('announce <text>');
5416 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5418 else if cmd
= 'game' then
5420 if gGameSettings
.GameType
<> GT_NONE
then
5422 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5425 if Length(P
) = 1 then
5427 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5430 // game not started yet, load fist map from some wad
5432 s
:= addWadExtension(P
[1]);
5433 found
:= e_FindResource(AllMapDirs
, s
);
5437 P
[1] := ExpandFileName(P
[1]);
5438 // if map not choosed then set first map
5439 if Length(P
) < 3 then
5442 P
[2] := g_Game_GetFirstMap(P
[1]);
5445 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5447 if g_Map_Exist(s
) then
5451 with gGameSettings
do
5453 Options
:= gsGameFlags
;
5454 GameMode
:= g_Game_TextToMode(gsGameMode
);
5455 if gSwitchGameMode
<> GM_NONE
then
5456 GameMode
:= gSwitchGameMode
;
5457 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5458 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5460 if Length(P
) >= 4 then
5461 b
:= StrToIntDef(P
[3], 1);
5462 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5463 ScoreLimit
, MaxLives
, Options
, b
);
5468 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5470 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5472 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5474 else if cmd
= 'host' then
5476 if gGameSettings
.GameType
<> GT_NONE
then
5478 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5481 if Length(P
) < 4 then
5483 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5486 if not StrToIp(P
[1], listen
) then
5488 prt
:= StrToIntDef(P
[2], 25666);
5490 s
:= addWadExtension(P
[3]);
5491 found
:= e_FindResource(AllMapDirs
, s
);
5495 // get first map in wad, if not specified
5496 if Length(P
) < 5 then
5499 P
[4] := g_Game_GetFirstMap(P
[1]);
5501 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5502 if g_Map_Exist(s
) then
5506 with gGameSettings
do
5508 Options
:= gsGameFlags
;
5509 GameMode
:= g_Game_TextToMode(gsGameMode
);
5510 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5511 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5512 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5514 if Length(P
) >= 6 then
5515 b
:= StrToIntDef(P
[5], 0);
5516 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5522 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5524 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5529 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5532 else if cmd
= 'map' then
5534 if Length(P
) = 1 then
5536 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5538 g_Console_Add(cmd
+ ' <MAP>');
5539 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5543 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5548 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5550 if Length(P
) < 3 then
5552 // first param is map or wad
5553 s
:= UpperCase(P
[1]);
5554 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5556 gExitByTrigger
:= False;
5559 // already in game, finish current map
5561 gExit
:= EXIT_ENDLEVELCUSTOM
;
5565 // intermission, so change map immediately
5572 found
:= e_FindResource(AllMapDirs
, s
);
5574 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5577 // no such map, found wad
5580 P
[1] := ExpandFileName(pw
);
5581 P
[2] := g_Game_GetFirstMap(P
[1]);
5582 s
:= P
[1] + ':\' + P
[2];
5583 if g_Map_Exist(s
) then
5585 gExitByTrigger
:= False;
5588 // already in game, finish current map
5590 gExit
:= EXIT_ENDLEVELCUSTOM
5594 // intermission, so change map immediately
5601 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5603 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5608 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5614 s
:= addWadExtension(P
[1]);
5615 found
:= e_FindResource(AllMapDirs
, s
);
5619 P
[2] := UpperCase(P
[2]);
5620 s
:= P
[1] + ':\' + P
[2];
5621 if g_Map_Exist(s
) then
5623 gExitByTrigger
:= False;
5627 gExit
:= EXIT_ENDLEVELCUSTOM
5636 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5641 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5647 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5651 else if cmd
= 'nextmap' then
5653 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5655 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5660 if Length(P
) = 1 then
5662 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5664 g_Console_Add(cmd
+ ' <MAP>');
5665 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5670 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5676 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5678 if Length(P
) < 3 then
5680 // first param is map or wad
5681 s
:= UpperCase(P
[1]);
5682 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5685 gExitByTrigger
:= False;
5691 // no such map, found wad
5692 pw
:= addWadExtension(P
[1]);
5693 found
:= e_FindResource(MapDirs
, pw
);
5695 found
:= e_FindResource(WadDirs
, pw
);
5697 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5700 // map not specified, select first map
5702 P
[2] := g_Game_GetFirstMap(P
[1]);
5703 s
:= P
[1] + ':\' + P
[2];
5704 if g_Map_Exist(s
) then
5706 gExitByTrigger
:= False;
5713 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5715 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5720 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5726 // specified two params wad + map
5727 pw
:= addWadExtension(P
[1]);
5728 found
:= e_FindResource(MapDirs
, pw
);
5730 found
:= e_FindResource(MapDirs
, pw
);
5734 P
[2] := UpperCase(P
[2]);
5735 s
:= P
[1] + ':\' + P
[2];
5736 if g_Map_Exist(s
) then
5738 gExitByTrigger
:= False;
5744 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5749 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5755 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5760 if gNextMap
= '' then
5761 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5763 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5767 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5771 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5775 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5777 gExitByTrigger
:= False;
5778 // next map not specified, try to find trigger EXIT
5779 if (gNextMap
= '') and (gTriggers
<> nil) then
5781 for a
:= 0 to High(gTriggers
) do
5783 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5785 gExitByTrigger
:= True;
5786 //gNextMap := gTriggers[a].Data.MapName;
5787 gNextMap
:= gTriggers
[a
].tgcMap
;
5792 if gNextMap
= '' then
5793 gNextMap
:= g_Game_GetNextMap();
5794 if not isWadPath(gNextMap
) then
5795 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5798 if g_Map_Exist(s
) then
5799 gExit
:= EXIT_ENDLEVELCUSTOM
5801 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5805 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5809 else if (cmd
= 'event') then
5811 if (Length(P
) <= 1) then
5813 for a
:= 0 to High(gEvents
) do
5814 if gEvents
[a
].Command
= '' then
5815 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5817 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5820 if (Length(P
) = 2) then
5822 for a
:= 0 to High(gEvents
) do
5823 if gEvents
[a
].Name
= P
[1] then
5824 if gEvents
[a
].Command
= '' then
5825 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5827 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5830 for a
:= 0 to High(gEvents
) do
5831 if gEvents
[a
].Name
= P
[1] then
5833 gEvents
[a
].Command
:= '';
5834 for b
:= 2 to High(P
) do
5835 if Pos(' ', P
[b
]) = 0 then
5836 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5838 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5839 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5843 else if cmd
= 'suicide' then
5847 if g_Game_IsClient
then
5848 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5851 if gPlayer1
<> nil then
5852 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5853 if gPlayer2
<> nil then
5854 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5858 else if cmd
= 'screenshot' then
5864 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5866 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5868 gWeaponAction
[0, WP_PREV
] := True;
5870 gWeaponAction
[0, WP_NEXT
] := True;
5872 else if cmd
= 'weapon' then
5874 if Length(p
) = 2 then
5876 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5877 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5878 gSelectWeapon
[0, a
] := True
5881 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5882 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5884 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5885 b
:= ord(cmd
[2]) - ord('1');
5887 gWeaponAction
[b
, WP_PREV
] := True;
5889 gWeaponAction
[b
, WP_NEXT
] := True;
5891 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5893 if Length(p
) = 2 then
5895 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5896 b
:= ord(cmd
[2]) - ord('1');
5897 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5898 gSelectWeapon
[b
, a
] := True
5901 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
5903 b
:= ord(cmd
[2]) - ord('1');
5905 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
5907 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
5909 else if (cmd
= 'dropflag') then
5911 if g_Game_IsServer
then
5913 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
5914 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
5917 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5919 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
5921 b
:= ord(cmd
[2]) - ord('1');
5922 if g_Game_IsServer
then
5924 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
5925 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
5928 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5930 // Команды Своей игры:
5931 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5933 if cmd
= 'bot_addred' then
5935 if Length(P
) > 1 then
5936 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5938 g_Bot_Add(TEAM_RED
, 2);
5940 else if cmd
= 'bot_addblue' then
5942 if Length(P
) > 1 then
5943 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5945 g_Bot_Add(TEAM_BLUE
, 2);
5947 else if cmd
= 'spectate' then
5953 else if cmd
= 'say' then
5955 if g_Game_IsServer
and g_Game_IsNet
then
5957 if Length(P
) > 1 then
5960 for a
:= 1 to High(P
) do
5961 chstr
:= chstr
+ P
[a
] + ' ';
5963 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5965 if Length(chstr
) < 1 then
5967 g_Console_Add('say <text>');
5971 chstr
:= b_Text_Format(chstr
);
5972 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5974 else g_Console_Add('say <text>');
5976 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5978 else if cmd
= 'tell' then
5980 if g_Game_IsServer
and g_Game_IsNet
then
5982 if (Length(P
) > 2) and (P
[1] <> '') then
5985 for a
:= 2 to High(P
) do
5986 chstr
:= chstr
+ P
[a
] + ' ';
5988 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5990 if Length(chstr
) < 1 then
5992 g_Console_Add('tell <playername> <text>');
5996 pl
:= g_Net_Client_ByName(P
[1]);
5998 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6000 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6002 else g_Console_Add('tell <playername> <text>');
6004 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6006 else if cmd
= 'centerprint' then
6008 if (Length(P
) > 2) and (P
[1] <> '') then
6011 for a
:= 2 to High(P
) do
6012 chstr
:= chstr
+ P
[a
] + ' ';
6014 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6016 if Length(chstr
) < 1 then
6018 g_Console_Add('centerprint <timeout> <text>');
6022 a
:= StrToIntDef(P
[1], 100);
6023 chstr
:= b_Text_Format(chstr
);
6024 g_Game_Message(chstr
, a
);
6025 if g_Game_IsNet
and g_Game_IsServer
then
6026 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6028 else g_Console_Add('centerprint <timeout> <text>');
6030 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6032 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6034 // Дополнительное время:
6035 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6037 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6038 [gGameSettings
.TimeLimit
div 3600,
6039 (gGameSettings
.TimeLimit
div 60) mod 60,
6040 gGameSettings
.TimeLimit
mod 60]));
6041 if g_Game_IsNet
then MH_SEND_GameSettings
;
6043 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6045 if (Length(P
) <= 1) then
6046 g_Console_Add('rcon_password <password>')
6048 MC_SEND_RCONPassword(P
[1]);
6050 else if cmd
= 'rcon' then
6052 if g_Game_IsClient
then
6054 if Length(P
) > 1 then
6057 for a
:= 1 to High(P
) do
6058 chstr
:= chstr
+ P
[a
] + ' ';
6060 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6062 if Length(chstr
) < 1 then
6064 g_Console_Add('rcon <command>');
6068 MC_SEND_RCONCommand(chstr
);
6070 else g_Console_Add('rcon <command>');
6073 else if cmd
= 'ready' then
6075 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6076 gLMSRespawnTime
:= gTime
+ 100;
6078 else if (cmd
= 'callvote') and g_Game_IsNet
then
6080 if Length(P
) > 1 then
6083 for a
:= 1 to High(P
) do begin
6084 if a
> 1 then chstr
:= chstr
+ ' ';
6085 chstr
:= chstr
+ P
[a
];
6088 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6090 if Length(chstr
) < 1 then
6092 g_Console_Add('callvote <command>');
6096 if g_Game_IsClient
then
6097 MC_SEND_Vote(True, chstr
)
6099 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6100 g_Console_Process('vote', True);
6103 g_Console_Add('callvote <command>');
6105 else if (cmd
= 'vote') and g_Game_IsNet
then
6107 if g_Game_IsClient
then
6109 else if gVoteInProgress
then
6111 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6112 a
:= Floor((NetClientCount
+1)/2.0) + 1
6114 a
:= Floor(NetClientCount
/2.0) + 1;
6119 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6120 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6126 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6127 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6135 procedure SystemCommands(P
: SSArray
);
6139 cmd
:= LowerCase(P
[0]);
6152 if Length(p
) = 2 then
6154 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6156 gFrameTime
:= 1000 div gMaxFPS
6160 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6164 if Length(p
) = 2 then
6166 gAskLanguage
:= true;
6167 gLanguage
:= LANGUAGE_ENGLISH
;
6168 case LowerCase(p
[1]) of
6171 gAskLanguage
:= false;
6172 gLanguage
:= LANGUAGE_ENGLISH
;
6176 gAskLanguage
:= false;
6177 gLanguage
:= LANGUAGE_RUSSIAN
;
6181 gAskLanguage
:= true;
6182 gLanguage
:= LANGUAGE_ENGLISH
;
6185 g_Language_Set(gLanguage
);
6189 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6196 procedure g_TakeScreenShot(Filename
: string = '');
6197 var t
: TDateTime
; dir
, date
, name
: String;
6199 if e_NoGraphics
then
6202 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6203 if Filename
= '' then
6206 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6207 Filename
:= 'screenshot-' + date
;
6210 name
:= e_CatPath(dir
, Filename
+ '.png');
6211 if r_Render_WriteScreenShot(name
) then
6212 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6214 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6218 {$IFDEF ENABLE_MENU}
6219 procedure g_Game_InGameMenu(Show
: Boolean);
6221 if (g_ActiveWindow
= nil) and Show
then
6223 if gGameSettings
.GameType
= GT_SINGLE
then
6224 g_GUI_ShowWindow('GameSingleMenu')
6227 if g_Game_IsClient
then
6228 g_GUI_ShowWindow('GameClientMenu')
6230 if g_Game_IsNet
then
6231 g_GUI_ShowWindow('GameServerMenu')
6233 g_GUI_ShowWindow('GameCustomMenu');
6235 g_Sound_PlayEx('MENU_OPEN');
6237 // Пауза при меню только в одиночной игре:
6238 if (not g_Game_IsNet
) then
6242 if (g_ActiveWindow
<> nil) and (not Show
) then
6244 // Пауза при меню только в одиночной игре:
6245 if (not g_Game_IsNet
) then
6246 g_Game_Pause(False);
6251 procedure g_Game_Pause (Enable
: Boolean);
6255 if not gGameOn
then exit
;
6257 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6260 gPauseMain
:= Enable
;
6262 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6265 procedure g_Game_HolmesPause (Enable
: Boolean);
6269 if not gGameOn
then exit
;
6270 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6273 gPauseHolmes
:= Enable
;
6275 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6278 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6283 if gTriggers
<> nil then
6284 for i
:= 0 to High(gTriggers
) do
6285 with gTriggers
[i
] do
6286 if (TriggerType
= TRIGGER_SOUND
) and
6288 Sound
.IsPlaying() then
6290 Sound
.Pause(Enable
);
6294 if gPlayers
<> nil then
6295 for i
:= 0 to High(gPlayers
) do
6296 if gPlayers
[i
] <> nil then
6297 gPlayers
[i
].PauseSounds(Enable
);
6300 if gMusic
<> nil then
6301 gMusic
.Pause(Enable
);
6304 procedure g_Game_StopAllSounds(all
: Boolean);
6308 if gTriggers
<> nil then
6309 for i
:= 0 to High(gTriggers
) do
6310 with gTriggers
[i
] do
6311 if (TriggerType
= TRIGGER_SOUND
) and
6315 if gMusic
<> nil then
6322 procedure g_Game_UpdateTriggerSounds
;
6325 if gTriggers
<> nil then
6326 for i
:= 0 to High(gTriggers
) do
6327 with gTriggers
[i
] do
6328 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6329 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6332 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6335 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6340 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6345 if gSpectMode
<> SPECT_PLAYERS
then
6347 if gSpectPID1
= UID
then
6352 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6359 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6364 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6369 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6374 if gSpectMode
<> SPECT_PLAYERS
then
6376 Pl
:= g_Player_Get(gSpectPID1
);
6377 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6382 if gSpectViewTwo
then
6384 Pl
:= g_Player_Get(gSpectPID2
);
6385 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6393 procedure g_Game_Message (Msg
: string; Time
: Word);
6396 MessageTime
:= Time
;
6399 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6401 punct
: Array[0..13] of String =
6402 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6408 function IsPunctuation(S
: String): Boolean;
6413 if Length(S
) <> 1 then
6415 for i
:= Low(punct
) to High(punct
) do
6416 if S
= punct
[i
] then
6422 function FilterPunctuation(S
: String): String;
6426 for i
:= Low(punct
) to High(punct
) do
6427 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6433 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6435 // remove player name
6436 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6437 // for FullWord check
6438 Text := toLowerCase1251(' ' + Text + ' ');
6439 fpText
:= FilterPunctuation(Text);
6441 for i
:= 0 to Length(gChatSounds
) - 1 do
6444 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6446 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6447 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6449 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6455 gChatSounds
[i
].Sound
.Play();
6461 g_Sound_PlayEx('SOUND_GAME_RADIO');
6464 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6473 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6477 if goodsnd
[a
].IsPlaying() then
6480 goodsnd
[Random(4)].Play();
6483 procedure g_Game_Announce_KillCombo(Param
: Integer);
6490 UID
:= Param
and $FFFF;
6495 Pl
:= g_Player_Get(UID
);
6504 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6508 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6512 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6516 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6524 if not g_Game_IsWatchedPlayer(UID
) then
6527 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6531 if killsnd
[n
].IsPlaying() then
6536 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6544 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6548 if hahasnd
[a
].IsPlaying() then
6551 hahasnd
[Random(3)].Play();
6554 procedure g_Game_StartVote(Command
, Initiator
: string);
6558 if not gVotesEnabled
then Exit
;
6559 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6560 if gVoteInProgress
or gVotePassed
then
6562 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6563 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6566 gVoteInProgress
:= True;
6567 gVotePassed
:= False;
6568 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6571 gVoteCommand
:= Command
;
6573 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6574 Need
:= Floor((NetClientCount
+1)/2.0)+1
6576 Need
:= Floor(NetClientCount
/2.0)+1;
6577 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6578 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6581 procedure g_Game_CheckVote
;
6585 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6586 if not gVoteInProgress
then Exit
;
6588 if (gTime
>= gVoteTimer
) then
6590 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6591 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6593 Need
:= Floor(NetClientCount
/2.0) + 1;
6594 if gVoteCount
>= Need
then
6596 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6597 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6598 gVotePassed
:= True;
6599 gVoteCmdTimer
:= gTime
+ 5000;
6603 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6604 MH_SEND_VoteEvent(NET_VE_FAILED
);
6606 if NetClients
<> nil then
6607 for I
:= Low(NetClients
) to High(NetClients
) do
6608 if NetClients
[i
].Used
then
6609 NetClients
[i
].Voted
:= False;
6610 gVoteInProgress
:= False;
6616 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6617 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6619 Need
:= Floor(NetClientCount
/2.0) + 1;
6620 if gVoteCount
>= Need
then
6622 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6623 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6624 gVoteInProgress
:= False;
6625 gVotePassed
:= True;
6626 gVoteCmdTimer
:= gTime
+ 5000;
6629 if NetClients
<> nil then
6630 for I
:= Low(NetClients
) to High(NetClients
) do
6631 if NetClients
[i
].Used
then
6632 NetClients
[i
].Voted
:= False;
6637 procedure g_Game_LoadMapList(FileName
: string);
6645 if not FileExists(FileName
) then Exit
;
6647 AssignFile(ListFile
, FileName
);
6649 while not EOF(ListFile
) do
6651 ReadLn(ListFile
, s
);
6654 if s
= '' then Continue
;
6656 SetLength(MapList
, Length(MapList
)+1);
6657 MapList
[High(MapList
)] := s
;
6659 CloseFile(ListFile
);
6662 procedure g_Game_SetDebugMode();
6665 // Читы (даже в своей игре):
6669 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6673 if Length(LoadingStat
.Msgs
) = 0 then
6679 begin // Переходим на следующую строку или скроллируем:
6680 if NextMsg
= Length(Msgs
) then
6682 for i
:= 0 to High(Msgs
)-1 do
6683 Msgs
[i
] := Msgs
[i
+1];
6691 Msgs
[NextMsg
-1] := Text;
6695 PBarWasHere
:= false;
6698 {$IFDEF ENABLE_MENU}
6699 g_ActiveWindow
:= nil;
6702 ProcessLoading(true);
6705 procedure g_Game_StepLoading(Value
: Integer = -1);
6717 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6720 ProcessLoading(False);
6725 procedure g_Game_ClearLoading();
6734 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6735 if len
< 1 then len
:= 1;
6736 SetLength(Msgs
, len
);
6737 for len
:= Low(Msgs
) to High(Msgs
) do
6740 PBarWasHere
:= false;
6744 procedure Parse_Params(var pars
: TParamStrValues
);
6751 while i
<= ParamCount
do
6754 if (Length(s
) > 1) and (s
[1] = '-') then
6756 if (Length(s
) > 2) and (s
[2] = '-') then
6757 begin // Одиночный параметр
6758 SetLength(pars
, Length(pars
) + 1);
6759 with pars
[High(pars
)] do
6761 Name
:= LowerCase(s
);
6766 if (i
< ParamCount
) then
6767 begin // Параметр со значением
6769 SetLength(pars
, Length(pars
) + 1);
6770 with pars
[High(pars
)] do
6772 Name
:= LowerCase(s
);
6773 Value
:= LowerCase(ParamStr(i
));
6782 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6787 for i
:= 0 to High(pars
) do
6788 if pars
[i
].Name
= aName
then
6790 Result
:= pars
[i
].Value
;
6795 procedure g_Game_Process_Params();
6797 pars
: TParamStrValues
;
6800 LimT
, LimS
: Integer;
6811 s
:= Find_Param_Value(pars
, '--debug');
6814 g_Game_SetDebugMode();
6815 s
:= Find_Param_Value(pars
, '--netdump');
6820 // Connect when game loads
6821 ip
:= Find_Param_Value(pars
, '-connect');
6825 s
:= Find_Param_Value(pars
, '-port');
6826 if (s
= '') or not TryStrToInt(s
, Port
) then
6829 s
:= Find_Param_Value(pars
, '-pw');
6831 g_Game_StartClient(ip
, Port
, s
);
6835 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6838 gDefaultMegawadStart
:= s
;
6841 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6842 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6844 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6847 // Start map when game loads:
6848 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6849 if isWadPath(map
) then
6852 s
:= Find_Param_Value(pars
, '-gm');
6853 GMode
:= g_Game_TextToMode(s
);
6854 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6855 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6858 s
:= Find_Param_Value(pars
, '-limt');
6859 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6865 s
:= Find_Param_Value(pars
, '-lims');
6866 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6872 s
:= Find_Param_Value(pars
, '-lives');
6873 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6879 s
:= Find_Param_Value(pars
, '-opt');
6883 Opt
:= StrToIntDef(s
, 0);
6886 s
:= Find_Param_Value(pars
, '--close');
6890 // Override map to test:
6891 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6894 if e_IsValidResourceName(s
) then
6895 e_FindResource(AllMapDirs
, s
);
6896 gTestMap
:= ExpandFileName(s
);
6899 // Delete test map after play:
6900 s
:= Find_Param_Value(pars
, '--testdelete');
6903 //gMapToDelete := MapsDir + map;
6904 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6908 // Delete temporary WAD after play:
6909 s
:= Find_Param_Value(pars
, '--tempdelete');
6910 if (s
<> '') and (gTestMap
<> '') then
6912 gMapToDelete
:= gTestMap
;
6913 gTempDelete
:= True;
6916 // Number of players:
6917 s
:= Find_Param_Value(pars
, '-pl');
6919 n
:= DEFAULT_PLAYERS
6921 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6924 s
:= Find_Param_Value(pars
, '-port');
6925 if (s
= '') or not TryStrToInt(s
, Port
) then
6926 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6928 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6931 // Execute script when game loads:
6932 s
:= Find_Param_Value(pars
, '-exec');
6935 // if not isWadPath(s) then
6936 // s := GameDir + '/' + s;
6941 if IOResult
<> 0 then
6943 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6944 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6948 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6949 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6954 if IOResult
<> 0 then
6956 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6957 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6961 if Pos('#', s
) <> 1 then // script comment
6962 g_Console_Process(s
, True);
6973 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6974 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6975 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6976 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6978 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6979 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6980 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6981 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6984 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6985 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6988 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6989 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6991 {$IFDEF ENABLE_HOLMES}
6992 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6995 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6997 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6998 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7000 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7001 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7003 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
7004 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
7005 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
7006 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
7007 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7008 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7009 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7010 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7011 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');