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}
464 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
465 g_playermodel
, g_gfx
, g_options
, Math
,
466 g_triggers
, g_monsters
, e_sound
, CONFIG
,
467 g_language
, g_net
, g_phys
,
468 ENet
, e_msg
, g_netmsg
, g_netmaster
,
472 charbuff
: packed array [0..15] of AnsiChar = (
473 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
476 function Translit (const S
: AnsiString): AnsiString;
481 for i
:= 1 to Length(Result
) do
484 #
$C9: Result
[i
] := 'Q';
485 #
$D6: Result
[i
] := 'W';
486 #
$D3: Result
[i
] := 'E';
487 #
$CA: Result
[i
] := 'R';
488 #
$C5: Result
[i
] := 'T';
489 #
$CD: Result
[i
] := 'Y';
490 #
$C3: Result
[i
] := 'U';
491 #
$D8: Result
[i
] := 'I';
492 #
$D9: Result
[i
] := 'O';
493 #
$C7: Result
[i
] := 'P';
494 #
$D5: Result
[i
] := '['; //Chr(219);
495 #
$DA: Result
[i
] := ']'; //Chr(221);
496 #
$D4: Result
[i
] := 'A';
497 #
$DB: Result
[i
] := 'S';
498 #
$C2: Result
[i
] := 'D';
499 #
$C0: Result
[i
] := 'F';
500 #
$CF: Result
[i
] := 'G';
501 #
$D0: Result
[i
] := 'H';
502 #
$CE: Result
[i
] := 'J';
503 #
$CB: Result
[i
] := 'K';
504 #
$C4: Result
[i
] := 'L';
505 #
$C6: Result
[i
] := ';'; //Chr(186);
506 #
$DD: Result
[i
] := #39; //Chr(222);
507 #
$DF: Result
[i
] := 'Z';
508 #
$D7: Result
[i
] := 'X';
509 #
$D1: Result
[i
] := 'C';
510 #
$CC: Result
[i
] := 'V';
511 #
$C8: Result
[i
] := 'B';
512 #
$D2: Result
[i
] := 'N';
513 #
$DC: Result
[i
] := 'M';
514 #
$C1: Result
[i
] := ','; //Chr(188);
515 #
$DE: Result
[i
] := '.'; //Chr(190);
521 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
526 ls2
:= Translit(CheatRus
[ct
]);
527 if length(ls1
) = 0 then ls1
:= '~';
528 if length(ls2
) = 0 then ls2
:= '~';
530 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
531 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
532 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
533 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
535 if ct = I_GAME_CHEAT_JETPACK then
537 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
538 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
539 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
540 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
541 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
542 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
558 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
559 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
560 or g_Game_IsNet then Exit;
562 if not gGameOn
then exit
;
563 if not conIsCheatsEnabled
then exit
;
565 s
:= 'SOUND_GAME_RADIO';
568 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
570 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
571 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
575 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
577 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
578 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
582 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
584 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
585 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
589 if CheckCheat(I_GAME_CHEAT_DEATH
) then
591 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
592 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
593 s
:= 'SOUND_MONSTER_HAHA';
597 if CheckCheat(I_GAME_CHEAT_DOORS
) then
599 g_Triggers_OpenAll();
603 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
605 if gTriggers
<> nil then
606 for a
:= 0 to High(gTriggers
) do
607 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
609 gExitByTrigger
:= True;
610 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
611 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
617 s2
:= Copy(charbuff
, 15, 2);
618 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
620 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
628 if CheckCheat(I_GAME_CHEAT_FLY
) then
634 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
636 VEL_JUMP
:= 30-VEL_JUMP
;
640 if CheckCheat(I_GAME_CHEAT_SPEED
) then
642 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
646 if CheckCheat(I_GAME_CHEAT_SUIT
) then
648 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
649 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
653 if CheckCheat(I_GAME_CHEAT_AIR
) then
655 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
656 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
660 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
662 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
663 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
667 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
669 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
670 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
674 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
676 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
677 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
681 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
683 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
684 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
688 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
690 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
691 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
694 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
696 gAimLine
:= not gAimLine
;
699 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
701 gShowMap
:= not gShowMap
;
712 procedure KeyPress (K
: Word);
713 var Msg
: g_gui
.TMessage
;
718 if (g_ActiveWindow
<> nil) then
720 Msg
.Msg
:= WM_KEYDOWN
;
721 Msg
.WParam
:= VK_ESCAPE
;
722 g_ActiveWindow
.OnMessage(Msg
);
723 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
725 else if (gState
<> STATE_FOLD
) then
727 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
729 g_Game_InGameMenu(True);
731 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
733 if (gState
<> STATE_MENU
) then
735 if (NetMode
<> NET_NONE
) then
737 g_Game_StopAllSounds(True);
739 gState
:= STATE_MENU
;
743 g_GUI_ShowWindow('MainMenu');
744 g_Sound_PlayEx('MENU_OPEN');
749 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
750 begin // <F2> .. <F6> � <F12>
751 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
753 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
754 if (not g_Game_IsNet
) then g_Game_Pause(True);
756 IK_F2
: g_Menu_Show_SaveMenu();
757 IK_F3
: g_Menu_Show_LoadMenu();
758 IK_F4
: g_Menu_Show_GameSetGame();
759 IK_F5
: g_Menu_Show_OptionsVideo();
760 IK_F6
: g_Menu_Show_OptionsSound();
761 IK_F7
: g_Menu_Show_EndGameMenu();
762 IK_F10
: g_Menu_Show_QuitGameMenu();
769 gJustChatted
:= False;
770 if gConsoleShow
or gChatShow
then
772 g_Console_Control(K
);
774 else if (g_ActiveWindow
<> nil) then
776 Msg
.Msg
:= WM_KEYDOWN
;
778 g_ActiveWindow
.OnMessage(Msg
);
780 else if (gState
= STATE_MENU
) then
782 g_GUI_ShowWindow('MainMenu');
783 g_Sound_PlayEx('MENU_OPEN');
789 procedure KeyPress (K
: Word);
791 gJustChatted
:= False;
792 if gConsoleShow
or gChatShow
then
794 g_Console_Control(K
);
800 procedure CharPress (C
: AnsiChar);
802 var Msg
: g_gui
.TMessage
;
806 if gConsoleShow
or gChatShow
then
811 else if g_ActiveWindow
<> nil then
814 Msg
.WParam
:= Ord(C
);
815 g_ActiveWindow
.OnMessage(Msg
);
822 charbuff
[a
] := charbuff
[a
+ 1];
824 charbuff
[15] := upcase1251(C
);
831 // ////////////////////////////////////////////////////////////////////////// //
832 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
834 procedure g_ResetDynlights ();
838 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
840 for idx
:= 0 to g_dynLightCount
-1 do
842 if g_dynLights
[idx
].exploCount
= -666 then
849 Inc(g_dynLights
[idx
].exploCount
);
850 if (g_dynLights
[idx
].exploCount
< 10) then
852 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
853 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
854 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
855 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
860 g_dynLightCount
:= lnum
;
863 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
865 if not gwin_has_stencil
then exit
;
866 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
867 g_dynLights
[g_dynLightCount
].x
:= x
;
868 g_dynLights
[g_dynLightCount
].y
:= y
;
869 g_dynLights
[g_dynLightCount
].radius
:= radius
;
870 g_dynLights
[g_dynLightCount
].r
:= r
;
871 g_dynLights
[g_dynLightCount
].g
:= g
;
872 g_dynLights
[g_dynLightCount
].b
:= b
;
873 g_dynLights
[g_dynLightCount
].a
:= a
;
874 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
875 Inc(g_dynLightCount
);
878 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
880 if not gwin_has_stencil
then exit
;
881 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
882 g_dynLights
[g_dynLightCount
].x
:= x
;
883 g_dynLights
[g_dynLightCount
].y
:= y
;
884 g_dynLights
[g_dynLightCount
].radius
:= 0;
885 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
886 g_dynLights
[g_dynLightCount
].r
:= r
;
887 g_dynLights
[g_dynLightCount
].g
:= g
;
888 g_dynLights
[g_dynLightCount
].b
:= b
;
889 g_dynLights
[g_dynLightCount
].a
:= 0;
890 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
891 Inc(g_dynLightCount
);
894 // ////////////////////////////////////////////////////////////////////////// //
895 function conIsCheatsEnabled (): Boolean; inline;
898 if g_Game_IsNet
then exit
;
899 if not gDebugMode
then
901 //if not gCheats then exit;
902 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
903 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
908 // ////////////////////////////////////////////////////////////////////////// //
910 TParamStrValue
= record
915 TParamStrValues
= Array of TParamStrValue
;
918 INTER_ACTION_TEXT
= 1;
919 INTER_ACTION_PIC
= 2;
920 INTER_ACTION_MUSIC
= 3;
925 DataLoaded
: Boolean = False;
927 MapList
: SSArray
= nil;
928 MapIndex
: Integer = -1;
929 InterReadyTime
: Integer = -1;
930 StatDate
: string = '';
945 function Compare(a
, b
: TPlayerStat
): Integer;
947 if a
.Spectator
then Result
:= 1
948 else if b
.Spectator
then Result
:= -1
949 else if a
.Frags
< b
.Frags
then Result
:= 1
950 else if a
.Frags
> b
.Frags
then Result
:= -1
951 else if a
.Deaths
< b
.Deaths
then Result
:= -1
952 else if a
.Deaths
> b
.Deaths
then Result
:= 1
953 else if a
.Kills
< b
.Kills
then Result
:= -1
957 procedure SortGameStat(var stat
: TPlayerStatArray
);
962 if stat
= nil then Exit
;
964 for I
:= High(stat
) downto Low(stat
) do
965 for J
:= Low(stat
) to High(stat
) - 1 do
966 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
969 stat
[J
] := stat
[J
+ 1];
974 // saves a shitty CSV containing the game stats passed to it
975 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
978 dir
, fname
, map
, mode
, etime
: String;
982 dir
:= e_GetWriteableDir(StatsDirs
);
983 // stats are placed in stats/yy/mm/dd/*.csv
984 fname
:= e_CatPath(dir
, Path
);
985 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
986 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
987 AssignFile(s
, fname
);
989 SetTextCodePage(s
, CP_UTF8
);
991 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
992 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
993 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
994 mode
:= g_Game_ModeToText(Stat
.GameMode
);
995 etime
:= Format('%d:%.2d:%.2d', [
996 Stat
.GameTime
div 1000 div 3600,
997 (Stat
.GameTime
div 1000 div 60) mod 60,
998 Stat
.GameTime
div 1000 mod 60
1000 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
1001 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
1007 gGameSettings
.TimeLimit
,
1008 gGameSettings
.ScoreLimit
,
1009 gGameSettings
.Options
,
1011 Length(Stat
.PlayerStat
)
1013 // line 2: game specific shit
1014 // if it's a team game: red score, blue score
1015 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1016 // otherwise nothing
1017 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1019 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
1020 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1022 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1023 // lines 3-...: team, player name, frags, deaths
1024 WriteLn(s
, 'team,name,frags,deaths');
1025 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1026 with Stat
.PlayerStat
[I
] do
1027 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1029 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1032 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1037 procedure ClearDebugCvars();
1039 g_debug_Sounds
:= False;
1040 g_debug_Frames
:= False;
1041 g_debug_WinMsgs
:= False;
1042 g_debug_MonsterOff
:= False;
1043 g_debug_BotAIOff
:= 0;
1044 g_debug_HealthBar
:= False;
1045 g_Debug_Player
:= False;
1048 function g_Game_ModeToText(Mode
: Byte): string;
1052 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1053 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1054 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1055 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1056 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1060 function g_Game_TextToMode(Mode
: string): Byte;
1063 Mode
:= UpperCase(Mode
);
1064 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1069 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1074 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1079 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1084 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1086 Result
:= GM_SINGLE
;
1091 function g_Game_IsNet(): Boolean;
1093 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1096 function g_Game_IsServer(): Boolean;
1098 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1101 function g_Game_IsClient(): Boolean;
1103 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1106 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1113 Result
.name
:= ExtractFileName(WAD
);
1114 Result
.description
:= '';
1115 Result
.author
:= '';
1117 w
:= TWADFile
.Create();
1120 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1126 cfg
:= TConfig
.CreateMem(p
, len
);
1127 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1128 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1129 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1130 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1136 procedure g_Game_FreeWAD
;
1139 g_Sound_Delete('MUSIC_endmus');
1140 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1141 gGameSettings
.WAD
:= '';
1144 procedure g_Game_LoadWAD(WAD
: string);
1153 gGameSettings
.WAD
:= WAD
;
1154 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1157 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1159 w
:= TWADFile
.Create();
1162 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1168 cfg
:= TConfig
.CreateMem(p
, len
);
1171 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1172 if MegaWAD
.endpic
<> '' then
1173 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1175 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1176 if MegaWAD
.endmus
<> '' then
1178 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1179 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1187 {procedure start_trigger(t: string);
1191 function next_trigger(): Boolean;
1195 procedure DisableCheats();
1201 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1202 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1203 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1204 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1206 {$IF DEFINED(D2F_DEBUG)}
1207 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1208 gAimLine
:= g_dbg_aimline_on
;
1212 procedure g_Game_ExecuteEvent(Name
: String);
1218 if gEvents
= nil then
1220 for a
:= 0 to High(gEvents
) do
1221 if gEvents
[a
].Name
= Name
then
1223 if gEvents
[a
].Command
<> '' then
1224 g_Console_Process(gEvents
[a
].Command
, True);
1229 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1234 if gDelayedEvents
<> nil then
1235 for a
:= 0 to High(gDelayedEvents
) do
1236 if not gDelayedEvents
[a
].Pending
then
1243 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1244 n
:= High(gDelayedEvents
);
1246 gDelayedEvents
[n
].Pending
:= True;
1247 gDelayedEvents
[n
].DEType
:= DEType
;
1248 gDelayedEvents
[n
].DENum
:= Num
;
1249 gDelayedEvents
[n
].DEStr
:= Str
;
1250 if DEType
= DE_GLOBEVENT
then
1251 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1253 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1257 procedure EndGame();
1263 if g_Game_IsNet
and g_Game_IsServer
then
1264 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1267 gPauseMain
:= false;
1268 gPauseHolmes
:= false;
1271 g_Game_StopAllSounds(False);
1276 EndingGameCounter
:= 0;
1278 {$IFDEF ENABLE_MENU}
1279 g_ActiveWindow
:= nil;
1282 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1283 gLMSRespawnTime
:= 0;
1286 EXIT_SIMPLE
: // Выход через меню или конец теста
1290 begin // Это был тест
1294 begin // Выход в главное меню
1295 {$IFDEF DISABLE_MENU}
1296 gState
:= STATE_MENU
; // ???
1298 gMusic
.SetByName('MUSIC_MENU');
1300 if gState
<> STATE_SLIST
then
1302 g_GUI_ShowWindow('MainMenu');
1303 gState
:= STATE_MENU
;
1307 // Обновляем список серверов
1308 slReturnPressed
:= True;
1309 if g_Net_Slist_Fetch(slCurrent
) then
1311 if slCurrent
= nil then
1312 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1315 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1316 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1319 g_Game_ExecuteEvent('ongameend');
1323 EXIT_RESTART
: // Начать уровень сначала
1325 if not g_Game_IsClient
then g_Game_Restart();
1328 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1330 // Статистика Своей игры:
1331 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1333 CustomStat
.GameTime
:= gTime
;
1334 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1335 CustomStat
.MapName
:= gMapInfo
.Name
;
1336 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1337 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1338 CustomStat
.TeamStat
:= gTeamStat
;
1340 CustomStat
.PlayerStat
:= nil;
1342 // Статистика игроков:
1343 if gPlayers
<> nil then
1345 for a
:= 0 to High(gPlayers
) do
1346 if gPlayers
[a
] <> nil then
1348 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1349 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1352 Name
:= gPlayers
[a
].Name
;
1353 Frags
:= gPlayers
[a
].Frags
;
1354 Deaths
:= gPlayers
[a
].Death
;
1355 Kills
:= gPlayers
[a
].Kills
;
1356 Team
:= gPlayers
[a
].Team
;
1357 Color
:= gPlayers
[a
].Model
.Color
;
1358 Spectator
:= gPlayers
[a
].FSpectator
;
1362 SortGameStat(CustomStat
.PlayerStat
);
1364 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1367 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1368 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1369 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1370 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1372 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1375 StatShotDone
:= False;
1378 g_Game_ExecuteEvent('onmapend');
1379 if not g_Game_IsClient
then g_Player_ResetReady
;
1380 gInterReadyCount
:= 0;
1382 // Затухающий экран:
1383 EndingGameCounter
:= 255;
1384 gState
:= STATE_FOLD
;
1386 if gDefInterTime
< 0 then
1387 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1389 gInterEndTime
:= gDefInterTime
* 1000;
1392 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1394 // Статистика Одиночной игры:
1395 SingleStat
.GameTime
:= gTime
;
1396 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1397 SingleStat
.TotalSecrets
:= gSecretsCount
;
1398 // Статистика первого игрока:
1399 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1400 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1401 // Статистика второго игрока (если есть):
1402 if SingleStat
.TwoPlayers
then
1404 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1405 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1408 g_Game_ExecuteEvent('onmapend');
1411 if gNextMap
<> '' then
1413 gMusic
.SetByName('MUSIC_INTERMUS');
1415 gState
:= STATE_INTERSINGLE
;
1418 g_Game_ExecuteEvent('oninter');
1420 else // Больше нет карт
1422 // Затухающий экран:
1423 EndingGameCounter
:= 255;
1424 gState
:= STATE_FOLD
;
1429 // Окончание обработано:
1430 if gExit
<> EXIT_QUIT
then
1434 procedure g_Game_Init();
1438 gTempDelete
:= False;
1440 sfsGCDisable(); // temporary disable removing of temporary volumes
1443 g_Game_ClearLoading();
1444 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1445 g_Game_SetLoadingText('', 0, False);
1447 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1450 gPauseMain
:= false;
1451 gPauseHolmes
:= false;
1454 {e_MouseInfo.Accel := 1.0;}
1456 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1459 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1460 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1461 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1462 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1463 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1465 gMusic
:= TMusic
.Create();
1466 gMusic
.SetByName('MUSIC_MENU');
1469 gGameSettings
.WarmupTime
:= 30;
1471 gState
:= STATE_MENU
;
1473 SetLength(gEvents
, 6);
1474 gEvents
[0].Name
:= 'ongamestart';
1475 gEvents
[1].Name
:= 'ongameend';
1476 gEvents
[2].Name
:= 'onmapstart';
1477 gEvents
[3].Name
:= 'onmapend';
1478 gEvents
[4].Name
:= 'oninter';
1479 gEvents
[5].Name
:= 'onwadend';
1481 sfsGCEnable(); // enable releasing unused volumes
1485 procedure g_Game_Free(freeTextures
: Boolean=true);
1487 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1488 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1490 g_Map_Free(freeTextures
);
1492 g_Player_RemoveAllCorpses();
1494 gGameSettings
.GameType
:= GT_NONE
;
1495 if gGameSettings
.GameMode
= GM_SINGLE
then
1496 gGameSettings
.GameMode
:= GM_DM
;
1497 gSwitchGameMode
:= gGameSettings
.GameMode
;
1500 gExitByTrigger
:= False;
1503 function IsActivePlayer(p
: TPlayer
): Boolean;
1508 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1511 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1517 if gPlayers
= nil then
1521 for a
:= Low(gPlayers
) to High(gPlayers
) do
1522 if IsActivePlayer(gPlayers
[a
]) then
1524 SetLength(ids
, Length(ids
) + 1);
1525 ids
[High(ids
)] := gPlayers
[a
].UID
;
1526 if gPlayers
[a
].UID
= Skip
then
1529 if Length(ids
) = 0 then
1534 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1537 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1543 if gPlayers
= nil then
1547 for a
:= Low(gPlayers
) to High(gPlayers
) do
1548 if IsActivePlayer(gPlayers
[a
]) then
1550 SetLength(ids
, Length(ids
) + 1);
1551 ids
[High(ids
)] := gPlayers
[a
].UID
;
1552 if gPlayers
[a
].UID
= Skip
then
1555 if Length(ids
) = 0 then
1558 Result
:= ids
[Length(ids
) - 1]
1560 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1563 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1569 if gPlayers
= nil then
1573 for a
:= Low(gPlayers
) to High(gPlayers
) do
1574 if IsActivePlayer(gPlayers
[a
]) then
1576 SetLength(ids
, Length(ids
) + 1);
1577 ids
[High(ids
)] := gPlayers
[a
].UID
;
1578 if gPlayers
[a
].UID
= Skip
then
1581 if Length(ids
) = 0 then
1583 if Length(ids
) = 1 then
1588 Result
:= ids
[Random(Length(ids
))];
1590 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1592 Result
:= ids
[Random(Length(ids
))];
1597 function GetRandomSpectMode(Current
: Byte): Byte;
1604 0: Result
:= SPECT_STATS
;
1605 1: Result
:= SPECT_MAPVIEW
;
1606 2: Result
:= SPECT_MAPVIEW
;
1607 3: Result
:= SPECT_PLAYERS
;
1608 4: Result
:= SPECT_PLAYERS
;
1609 5: Result
:= SPECT_PLAYERS
;
1610 6: Result
:= SPECT_PLAYERS
;
1612 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1616 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1622 if (plr
= nil) then exit
;
1623 if (p
= 2) then time
:= 1000 else time
:= 1;
1624 strafeDir
:= MoveButton
shr 4;
1625 MoveButton
:= MoveButton
and $0F;
1627 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1628 MoveButton
:= 1 // Нажата только "Влево"
1629 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1630 MoveButton
:= 2 // Нажата только "Вправо"
1631 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1632 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1634 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1635 if MoveButton
= 1 then
1636 plr
.PressKey(KEY_LEFT
, time
)
1637 else if MoveButton
= 2 then
1638 plr
.PressKey(KEY_RIGHT
, time
);
1640 // if we have "strafe" key, turn off old strafe mechanics
1641 if gPlayerAction
[p
, ACTION_STRAFE
] then
1643 // new strafe mechanics
1644 if (strafeDir
= 0) then
1645 strafeDir
:= MoveButton
; // start strafing
1646 // now set direction according to strafe (reversed)
1647 if (strafeDir
= 2) then
1648 plr
.SetDirection(TDirection
.D_LEFT
)
1649 else if (strafeDir
= 1) then
1650 plr
.SetDirection(TDirection
.D_RIGHT
)
1654 strafeDir
:= 0; // not strafing anymore
1655 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1656 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1657 plr
.SetDirection(TDirection
.D_LEFT
)
1658 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1659 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1660 plr
.SetDirection(TDirection
.D_RIGHT
)
1661 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1662 else if MoveButton
<> 0 then
1663 plr
.SetDirection(TDirection(MoveButton
-1))
1666 // fix movebutton state
1667 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1669 // Остальные клавиши:
1670 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1671 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1672 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1673 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1674 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1676 for i
:= WP_FACT
to WP_LACT
do
1678 if gWeaponAction
[p
, i
] then
1680 plr
.ProcessWeaponAction(i
);
1681 gWeaponAction
[p
, i
] := False
1685 for i
:= WP_FIRST
to WP_LAST
do
1687 if gSelectWeapon
[p
, i
] then
1689 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1690 gSelectWeapon
[p
, i
] := False
1694 {$IFDEF ENABLE_MENU}
1695 // HACK: add dynlight here
1696 if gwin_k8_enable_light_experiments
then
1698 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1700 g_playerLight
:= true;
1702 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1704 g_playerLight
:= false;
1708 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1712 // HACK: don't have a "key was pressed" function
1713 procedure InterReady();
1715 if InterReadyTime
> gTime
then Exit
;
1716 InterReadyTime
:= gTime
+ 3000;
1717 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1720 procedure g_Game_PreUpdate();
1722 // these are in separate PreUpdate functions because they can interact during Update()
1723 // and are synced over the net
1724 // we don't care that much about corpses and gibs
1725 g_Player_PreUpdate();
1726 g_Monsters_PreUpdate();
1727 g_Items_PreUpdate();
1728 g_Weapon_PreUpdate();
1731 procedure g_Game_Update();
1733 {$IFDEF ENABLE_MENU}
1734 Msg
: g_gui
.TMessage
;
1741 function sendMonsPos (mon
: TMonster
): Boolean;
1743 result
:= false; // don't stop
1744 // this will also reset "need-send" flag
1745 if mon
.gncNeedSend
then
1747 MH_SEND_MonsterPos(mon
.UID
);
1749 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1751 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1753 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1755 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1759 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1761 result
:= false; // don't stop
1762 // this will also reset "need-send" flag
1763 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1766 function sendItemPos (it
: PItem
): Boolean;
1768 result
:= false; // don't stop
1771 MH_SEND_ItemPos(it
.myId
);
1772 it
.needSend
:= False;
1777 reliableUpdate
: Boolean;
1782 // Пора выключать игру:
1783 if gExit
= EXIT_QUIT
then
1785 // Игра закончилась - обрабатываем:
1789 if gExit
= EXIT_QUIT
then
1793 // Читаем клавиатуру и джойстик, если окно активно
1794 // no need to, as we'll do it in event handler
1796 // Обновляем консоль (движение и сообщения):
1799 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1801 gExit
:= EXIT_SIMPLE
;
1806 // process master server communications
1807 g_Net_Slist_Pulse();
1810 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1811 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1812 STATE_INTERTEXT
, // Текст между уровнями
1813 STATE_INTERPIC
: // Картинка между уровнями
1815 if g_Game_IsNet
and g_Game_IsServer
then
1817 gInterTime
:= gInterTime
+ GAME_TICK
;
1818 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1819 if a
<> gServInterTime
then
1821 gServInterTime
:= a
;
1822 MH_SEND_TimeSync(gServInterTime
);
1826 if (not g_Game_IsClient
) and
1830 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1831 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1832 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1833 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1835 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1836 {$IFDEF ENABLE_MENU}
1837 and (g_ActiveWindow
= nil)
1840 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1843 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1844 g_Game_StopAllSounds(True);
1846 if gMapOnce
then // Это был тест
1847 gExit
:= EXIT_SIMPLE
1849 if gNextMap
<> '' then // Переходим на следующую карту
1850 g_Game_ChangeMap(gNextMap
)
1851 else // Следующей карты нет
1853 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1855 // Выход в главное меню:
1857 {$IFDEF ENABLE_MENU}
1858 g_GUI_ShowWindow('MainMenu');
1859 gMusic
.SetByName('MUSIC_MENU');
1862 gState
:= STATE_MENU
;
1865 // Финальная картинка:
1866 g_Game_ExecuteEvent('onwadend');
1868 if not gMusic
.SetByName('MUSIC_endmus') then
1869 gMusic
.SetByName('MUSIC_STDENDMUS');
1871 gState
:= STATE_ENDPIC
;
1873 g_Game_ExecuteEvent('ongameend');
1878 else if g_Game_IsClient
and
1881 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1882 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1883 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1884 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1886 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1887 {$IFDEF ENABLE_MENU}
1888 and (g_ActiveWindow
= nil)
1897 if gState
= STATE_INTERTEXT
then
1898 if InterText
.counter
> 0 then
1899 InterText
.counter
:= InterText
.counter
- 1;
1902 STATE_FOLD
: // Затухание экрана
1904 if EndingGameCounter
= 0 then
1906 // Закончился уровень в Своей игре:
1907 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1909 gState
:= STATE_INTERCUSTOM
;
1910 InterReadyTime
:= -1;
1911 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1913 g_Game_ExecuteEvent('onwadend');
1914 if not gMusic
.SetByName('MUSIC_endmus') then
1915 gMusic
.SetByName('MUSIC_STDENDMUS');
1918 gMusic
.SetByName('MUSIC_ROUNDMUS');
1922 else // Закончилась последняя карта в Одиночной игре
1924 gMusic
.SetByName('MUSIC_INTERMUS');
1926 gState
:= STATE_INTERSINGLE
;
1929 g_Game_ExecuteEvent('oninter');
1932 DecMin(EndingGameCounter
, 6, 0);
1935 STATE_ENDPIC
: // Картинка окончания мегаВада
1937 if gMapOnce
then // Это был тест
1939 gExit
:= EXIT_SIMPLE
;
1945 g_Serverlist_Control(slCurrent
, slTable
);
1948 // Статистика по Tab:
1950 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1953 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1955 // Время += 28 миллисекунд:
1956 gTime
:= gTime
+ GAME_TICK
;
1958 // Сообщение посередине экрана:
1959 if MessageTime
= 0 then
1961 if MessageTime
> 0 then
1962 MessageTime
:= MessageTime
- 1;
1964 if (g_Game_IsServer
) then
1966 // Был задан лимит времени:
1967 if (gGameSettings
.TimeLimit
> 0) then
1968 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1969 begin // Он прошел => конец уровня
1974 // Надо респавнить игроков в LMS:
1975 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1976 g_Game_RestartRound(gLMSSoftSpawn
);
1978 // Проверим результат голосования, если время прошло
1979 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1981 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1983 g_Console_Process(gVoteCommand
);
1985 gVotePassed
:= False;
1988 // Замеряем время захвата флагов
1989 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1990 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1991 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1992 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1994 // Был задан лимит побед:
1995 if (gGameSettings
.ScoreLimit
> 0) then
1999 if gGameSettings
.GameMode
= GM_DM
then
2000 begin // В DM ищем игрока с max фрагами
2001 for i
:= 0 to High(gPlayers
) do
2002 if gPlayers
[i
] <> nil then
2003 if gPlayers
[i
].Frags
> b
then
2004 b
:= gPlayers
[i
].Frags
;
2007 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2008 begin // В CTF/TDM выбираем команду с наибольшим счетом
2009 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2012 // Лимит побед набран => конец уровня:
2013 if b
>= gGameSettings
.ScoreLimit
then
2020 // Обрабатываем клавиши игроков:
2021 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2022 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2023 {$IFDEF DISABLE_MENU}
2024 if (not gConsoleShow
) and (not gChatShow
) then
2026 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2029 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2030 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2031 end // if not console
2034 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2036 // process weapon switch queue
2040 if (gPlayer1
= nil) and (gPlayer2
= nil)
2041 and (not gConsoleShow
) and (not gChatShow
)
2042 {$IFDEF ENABLE_MENU}
2043 and (g_ActiveWindow
= nil)
2047 if not gSpectKeyPress
then
2049 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2051 // switch spect mode
2053 SPECT_NONE
: ; // not spectator
2055 SPECT_MAPVIEW
: Inc(gSpectMode
);
2056 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2058 gSpectKeyPress
:= True;
2060 if (gSpectMode
= SPECT_MAPVIEW
)
2061 and (not gSpectAuto
) then
2063 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2064 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2065 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2066 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2067 if gPlayerAction
[0, ACTION_LOOKUP
] then
2068 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2069 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2070 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2071 if gWeaponAction
[0, WP_PREV
] then
2074 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2075 gWeaponAction
[0, WP_PREV
] := False;
2077 if gWeaponAction
[0, WP_NEXT
] then
2080 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2081 gWeaponAction
[0, WP_NEXT
] := False;
2084 if (gSpectMode
= SPECT_PLAYERS
)
2085 and (not gSpectAuto
) then
2087 if gPlayerAction
[0, ACTION_LOOKUP
] then
2090 gSpectViewTwo
:= True;
2091 gSpectKeyPress
:= True;
2093 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2095 // remove second view
2096 gSpectViewTwo
:= False;
2097 gSpectKeyPress
:= True;
2099 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2101 // prev player (view 1)
2102 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2103 gSpectKeyPress
:= True;
2105 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2107 // next player (view 1)
2108 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2109 gSpectKeyPress
:= True;
2111 if gWeaponAction
[0, WP_PREV
] then
2113 // prev player (view 2)
2114 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2115 gWeaponAction
[0, WP_PREV
] := False;
2117 if gWeaponAction
[0, WP_NEXT
] then
2119 // next player (view 2)
2120 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2121 gWeaponAction
[0, WP_NEXT
] := False;
2124 if gPlayerAction
[0, ACTION_ATTACK
] then
2126 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2129 gSpectAutoNext
:= 0;
2130 gSpectViewTwo
:= False;
2131 gSpectKeyPress
:= True;
2136 gSpectMode
:= SPECT_STATS
;
2137 gSpectAuto
:= False;
2138 gSpectKeyPress
:= True;
2143 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2144 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2145 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2146 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2147 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2148 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2149 gSpectKeyPress
:= False;
2153 if gSpectMode
= SPECT_MAPVIEW
then
2155 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2157 gSpectAutoNext
:= gTime
2160 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2162 gSpectAutoNext
:= gTime
2166 if gSpectAutoNext
<= gTime
then
2168 if gSpectAutoNext
> 0 then
2170 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2174 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2175 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2176 gSpectAutoStepX
:= Random(9) - 4;
2177 gSpectAutoStepY
:= Random(9) - 4;
2178 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2179 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2180 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2181 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2182 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2183 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2187 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2192 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2193 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2194 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2200 // Обновляем все остальное:
2203 g_Triggers_Update();
2205 g_Monsters_Update();
2207 g_Player_UpdateAll();
2208 g_Player_UpdatePhysicalObjects();
2210 // server: send newly spawned monsters unconditionally
2211 if (gGameSettings
.GameType
= GT_SERVER
) then
2213 if (Length(gMonstersSpawned
) > 0) then
2215 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2216 SetLength(gMonstersSpawned
, 0);
2220 if (gSoundTriggerTime
> 8) then
2222 g_Game_UpdateTriggerSounds();
2223 gSoundTriggerTime
:= 0;
2227 Inc(gSoundTriggerTime
);
2230 if (NetMode
= NET_SERVER
) then
2232 Inc(NetTimeToUpdate
);
2233 Inc(NetTimeToReliable
);
2235 // send monster updates
2236 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2238 // send all monsters (periodic sync)
2239 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2241 for I
:= 0 to High(gPlayers
) do
2243 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2246 g_Mons_ForEach(sendMonsPos
);
2248 // update flags that aren't stationary
2249 if gGameSettings
.GameMode
= GM_CTF
then
2250 for I
:= FLAG_RED
to FLAG_BLUE
do
2251 if gFlags
[I
].NeedSend
then
2253 gFlags
[I
].NeedSend
:= False;
2257 // update items that aren't stationary
2258 g_Items_ForEachAlive(sendItemPos
);
2260 if reliableUpdate
then
2262 NetTimeToReliable
:= 0;
2263 NetTimeToUpdate
:= NetUpdateRate
;
2267 NetTimeToUpdate
:= 0;
2272 // send only mosters with some unexpected changes
2273 g_Mons_ForEach(sendMonsPosUnexpected
);
2276 // send unexpected platform changes
2277 g_Map_NetSendInterestingPanels();
2279 g_Net_Slist_ServerUpdate();
2281 if NetUseMaster then
2283 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2285 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2287 NetTimeToMaster := gTime + NetMasterRate;
2292 else if (NetMode
= NET_CLIENT
) then
2294 MC_SEND_PlayerPos();
2296 end; // if gameOn ...
2298 // Активно окно интерфейса - передаем клавиши ему:
2299 {$IFDEF ENABLE_MENU}
2300 if g_ActiveWindow
<> nil then
2302 w
:= e_GetFirstKeyPressed();
2304 if (w
<> IK_INVALID
) then
2306 Msg
.Msg
:= MESSAGE_DIKEY
;
2308 g_ActiveWindow
.OnMessage(Msg
);
2311 // Если оно от этого не закрылось, то обновляем:
2312 if g_ActiveWindow
<> nil then
2313 g_ActiveWindow
.Update();
2315 // Нужно сменить разрешение:
2316 if gResolutionChange
then
2319 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2322 gResolutionChange
:= False;
2323 g_ActiveWindow
:= nil;
2326 // Нужно сменить язык:
2327 if gLanguageChange
then
2329 //e_WriteLog('Read language file', MSG_NOTIFY);
2330 //g_Language_Load(DataDir + gLanguage + '.txt');
2331 g_Language_Set(gLanguage
);
2333 gLanguageChange
:= False;
2337 // Горячая клавиша для вызова меню выхода из игры (F10):
2338 if e_KeyPressed(IK_F10
) and
2340 (not gConsoleShow
) and
2341 (g_ActiveWindow
= nil) then
2347 Time
:= GetTickCount64() {div 1000};
2349 // Обработка отложенных событий:
2350 if gDelayedEvents
<> nil then
2351 for a
:= 0 to High(gDelayedEvents
) do
2352 if gDelayedEvents
[a
].Pending
and
2354 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2355 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2358 case gDelayedEvents
[a
].DEType
of
2360 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2363 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2367 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2368 if g_Game_IsNet
and g_Game_IsServer
then
2369 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2373 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2375 gDelayedEvents
[a
].Pending
:= False;
2378 // Каждую секунду обновляем счетчик обновлений:
2379 UPSCounter
:= UPSCounter
+ 1;
2380 if Time
- UPSTime
>= 1000 then
2389 g_Weapon_AddDynLights();
2390 g_Items_AddDynLights();
2394 procedure g_Game_LoadChatSounds(Resource
: string);
2397 FileName
, Snd
: string;
2399 len
, cnt
, tags
, i
, j
: Integer;
2402 FileName
:= g_ExtractWadName(Resource
);
2404 WAD
:= TWADFile
.Create();
2405 WAD
.ReadFile(FileName
);
2407 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2414 cfg
:= TConfig
.CreateMem(p
, len
);
2415 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2417 SetLength(gChatSounds
, cnt
);
2418 for i
:= 0 to Length(gChatSounds
) - 1 do
2420 gChatSounds
[i
].Sound
:= nil;
2421 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2422 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2423 if (Snd
= '') or (Tags
<= 0) then
2425 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2426 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2427 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2428 SetLength(gChatSounds
[i
].Tags
, tags
);
2429 for j
:= 0 to tags
- 1 do
2430 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2431 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2438 procedure g_Game_FreeChatSounds();
2442 for i
:= 0 to Length(gChatSounds
) - 1 do
2444 gChatSounds
[i
].Sound
.Free();
2445 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2447 SetLength(gChatSounds
, 0);
2451 procedure g_Game_LoadData();
2453 if DataLoaded
then Exit
;
2455 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2457 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2458 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2459 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2460 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2461 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2462 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2463 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2464 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2465 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2466 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2467 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2468 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2469 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2470 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2471 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2472 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2473 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2474 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2475 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2476 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2477 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2478 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2479 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2480 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2481 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2482 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2483 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2484 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2485 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2486 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2487 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2488 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2490 goodsnd
[0] := TPlayableSound
.Create();
2491 goodsnd
[1] := TPlayableSound
.Create();
2492 goodsnd
[2] := TPlayableSound
.Create();
2493 goodsnd
[3] := TPlayableSound
.Create();
2495 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2496 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2497 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2498 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2500 killsnd
[0] := TPlayableSound
.Create();
2501 killsnd
[1] := TPlayableSound
.Create();
2502 killsnd
[2] := TPlayableSound
.Create();
2503 killsnd
[3] := TPlayableSound
.Create();
2505 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2506 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2507 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2508 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2510 hahasnd
[0] := TPlayableSound
.Create();
2511 hahasnd
[1] := TPlayableSound
.Create();
2512 hahasnd
[2] := TPlayableSound
.Create();
2514 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2515 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2516 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2518 sound_get_flag
[0] := TPlayableSound
.Create();
2519 sound_get_flag
[1] := TPlayableSound
.Create();
2520 sound_lost_flag
[0] := TPlayableSound
.Create();
2521 sound_lost_flag
[1] := TPlayableSound
.Create();
2522 sound_ret_flag
[0] := TPlayableSound
.Create();
2523 sound_ret_flag
[1] := TPlayableSound
.Create();
2524 sound_cap_flag
[0] := TPlayableSound
.Create();
2525 sound_cap_flag
[1] := TPlayableSound
.Create();
2527 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2528 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2529 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2530 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2531 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2532 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2533 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2534 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2536 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2538 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2541 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2542 g_Weapon_LoadData();
2544 g_Monsters_LoadData();
2549 procedure g_Game_Quit();
2551 g_Game_StopAllSounds(True);
2554 g_PlayerModel_FreeData();
2556 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2559 if NetInitDone
then g_Net_Free
;
2561 // remove map after test
2562 if gMapToDelete
<> '' then
2563 g_Game_DeleteTestMap();
2572 procedure g_Game_FreeData();
2574 if not DataLoaded
then Exit
;
2577 g_Weapon_FreeData();
2578 g_Monsters_FreeData();
2580 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2582 g_Sound_Delete('SOUND_GAME_TELEPORT');
2583 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2584 g_Sound_Delete('SOUND_GAME_SECRET');
2585 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2586 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2587 g_Sound_Delete('SOUND_GAME_BULK1');
2588 g_Sound_Delete('SOUND_GAME_BULK2');
2589 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2590 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2591 g_Sound_Delete('SOUND_GAME_BURNING');
2592 g_Sound_Delete('SOUND_GAME_SWITCH1');
2593 g_Sound_Delete('SOUND_GAME_SWITCH0');
2600 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2601 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2602 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2603 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2610 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2611 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2612 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2613 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2619 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2620 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2621 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2623 sound_get_flag
[0].Free();
2624 sound_get_flag
[1].Free();
2625 sound_lost_flag
[0].Free();
2626 sound_lost_flag
[1].Free();
2627 sound_ret_flag
[0].Free();
2628 sound_ret_flag
[1].Free();
2629 sound_cap_flag
[0].Free();
2630 sound_cap_flag
[1].Free();
2632 g_Sound_Delete('SOUND_CTF_GET1');
2633 g_Sound_Delete('SOUND_CTF_GET2');
2634 g_Sound_Delete('SOUND_CTF_LOST1');
2635 g_Sound_Delete('SOUND_CTF_LOST2');
2636 g_Sound_Delete('SOUND_CTF_RETURN1');
2637 g_Sound_Delete('SOUND_CTF_RETURN2');
2638 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2639 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2641 g_Game_FreeChatSounds();
2643 DataLoaded
:= False;
2646 procedure g_FatalError(Text: String);
2648 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2649 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2651 gExit
:= EXIT_SIMPLE
;
2652 if gGameOn
then EndGame
;
2655 procedure g_SimpleError(Text: String);
2657 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2658 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2661 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2663 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2664 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2667 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2670 if gPlayer1
= nil then
2672 if g_Game_IsClient
then
2674 if NetPlrUID1
> -1 then
2675 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2679 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2680 Team
:= gPlayer1Settings
.Team
;
2682 // Создание первого игрока:
2683 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2684 gPlayer1Settings
.Color
,
2686 if gPlayer1
= nil then
2687 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2690 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2691 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2692 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2693 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2694 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2695 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2696 if g_Game_IsServer
and g_Game_IsNet
then
2697 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2698 gPlayer1
.Respawn(False, True);
2699 g_Net_Slist_ServerPlayerComes();
2704 if gPlayer2
= nil then
2706 if g_Game_IsClient
then
2708 if NetPlrUID2
> -1 then
2709 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2713 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2714 Team
:= gPlayer2Settings
.Team
;
2716 // Создание второго игрока:
2717 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2718 gPlayer2Settings
.Color
,
2720 if gPlayer2
= nil then
2721 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2724 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2725 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2726 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2727 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2728 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2729 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2730 if g_Game_IsServer
and g_Game_IsNet
then
2731 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2732 gPlayer2
.Respawn(False, True);
2733 g_Net_Slist_ServerPlayerComes();
2740 procedure g_Game_RemovePlayer();
2744 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2745 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2750 if g_Game_IsServer
then
2753 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2754 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2755 g_Player_Remove(Pl
.UID
);
2756 g_Net_Slist_ServerPlayerLeaves();
2760 gSpectLatchPID2
:= Pl
.UID
;
2768 if g_Game_IsServer
then
2771 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2772 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2773 g_Player_Remove(Pl
.UID
);
2774 g_Net_Slist_ServerPlayerLeaves();
2777 gSpectLatchPID1
:= Pl
.UID
;
2779 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2783 g_Net_Slist_ServerPlayerLeaves();
2786 procedure g_Game_Spectate();
2788 g_Game_RemovePlayer();
2789 if gPlayer1
<> nil then
2790 g_Game_RemovePlayer();
2793 procedure g_Game_SpectateCenterView();
2795 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2796 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2799 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2806 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2808 g_Game_ClearLoading();
2811 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2814 gGameSettings
.GameType
:= GT_SINGLE
;
2815 gGameSettings
.MaxLives
:= 0;
2816 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2817 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2818 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2819 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2820 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2821 gSwitchGameMode
:= GM_SINGLE
;
2823 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2824 gLMSRespawnTime
:= 0;
2825 gSpectLatchPID1
:= 0;
2826 gSpectLatchPID2
:= 0;
2828 g_Game_ExecuteEvent('ongamestart');
2830 // Создание первого игрока:
2831 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2832 gPlayer1Settings
.Color
,
2833 gPlayer1Settings
.Team
, False));
2834 if gPlayer1
= nil then
2836 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2840 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2841 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2842 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2843 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2844 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2847 // Создание второго игрока, если есть:
2850 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2851 gPlayer2Settings
.Color
,
2852 gPlayer2Settings
.Team
, False));
2853 if gPlayer2
= nil then
2855 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2859 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2860 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2861 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2862 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2863 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2867 // Загрузка и запуск карты:
2868 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2870 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2871 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2875 // Настройки игроков и ботов:
2879 for i
:= nPl
+1 to nPlayers
do
2880 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2883 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2884 TimeLimit
, ScoreLimit
: Word;
2886 Options
: LongWord; nPlayers
: Byte);
2892 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2894 g_Game_ClearLoading();
2897 gGameSettings
.GameType
:= GT_CUSTOM
;
2898 gGameSettings
.GameMode
:= GameMode
;
2899 gSwitchGameMode
:= GameMode
;
2900 gGameSettings
.TimeLimit
:= TimeLimit
;
2901 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2902 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2903 gGameSettings
.Options
:= Options
;
2905 gCoopTotalMonstersKilled
:= 0;
2906 gCoopTotalSecretsFound
:= 0;
2907 gCoopTotalMonsters
:= 0;
2908 gCoopTotalSecrets
:= 0;
2912 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2913 gLMSRespawnTime
:= 0;
2914 gSpectLatchPID1
:= 0;
2915 gSpectLatchPID2
:= 0;
2917 g_Game_ExecuteEvent('ongamestart');
2919 // Режим наблюдателя:
2920 if nPlayers
= 0 then
2927 if nPlayers
>= 1 then
2929 // Создание первого игрока:
2930 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2931 gPlayer1Settings
.Color
,
2932 gPlayer1Settings
.Team
, False));
2933 if gPlayer1
= nil then
2935 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2939 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2940 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2941 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2942 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2943 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2947 if nPlayers
>= 2 then
2949 // Создание второго игрока:
2950 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2951 gPlayer2Settings
.Color
,
2952 gPlayer2Settings
.Team
, False));
2953 if gPlayer2
= nil then
2955 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2959 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2960 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2961 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2962 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2963 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2967 // Загрузка и запуск карты:
2968 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
2970 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2974 // Нет точек появления:
2975 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2976 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2977 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2978 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2979 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2981 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2985 // Настройки игроков и ботов:
2989 for i
:= nPl
+1 to nPlayers
do
2990 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2993 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
2994 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
2995 Options
: LongWord; nPlayers
: Byte;
2996 IPAddr
: LongWord; Port
: Word);
2999 g_Net_Slist_ServerClosed();
3001 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3003 g_Game_ClearLoading();
3008 gGameSettings
.GameType
:= GT_SERVER
;
3009 gGameSettings
.GameMode
:= GameMode
;
3010 gSwitchGameMode
:= GameMode
;
3011 gGameSettings
.TimeLimit
:= TimeLimit
;
3012 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3013 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3014 gGameSettings
.Options
:= Options
;
3016 gCoopTotalMonstersKilled
:= 0;
3017 gCoopTotalSecretsFound
:= 0;
3018 gCoopTotalMonsters
:= 0;
3019 gCoopTotalSecrets
:= 0;
3023 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3024 gLMSRespawnTime
:= 0;
3025 gSpectLatchPID1
:= 0;
3026 gSpectLatchPID2
:= 0;
3028 g_Game_ExecuteEvent('ongamestart');
3030 // Режим наблюдателя:
3031 if nPlayers
= 0 then
3037 if nPlayers
>= 1 then
3039 // Создание первого игрока:
3040 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3041 gPlayer1Settings
.Color
,
3042 gPlayer1Settings
.Team
, False));
3043 if gPlayer1
= nil then
3045 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3049 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3050 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3051 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3052 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3053 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3056 if nPlayers
>= 2 then
3058 // Создание второго игрока:
3059 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3060 gPlayer2Settings
.Color
,
3061 gPlayer2Settings
.Team
, False));
3062 if gPlayer2
= nil then
3064 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3068 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3069 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3070 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3071 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3072 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3075 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3076 if NetForwardPorts
then
3077 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3080 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3082 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3086 g_Net_Slist_Set(NetMasterList
);
3088 g_Net_Slist_ServerStarted();
3090 // Загрузка и запуск карты:
3091 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3093 g_Net_Slist_ServerClosed();
3094 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3098 // Нет точек появления:
3099 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3100 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3101 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3102 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3103 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3105 g_Net_Slist_ServerClosed();
3106 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3110 // Настройки игроков и ботов:
3113 g_Net_Slist_ServerMapStarted();
3114 NetState
:= NET_STATE_GAME
;
3117 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3132 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3133 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3135 g_Game_ClearLoading();
3140 gGameSettings
.GameType
:= GT_CLIENT
;
3142 gCoopTotalMonstersKilled
:= 0;
3143 gCoopTotalSecretsFound
:= 0;
3144 gCoopTotalMonsters
:= 0;
3145 gCoopTotalSecrets
:= 0;
3149 g_Game_ExecuteEvent('ongamestart');
3151 NetState
:= NET_STATE_AUTH
;
3153 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3155 // create (or update) map/resource databases
3156 g_Res_CreateDatabases(true);
3158 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3159 gLMSRespawnTime
:= 0;
3160 gSpectLatchPID1
:= 0;
3161 gSpectLatchPID2
:= 0;
3164 if not g_Net_Connect(Addr
, Port
) then
3166 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3167 NetState
:= NET_STATE_NONE
;
3171 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3173 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3178 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3179 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3180 // thank you, enet. let's ignore failures altogether then.
3181 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3183 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3185 Ptr
:= NetEvent
.packet
^.data
;
3186 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3188 enet_packet_destroy(NetEvent
.packet
);
3192 InMsg
.ReadLongWord(); // skip size
3193 MID
:= InMsg
.ReadByte();
3195 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3197 NetMyID
:= InMsg
.ReadByte();
3198 NetPlrUID1
:= InMsg
.ReadWord();
3200 WadName
:= InMsg
.ReadString();
3201 Map
:= InMsg
.ReadString();
3203 gWADHash
:= InMsg
.ReadMD5();
3205 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3206 gSwitchGameMode
:= gGameSettings
.GameMode
;
3207 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3208 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3209 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3210 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3211 T
:= InMsg
.ReadLongWord();
3213 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3214 //if newResPath = '' then
3216 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3217 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3218 if newResPath
= '' then
3220 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3221 enet_packet_destroy(NetEvent
.packet
);
3222 NetState
:= NET_STATE_NONE
;
3225 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3227 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3230 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3231 gPlayer1Settings
.Color
,
3232 gPlayer1Settings
.Team
, False));
3234 if gPlayer1
= nil then
3236 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3238 enet_packet_destroy(NetEvent
.packet
);
3239 NetState
:= NET_STATE_NONE
;
3243 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3244 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3245 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3246 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3247 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3248 gPlayer1
.UID
:= NetPlrUID1
;
3249 gPlayer1
.Reset(True);
3251 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3253 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3255 enet_packet_destroy(NetEvent
.packet
);
3256 NetState
:= NET_STATE_NONE
;
3264 enet_packet_destroy(NetEvent
.packet
);
3268 enet_packet_destroy(NetEvent
.packet
);
3272 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3275 if (NetEvent
.data
<= NET_DISC_MAX
) then
3276 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3277 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3284 ProcessLoading(True);
3285 if g_Net_UserRequestExit() then
3294 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3295 NetState
:= NET_STATE_NONE
;
3300 NetState
:= NET_STATE_GAME
;
3301 MC_SEND_FullStateRequest
;
3302 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3306 lastAsMegaWad
: Boolean = false;
3308 procedure g_Game_ChangeMap(const MapPath
: String);
3312 g_Game_ClearLoading();
3314 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3315 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3316 if gExitByTrigger
then
3319 gExitByTrigger
:= False;
3321 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3322 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3325 procedure g_Game_Restart();
3329 if g_Game_IsClient
then
3331 map
:= g_ExtractFileName(gMapInfo
.Map
);
3332 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3336 g_Game_ClearLoading();
3337 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3340 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3342 NewWAD
, ResName
: String;
3346 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3347 g_Player_RemoveAllCorpses();
3349 if (not g_Game_IsClient
) and
3350 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3351 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3353 if gSwitchGameMode
= GM_CTF
then
3354 gGameSettings
.MaxLives
:= 0;
3355 gGameSettings
.GameMode
:= gSwitchGameMode
;
3358 gSwitchGameMode
:= gGameSettings
.GameMode
;
3360 g_Player_ResetTeams();
3362 lastAsMegaWad
:= asMegawad
;
3363 if isWadPath(Map
) then
3365 NewWAD
:= g_ExtractWadName(Map
);
3366 ResName
:= g_ExtractFileName(Map
);
3367 if g_Game_IsServer
then
3369 nws
:= findDiskWad(NewWAD
);
3370 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3373 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3374 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3378 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3379 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3381 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3382 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3384 if (length(nws
) = 0) then
3386 ResName
:= ''; // failed
3391 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3392 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3393 g_Game_LoadWAD(NewWAD
);
3398 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3399 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3404 NewWAD
:= gGameSettings
.WAD
;
3410 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3412 if (ResName
<> '') and (NewWAD
<> '') then
3414 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3415 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3417 r_Render_LoadTextures
;
3422 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3424 gState
:= STATE_NONE
;
3425 {$IFDEF ENABLE_MENU}
3426 g_ActiveWindow
:= nil;
3431 wNeedTimeReset
:= True;
3433 if gGameSettings
.GameMode
= GM_CTF
then
3435 g_Map_ResetFlag(FLAG_RED
);
3436 g_Map_ResetFlag(FLAG_BLUE
);
3437 // CTF, а флагов нет:
3438 if not g_Map_HaveFlagPoints() then
3439 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3444 gState
:= STATE_MENU
;
3449 gPauseMain
:= false;
3450 gPauseHolmes
:= false;
3451 NetTimeToUpdate
:= 1;
3452 NetTimeToReliable
:= 0;
3453 NetTimeToMaster
:= NetMasterRate
;
3454 gSpectLatchPID1
:= 0;
3455 gSpectLatchPID2
:= 0;
3456 gMissionFailed
:= False;
3459 gCoopMonstersKilled
:= 0;
3460 gCoopSecretsFound
:= 0;
3462 gVoteInProgress
:= False;
3463 gVotePassed
:= False;
3469 if not gGameOn
then Exit
;
3471 g_Game_SpectateCenterView();
3473 if g_Game_IsServer
then
3475 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3477 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3478 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3479 gLMSSoftSpawn
:= True;
3480 if g_Game_IsNet
then
3481 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3485 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3486 gLMSRespawnTime
:= 0;
3490 if NetMode
= NET_SERVER
then
3492 // reset full state flags
3493 if NetClients
<> nil then
3494 for I
:= 0 to High(NetClients
) do
3495 NetClients
[I
].FullUpdateSent
:= False;
3497 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3500 g_Net_Slist_ServerMapStarted();
3502 if NetClients
<> nil then
3503 for I
:= 0 to High(NetClients
) do
3504 if NetClients
[I
].Used
then
3506 NetClients
[I
].Voted
:= False;
3507 if NetClients
[I
].RequestedFullUpdate
then
3509 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3510 NetClients
[I
].RequestedFullUpdate
:= False;
3514 g_Net_UnbanNonPermHosts();
3519 gCoopTotalMonstersKilled
:= 0;
3520 gCoopTotalSecretsFound
:= 0;
3521 gCoopTotalMonsters
:= 0;
3522 gCoopTotalSecrets
:= 0;
3526 g_Game_ExecuteEvent('onmapstart');
3529 procedure SetFirstLevel
;
3533 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3534 if MapList
= nil then
3537 SortSArray(MapList
);
3538 gNextMap
:= MapList
[Low(MapList
)];
3543 procedure g_Game_ExitLevel(const Map
: AnsiString);
3547 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3548 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3549 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3550 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3552 // Вышли в выход в Одиночной игре:
3553 if gGameSettings
.GameType
= GT_SINGLE
then
3554 gExit
:= EXIT_ENDLEVELSINGLE
3555 else // Вышли в выход в Своей игре
3557 gExit
:= EXIT_ENDLEVELCUSTOM
;
3558 if gGameSettings
.GameMode
= GM_COOP
then
3559 g_Player_RememberAll
;
3561 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3564 if gGameSettings
.GameMode
= GM_COOP
then
3567 gStatsPressed
:= True;
3568 gNextMap
:= 'MAP01';
3570 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3573 if g_Game_IsNet
then
3575 MH_SEND_GameStats();
3576 MH_SEND_CoopStats();
3582 procedure g_Game_RestartLevel();
3586 if gGameSettings
.GameMode
= GM_SINGLE
then
3591 gExit
:= EXIT_ENDLEVELCUSTOM
;
3592 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3596 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3598 gWAD
{, xwad}: String;
3601 if not g_Game_IsClient
then Exit
;
3602 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3604 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3609 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3613 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3616 g_Game_LoadWAD(NewWAD
);
3620 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3621 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3624 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3625 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3629 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3633 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3634 g_Game_LoadWAD(NewWAD);
3638 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3640 i
, n
, nb
, nr
: Integer;
3642 if not g_Game_IsServer
then Exit
;
3643 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3644 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3645 gLMSRespawnTime
:= 0;
3648 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3650 gMissionFailed
:= True;
3651 g_Game_RestartLevel
;
3655 n
:= 0; nb
:= 0; nr
:= 0;
3656 for i
:= Low(gPlayers
) to High(gPlayers
) do
3657 if (gPlayers
[i
] <> nil) and
3658 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3659 (gPlayers
[i
] is TBot
)) then
3662 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3663 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3666 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3668 // wait a second until the fuckers finally decide to join
3669 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3670 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3671 gLMSSoftSpawn
:= NoMapRestart
;
3672 if g_Game_IsNet
then
3673 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3677 g_Player_RemoveAllCorpses
;
3678 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3679 if g_Game_IsNet
then
3680 MH_SEND_GameEvent(NET_EV_LMS_START
);
3682 for i
:= Low(gPlayers
) to High(gPlayers
) do
3684 if gPlayers
[i
] = nil then continue
;
3685 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3686 // don't touch normal spectators
3687 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3689 gPlayers
[i
].FNoRespawn
:= True;
3690 gPlayers
[i
].Lives
:= 0;
3691 if g_Game_IsNet
then
3692 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3695 gPlayers
[i
].FNoRespawn
:= False;
3696 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3697 gPlayers
[i
].Respawn(False, True);
3698 if gGameSettings
.GameMode
= GM_COOP
then
3700 gPlayers
[i
].Frags
:= 0;
3701 gPlayers
[i
].RecallState
;
3703 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3704 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3705 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3706 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3709 g_Items_RestartRound();
3711 gLMSSoftSpawn
:= False;
3714 function g_Game_GetFirstMap(WAD
: String): String;
3718 MapList
:= g_Map_GetMapsList(WAD
);
3719 if MapList
= nil then
3722 SortSArray(MapList
);
3723 Result
:= MapList
[Low(MapList
)];
3725 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3731 function g_Game_GetNextMap(): String;
3738 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3739 if MapList
= nil then
3742 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3744 SortSArray(MapList
);
3746 for I
:= Low(MapList
) to High(MapList
) do
3747 if Map
= MapList
[I
] then
3753 if MapIndex
<> -255 then
3755 if MapIndex
= High(MapList
) then
3756 Result
:= MapList
[Low(MapList
)]
3758 Result
:= MapList
[MapIndex
+ 1];
3760 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3766 procedure g_Game_NextLevel();
3768 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3769 gExit
:= EXIT_ENDLEVELCUSTOM
3772 gExit
:= EXIT_ENDLEVELSINGLE
;
3776 if gNextMap
<> '' then Exit
;
3777 gNextMap
:= g_Game_GetNextMap();
3780 function g_Game_IsTestMap(): Boolean;
3782 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3785 procedure g_Game_DeleteTestMap();
3788 //MapName: AnsiString;
3796 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3797 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3798 if (a
= 0) then exit
;
3800 // Выделяем имя wad-файла и имя карты
3801 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3802 Delete(gMapToDelete
, 1, a
+5);
3803 gMapToDelete
:= UpperCase(gMapToDelete
);
3805 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3808 // Имя карты не стандартное тестовое:
3809 if MapName <> TEST_MAP_NAME then
3812 if not gTempDelete then
3814 time := g_GetFileTime(WadName);
3815 WAD := TWADFile.Create();
3818 if not WAD.ReadFile(WadName) then
3819 begin // Нет такого WAD-файла
3824 // Составляем список карт и ищем нужную:
3826 MapList := WAD.GetResourcesList('');
3828 if MapList <> nil then
3829 for a := 0 to High(MapList) do
3830 if MapList[a] = MapName then
3832 // Удаляем и сохраняем:
3833 WAD.RemoveResource('', MapName);
3834 WAD.SaveTo(WadName);
3839 g_SetFileTime(WadName, time);
3842 if gTempDelete
then DeleteFile(WadName
);
3845 procedure GameCVars(P
: SSArray
);
3848 stat
: TPlayerStatArray
;
3851 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3855 if Length(P
) > 1 then
3860 gsGameFlags
:= gsGameFlags
or Flag
3862 gsGameFlags
:= gsGameFlags
and (not Flag
);
3864 if g_Game_IsServer
then
3867 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3869 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3870 if g_Game_IsNet
then MH_SEND_GameSettings
;
3874 if LongBool(gsGameFlags
and Flag
) then
3875 g_Console_Add(_lc
[OnMsg
])
3877 g_Console_Add(_lc
[OffMsg
]);
3879 if OnMapChange
and g_Game_IsServer
then
3880 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3885 cmd
:= LowerCase(P
[0]);
3887 if cmd
= 'g_gamemode' then
3889 if (Length(P
) > 1) then
3891 a
:= g_Game_TextToMode(P
[1]);
3892 if a
= GM_SINGLE
then a
:= GM_COOP
;
3893 gsGameMode
:= g_Game_ModeToText(a
);
3894 if g_Game_IsServer
then
3896 gSwitchGameMode
:= a
;
3897 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3898 (gState
= STATE_INTERSINGLE
) then
3899 gSwitchGameMode
:= GM_SINGLE
;
3901 gGameSettings
.GameMode
:= gSwitchGameMode
;
3905 if gSwitchGameMode
= gGameSettings
.GameMode
then
3906 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3907 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3909 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3910 [g_Game_ModeToText(gGameSettings
.GameMode
),
3911 g_Game_ModeToText(gSwitchGameMode
)]));
3913 else if cmd
= 'g_friendlyfire' then
3915 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3917 else if cmd
= 'g_friendly_absorb_damage' then
3919 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
3921 else if cmd
= 'g_friendly_hit_trace' then
3923 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
3925 else if cmd
= 'g_friendly_hit_projectile' then
3927 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
3929 else if cmd
= 'g_weaponstay' then
3931 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3933 else if cmd
= 'g_allow_exit' then
3935 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3937 else if cmd
= 'g_allow_monsters' then
3939 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3941 else if cmd
= 'g_allow_dropflag' then
3943 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
3945 else if cmd
= 'g_throw_flag' then
3947 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
3949 else if cmd
= 'g_bot_vsplayers' then
3951 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3953 else if cmd
= 'g_bot_vsmonsters' then
3955 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3957 else if cmd
= 'g_dm_keys' then
3959 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
3961 else if cmd
= 'g_gameflags' then
3963 if Length(P
) > 1 then
3965 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
3966 if g_Game_IsServer
then
3968 gGameSettings
.Options
:= gsGameFlags
;
3969 if g_Game_IsNet
then MH_SEND_GameSettings
;
3973 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
3975 else if cmd
= 'g_warmup_time' then
3977 if Length(P
) > 1 then
3979 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
3980 if g_Game_IsServer
then
3982 gGameSettings
.WarmupTime
:= gsWarmupTime
;
3983 // extend warmup if it's already going
3984 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
3986 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
3987 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3989 if g_Game_IsNet
then MH_SEND_GameSettings
;
3993 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
3994 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3996 else if cmd
= 'g_spawn_invul' then
3998 if Length(P
) > 1 then
4000 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4001 if g_Game_IsServer
then
4003 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4004 if g_Game_IsNet
then MH_SEND_GameSettings
;
4008 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4010 else if cmd
= 'g_item_respawn_time' then
4012 if Length(P
) > 1 then
4014 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4015 if g_Game_IsServer
then
4017 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4018 if g_Game_IsNet
then MH_SEND_GameSettings
;
4022 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4023 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4025 else if cmd
= 'sv_intertime' then
4027 if (Length(P
) > 1) then
4028 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4030 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4032 else if cmd
= 'g_max_particles' then
4034 if Length(p
) = 2 then
4036 a
:= Max(0, StrToIntDef(p
[1], 0));
4039 else if Length(p
) = 1 then
4041 e_LogWritefln('%s', [g_GFX_GetMax()])
4045 e_LogWritefln('usage: %s <n>', [cmd
])
4048 else if cmd
= 'g_max_shells' then
4050 if Length(p
) = 2 then
4052 a
:= Max(0, StrToIntDef(p
[1], 0));
4055 else if Length(p
) = 1 then
4057 e_LogWritefln('%s', [g_Shells_GetMax()])
4061 e_LogWritefln('usage: %s <n>', [cmd
])
4064 else if cmd
= 'g_max_gibs' then
4066 if Length(p
) = 2 then
4068 a
:= Max(0, StrToIntDef(p
[1], 0));
4071 else if Length(p
) = 1 then
4073 e_LogWritefln('%s', [g_Gibs_GetMax()])
4077 e_LogWritefln('usage: %s <n>', [cmd
])
4080 else if cmd
= 'g_max_corpses' then
4082 if Length(p
) = 2 then
4084 a
:= Max(0, StrToIntDef(p
[1], 0));
4087 else if Length(p
) = 1 then
4089 e_LogWritefln('%s', [g_Corpses_GetMax()])
4093 e_LogWritefln('usage: %s <n>', [cmd
])
4096 else if cmd
= 'g_force_model' then
4098 if Length(p
) = 2 then
4100 a
:= StrToIntDef(p
[1], 0);
4101 g_Force_Model_Set(a
);
4102 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4104 for a
:= Low(gPlayers
) to High(gPlayers
) do
4106 if (gPlayers
[a
] <> nil) then
4108 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4110 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4112 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4116 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4118 for a
:= Low(gPlayers
) to High(gPlayers
) do
4120 if (gPlayers
[a
] <> nil) then
4122 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4124 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4126 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4132 else if cmd
= 'g_force_model_name' then
4134 if (Length(P
) > 1) then
4136 cmd
:= b_Text_Unformat(P
[1]);
4137 g_Forced_Model_SetName(cmd
);
4138 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4140 for a
:= Low(gPlayers
) to High(gPlayers
) do
4142 if (gPlayers
[a
] <> nil) then
4144 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4146 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4148 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4154 else if cmd
= 'g_scorelimit' then
4156 if Length(P
) > 1 then
4158 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4160 if g_Game_IsServer
then
4163 if gGameSettings
.GameMode
= GM_DM
then
4165 stat
:= g_Player_GetStats();
4167 for a
:= 0 to High(stat
) do
4168 if stat
[a
].Frags
> b
then
4172 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4174 // if someone has a higher score, set it to that instead
4175 gsScoreLimit
:= max(gsScoreLimit
, b
);
4176 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4178 if g_Game_IsNet
then MH_SEND_GameSettings
;
4182 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4184 else if cmd
= 'g_timelimit' then
4186 if Length(P
) > 1 then
4188 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4189 if g_Game_IsServer
then
4191 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4192 if g_Game_IsNet
then MH_SEND_GameSettings
;
4195 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4196 [gsTimeLimit
div 3600,
4197 (gsTimeLimit
div 60) mod 60,
4198 gsTimeLimit
mod 60]));
4200 else if cmd
= 'g_max_bots' then
4202 if Length(P
) > 1 then
4203 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4204 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4206 else if cmd
= 'g_maxlives' then
4208 if Length(P
) > 1 then
4210 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4211 if g_Game_IsServer
then
4213 gGameSettings
.MaxLives
:= gsMaxLives
;
4214 if g_Game_IsNet
then MH_SEND_GameSettings
;
4218 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4222 procedure PlayerSettingsCVars(P
: SSArray
);
4227 function ParseTeam(s
: string): Byte;
4231 'red', '1': result
:= TEAM_RED
;
4232 'blue', '2': result
:= TEAM_BLUE
;
4233 else result
:= TEAM_NONE
;
4237 cmd
:= LowerCase(P
[0]);
4241 if (Length(P
) > 1) then
4243 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4244 if g_Game_IsClient
then
4245 MC_SEND_PlayerSettings
4246 else if gGameOn
and (gPlayer1
<> nil) then
4248 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4249 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4255 if (Length(P
) > 1) then
4257 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4258 if g_Game_IsClient
then
4259 MC_SEND_PlayerSettings
4260 else if gGameOn
and (gPlayer2
<> nil) then
4262 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4263 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4269 if Length(P
) > 3 then
4271 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4272 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4273 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4274 if g_Game_IsClient
then
4275 MC_SEND_PlayerSettings
4276 else if gGameOn
and (gPlayer1
<> nil) then
4278 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4279 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4285 if Length(P
) > 3 then
4287 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4288 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4289 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4290 if g_Game_IsClient
then
4291 MC_SEND_PlayerSettings
4292 else if gGameOn
and (gPlayer2
<> nil) then
4294 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4295 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4301 if (Length(P
) > 1) then
4303 gPlayer1Settings
.Model
:= P
[1];
4304 if g_Game_IsClient
then
4305 MC_SEND_PlayerSettings
4306 else if gGameOn
and (gPlayer1
<> nil) then
4308 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4309 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4310 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4316 if (Length(P
) > 1) then
4318 gPlayer2Settings
.Model
:= P
[1];
4319 if g_Game_IsClient
then
4320 MC_SEND_PlayerSettings
4321 else if gGameOn
and (gPlayer2
<> nil) then
4323 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4324 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4325 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4331 // TODO: switch teams if in game or store this separately
4332 if (Length(P
) > 1) then
4334 team
:= ParseTeam(P
[1]);
4335 if team
= TEAM_NONE
then
4336 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4337 else if not gGameOn
and not g_Game_IsNet
then
4338 gPlayer1Settings
.Team
:= team
4340 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4345 // TODO: switch teams if in game or store this separately
4346 if (Length(P
) > 1) then
4348 team
:= ParseTeam(P
[1]);
4349 if team
= TEAM_NONE
then
4350 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4351 else if not gGameOn
and not g_Game_IsNet
then
4352 gPlayer2Settings
.Team
:= team
4354 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4359 if (Length(P
) = 2) then
4360 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4364 if (Length(P
) = 2) then
4365 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4369 if (Length(P
) = 2) then
4370 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4374 if (Length(P
) = 2) then
4375 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4379 if (Length(P
) = 2) then
4380 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4384 if (Length(P
) = 2) then
4385 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4387 'p1_priority_kastet':
4389 if (Length(P
) = 2) then
4390 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4392 'p2_priority_kastet':
4394 if (Length(P
) = 2) then
4395 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4399 if (Length(P
) = 2) then
4400 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4404 if (Length(P
) = 2) then
4405 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4407 'p1_priority_pistol':
4409 if (Length(P
) = 2) then
4410 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4412 'p2_priority_pistol':
4414 if (Length(P
) = 2) then
4415 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4417 'p1_priority_shotgun1':
4419 if (Length(P
) = 2) then
4420 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4422 'p2_priority_shotgun1':
4424 if (Length(P
) = 2) then
4425 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4427 'p1_priority_shotgun2':
4429 if (Length(P
) = 2) then
4430 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4432 'p2_priority_shotgun2':
4434 if (Length(P
) = 2) then
4435 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4437 'p1_priority_chaingun':
4439 if (Length(P
) = 2) then
4440 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4442 'p2_priority_chaingun':
4444 if (Length(P
) = 2) then
4445 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4447 'p1_priority_rocketlauncher':
4449 if (Length(P
) = 2) then
4450 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4452 'p2_priority_rocketlauncher':
4454 if (Length(P
) = 2) then
4455 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4457 'p1_priority_plasma':
4459 if (Length(P
) = 2) then
4460 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4462 'p2_priority_plasma':
4464 if (Length(P
) = 2) then
4465 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4469 if (Length(P
) = 2) then
4470 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4474 if (Length(P
) = 2) then
4475 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4477 'p1_priority_super':
4479 if (Length(P
) = 2) then
4480 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4482 'p2_priority_super':
4484 if (Length(P
) = 2) then
4485 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4487 'p1_priority_flamethrower':
4489 if (Length(P
) = 2) then
4490 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4492 'p2_priority_flamethrower':
4494 if (Length(P
) = 2) then
4495 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4497 'p1_priority_berserk':
4499 if (Length(P
) = 2) then
4500 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4502 'p2_priority_berserk':
4504 if (Length(P
) = 2) then
4505 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4510 procedure PrintHeapStats();
4514 hs
:= GetFPCHeapStatus();
4515 e_LogWriteLn ('v===== heap status =====v');
4516 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4517 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4518 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4519 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4520 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4521 e_LogWriteLn ('^=======================^');
4524 procedure DebugCommands(P
: SSArray
);
4531 // Команды отладочного режима:
4532 if {gDebugMode}conIsCheatsEnabled
then
4534 cmd
:= LowerCase(P
[0]);
4535 if cmd
= 'd_window' then
4537 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4538 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4540 else if cmd
= 'd_sounds' then
4542 if (Length(P
) > 1) and
4543 ((P
[1] = '1') or (P
[1] = '0')) then
4544 g_Debug_Sounds
:= (P
[1][1] = '1');
4546 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4548 else if cmd
= 'd_frames' then
4550 if (Length(P
) > 1) and
4551 ((P
[1] = '1') or (P
[1] = '0')) then
4552 g_Debug_Frames
:= (P
[1][1] = '1');
4554 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4556 else if cmd
= 'd_winmsg' then
4558 if (Length(P
) > 1) and
4559 ((P
[1] = '1') or (P
[1] = '0')) then
4560 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4562 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4564 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4566 if (Length(P
) > 1) and
4567 ((P
[1] = '1') or (P
[1] = '0')) then
4568 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4570 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4572 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4574 if Length(P
) > 1 then
4576 '0': g_debug_BotAIOff
:= 0;
4577 '1': g_debug_BotAIOff
:= 1;
4578 '2': g_debug_BotAIOff
:= 2;
4579 '3': g_debug_BotAIOff
:= 3;
4582 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4584 else if cmd
= 'd_monster' then
4586 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4587 if Length(P
) < 2 then
4589 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4590 g_Console_Add('ID | Name');
4591 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4592 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4593 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4596 a
:= StrToIntDef(P
[1], 0);
4597 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4598 a
:= g_Mons_TypeIdByName(P
[1]);
4600 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4601 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4604 with gPlayer1
.Obj
do
4606 mon
:= g_Monsters_Create(a
,
4607 X
+ Rect
.X
+ (Rect
.Width
div 2),
4608 Y
+ Rect
.Y
+ Rect
.Height
,
4609 gPlayer1
.Direction
, True);
4611 if (Length(P
) > 2) and (mon
<> nil) then
4613 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4614 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4615 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4616 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4617 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4618 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4619 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4620 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4621 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4626 else if (cmd
= 'd_health') then
4628 if (Length(P
) > 1) and
4629 ((P
[1] = '1') or (P
[1] = '0')) then
4630 g_debug_HealthBar
:= (P
[1][1] = '1');
4632 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4634 else if (cmd
= 'd_player') then
4636 if (Length(P
) > 1) and
4637 ((P
[1] = '1') or (P
[1] = '0')) then
4638 g_debug_Player
:= (P
[1][1] = '1');
4640 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4642 else if (cmd
= 'd_mem') then
4648 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4652 procedure GameCheats(P
: SSArray
);
4658 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4660 g_Console_Add('not available');
4666 g_Console_Add('where is the player?!');
4669 cmd
:= LowerCase(P
[0]);
4673 plr
.GodMode
:= not plr
.GodMode
;
4674 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4677 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4678 if cmd
= 'give' then
4680 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4681 for f
:= 1 to High(P
) do
4683 cmd
:= LowerCase(P
[f
]);
4684 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4685 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4686 if cmd
= 'exit' then
4688 if gTriggers
<> nil then
4690 for a
:= 0 to High(gTriggers
) do
4692 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4694 g_Console_Add('player left the map');
4695 gExitByTrigger
:= True;
4696 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4697 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4705 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4706 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4707 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4708 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4709 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4711 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4712 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4714 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4715 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;
4717 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4718 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4720 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4721 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4723 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4724 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4726 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4727 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4728 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4730 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4731 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4732 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4733 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;
4734 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4735 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4737 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;
4738 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;
4739 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;
4740 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;
4741 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;
4742 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;
4744 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4745 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;
4747 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;
4748 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;
4750 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4752 if cmd
= 'ammo' then
4754 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4755 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4756 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4757 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4758 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4759 g_Console_Add('player got some ammo');
4763 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4764 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4766 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4767 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4769 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4770 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4772 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4773 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4775 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4777 if cmd
= 'weapons' then
4779 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4780 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4781 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4782 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4783 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4784 plr
.GiveItem(ITEM_WEAPON_BFG
);
4785 g_Console_Add('player got weapons');
4789 if cmd
= 'keys' then
4791 plr
.GiveItem(ITEM_KEY_RED
);
4792 plr
.GiveItem(ITEM_KEY_GREEN
);
4793 plr
.GiveItem(ITEM_KEY_BLUE
);
4794 g_Console_Add('player got all keys');
4798 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4803 if cmd
= 'open' then
4805 g_Console_Add('player activated sesame');
4806 g_Triggers_OpenAll();
4813 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4817 if cmd
= 'noclip' then
4820 g_Console_Add('wall hardeness adjusted');
4824 if cmd
= 'notarget' then
4826 plr
.NoTarget
:= not plr
.NoTarget
;
4827 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4831 if cmd
= 'noreload' then
4833 plr
.NoReload
:= not plr
.NoReload
;
4834 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4838 if cmd
= 'speedy' then
4840 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4841 g_Console_Add('speed adjusted');
4845 if cmd
= 'jumpy' then
4847 VEL_JUMP
:= 30-VEL_JUMP
;
4848 g_Console_Add('jump height adjusted');
4852 if cmd
= 'automap' then
4854 gShowMap
:= not gShowMap
;
4855 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4859 if cmd
= 'aimline' then
4861 gAimLine
:= not gAimLine
;
4862 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4867 procedure GameCommands(P
: SSArray
);
4873 pl
: pTNetClient
= nil;
4881 cmd
:= LowerCase(P
[0]);
4883 if cmd
= 'pause' then
4885 {$IFDEF ENABLE_MENU}
4886 if (g_ActiveWindow
= nil) then
4887 g_Game_Pause(not gPauseMain
);
4889 g_Game_Pause(not gPauseMain
);
4892 else if cmd
= 'endgame' then
4893 gExit
:= EXIT_SIMPLE
4894 else if cmd
= 'restart' then
4896 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4898 if g_Game_IsClient
then
4900 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4905 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4907 else if cmd
= 'kick' then
4909 if g_Game_IsServer
then
4911 if Length(P
) < 2 then
4913 g_Console_Add('kick <name>');
4918 g_Console_Add('kick <name>');
4922 if g_Game_IsNet
then
4923 pl
:= g_Net_Client_ByName(P
[1]);
4926 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4927 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4928 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4929 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4930 g_Net_Slist_ServerPlayerLeaves();
4931 end else if gPlayers
<> nil then
4932 for a
:= Low(gPlayers
) to High(gPlayers
) do
4933 if gPlayers
[a
] <> nil then
4934 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4936 // Не отключать основных игроков в сингле
4937 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4939 gPlayers
[a
].Lives
:= 0;
4940 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4941 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4942 g_Player_Remove(gPlayers
[a
].UID
);
4943 g_Net_Slist_ServerPlayerLeaves();
4944 // Если не перемешать, при добавлении новых ботов появятся старые
4948 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4950 else if cmd
= 'kick_id' then
4952 if g_Game_IsServer
and g_Game_IsNet
then
4954 if Length(P
) < 2 then
4956 g_Console_Add('kick_id <client ID>');
4961 g_Console_Add('kick_id <client ID>');
4965 a
:= StrToIntDef(P
[1], 0);
4966 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4968 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4970 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4971 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
4972 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4973 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4974 g_Net_Slist_ServerPlayerLeaves();
4978 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4980 else if cmd
= 'kick_pid' then
4982 if g_Game_IsServer
and g_Game_IsNet
then
4984 if Length(P
) < 2 then
4986 g_Console_Add('kick_pid <player ID>');
4991 g_Console_Add('kick_pid <player ID>');
4995 a
:= StrToIntDef(P
[1], 0);
4996 pl
:= g_Net_Client_ByPlayer(a
);
4997 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4999 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5000 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5001 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5002 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5003 g_Net_Slist_ServerPlayerLeaves();
5006 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5008 else if cmd
= 'ban' then
5010 if g_Game_IsServer
and g_Game_IsNet
then
5012 if Length(P
) < 2 then
5014 g_Console_Add('ban <name>');
5019 g_Console_Add('ban <name>');
5023 pl
:= g_Net_Client_ByName(P
[1]);
5026 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5027 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5028 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5029 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5030 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5031 g_Net_Slist_ServerPlayerLeaves();
5033 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5035 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5037 else if cmd
= 'ban_id' then
5039 if g_Game_IsServer
and g_Game_IsNet
then
5041 if Length(P
) < 2 then
5043 g_Console_Add('ban_id <client ID>');
5048 g_Console_Add('ban_id <client ID>');
5052 a
:= StrToIntDef(P
[1], 0);
5053 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5054 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5056 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5057 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5058 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5059 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5060 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5061 g_Net_Slist_ServerPlayerLeaves();
5064 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5066 else if cmd
= 'ban_pid' then
5068 if g_Game_IsServer
and g_Game_IsNet
then
5070 if Length(P
) < 2 then
5072 g_Console_Add('ban_pid <player ID>');
5077 g_Console_Add('ban_pid <player ID>');
5081 a
:= StrToIntDef(P
[1], 0);
5082 pl
:= g_Net_Client_ByPlayer(a
);
5083 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5085 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5086 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5087 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5088 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5089 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5090 g_Net_Slist_ServerPlayerLeaves();
5093 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5095 else if cmd
= 'permban' then
5097 if g_Game_IsServer
and g_Game_IsNet
then
5099 if Length(P
) < 2 then
5101 g_Console_Add('permban <name>');
5106 g_Console_Add('permban <name>');
5110 pl
:= g_Net_Client_ByName(P
[1]);
5113 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5114 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5115 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5116 g_Net_SaveBanList();
5117 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5118 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5119 g_Net_Slist_ServerPlayerLeaves();
5121 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5123 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5125 else if cmd
= 'permban_id' then
5127 if g_Game_IsServer
and g_Game_IsNet
then
5129 if Length(P
) < 2 then
5131 g_Console_Add('permban_id <client ID>');
5136 g_Console_Add('permban_id <client ID>');
5140 a
:= StrToIntDef(P
[1], 0);
5141 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5142 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5144 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5145 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5146 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5147 g_Net_SaveBanList();
5148 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5149 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5150 g_Net_Slist_ServerPlayerLeaves();
5153 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5155 else if cmd
= 'permban_pid' then
5157 if g_Game_IsServer
and g_Game_IsNet
then
5159 if Length(P
) < 2 then
5161 g_Console_Add('permban_pid <player ID>');
5166 g_Console_Add('permban_pid <player ID>');
5170 a
:= StrToIntDef(P
[1], 0);
5171 pl
:= g_Net_Client_ByPlayer(a
);
5172 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5174 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5175 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5176 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5177 g_Net_SaveBanList();
5178 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5179 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5180 g_Net_Slist_ServerPlayerLeaves();
5183 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5185 else if cmd
= 'permban_ip' then
5187 if g_Game_IsServer
and g_Game_IsNet
then
5189 if Length(P
) < 2 then
5191 g_Console_Add('permban_ip <IP address>');
5196 g_Console_Add('permban_ip <IP address>');
5200 g_Net_BanHost(P
[1]);
5201 g_Net_SaveBanList();
5202 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5204 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5206 else if cmd
= 'unban' then
5208 if g_Game_IsServer
and g_Game_IsNet
then
5210 if Length(P
) < 2 then
5212 g_Console_Add('unban <IP Address>');
5217 g_Console_Add('unban <IP Address>');
5221 if g_Net_UnbanHost(P
[1]) then
5223 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5224 g_Net_SaveBanList();
5226 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5228 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5230 else if cmd
= 'clientlist' then
5232 if g_Game_IsServer
and g_Game_IsNet
then
5235 if NetClients
<> nil then
5236 for a
:= Low(NetClients
) to High(NetClients
) do
5237 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5239 plr
:= g_Player_Get(NetClients
[a
].Player
);
5240 if plr
= nil then continue
;
5242 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5243 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5246 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5248 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5250 else if cmd
= 'connect' then
5252 if (NetMode
= NET_NONE
) then
5254 if Length(P
) < 2 then
5256 g_Console_Add('connect <IP> [port] [password]');
5261 g_Console_Add('connect <IP> [port] [password]');
5265 if Length(P
) > 2 then
5266 prt
:= StrToIntDef(P
[2], 25666)
5270 if Length(P
) > 3 then
5275 g_Game_StartClient(P
[1], prt
, pw
);
5278 else if cmd
= 'disconnect' then
5280 if (NetMode
= NET_CLIENT
) then
5283 else if cmd
= 'reconnect' then
5285 if (NetMode
= NET_SERVER
) then
5288 if (NetMode
= NET_CLIENT
) then
5291 gExit
:= EXIT_SIMPLE
;
5295 //TODO: Use last successful password to reconnect, instead of ''
5296 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5298 else if (cmd
= 'addbot') or
5299 (cmd
= 'bot_add') then
5301 if Length(P
) > 2 then
5302 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5303 else if Length(P
) > 1 then
5304 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5306 g_Bot_Add(TEAM_NONE
, 2);
5308 else if cmd
= 'bot_addlist' then
5310 if Length(P
) > 1 then
5312 if Length(P
) = 2 then
5313 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5314 else if Length(P
) = 3 then
5315 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5317 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5320 else if cmd
= 'bot_removeall' then
5322 else if cmd
= 'chat' then
5324 if g_Game_IsNet
then
5326 if Length(P
) > 1 then
5328 for a
:= 1 to High(P
) do
5329 chstr
:= chstr
+ P
[a
] + ' ';
5331 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5333 if Length(chstr
) < 1 then
5335 g_Console_Add('chat <text>');
5339 chstr
:= b_Text_Format(chstr
);
5340 if g_Game_IsClient
then
5341 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5343 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5346 g_Console_Add('chat <text>');
5348 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5350 else if cmd
= 'teamchat' then
5352 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5354 if Length(P
) > 1 then
5356 for a
:= 1 to High(P
) do
5357 chstr
:= chstr
+ P
[a
] + ' ';
5359 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5361 if Length(chstr
) < 1 then
5363 g_Console_Add('teamchat <text>');
5367 chstr
:= b_Text_Format(chstr
);
5368 if g_Game_IsClient
then
5369 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5371 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5372 gPlayer1Settings
.Team
);
5375 g_Console_Add('teamchat <text>');
5377 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5379 else if (cmd
= 'an') or (cmd
= 'announce') then
5381 if g_Game_IsNet
then
5383 if Length(P
) > 1 then
5385 for a
:= 1 to High(P
) do
5386 chstr
:= chstr
+ P
[a
] + ' ';
5388 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5390 if Length(chstr
) < 1 then
5392 g_Console_Add('announce <text>');
5396 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5397 if g_Game_IsClient
then
5398 MC_SEND_RCONCommand(chstr
)
5400 g_Console_Process(chstr
, True);
5403 g_Console_Add('announce <text>');
5405 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5407 else if cmd
= 'game' then
5409 if gGameSettings
.GameType
<> GT_NONE
then
5411 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5414 if Length(P
) = 1 then
5416 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5419 // game not started yet, load fist map from some wad
5421 s
:= addWadExtension(P
[1]);
5422 found
:= e_FindResource(AllMapDirs
, s
);
5426 P
[1] := ExpandFileName(P
[1]);
5427 // if map not choosed then set first map
5428 if Length(P
) < 3 then
5431 P
[2] := g_Game_GetFirstMap(P
[1]);
5434 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5436 if g_Map_Exist(s
) then
5440 with gGameSettings
do
5442 Options
:= gsGameFlags
;
5443 GameMode
:= g_Game_TextToMode(gsGameMode
);
5444 if gSwitchGameMode
<> GM_NONE
then
5445 GameMode
:= gSwitchGameMode
;
5446 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5447 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5449 if Length(P
) >= 4 then
5450 b
:= StrToIntDef(P
[3], 1);
5451 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5452 ScoreLimit
, MaxLives
, Options
, b
);
5457 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5459 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5461 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5463 else if cmd
= 'host' then
5465 if gGameSettings
.GameType
<> GT_NONE
then
5467 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5470 if Length(P
) < 4 then
5472 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5475 if not StrToIp(P
[1], listen
) then
5477 prt
:= StrToIntDef(P
[2], 25666);
5479 s
:= addWadExtension(P
[3]);
5480 found
:= e_FindResource(AllMapDirs
, s
);
5484 // get first map in wad, if not specified
5485 if Length(P
) < 5 then
5488 P
[4] := g_Game_GetFirstMap(P
[1]);
5490 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5491 if g_Map_Exist(s
) then
5495 with gGameSettings
do
5497 Options
:= gsGameFlags
;
5498 GameMode
:= g_Game_TextToMode(gsGameMode
);
5499 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5500 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5501 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5503 if Length(P
) >= 6 then
5504 b
:= StrToIntDef(P
[5], 0);
5505 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5511 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5513 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5518 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5521 else if cmd
= 'map' then
5523 if Length(P
) = 1 then
5525 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5527 g_Console_Add(cmd
+ ' <MAP>');
5528 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5532 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5537 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5539 if Length(P
) < 3 then
5541 // first param is map or wad
5542 s
:= UpperCase(P
[1]);
5543 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5545 gExitByTrigger
:= False;
5548 // already in game, finish current map
5550 gExit
:= EXIT_ENDLEVELCUSTOM
;
5554 // intermission, so change map immediately
5561 found
:= e_FindResource(AllMapDirs
, s
);
5563 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5566 // no such map, found wad
5569 P
[1] := ExpandFileName(pw
);
5570 P
[2] := g_Game_GetFirstMap(P
[1]);
5571 s
:= P
[1] + ':\' + P
[2];
5572 if g_Map_Exist(s
) then
5574 gExitByTrigger
:= False;
5577 // already in game, finish current map
5579 gExit
:= EXIT_ENDLEVELCUSTOM
5583 // intermission, so change map immediately
5590 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5592 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5597 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5603 s
:= addWadExtension(P
[1]);
5604 found
:= e_FindResource(AllMapDirs
, s
);
5608 P
[2] := UpperCase(P
[2]);
5609 s
:= P
[1] + ':\' + P
[2];
5610 if g_Map_Exist(s
) then
5612 gExitByTrigger
:= False;
5616 gExit
:= EXIT_ENDLEVELCUSTOM
5625 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5630 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5636 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5640 else if cmd
= 'nextmap' then
5642 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5644 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5649 if Length(P
) = 1 then
5651 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5653 g_Console_Add(cmd
+ ' <MAP>');
5654 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5659 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5665 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5667 if Length(P
) < 3 then
5669 // first param is map or wad
5670 s
:= UpperCase(P
[1]);
5671 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5674 gExitByTrigger
:= False;
5680 // no such map, found wad
5681 pw
:= addWadExtension(P
[1]);
5682 found
:= e_FindResource(MapDirs
, pw
);
5684 found
:= e_FindResource(WadDirs
, pw
);
5686 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5689 // map not specified, select first map
5691 P
[2] := g_Game_GetFirstMap(P
[1]);
5692 s
:= P
[1] + ':\' + P
[2];
5693 if g_Map_Exist(s
) then
5695 gExitByTrigger
:= False;
5702 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5704 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5709 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5715 // specified two params wad + map
5716 pw
:= addWadExtension(P
[1]);
5717 found
:= e_FindResource(MapDirs
, pw
);
5719 found
:= e_FindResource(MapDirs
, pw
);
5723 P
[2] := UpperCase(P
[2]);
5724 s
:= P
[1] + ':\' + P
[2];
5725 if g_Map_Exist(s
) then
5727 gExitByTrigger
:= False;
5733 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5738 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5744 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5749 if gNextMap
= '' then
5750 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5752 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5756 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5760 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5764 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5766 gExitByTrigger
:= False;
5767 // next map not specified, try to find trigger EXIT
5768 if (gNextMap
= '') and (gTriggers
<> nil) then
5770 for a
:= 0 to High(gTriggers
) do
5772 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5774 gExitByTrigger
:= True;
5775 //gNextMap := gTriggers[a].Data.MapName;
5776 gNextMap
:= gTriggers
[a
].tgcMap
;
5781 if gNextMap
= '' then
5782 gNextMap
:= g_Game_GetNextMap();
5783 if not isWadPath(gNextMap
) then
5784 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5787 if g_Map_Exist(s
) then
5788 gExit
:= EXIT_ENDLEVELCUSTOM
5790 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5794 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5798 else if (cmd
= 'event') then
5800 if (Length(P
) <= 1) then
5802 for a
:= 0 to High(gEvents
) do
5803 if gEvents
[a
].Command
= '' then
5804 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5806 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5809 if (Length(P
) = 2) then
5811 for a
:= 0 to High(gEvents
) do
5812 if gEvents
[a
].Name
= P
[1] then
5813 if gEvents
[a
].Command
= '' then
5814 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5816 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5819 for a
:= 0 to High(gEvents
) do
5820 if gEvents
[a
].Name
= P
[1] then
5822 gEvents
[a
].Command
:= '';
5823 for b
:= 2 to High(P
) do
5824 if Pos(' ', P
[b
]) = 0 then
5825 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5827 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5828 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5832 else if cmd
= 'suicide' then
5836 if g_Game_IsClient
then
5837 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5840 if gPlayer1
<> nil then
5841 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5842 if gPlayer2
<> nil then
5843 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5847 else if cmd
= 'screenshot' then
5853 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5855 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5857 gWeaponAction
[0, WP_PREV
] := True;
5859 gWeaponAction
[0, WP_NEXT
] := True;
5861 else if cmd
= 'weapon' then
5863 if Length(p
) = 2 then
5865 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5866 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5867 gSelectWeapon
[0, a
] := True
5870 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5871 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5873 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5874 b
:= ord(cmd
[2]) - ord('1');
5876 gWeaponAction
[b
, WP_PREV
] := True;
5878 gWeaponAction
[b
, WP_NEXT
] := True;
5880 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5882 if Length(p
) = 2 then
5884 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5885 b
:= ord(cmd
[2]) - ord('1');
5886 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5887 gSelectWeapon
[b
, a
] := True
5890 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
5892 b
:= ord(cmd
[2]) - ord('1');
5894 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
5896 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
5898 else if (cmd
= 'dropflag') then
5900 if g_Game_IsServer
then
5902 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
5903 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
5906 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5908 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
5910 b
:= ord(cmd
[2]) - ord('1');
5911 if g_Game_IsServer
then
5913 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
5914 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
5917 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5919 // Команды Своей игры:
5920 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5922 if cmd
= 'bot_addred' then
5924 if Length(P
) > 1 then
5925 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5927 g_Bot_Add(TEAM_RED
, 2);
5929 else if cmd
= 'bot_addblue' then
5931 if Length(P
) > 1 then
5932 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5934 g_Bot_Add(TEAM_BLUE
, 2);
5936 else if cmd
= 'spectate' then
5942 else if cmd
= 'say' then
5944 if g_Game_IsServer
and g_Game_IsNet
then
5946 if Length(P
) > 1 then
5949 for a
:= 1 to High(P
) do
5950 chstr
:= chstr
+ P
[a
] + ' ';
5952 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5954 if Length(chstr
) < 1 then
5956 g_Console_Add('say <text>');
5960 chstr
:= b_Text_Format(chstr
);
5961 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5963 else g_Console_Add('say <text>');
5965 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5967 else if cmd
= 'tell' then
5969 if g_Game_IsServer
and g_Game_IsNet
then
5971 if (Length(P
) > 2) and (P
[1] <> '') then
5974 for a
:= 2 to High(P
) do
5975 chstr
:= chstr
+ P
[a
] + ' ';
5977 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5979 if Length(chstr
) < 1 then
5981 g_Console_Add('tell <playername> <text>');
5985 pl
:= g_Net_Client_ByName(P
[1]);
5987 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5989 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5991 else g_Console_Add('tell <playername> <text>');
5993 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5995 else if cmd
= 'centerprint' then
5997 if (Length(P
) > 2) and (P
[1] <> '') then
6000 for a
:= 2 to High(P
) do
6001 chstr
:= chstr
+ P
[a
] + ' ';
6003 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6005 if Length(chstr
) < 1 then
6007 g_Console_Add('centerprint <timeout> <text>');
6011 a
:= StrToIntDef(P
[1], 100);
6012 chstr
:= b_Text_Format(chstr
);
6013 g_Game_Message(chstr
, a
);
6014 if g_Game_IsNet
and g_Game_IsServer
then
6015 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6017 else g_Console_Add('centerprint <timeout> <text>');
6019 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6021 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6023 // Дополнительное время:
6024 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6026 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6027 [gGameSettings
.TimeLimit
div 3600,
6028 (gGameSettings
.TimeLimit
div 60) mod 60,
6029 gGameSettings
.TimeLimit
mod 60]));
6030 if g_Game_IsNet
then MH_SEND_GameSettings
;
6032 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6034 if (Length(P
) <= 1) then
6035 g_Console_Add('rcon_password <password>')
6037 MC_SEND_RCONPassword(P
[1]);
6039 else if cmd
= 'rcon' then
6041 if g_Game_IsClient
then
6043 if Length(P
) > 1 then
6046 for a
:= 1 to High(P
) do
6047 chstr
:= chstr
+ P
[a
] + ' ';
6049 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6051 if Length(chstr
) < 1 then
6053 g_Console_Add('rcon <command>');
6057 MC_SEND_RCONCommand(chstr
);
6059 else g_Console_Add('rcon <command>');
6062 else if cmd
= 'ready' then
6064 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6065 gLMSRespawnTime
:= gTime
+ 100;
6067 else if (cmd
= 'callvote') and g_Game_IsNet
then
6069 if Length(P
) > 1 then
6072 for a
:= 1 to High(P
) do begin
6073 if a
> 1 then chstr
:= chstr
+ ' ';
6074 chstr
:= chstr
+ P
[a
];
6077 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6079 if Length(chstr
) < 1 then
6081 g_Console_Add('callvote <command>');
6085 if g_Game_IsClient
then
6086 MC_SEND_Vote(True, chstr
)
6088 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6089 g_Console_Process('vote', True);
6092 g_Console_Add('callvote <command>');
6094 else if (cmd
= 'vote') and g_Game_IsNet
then
6096 if g_Game_IsClient
then
6098 else if gVoteInProgress
then
6100 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6101 a
:= Floor((NetClientCount
+1)/2.0) + 1
6103 a
:= Floor(NetClientCount
/2.0) + 1;
6108 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6109 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6115 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6116 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6124 procedure SystemCommands(P
: SSArray
);
6128 cmd
:= LowerCase(P
[0]);
6141 if Length(p
) = 2 then
6143 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6145 gFrameTime
:= 1000 div gMaxFPS
6149 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6153 if Length(p
) = 2 then
6155 gAskLanguage
:= true;
6156 gLanguage
:= LANGUAGE_ENGLISH
;
6157 case LowerCase(p
[1]) of
6160 gAskLanguage
:= false;
6161 gLanguage
:= LANGUAGE_ENGLISH
;
6165 gAskLanguage
:= false;
6166 gLanguage
:= LANGUAGE_RUSSIAN
;
6170 gAskLanguage
:= true;
6171 gLanguage
:= LANGUAGE_ENGLISH
;
6174 g_Language_Set(gLanguage
);
6178 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6185 procedure g_TakeScreenShot(Filename
: string = '');
6186 var t
: TDateTime
; dir
, date
, name
: String;
6188 if e_NoGraphics
then
6191 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6192 if Filename
= '' then
6195 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6196 Filename
:= 'screenshot-' + date
;
6199 name
:= e_CatPath(dir
, Filename
+ '.png');
6200 if r_Render_WriteScreenShot(name
) then
6201 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6203 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6207 {$IFDEF ENABLE_MENU}
6208 procedure g_Game_InGameMenu(Show
: Boolean);
6210 if (g_ActiveWindow
= nil) and Show
then
6212 if gGameSettings
.GameType
= GT_SINGLE
then
6213 g_GUI_ShowWindow('GameSingleMenu')
6216 if g_Game_IsClient
then
6217 g_GUI_ShowWindow('GameClientMenu')
6219 if g_Game_IsNet
then
6220 g_GUI_ShowWindow('GameServerMenu')
6222 g_GUI_ShowWindow('GameCustomMenu');
6224 g_Sound_PlayEx('MENU_OPEN');
6226 // Пауза при меню только в одиночной игре:
6227 if (not g_Game_IsNet
) then
6231 if (g_ActiveWindow
<> nil) and (not Show
) then
6233 // Пауза при меню только в одиночной игре:
6234 if (not g_Game_IsNet
) then
6235 g_Game_Pause(False);
6240 procedure g_Game_Pause (Enable
: Boolean);
6244 if not gGameOn
then exit
;
6246 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6249 gPauseMain
:= Enable
;
6251 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6254 procedure g_Game_HolmesPause (Enable
: Boolean);
6258 if not gGameOn
then exit
;
6259 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6262 gPauseHolmes
:= Enable
;
6264 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6267 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6272 if gTriggers
<> nil then
6273 for i
:= 0 to High(gTriggers
) do
6274 with gTriggers
[i
] do
6275 if (TriggerType
= TRIGGER_SOUND
) and
6277 Sound
.IsPlaying() then
6279 Sound
.Pause(Enable
);
6283 if gPlayers
<> nil then
6284 for i
:= 0 to High(gPlayers
) do
6285 if gPlayers
[i
] <> nil then
6286 gPlayers
[i
].PauseSounds(Enable
);
6289 if gMusic
<> nil then
6290 gMusic
.Pause(Enable
);
6293 procedure g_Game_StopAllSounds(all
: Boolean);
6297 if gTriggers
<> nil then
6298 for i
:= 0 to High(gTriggers
) do
6299 with gTriggers
[i
] do
6300 if (TriggerType
= TRIGGER_SOUND
) and
6304 if gMusic
<> nil then
6311 procedure g_Game_UpdateTriggerSounds
;
6314 if gTriggers
<> nil then
6315 for i
:= 0 to High(gTriggers
) do
6316 with gTriggers
[i
] do
6317 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6318 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6321 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6324 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6329 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6334 if gSpectMode
<> SPECT_PLAYERS
then
6336 if gSpectPID1
= UID
then
6341 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6348 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6353 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6358 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6363 if gSpectMode
<> SPECT_PLAYERS
then
6365 Pl
:= g_Player_Get(gSpectPID1
);
6366 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6371 if gSpectViewTwo
then
6373 Pl
:= g_Player_Get(gSpectPID2
);
6374 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6382 procedure g_Game_Message (Msg
: string; Time
: Word);
6385 MessageTime
:= Time
;
6388 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6390 punct
: Array[0..13] of String =
6391 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6397 function IsPunctuation(S
: String): Boolean;
6402 if Length(S
) <> 1 then
6404 for i
:= Low(punct
) to High(punct
) do
6405 if S
= punct
[i
] then
6411 function FilterPunctuation(S
: String): String;
6415 for i
:= Low(punct
) to High(punct
) do
6416 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6422 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6424 // remove player name
6425 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6426 // for FullWord check
6427 Text := toLowerCase1251(' ' + Text + ' ');
6428 fpText
:= FilterPunctuation(Text);
6430 for i
:= 0 to Length(gChatSounds
) - 1 do
6433 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6435 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6436 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6438 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6444 gChatSounds
[i
].Sound
.Play();
6450 g_Sound_PlayEx('SOUND_GAME_RADIO');
6453 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6462 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6466 if goodsnd
[a
].IsPlaying() then
6469 goodsnd
[Random(4)].Play();
6472 procedure g_Game_Announce_KillCombo(Param
: Integer);
6479 UID
:= Param
and $FFFF;
6484 Pl
:= g_Player_Get(UID
);
6493 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6497 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6501 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6505 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6513 if not g_Game_IsWatchedPlayer(UID
) then
6516 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6520 if killsnd
[n
].IsPlaying() then
6525 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6533 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6537 if hahasnd
[a
].IsPlaying() then
6540 hahasnd
[Random(3)].Play();
6543 procedure g_Game_StartVote(Command
, Initiator
: string);
6547 if not gVotesEnabled
then Exit
;
6548 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6549 if gVoteInProgress
or gVotePassed
then
6551 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6552 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6555 gVoteInProgress
:= True;
6556 gVotePassed
:= False;
6557 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6560 gVoteCommand
:= Command
;
6562 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6563 Need
:= Floor((NetClientCount
+1)/2.0)+1
6565 Need
:= Floor(NetClientCount
/2.0)+1;
6566 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6567 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6570 procedure g_Game_CheckVote
;
6574 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6575 if not gVoteInProgress
then Exit
;
6577 if (gTime
>= gVoteTimer
) then
6579 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6580 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6582 Need
:= Floor(NetClientCount
/2.0) + 1;
6583 if gVoteCount
>= Need
then
6585 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6586 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6587 gVotePassed
:= True;
6588 gVoteCmdTimer
:= gTime
+ 5000;
6592 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6593 MH_SEND_VoteEvent(NET_VE_FAILED
);
6595 if NetClients
<> nil then
6596 for I
:= Low(NetClients
) to High(NetClients
) do
6597 if NetClients
[i
].Used
then
6598 NetClients
[i
].Voted
:= False;
6599 gVoteInProgress
:= False;
6605 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6606 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6608 Need
:= Floor(NetClientCount
/2.0) + 1;
6609 if gVoteCount
>= Need
then
6611 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6612 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6613 gVoteInProgress
:= False;
6614 gVotePassed
:= True;
6615 gVoteCmdTimer
:= gTime
+ 5000;
6618 if NetClients
<> nil then
6619 for I
:= Low(NetClients
) to High(NetClients
) do
6620 if NetClients
[i
].Used
then
6621 NetClients
[i
].Voted
:= False;
6626 procedure g_Game_LoadMapList(FileName
: string);
6634 if not FileExists(FileName
) then Exit
;
6636 AssignFile(ListFile
, FileName
);
6638 while not EOF(ListFile
) do
6640 ReadLn(ListFile
, s
);
6643 if s
= '' then Continue
;
6645 SetLength(MapList
, Length(MapList
)+1);
6646 MapList
[High(MapList
)] := s
;
6648 CloseFile(ListFile
);
6651 procedure g_Game_SetDebugMode();
6654 // Читы (даже в своей игре):
6658 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6662 if Length(LoadingStat
.Msgs
) = 0 then
6668 begin // Переходим на следующую строку или скроллируем:
6669 if NextMsg
= Length(Msgs
) then
6671 for i
:= 0 to High(Msgs
)-1 do
6672 Msgs
[i
] := Msgs
[i
+1];
6680 Msgs
[NextMsg
-1] := Text;
6684 PBarWasHere
:= false;
6687 {$IFDEF ENABLE_MENU}
6688 g_ActiveWindow
:= nil;
6691 ProcessLoading(true);
6694 procedure g_Game_StepLoading(Value
: Integer = -1);
6706 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6709 ProcessLoading(False);
6714 procedure g_Game_ClearLoading();
6723 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6724 if len
< 1 then len
:= 1;
6725 SetLength(Msgs
, len
);
6726 for len
:= Low(Msgs
) to High(Msgs
) do
6729 PBarWasHere
:= false;
6733 procedure Parse_Params(var pars
: TParamStrValues
);
6740 while i
<= ParamCount
do
6743 if (Length(s
) > 1) and (s
[1] = '-') then
6745 if (Length(s
) > 2) and (s
[2] = '-') then
6746 begin // Одиночный параметр
6747 SetLength(pars
, Length(pars
) + 1);
6748 with pars
[High(pars
)] do
6750 Name
:= LowerCase(s
);
6755 if (i
< ParamCount
) then
6756 begin // Параметр со значением
6758 SetLength(pars
, Length(pars
) + 1);
6759 with pars
[High(pars
)] do
6761 Name
:= LowerCase(s
);
6762 Value
:= LowerCase(ParamStr(i
));
6771 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6776 for i
:= 0 to High(pars
) do
6777 if pars
[i
].Name
= aName
then
6779 Result
:= pars
[i
].Value
;
6784 procedure g_Game_Process_Params();
6786 pars
: TParamStrValues
;
6789 LimT
, LimS
: Integer;
6800 s
:= Find_Param_Value(pars
, '--debug');
6803 g_Game_SetDebugMode();
6804 s
:= Find_Param_Value(pars
, '--netdump');
6809 // Connect when game loads
6810 ip
:= Find_Param_Value(pars
, '-connect');
6814 s
:= Find_Param_Value(pars
, '-port');
6815 if (s
= '') or not TryStrToInt(s
, Port
) then
6818 s
:= Find_Param_Value(pars
, '-pw');
6820 g_Game_StartClient(ip
, Port
, s
);
6824 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6827 gDefaultMegawadStart
:= s
;
6830 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6831 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6833 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6836 // Start map when game loads:
6837 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6838 if isWadPath(map
) then
6841 s
:= Find_Param_Value(pars
, '-gm');
6842 GMode
:= g_Game_TextToMode(s
);
6843 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6844 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6847 s
:= Find_Param_Value(pars
, '-limt');
6848 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6854 s
:= Find_Param_Value(pars
, '-lims');
6855 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6861 s
:= Find_Param_Value(pars
, '-lives');
6862 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6868 s
:= Find_Param_Value(pars
, '-opt');
6872 Opt
:= StrToIntDef(s
, 0);
6875 s
:= Find_Param_Value(pars
, '--close');
6879 // Override map to test:
6880 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6883 if e_IsValidResourceName(s
) then
6884 e_FindResource(AllMapDirs
, s
);
6885 gTestMap
:= ExpandFileName(s
);
6888 // Delete test map after play:
6889 s
:= Find_Param_Value(pars
, '--testdelete');
6892 //gMapToDelete := MapsDir + map;
6893 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6897 // Delete temporary WAD after play:
6898 s
:= Find_Param_Value(pars
, '--tempdelete');
6899 if (s
<> '') and (gTestMap
<> '') then
6901 gMapToDelete
:= gTestMap
;
6902 gTempDelete
:= True;
6905 // Number of players:
6906 s
:= Find_Param_Value(pars
, '-pl');
6908 n
:= DEFAULT_PLAYERS
6910 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6913 s
:= Find_Param_Value(pars
, '-port');
6914 if (s
= '') or not TryStrToInt(s
, Port
) then
6915 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6917 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6920 // Execute script when game loads:
6921 s
:= Find_Param_Value(pars
, '-exec');
6924 // if not isWadPath(s) then
6925 // s := GameDir + '/' + s;
6930 if IOResult
<> 0 then
6932 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6933 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6937 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6938 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6943 if IOResult
<> 0 then
6945 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6946 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6950 if Pos('#', s
) <> 1 then // script comment
6951 g_Console_Process(s
, True);
6962 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6963 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6964 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6965 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6967 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6968 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6969 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6970 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6972 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6973 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6975 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6976 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6978 {$IFDEF ENABLE_HOLMES}
6979 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6982 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6984 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6985 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6987 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6988 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6990 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6991 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6992 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6993 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
6994 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6995 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6996 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6997 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6998 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');