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
;
135 procedure g_FatalError(Text: String);
136 procedure g_SimpleError(Text: String);
137 function g_Game_IsTestMap(): Boolean;
138 procedure g_Game_DeleteTestMap();
139 procedure GameCVars(P
: SSArray
);
140 procedure PlayerSettingsCVars(P
: SSArray
);
141 procedure SystemCommands(P
: SSArray
);
142 procedure GameCommands(P
: SSArray
);
143 procedure GameCheats(P
: SSArray
);
144 procedure DebugCommands(P
: SSArray
);
145 procedure g_Game_Process_Params
;
146 procedure g_Game_SetDebugMode();
148 function IsActivePlayer(p
: TPlayer
): Boolean;
149 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
150 procedure SortGameStat(var stat
: TPlayerStatArray
);
154 procedure g_Game_InGameMenu(Show
: Boolean);
156 {$IFDEF ENABLE_SYSTEM}
157 procedure CharPress (C
: AnsiChar);
160 procedure KeyPress (K
: Word);
162 { procedure SetWinPause(Enable: Boolean); }
183 EXIT_ENDLEVELSINGLE
= 4;
184 EXIT_ENDLEVELCUSTOM
= 5;
186 GAME_OPTION_RESERVED
= 1;
187 GAME_OPTION_TEAMDAMAGE
= 2;
188 GAME_OPTION_ALLOWEXIT
= 4;
189 GAME_OPTION_WEAPONSTAY
= 8;
190 GAME_OPTION_MONSTERS
= 16;
191 GAME_OPTION_BOTVSPLAYER
= 32;
192 GAME_OPTION_BOTVSMONSTER
= 64;
193 GAME_OPTION_DMKEYS
= 128;
194 GAME_OPTION_TEAMHITTRACE
= 256;
195 GAME_OPTION_TEAMHITPROJECTILE
= 512;
196 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
197 GAME_OPTION_ALLOWDROPFLAG
= 2048;
198 GAME_OPTION_THROWFLAG
= 4096;
203 STATE_INTERCUSTOM
= 3;
204 STATE_INTERSINGLE
= 4;
210 LMS_RESPAWN_NONE
= 0;
211 LMS_RESPAWN_WARMUP
= 1;
212 LMS_RESPAWN_FINAL
= 2;
229 CONFIG_FILENAME
= 'Doom2DF.cfg';
231 TEST_MAP_NAME
= '$$$_TEST_$$$';
233 STD_PLAYER_MODEL
= 'Doomer';
241 STATFILE_VERSION
= $03;
244 gGameSettings
: TGameSettings
;
245 gPlayer1Settings
: TPlayerSettings
;
246 gPlayer2Settings
: TPlayerSettings
;
248 gPlayerScreenSize
: TDFPoint
;
249 gPlayer1
: TPlayer
= nil;
250 gPlayer2
: TPlayer
= nil;
252 gLerpFactor
: Single = 1.0;
253 gSwitchGameMode
: Byte = GM_DM
;
254 gHearPoint1
, gHearPoint2
: THearPoint
;
255 gMaxDist
: Integer = 1; // for sound
256 gSoundEffectsDF
: Boolean = False;
257 gSoundTriggerTime
: Word = 0;
258 gAnnouncer
: Integer = ANNOUNCE_NONE
;
259 goodsnd
: array[0..3] of TPlayableSound
;
260 killsnd
: array[0..3] of TPlayableSound
;
261 hahasnd
: array[0..2] of TPlayableSound
;
262 sound_get_flag
: array[0..1] of TPlayableSound
;
263 sound_lost_flag
: array[0..1] of TPlayableSound
;
264 sound_ret_flag
: array[0..1] of TPlayableSound
;
265 sound_cap_flag
: array[0..1] of TPlayableSound
;
266 gBodyKillEvent
: Integer = -1;
267 gDefInterTime
: ShortInt = -1;
268 gInterEndTime
: LongWord = 0;
269 gInterTime
: LongWord = 0;
270 gServInterTime
: Byte = 0;
271 gGameStartTime
: LongWord = 0;
272 gTotalMonsters
: Integer = 0;
273 gPauseMain
: Boolean = false;
274 gPauseHolmes
: Boolean = false;
275 gShowTime
: Boolean = False;
276 gShowFPS
: Boolean = False;
277 gShowScore
: Boolean = True;
278 gShowStat
: Boolean = True;
279 gShowPIDs
: Boolean = False;
280 gShowKillMsg
: Boolean = True;
281 gShowLives
: Boolean = True;
282 gShowPing
: Boolean = False;
283 gShowMap
: Boolean = False;
285 gState
: Byte = STATE_NONE
;
287 sWidth
, sHeight
: Word;
288 gSpectMode
: Byte = SPECT_NONE
;
289 gSpectHUD
: Boolean = True;
290 gSpectKeyPress
: Boolean = False;
291 gSpectX
: Integer = 0;
292 gSpectY
: Integer = 0;
293 gSpectStep
: Byte = 8;
294 gSpectViewTwo
: Boolean = False;
295 gSpectPID1
: Integer = -1;
296 gSpectPID2
: Integer = -1;
297 gSpectAuto
: Boolean = False;
298 gSpectAutoNext
: LongWord;
299 gSpectAutoStepX
: Integer;
300 gSpectAutoStepY
: Integer;
301 gMusic
: TMusic
= nil;
302 gLoadGameMode
: Boolean;
303 gCheats
: Boolean = False;
304 gMapOnce
: Boolean = False;
305 gMapToDelete
: String;
306 gTempDelete
: Boolean = False;
307 gLastMap
: Boolean = False;
310 gResolutionChange
: Boolean = False;
311 gRC_Width
, gRC_Height
: Integer;
312 gRC_FullScreen
, gRC_Maximized
: Boolean;
313 gLanguageChange
: Boolean = False;
314 gDebugMode
: Boolean = False;
315 g_debug_WinMsgs
: Boolean = False;
316 g_debug_MonsterOff
: Boolean = False;
317 g_debug_BotAIOff
: Byte = 0;
318 g_Debug_Player
: Boolean = False;
319 gCoopMonstersKilled
: Word = 0;
320 gCoopSecretsFound
: Word = 0;
321 gCoopTotalMonstersKilled
: Word = 0;
322 gCoopTotalSecretsFound
: Word = 0;
323 gCoopTotalMonsters
: Word = 0;
324 gCoopTotalSecrets
: Word = 0;
325 gStatsOff
: Boolean = False;
326 gStatsPressed
: Boolean = False;
327 gExitByTrigger
: Boolean = False;
328 gNextMap
: String = '';
329 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
330 gLMSRespawnTime
: Cardinal = 0;
331 gLMSSoftSpawn
: Boolean = False;
332 gMissionFailed
: Boolean = False;
333 gVoteInProgress
: Boolean = False;
334 gVotePassed
: Boolean = False;
335 gVoteCommand
: string = '';
336 gVoteTimer
: Cardinal = 0;
337 gVoteCmdTimer
: Cardinal = 0;
338 gVoteCount
: Integer = 0;
339 gVoteTimeout
: Cardinal = 30;
340 gVoted
: Boolean = False;
341 gVotesEnabled
: Boolean = True;
342 gEvents
: Array of TGameEvent
;
343 gDelayedEvents
: Array of TDelayedEvent
;
344 gUseChatSounds
: Boolean = True;
345 gChatSounds
: Array of TChatSound
;
346 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
347 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
348 gInterReadyCount
: Integer = 0;
349 gMaxBots
: Integer = 127;
351 g_dbg_ignore_bounds
: Boolean = false;
352 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
353 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
355 // move button values:
356 // bits 0-1: l/r state:
357 // 0: neither left, nor right pressed
360 // bits 4-5: l/r state when strafe was pressed
361 P1MoveButton
: Byte = 0;
362 P2MoveButton
: Byte = 0;
364 g_profile_frame_update
: Boolean = false;
365 g_profile_frame_draw
: Boolean = false;
366 g_profile_collision
: Boolean = false;
367 g_profile_los
: Boolean = false;
368 g_profile_history_size
: Integer = 1000;
370 g_rlayer_back
: Boolean = true;
371 g_rlayer_step
: Boolean = true;
372 g_rlayer_wall
: Boolean = true;
373 g_rlayer_door
: Boolean = true;
374 g_rlayer_acid1
: Boolean = true;
375 g_rlayer_acid2
: Boolean = true;
376 g_rlayer_water
: Boolean = true;
377 g_rlayer_fore
: Boolean = true;
379 wNeedTimeReset
: Boolean = false;
381 procedure g_ResetDynlights ();
382 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
383 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
385 function conIsCheatsEnabled (): Boolean; inline;
386 function gPause (): Boolean; inline;
388 type (* private state *)
389 TEndCustomGameStat
= record
390 PlayerStat
: TPlayerStatArray
;
394 Map
, MapName
: String;
397 TEndSingleGameStat
= record
398 PlayerStat
: Array [0..1] of record
404 TotalSecrets
: Integer;
408 x
, y
, radius
: Integer;
411 exploRadius
: Integer;
414 var (* private state *)
415 CustomStat
: TEndCustomGameStat
;
416 StatShotDone
: Boolean;
417 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
418 SingleStat
: TEndSingleGameStat
;
421 EndingGameCounter
: Byte;
423 g_playerLight
: Boolean;
424 g_dynLights
: array of TDynLight
= nil;
425 g_dynLightCount
: Integer = 0;
426 EndPicPath
: AnsiString; // full path, used by render
431 {$IFDEF ENABLE_HOLMES}
443 {$IFDEF ENABLE_SHELLS}
446 {$IFDEF ENABLE_CORPSES}
449 {$IFDEF ENABLE_RENDER}
452 {$IFDEF ENABLE_SYSTEM}
456 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
457 g_playermodel
, g_options
, Math
,
458 g_triggers
, g_monsters
, e_sound
, CONFIG
,
459 g_language
, g_net
, g_phys
,
460 ENet
, e_msg
, g_netmsg
, g_netmaster
,
464 charbuff
: packed array [0..15] of AnsiChar = (
465 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
468 function Translit (const S
: AnsiString): AnsiString;
473 for i
:= 1 to Length(Result
) do
476 #
$C9: Result
[i
] := 'Q';
477 #
$D6: Result
[i
] := 'W';
478 #
$D3: Result
[i
] := 'E';
479 #
$CA: Result
[i
] := 'R';
480 #
$C5: Result
[i
] := 'T';
481 #
$CD: Result
[i
] := 'Y';
482 #
$C3: Result
[i
] := 'U';
483 #
$D8: Result
[i
] := 'I';
484 #
$D9: Result
[i
] := 'O';
485 #
$C7: Result
[i
] := 'P';
486 #
$D5: Result
[i
] := '['; //Chr(219);
487 #
$DA: Result
[i
] := ']'; //Chr(221);
488 #
$D4: Result
[i
] := 'A';
489 #
$DB: Result
[i
] := 'S';
490 #
$C2: Result
[i
] := 'D';
491 #
$C0: Result
[i
] := 'F';
492 #
$CF: Result
[i
] := 'G';
493 #
$D0: Result
[i
] := 'H';
494 #
$CE: Result
[i
] := 'J';
495 #
$CB: Result
[i
] := 'K';
496 #
$C4: Result
[i
] := 'L';
497 #
$C6: Result
[i
] := ';'; //Chr(186);
498 #
$DD: Result
[i
] := #39; //Chr(222);
499 #
$DF: Result
[i
] := 'Z';
500 #
$D7: Result
[i
] := 'X';
501 #
$D1: Result
[i
] := 'C';
502 #
$CC: Result
[i
] := 'V';
503 #
$C8: Result
[i
] := 'B';
504 #
$D2: Result
[i
] := 'N';
505 #
$DC: Result
[i
] := 'M';
506 #
$C1: Result
[i
] := ','; //Chr(188);
507 #
$DE: Result
[i
] := '.'; //Chr(190);
513 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
518 ls2
:= Translit(CheatRus
[ct
]);
519 if length(ls1
) = 0 then ls1
:= '~';
520 if length(ls2
) = 0 then ls2
:= '~';
522 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
523 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
524 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
525 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
527 if ct = I_GAME_CHEAT_JETPACK then
529 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
530 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
531 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
532 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
533 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
534 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
550 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
551 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
552 or g_Game_IsNet then Exit;
554 if not gGameOn
then exit
;
555 if not conIsCheatsEnabled
then exit
;
557 s
:= 'SOUND_GAME_RADIO';
560 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
562 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
563 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
567 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
569 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
570 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
574 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
576 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
577 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
581 if CheckCheat(I_GAME_CHEAT_DEATH
) then
583 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
584 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
585 s
:= 'SOUND_MONSTER_HAHA';
589 if CheckCheat(I_GAME_CHEAT_DOORS
) then
591 g_Triggers_OpenAll();
595 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
597 if gTriggers
<> nil then
598 for a
:= 0 to High(gTriggers
) do
599 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
601 gExitByTrigger
:= True;
602 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
603 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
609 s2
:= Copy(charbuff
, 15, 2);
610 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
612 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
620 if CheckCheat(I_GAME_CHEAT_FLY
) then
626 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
628 VEL_JUMP
:= 30-VEL_JUMP
;
632 if CheckCheat(I_GAME_CHEAT_SPEED
) then
634 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
638 if CheckCheat(I_GAME_CHEAT_SUIT
) then
640 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
641 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
645 if CheckCheat(I_GAME_CHEAT_AIR
) then
647 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
648 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
652 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
654 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
655 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
659 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
661 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
662 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
666 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
668 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
669 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
673 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
675 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
676 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
680 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
682 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
683 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
686 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
688 gAimLine
:= not gAimLine
;
691 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
693 gShowMap
:= not gShowMap
;
704 procedure KeyPress (K
: Word);
705 var Msg
: g_gui
.TMessage
;
710 if (g_ActiveWindow
<> nil) then
712 Msg
.Msg
:= WM_KEYDOWN
;
713 Msg
.WParam
:= VK_ESCAPE
;
714 g_ActiveWindow
.OnMessage(Msg
);
715 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
717 else if (gState
<> STATE_FOLD
) then
719 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
721 g_Game_InGameMenu(True);
723 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
725 if (gState
<> STATE_MENU
) then
727 if (NetMode
<> NET_NONE
) then
729 g_Game_StopAllSounds(True);
731 gState
:= STATE_MENU
;
735 g_GUI_ShowWindow('MainMenu');
736 g_Sound_PlayEx('MENU_OPEN');
741 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
742 begin // <F2> .. <F6> � <F12>
743 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
745 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
746 if (not g_Game_IsNet
) then g_Game_Pause(True);
748 IK_F2
: g_Menu_Show_SaveMenu();
749 IK_F3
: g_Menu_Show_LoadMenu();
750 IK_F4
: g_Menu_Show_GameSetGame();
751 IK_F5
: g_Menu_Show_OptionsVideo();
752 IK_F6
: g_Menu_Show_OptionsSound();
753 IK_F7
: g_Menu_Show_EndGameMenu();
754 IK_F10
: g_Menu_Show_QuitGameMenu();
761 gJustChatted
:= False;
762 if gConsoleShow
or gChatShow
then
764 g_Console_Control(K
);
766 else if (g_ActiveWindow
<> nil) then
768 Msg
.Msg
:= WM_KEYDOWN
;
770 g_ActiveWindow
.OnMessage(Msg
);
772 else if (gState
= STATE_MENU
) then
774 g_GUI_ShowWindow('MainMenu');
775 g_Sound_PlayEx('MENU_OPEN');
781 procedure KeyPress (K
: Word);
783 gJustChatted
:= False;
784 if gConsoleShow
or gChatShow
then
786 g_Console_Control(K
);
791 {$IFDEF ENABLE_SYSTEM}
792 procedure CharPress (C
: AnsiChar);
794 var Msg
: g_gui
.TMessage
;
798 if gConsoleShow
or gChatShow
then
803 else if g_ActiveWindow
<> nil then
806 Msg
.WParam
:= Ord(C
);
807 g_ActiveWindow
.OnMessage(Msg
);
814 charbuff
[a
] := charbuff
[a
+ 1];
816 charbuff
[15] := upcase1251(C
);
823 // ////////////////////////////////////////////////////////////////////////// //
824 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
826 procedure g_ResetDynlights ();
830 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
832 for idx
:= 0 to g_dynLightCount
-1 do
834 if g_dynLights
[idx
].exploCount
= -666 then
841 Inc(g_dynLights
[idx
].exploCount
);
842 if (g_dynLights
[idx
].exploCount
< 10) then
844 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
845 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
846 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
847 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
852 g_dynLightCount
:= lnum
;
855 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
857 if not gwin_has_stencil
then exit
;
858 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
859 g_dynLights
[g_dynLightCount
].x
:= x
;
860 g_dynLights
[g_dynLightCount
].y
:= y
;
861 g_dynLights
[g_dynLightCount
].radius
:= radius
;
862 g_dynLights
[g_dynLightCount
].r
:= r
;
863 g_dynLights
[g_dynLightCount
].g
:= g
;
864 g_dynLights
[g_dynLightCount
].b
:= b
;
865 g_dynLights
[g_dynLightCount
].a
:= a
;
866 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
867 Inc(g_dynLightCount
);
870 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
872 if not gwin_has_stencil
then exit
;
873 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
874 g_dynLights
[g_dynLightCount
].x
:= x
;
875 g_dynLights
[g_dynLightCount
].y
:= y
;
876 g_dynLights
[g_dynLightCount
].radius
:= 0;
877 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
878 g_dynLights
[g_dynLightCount
].r
:= r
;
879 g_dynLights
[g_dynLightCount
].g
:= g
;
880 g_dynLights
[g_dynLightCount
].b
:= b
;
881 g_dynLights
[g_dynLightCount
].a
:= 0;
882 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
883 Inc(g_dynLightCount
);
886 // ////////////////////////////////////////////////////////////////////////// //
887 function conIsCheatsEnabled (): Boolean; inline;
890 if g_Game_IsNet
then exit
;
891 if not gDebugMode
then
893 //if not gCheats then exit;
894 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
895 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
900 // ////////////////////////////////////////////////////////////////////////// //
902 TParamStrValue
= record
907 TParamStrValues
= Array of TParamStrValue
;
910 INTER_ACTION_TEXT
= 1;
911 INTER_ACTION_PIC
= 2;
912 INTER_ACTION_MUSIC
= 3;
917 DataLoaded
: Boolean = False;
919 MapList
: SSArray
= nil;
920 MapIndex
: Integer = -1;
921 InterReadyTime
: Integer = -1;
922 StatDate
: string = '';
937 function Compare(a
, b
: TPlayerStat
): Integer;
939 if a
.Spectator
then Result
:= 1
940 else if b
.Spectator
then Result
:= -1
941 else if a
.Frags
< b
.Frags
then Result
:= 1
942 else if a
.Frags
> b
.Frags
then Result
:= -1
943 else if a
.Deaths
< b
.Deaths
then Result
:= -1
944 else if a
.Deaths
> b
.Deaths
then Result
:= 1
945 else if a
.Kills
< b
.Kills
then Result
:= -1
949 procedure SortGameStat(var stat
: TPlayerStatArray
);
954 if stat
= nil then Exit
;
956 for I
:= High(stat
) downto Low(stat
) do
957 for J
:= Low(stat
) to High(stat
) - 1 do
958 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
961 stat
[J
] := stat
[J
+ 1];
966 // saves a shitty CSV containing the game stats passed to it
967 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
970 dir
, fname
, map
, mode
, etime
: String;
974 dir
:= e_GetWriteableDir(StatsDirs
);
975 // stats are placed in stats/yy/mm/dd/*.csv
976 fname
:= e_CatPath(dir
, Path
);
977 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
978 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
979 AssignFile(s
, fname
);
981 SetTextCodePage(s
, CP_UTF8
);
983 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
984 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
985 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
986 mode
:= g_Game_ModeToText(Stat
.GameMode
);
987 etime
:= Format('%d:%.2d:%.2d', [
988 Stat
.GameTime
div 1000 div 3600,
989 (Stat
.GameTime
div 1000 div 60) mod 60,
990 Stat
.GameTime
div 1000 mod 60
992 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
993 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
999 gGameSettings
.TimeLimit
,
1000 gGameSettings
.ScoreLimit
,
1001 gGameSettings
.Options
,
1003 Length(Stat
.PlayerStat
)
1005 // line 2: game specific shit
1006 // if it's a team game: red score, blue score
1007 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1008 // otherwise nothing
1009 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1011 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
1012 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1014 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1015 // lines 3-...: team, player name, frags, deaths
1016 WriteLn(s
, 'team,name,frags,deaths');
1017 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1018 with Stat
.PlayerStat
[I
] do
1019 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1021 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1024 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1029 procedure ClearDebugCvars();
1031 g_debug_WinMsgs
:= False;
1032 g_debug_MonsterOff
:= False;
1033 g_debug_BotAIOff
:= 0;
1034 g_Debug_Player
:= False;
1037 function g_Game_ModeToText(Mode
: Byte): string;
1041 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1042 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1043 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1044 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1045 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1049 function g_Game_TextToMode(Mode
: string): Byte;
1052 Mode
:= UpperCase(Mode
);
1053 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1058 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1063 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1068 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1073 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1075 Result
:= GM_SINGLE
;
1080 function g_Game_IsNet(): Boolean;
1082 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1085 function g_Game_IsServer(): Boolean;
1087 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1090 function g_Game_IsClient(): Boolean;
1092 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1095 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1102 Result
.name
:= ExtractFileName(WAD
);
1103 Result
.description
:= '';
1104 Result
.author
:= '';
1106 w
:= TWADFile
.Create();
1109 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1115 cfg
:= TConfig
.CreateMem(p
, len
);
1116 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1117 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1118 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1119 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1125 procedure g_Game_FreeWAD
;
1128 g_Sound_Delete('MUSIC_endmus');
1129 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1130 gGameSettings
.WAD
:= '';
1133 procedure g_Game_LoadWAD(WAD
: string);
1142 gGameSettings
.WAD
:= WAD
;
1143 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1146 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1148 w
:= TWADFile
.Create();
1151 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1157 cfg
:= TConfig
.CreateMem(p
, len
);
1160 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1161 if MegaWAD
.endpic
<> '' then
1162 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1164 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1165 if MegaWAD
.endmus
<> '' then
1167 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1168 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1176 {procedure start_trigger(t: string);
1180 function next_trigger(): Boolean;
1184 procedure DisableCheats();
1190 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1191 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1192 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1193 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1195 {$IF DEFINED(D2F_DEBUG)}
1196 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1197 gAimLine
:= g_dbg_aimline_on
;
1201 procedure g_Game_ExecuteEvent(Name
: String);
1207 if gEvents
= nil then
1209 for a
:= 0 to High(gEvents
) do
1210 if gEvents
[a
].Name
= Name
then
1212 if gEvents
[a
].Command
<> '' then
1213 g_Console_Process(gEvents
[a
].Command
, True);
1218 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1223 if gDelayedEvents
<> nil then
1224 for a
:= 0 to High(gDelayedEvents
) do
1225 if not gDelayedEvents
[a
].Pending
then
1232 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1233 n
:= High(gDelayedEvents
);
1235 gDelayedEvents
[n
].Pending
:= True;
1236 gDelayedEvents
[n
].DEType
:= DEType
;
1237 gDelayedEvents
[n
].DENum
:= Num
;
1238 gDelayedEvents
[n
].DEStr
:= Str
;
1239 if DEType
= DE_GLOBEVENT
then
1240 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1242 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1246 procedure EndGame();
1252 if g_Game_IsNet
and g_Game_IsServer
then
1253 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1256 gPauseMain
:= false;
1257 gPauseHolmes
:= false;
1260 g_Game_StopAllSounds(False);
1265 EndingGameCounter
:= 0;
1267 {$IFDEF ENABLE_MENU}
1268 g_ActiveWindow
:= nil;
1271 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1272 gLMSRespawnTime
:= 0;
1275 EXIT_SIMPLE
: // Выход через меню или конец теста
1279 begin // Это был тест
1283 begin // Выход в главное меню
1284 {$IFDEF DISABLE_MENU}
1285 gState
:= STATE_MENU
; // ???
1287 gMusic
.SetByName('MUSIC_MENU');
1289 if gState
<> STATE_SLIST
then
1291 g_GUI_ShowWindow('MainMenu');
1292 gState
:= STATE_MENU
;
1296 // Обновляем список серверов
1297 slReturnPressed
:= True;
1298 if g_Net_Slist_Fetch(slCurrent
) then
1300 if slCurrent
= nil then
1301 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1304 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1305 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1308 g_Game_ExecuteEvent('ongameend');
1312 EXIT_RESTART
: // Начать уровень сначала
1314 if not g_Game_IsClient
then g_Game_Restart();
1317 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1319 // Статистика Своей игры:
1320 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1322 CustomStat
.GameTime
:= gTime
;
1323 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1324 CustomStat
.MapName
:= gMapInfo
.Name
;
1325 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1326 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1327 CustomStat
.TeamStat
:= gTeamStat
;
1329 CustomStat
.PlayerStat
:= nil;
1331 // Статистика игроков:
1332 if gPlayers
<> nil then
1334 for a
:= 0 to High(gPlayers
) do
1335 if gPlayers
[a
] <> nil then
1337 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1338 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1341 Name
:= gPlayers
[a
].Name
;
1342 Frags
:= gPlayers
[a
].Frags
;
1343 Deaths
:= gPlayers
[a
].Death
;
1344 Kills
:= gPlayers
[a
].Kills
;
1345 Team
:= gPlayers
[a
].Team
;
1346 Color
:= gPlayers
[a
].Model
.Color
;
1347 Spectator
:= gPlayers
[a
].FSpectator
;
1351 SortGameStat(CustomStat
.PlayerStat
);
1353 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1356 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1357 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1358 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1359 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1361 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1364 StatShotDone
:= False;
1367 g_Game_ExecuteEvent('onmapend');
1368 if not g_Game_IsClient
then g_Player_ResetReady
;
1369 gInterReadyCount
:= 0;
1371 // Затухающий экран:
1372 EndingGameCounter
:= 255;
1373 gState
:= STATE_FOLD
;
1375 if gDefInterTime
< 0 then
1376 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1378 gInterEndTime
:= gDefInterTime
* 1000;
1381 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1383 // Статистика Одиночной игры:
1384 SingleStat
.GameTime
:= gTime
;
1385 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1386 SingleStat
.TotalSecrets
:= gSecretsCount
;
1387 // Статистика первого игрока:
1388 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1389 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1390 // Статистика второго игрока (если есть):
1391 if SingleStat
.TwoPlayers
then
1393 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1394 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1397 g_Game_ExecuteEvent('onmapend');
1400 if gNextMap
<> '' then
1402 gMusic
.SetByName('MUSIC_INTERMUS');
1404 gState
:= STATE_INTERSINGLE
;
1407 g_Game_ExecuteEvent('oninter');
1409 else // Больше нет карт
1411 // Затухающий экран:
1412 EndingGameCounter
:= 255;
1413 gState
:= STATE_FOLD
;
1418 // Окончание обработано:
1419 if gExit
<> EXIT_QUIT
then
1423 procedure g_Game_Init();
1427 gTempDelete
:= False;
1429 sfsGCDisable(); // temporary disable removing of temporary volumes
1433 gPauseMain
:= false;
1434 gPauseHolmes
:= false;
1437 {e_MouseInfo.Accel := 1.0;}
1441 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1442 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1443 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1444 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1445 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1447 gMusic
:= TMusic
.Create();
1448 gMusic
.SetByName('MUSIC_MENU');
1451 gGameSettings
.WarmupTime
:= 30;
1453 gState
:= STATE_MENU
;
1455 SetLength(gEvents
, 6);
1456 gEvents
[0].Name
:= 'ongamestart';
1457 gEvents
[1].Name
:= 'ongameend';
1458 gEvents
[2].Name
:= 'onmapstart';
1459 gEvents
[3].Name
:= 'onmapend';
1460 gEvents
[4].Name
:= 'oninter';
1461 gEvents
[5].Name
:= 'onwadend';
1463 sfsGCEnable(); // enable releasing unused volumes
1467 procedure g_Game_Free(freeTextures
: Boolean=true);
1469 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1470 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1472 g_Map_Free(freeTextures
);
1475 {$IFDEF ENABLE_GIBS}
1478 {$IFDEF ENABLE_SHELLS}
1481 {$IFDEF ENABLE_CORPSES}
1482 g_Corpses_RemoveAll
;
1485 gGameSettings
.GameType
:= GT_NONE
;
1486 if gGameSettings
.GameMode
= GM_SINGLE
then
1487 gGameSettings
.GameMode
:= GM_DM
;
1488 gSwitchGameMode
:= gGameSettings
.GameMode
;
1491 gExitByTrigger
:= False;
1494 function IsActivePlayer(p
: TPlayer
): Boolean;
1499 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1502 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1508 if gPlayers
= nil then
1512 for a
:= Low(gPlayers
) to High(gPlayers
) do
1513 if IsActivePlayer(gPlayers
[a
]) then
1515 SetLength(ids
, Length(ids
) + 1);
1516 ids
[High(ids
)] := gPlayers
[a
].UID
;
1517 if gPlayers
[a
].UID
= Skip
then
1520 if Length(ids
) = 0 then
1525 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1528 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1534 if gPlayers
= nil then
1538 for a
:= Low(gPlayers
) to High(gPlayers
) do
1539 if IsActivePlayer(gPlayers
[a
]) then
1541 SetLength(ids
, Length(ids
) + 1);
1542 ids
[High(ids
)] := gPlayers
[a
].UID
;
1543 if gPlayers
[a
].UID
= Skip
then
1546 if Length(ids
) = 0 then
1549 Result
:= ids
[Length(ids
) - 1]
1551 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1554 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1560 if gPlayers
= nil then
1564 for a
:= Low(gPlayers
) to High(gPlayers
) do
1565 if IsActivePlayer(gPlayers
[a
]) then
1567 SetLength(ids
, Length(ids
) + 1);
1568 ids
[High(ids
)] := gPlayers
[a
].UID
;
1569 if gPlayers
[a
].UID
= Skip
then
1572 if Length(ids
) = 0 then
1574 if Length(ids
) = 1 then
1579 Result
:= ids
[Random(Length(ids
))];
1581 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1583 Result
:= ids
[Random(Length(ids
))];
1588 function GetRandomSpectMode(Current
: Byte): Byte;
1595 0: Result
:= SPECT_STATS
;
1596 1: Result
:= SPECT_MAPVIEW
;
1597 2: Result
:= SPECT_MAPVIEW
;
1598 3: Result
:= SPECT_PLAYERS
;
1599 4: Result
:= SPECT_PLAYERS
;
1600 5: Result
:= SPECT_PLAYERS
;
1601 6: Result
:= SPECT_PLAYERS
;
1603 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1607 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1613 if (plr
= nil) then exit
;
1614 if (p
= 2) then time
:= 1000 else time
:= 1;
1615 strafeDir
:= MoveButton
shr 4;
1616 MoveButton
:= MoveButton
and $0F;
1618 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1619 MoveButton
:= 1 // Нажата только "Влево"
1620 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1621 MoveButton
:= 2 // Нажата только "Вправо"
1622 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1623 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1625 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1626 if MoveButton
= 1 then
1627 plr
.PressKey(KEY_LEFT
, time
)
1628 else if MoveButton
= 2 then
1629 plr
.PressKey(KEY_RIGHT
, time
);
1631 // if we have "strafe" key, turn off old strafe mechanics
1632 if gPlayerAction
[p
, ACTION_STRAFE
] then
1634 // new strafe mechanics
1635 if (strafeDir
= 0) then
1636 strafeDir
:= MoveButton
; // start strafing
1637 // now set direction according to strafe (reversed)
1638 if (strafeDir
= 2) then
1639 plr
.SetDirection(TDirection
.D_LEFT
)
1640 else if (strafeDir
= 1) then
1641 plr
.SetDirection(TDirection
.D_RIGHT
)
1645 strafeDir
:= 0; // not strafing anymore
1646 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1647 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1648 plr
.SetDirection(TDirection
.D_LEFT
)
1649 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1650 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1651 plr
.SetDirection(TDirection
.D_RIGHT
)
1652 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1653 else if MoveButton
<> 0 then
1654 plr
.SetDirection(TDirection(MoveButton
-1))
1657 // fix movebutton state
1658 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1660 // Остальные клавиши:
1661 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1662 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1663 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1664 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1665 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1667 for i
:= WP_FACT
to WP_LACT
do
1669 if gWeaponAction
[p
, i
] then
1671 plr
.ProcessWeaponAction(i
);
1672 gWeaponAction
[p
, i
] := False
1676 for i
:= WP_FIRST
to WP_LAST
do
1678 if gSelectWeapon
[p
, i
] then
1680 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1681 gSelectWeapon
[p
, i
] := False
1685 {$IFDEF ENABLE_MENU}
1686 // HACK: add dynlight here
1687 if gwin_k8_enable_light_experiments
then
1689 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1691 g_playerLight
:= true;
1693 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1695 g_playerLight
:= false;
1699 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1703 // HACK: don't have a "key was pressed" function
1704 procedure InterReady();
1706 if InterReadyTime
> gTime
then Exit
;
1707 InterReadyTime
:= gTime
+ 3000;
1708 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1711 procedure g_Game_PreUpdate();
1713 // these are in separate PreUpdate functions because they can interact during Update()
1714 // and are synced over the net
1715 // we don't care that much about corpses and gibs
1716 g_Player_PreUpdate();
1717 g_Monsters_PreUpdate();
1718 g_Items_PreUpdate();
1719 g_Weapon_PreUpdate();
1722 procedure g_Game_SetupHearPoints
;
1723 var p1
, p2
: TPlayer
; a
, b
: Integer;
1727 gHearPoint1
.Active
:= false;
1728 gHearPoint2
.Active
:= false;
1729 if gSpectMode
= SPECT_MAPVIEW
then
1731 // TODO something better (render dependency)
1732 gHearPoint1
.Active
:= true;
1733 gHearPoint1
.Coords
.X
:= gSpectX
+ gScreenWidth
div 2;
1734 gHearPoint1
.Coords
.Y
:= gSpectY
+ gScreenHeight
div 2;
1736 else if gSpectMode
= SPECT_PLAYERS
then
1738 p1
:= g_Player_Get(gSpectPID1
);
1739 if gSpectViewTwo
then
1740 p2
:= g_Player_Get(gSpectPID2
);
1742 else if gSpectMode
= SPECT_NONE
then
1749 gHearPoint1
.Active
:= true;
1750 gHearPoint1
.Coords
.X
:= p1
.obj
.x
+ p1
.obj
.rect
.width
div 2;
1751 gHearPoint1
.Coords
.Y
:= p1
.obj
.y
+ p1
.obj
.rect
.height
div 2;
1753 if (p2
<> nil) and (p1
<> p2
) then
1755 gHearPoint2
.Active
:= true;
1756 gHearPoint2
.Coords
.X
:= p2
.obj
.x
+ p2
.obj
.rect
.width
div 2;
1757 gHearPoint2
.Coords
.Y
:= p2
.obj
.y
+ p2
.obj
.rect
.height
div 2;
1759 // TODO something better (render dependency)
1760 if (p1
<> nil) and (p2
<> nil) then
1762 gPlayerScreenSize
.X
:= gScreenWidth
- 196;
1763 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
1767 gPlayerScreenSize
.X
:= gScreenWidth
- 196;
1768 gPlayerScreenSize
.Y
:= gScreenHeight
;
1771 if gMapInfo
.Height
> gPlayerScreenSize
.Y
then a
:= gMapInfo
.Height
- gPlayerScreenSize
.Y
else a
:= gMapInfo
.Height
;
1772 if gMapInfo
.Width
> gPlayerScreenSize
.X
then b
:= gMapInfo
.Width
- gPlayerScreenSize
.X
else b
:= gMapInfo
.Width
;
1773 gMaxDist
:= Trunc(Hypot(a
, b
));
1776 procedure g_Game_Update();
1778 {$IFDEF ENABLE_MENU}
1779 Msg
: g_gui
.TMessage
;
1786 function sendMonsPos (mon
: TMonster
): Boolean;
1788 result
:= false; // don't stop
1789 // this will also reset "need-send" flag
1790 if mon
.gncNeedSend
then
1792 MH_SEND_MonsterPos(mon
.UID
);
1794 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1796 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1798 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1800 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1804 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1806 result
:= false; // don't stop
1807 // this will also reset "need-send" flag
1808 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1811 function sendItemPos (it
: PItem
): Boolean;
1813 result
:= false; // don't stop
1816 MH_SEND_ItemPos(it
.myId
);
1817 it
.needSend
:= False;
1822 reliableUpdate
: Boolean;
1823 rSpectX0
, rSpectY0
: Integer;
1824 rSpectX1
, rSpectY1
: Integer;
1829 // Пора выключать игру:
1830 if gExit
= EXIT_QUIT
then
1832 // Игра закончилась - обрабатываем:
1836 if gExit
= EXIT_QUIT
then
1840 // Читаем клавиатуру и джойстик, если окно активно
1841 // no need to, as we'll do it in event handler
1843 // Обновляем консоль (движение и сообщения):
1846 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1848 gExit
:= EXIT_SIMPLE
;
1853 // process master server communications
1854 g_Net_Slist_Pulse();
1857 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1858 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1859 STATE_INTERTEXT
, // Текст между уровнями
1860 STATE_INTERPIC
: // Картинка между уровнями
1862 if g_Game_IsNet
and g_Game_IsServer
then
1864 gInterTime
:= gInterTime
+ GAME_TICK
;
1865 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1866 if a
<> gServInterTime
then
1868 gServInterTime
:= a
;
1869 MH_SEND_TimeSync(gServInterTime
);
1873 if (not g_Game_IsClient
) and
1877 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1878 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1879 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1880 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1882 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1883 {$IFDEF ENABLE_MENU}
1884 and (g_ActiveWindow
= nil)
1887 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1890 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1891 g_Game_StopAllSounds(True);
1893 if gMapOnce
then // Это был тест
1894 gExit
:= EXIT_SIMPLE
1896 if gNextMap
<> '' then // Переходим на следующую карту
1897 g_Game_ChangeMap(gNextMap
)
1898 else // Следующей карты нет
1900 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1902 // Выход в главное меню:
1904 {$IFDEF ENABLE_MENU}
1905 g_GUI_ShowWindow('MainMenu');
1906 gMusic
.SetByName('MUSIC_MENU');
1909 gState
:= STATE_MENU
;
1912 // Финальная картинка:
1913 g_Game_ExecuteEvent('onwadend');
1915 if not gMusic
.SetByName('MUSIC_endmus') then
1916 gMusic
.SetByName('MUSIC_STDENDMUS');
1918 gState
:= STATE_ENDPIC
;
1920 g_Game_ExecuteEvent('ongameend');
1925 else if g_Game_IsClient
and
1928 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1929 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1930 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1931 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1933 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1934 {$IFDEF ENABLE_MENU}
1935 and (g_ActiveWindow
= nil)
1944 if gState
= STATE_INTERTEXT
then
1945 if InterText
.counter
> 0 then
1946 InterText
.counter
:= InterText
.counter
- 1;
1949 STATE_FOLD
: // Затухание экрана
1951 if EndingGameCounter
= 0 then
1953 // Закончился уровень в Своей игре:
1954 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1956 gState
:= STATE_INTERCUSTOM
;
1957 InterReadyTime
:= -1;
1958 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1960 g_Game_ExecuteEvent('onwadend');
1961 if not gMusic
.SetByName('MUSIC_endmus') then
1962 gMusic
.SetByName('MUSIC_STDENDMUS');
1965 gMusic
.SetByName('MUSIC_ROUNDMUS');
1969 else // Закончилась последняя карта в Одиночной игре
1971 gMusic
.SetByName('MUSIC_INTERMUS');
1973 gState
:= STATE_INTERSINGLE
;
1976 g_Game_ExecuteEvent('oninter');
1979 DecMin(EndingGameCounter
, 6, 0);
1982 STATE_ENDPIC
: // Картинка окончания мегаВада
1984 if gMapOnce
then // Это был тест
1986 gExit
:= EXIT_SIMPLE
;
1992 g_Serverlist_Control(slCurrent
, slTable
);
1995 // Статистика по Tab:
1998 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
2002 if g_Console_Action(ACTION_SCORES
) then
2004 if not gStatsPressed
then
2006 gStatsOff
:= not gStatsOff
;
2007 gStatsPressed
:= True;
2011 gStatsPressed
:= False;
2015 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
2017 // Время += 28 миллисекунд:
2018 gTime
:= gTime
+ GAME_TICK
;
2020 // Сообщение посередине экрана:
2021 if MessageTime
= 0 then
2023 if MessageTime
> 0 then
2024 MessageTime
:= MessageTime
- 1;
2026 if (g_Game_IsServer
) then
2028 // Был задан лимит времени:
2029 if (gGameSettings
.TimeLimit
> 0) then
2030 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
2031 begin // Он прошел => конец уровня
2036 // Надо респавнить игроков в LMS:
2037 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
2038 g_Game_RestartRound(gLMSSoftSpawn
);
2040 // Проверим результат голосования, если время прошло
2041 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2043 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2045 g_Console_Process(gVoteCommand
);
2047 gVotePassed
:= False;
2050 // Замеряем время захвата флагов
2051 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2052 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2053 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2054 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2056 // Был задан лимит побед:
2057 if (gGameSettings
.ScoreLimit
> 0) then
2061 if gGameSettings
.GameMode
= GM_DM
then
2062 begin // В DM ищем игрока с max фрагами
2063 for i
:= 0 to High(gPlayers
) do
2064 if gPlayers
[i
] <> nil then
2065 if gPlayers
[i
].Frags
> b
then
2066 b
:= gPlayers
[i
].Frags
;
2069 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2070 begin // В CTF/TDM выбираем команду с наибольшим счетом
2071 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2074 // Лимит побед набран => конец уровня:
2075 if b
>= gGameSettings
.ScoreLimit
then
2082 // Обрабатываем клавиши игроков:
2083 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2084 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2085 {$IFDEF DISABLE_MENU}
2086 if (not gConsoleShow
) and (not gChatShow
) then
2088 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2091 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2092 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2093 end // if not console
2096 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2098 // process weapon switch queue
2103 {$IFDEF ENABLE_RENDER}
2104 r_Render_GetSpectatorLimits(rSpectX0
, rSpectY0
, rSpectX1
, rSpectY1
);
2106 rSpectX0
:= 0; rSpectY0
:= 0;
2107 rSpectX1
:= gMapInfo
.Width
- 1; rSpectY1
:= gMapInfo
.Height
- 1;
2110 if (gPlayer1
= nil) and (gPlayer2
= nil)
2111 and (not gConsoleShow
) and (not gChatShow
)
2112 {$IFDEF ENABLE_MENU}
2113 and (g_ActiveWindow
= nil)
2117 if not gSpectKeyPress
then
2119 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2121 // switch spect mode
2123 SPECT_NONE
: ; // not spectator
2125 SPECT_MAPVIEW
: Inc(gSpectMode
);
2126 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2128 gSpectKeyPress
:= True;
2130 if (gSpectMode
= SPECT_MAPVIEW
)
2131 and (not gSpectAuto
) then
2133 if gPlayerAction
[0, ACTION_MOVELEFT
] then gSpectX
:= gSpectX
- gSpectStep
;
2134 if gPlayerAction
[0, ACTION_MOVERIGHT
] then gSpectX
:= gSpectX
+ gSpectStep
;
2135 if gPlayerAction
[0, ACTION_LOOKUP
] then gSpectY
:= gSpectY
- gSpectStep
;
2136 if gPlayerAction
[0, ACTION_LOOKDOWN
] then gSpectY
:= gSpectY
+ gSpectStep
;
2137 if gWeaponAction
[0, WP_PREV
] then
2140 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2141 gWeaponAction
[0, WP_PREV
] := False;
2143 if gWeaponAction
[0, WP_NEXT
] then
2146 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2147 gWeaponAction
[0, WP_NEXT
] := False;
2150 if (gSpectMode
= SPECT_PLAYERS
)
2151 and (not gSpectAuto
) then
2153 if gPlayerAction
[0, ACTION_LOOKUP
] then
2156 gSpectViewTwo
:= True;
2157 gSpectKeyPress
:= True;
2159 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2161 // remove second view
2162 gSpectViewTwo
:= False;
2163 gSpectKeyPress
:= True;
2165 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2167 // prev player (view 1)
2168 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2169 gSpectKeyPress
:= True;
2171 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2173 // next player (view 1)
2174 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2175 gSpectKeyPress
:= True;
2177 if gWeaponAction
[0, WP_PREV
] then
2179 // prev player (view 2)
2180 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2181 gWeaponAction
[0, WP_PREV
] := False;
2183 if gWeaponAction
[0, WP_NEXT
] then
2185 // next player (view 2)
2186 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2187 gWeaponAction
[0, WP_NEXT
] := False;
2190 if gPlayerAction
[0, ACTION_ATTACK
] then
2192 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2195 gSpectAutoNext
:= 0;
2196 gSpectViewTwo
:= False;
2197 gSpectKeyPress
:= True;
2202 gSpectMode
:= SPECT_STATS
;
2203 gSpectAuto
:= False;
2204 gSpectKeyPress
:= True;
2209 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2210 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2211 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2212 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2213 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2214 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2215 gSpectKeyPress
:= False;
2219 if gSpectMode
= SPECT_MAPVIEW
then
2221 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, rSpectX0
), rSpectX1
);
2223 gSpectAutoNext
:= gTime
2226 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, rSpectY0
), rSpectY1
);
2228 gSpectAutoNext
:= gTime
2232 if gSpectAutoNext
<= gTime
then
2234 if gSpectAutoNext
> 0 then
2236 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2240 gSpectX
:= rSpectX0
+ Random(rSpectX1
- rSpectX0
);
2241 gSpectY
:= rSpectY0
+ Random(rSpectY1
- rSpectY0
);
2242 gSpectAutoStepX
:= Random(9) - 4;
2243 gSpectAutoStepY
:= Random(9) - 4;
2244 if ((gSpectX
< rSpectX0
) and (gSpectAutoStepX
< 0)) or
2245 ((gSpectX
> rSpectX1
) and (gSpectAutoStepX
> 0)) then
2246 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2247 if ((gSpectY
< rSpectY0
) and (gSpectAutoStepY
< 0)) or
2248 ((gSpectY
> rSpectY1
) and (gSpectAutoStepY
> 0)) then
2249 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2253 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2258 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2259 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2260 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2265 if gSpectMode
= SPECT_MAPVIEW
then
2267 gSpectX
:= Max(gSpectX
, rSpectX0
);
2268 gSpectX
:= Min(gSpectX
, rSpectX1
);
2269 gSpectY
:= Max(gSpectY
, rSpectY0
);
2270 gSpectY
:= Min(gSpectY
, rSpectY1
);
2274 (* spectator state check from render *)
2276 if (gPlayer1
= nil) and (gPlayer2
= nil) then
2278 (* no local players -> automatically enable to spectator mode *)
2279 if gSpectMode
= SPECT_NONE
then gSpectMode
:= SPECT_STATS
;
2283 (* at least one local player -> automatically disable spectator mode *)
2284 gSpectMode
:= SPECT_NONE
;
2287 if IsActivePlayer(g_Player_Get(gSpectPID1
)) = false then
2288 gSpectPID1
:= GetActivePlayerID_Next();
2290 if IsActivePlayer(g_Player_Get(gSpectPID2
)) = false then
2291 gSpectPID2
:= GetActivePlayerID_Next();
2293 g_Game_SetupHearPoints
;
2295 // Обновляем все остальное:
2298 g_Triggers_Update();
2300 g_Monsters_Update();
2304 g_Player_UpdateAll();
2305 {$IFDEF ENABLE_GIBS}
2308 {$IFDEF ENABLE_CORPSES}
2311 {$IFDEF ENABLE_SHELLS}
2315 // server: send newly spawned monsters unconditionally
2316 if (gGameSettings
.GameType
= GT_SERVER
) then
2318 if (Length(gMonstersSpawned
) > 0) then
2320 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2321 SetLength(gMonstersSpawned
, 0);
2325 if (gSoundTriggerTime
> 8) then
2327 g_Game_UpdateTriggerSounds();
2328 gSoundTriggerTime
:= 0;
2332 Inc(gSoundTriggerTime
);
2335 if (NetMode
= NET_SERVER
) then
2337 Inc(NetTimeToUpdate
);
2338 Inc(NetTimeToReliable
);
2340 // send monster updates
2341 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2343 // send all monsters (periodic sync)
2344 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2346 for I
:= 0 to High(gPlayers
) do
2348 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2351 g_Mons_ForEach(sendMonsPos
);
2353 // update flags that aren't stationary
2354 if gGameSettings
.GameMode
= GM_CTF
then
2355 for I
:= FLAG_RED
to FLAG_BLUE
do
2356 if gFlags
[I
].NeedSend
then
2358 gFlags
[I
].NeedSend
:= False;
2362 // update items that aren't stationary
2363 g_Items_ForEachAlive(sendItemPos
);
2365 if reliableUpdate
then
2367 NetTimeToReliable
:= 0;
2368 NetTimeToUpdate
:= NetUpdateRate
;
2372 NetTimeToUpdate
:= 0;
2377 // send only mosters with some unexpected changes
2378 g_Mons_ForEach(sendMonsPosUnexpected
);
2381 // send unexpected platform changes
2382 g_Map_NetSendInterestingPanels();
2384 g_Net_Slist_ServerUpdate();
2386 if NetUseMaster then
2388 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2390 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2392 NetTimeToMaster := gTime + NetMasterRate;
2397 else if (NetMode
= NET_CLIENT
) then
2399 MC_SEND_PlayerPos();
2401 end; // if gameOn ...
2403 // Активно окно интерфейса - передаем клавиши ему:
2404 {$IFDEF ENABLE_MENU}
2405 if g_ActiveWindow
<> nil then
2407 w
:= e_GetFirstKeyPressed();
2409 if (w
<> IK_INVALID
) then
2411 Msg
.Msg
:= MESSAGE_DIKEY
;
2413 g_ActiveWindow
.OnMessage(Msg
);
2416 // Если оно от этого не закрылось, то обновляем:
2417 if g_ActiveWindow
<> nil then
2418 g_ActiveWindow
.Update();
2420 // Нужно сменить разрешение:
2421 if gResolutionChange
then
2423 {$IFDEF ENABLE_RENDER}
2424 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2427 gResolutionChange
:= False;
2428 g_ActiveWindow
:= nil;
2431 // Нужно сменить язык:
2432 if gLanguageChange
then
2434 //e_WriteLog('Read language file', MSG_NOTIFY);
2435 //g_Language_Load(DataDir + gLanguage + '.txt');
2436 g_Language_Set(gLanguage
);
2438 gLanguageChange
:= False;
2442 // Горячая клавиша для вызова меню выхода из игры (F10):
2443 if e_KeyPressed(IK_F10
) and
2445 (not gConsoleShow
) and
2446 (g_ActiveWindow
= nil) then
2452 Time
:= GetTickCount64() {div 1000};
2454 // Обработка отложенных событий:
2455 if gDelayedEvents
<> nil then
2456 for a
:= 0 to High(gDelayedEvents
) do
2457 if gDelayedEvents
[a
].Pending
and
2459 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2460 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2463 case gDelayedEvents
[a
].DEType
of
2465 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2468 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2472 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2473 if g_Game_IsNet
and g_Game_IsServer
then
2474 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2478 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2480 gDelayedEvents
[a
].Pending
:= False;
2483 // Каждую секунду обновляем счетчик обновлений:
2484 UPSCounter
:= UPSCounter
+ 1;
2485 if Time
- UPSTime
>= 1000 then
2494 g_Weapon_AddDynLights();
2495 g_Items_AddDynLights();
2499 procedure g_Game_LoadChatSounds(Resource
: string);
2502 FileName
, Snd
: string;
2504 len
, cnt
, tags
, i
, j
: Integer;
2507 FileName
:= g_ExtractWadName(Resource
);
2509 WAD
:= TWADFile
.Create();
2510 WAD
.ReadFile(FileName
);
2512 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2519 cfg
:= TConfig
.CreateMem(p
, len
);
2520 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2522 SetLength(gChatSounds
, cnt
);
2523 for i
:= 0 to Length(gChatSounds
) - 1 do
2525 gChatSounds
[i
].Sound
:= nil;
2526 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2527 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2528 if (Snd
= '') or (Tags
<= 0) then
2530 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2531 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2532 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2533 SetLength(gChatSounds
[i
].Tags
, tags
);
2534 for j
:= 0 to tags
- 1 do
2535 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2536 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2543 procedure g_Game_FreeChatSounds();
2547 for i
:= 0 to Length(gChatSounds
) - 1 do
2549 gChatSounds
[i
].Sound
.Free();
2550 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2552 SetLength(gChatSounds
, 0);
2556 procedure g_Game_LoadData();
2558 if DataLoaded
then Exit
;
2560 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2561 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
2563 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2564 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2565 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2566 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2567 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2568 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2569 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2570 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2571 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2572 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2573 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2574 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2575 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2576 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2577 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2578 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2579 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2580 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2581 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2582 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2583 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2584 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2585 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2586 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2587 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2588 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2589 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2590 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2591 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2592 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2593 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2594 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2596 goodsnd
[0] := TPlayableSound
.Create();
2597 goodsnd
[1] := TPlayableSound
.Create();
2598 goodsnd
[2] := TPlayableSound
.Create();
2599 goodsnd
[3] := TPlayableSound
.Create();
2601 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2602 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2603 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2604 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2606 killsnd
[0] := TPlayableSound
.Create();
2607 killsnd
[1] := TPlayableSound
.Create();
2608 killsnd
[2] := TPlayableSound
.Create();
2609 killsnd
[3] := TPlayableSound
.Create();
2611 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2612 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2613 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2614 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2616 hahasnd
[0] := TPlayableSound
.Create();
2617 hahasnd
[1] := TPlayableSound
.Create();
2618 hahasnd
[2] := TPlayableSound
.Create();
2620 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2621 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2622 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2624 sound_get_flag
[0] := TPlayableSound
.Create();
2625 sound_get_flag
[1] := TPlayableSound
.Create();
2626 sound_lost_flag
[0] := TPlayableSound
.Create();
2627 sound_lost_flag
[1] := TPlayableSound
.Create();
2628 sound_ret_flag
[0] := TPlayableSound
.Create();
2629 sound_ret_flag
[1] := TPlayableSound
.Create();
2630 sound_cap_flag
[0] := TPlayableSound
.Create();
2631 sound_cap_flag
[1] := TPlayableSound
.Create();
2633 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2634 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2635 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2636 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2637 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2638 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2639 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2640 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2642 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2646 g_Weapon_LoadData();
2648 g_Monsters_LoadData();
2653 procedure g_Game_Quit();
2655 g_Game_StopAllSounds(True);
2658 g_PlayerModel_FreeData();
2659 {$IFDEF ENABLE_MENU}
2660 // g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2663 if NetInitDone
then g_Net_Free
;
2665 // remove map after test
2666 if gMapToDelete
<> '' then
2667 g_Game_DeleteTestMap();
2671 {$IFDEF ENABLE_SYSTEM}
2676 procedure g_Game_FreeData();
2678 if not DataLoaded
then Exit
;
2681 g_Weapon_FreeData();
2682 g_Monsters_FreeData();
2684 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2686 g_Sound_Delete('SOUND_GAME_TELEPORT');
2687 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2688 g_Sound_Delete('SOUND_GAME_SECRET');
2689 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2690 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2691 g_Sound_Delete('SOUND_GAME_BULK1');
2692 g_Sound_Delete('SOUND_GAME_BULK2');
2693 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2694 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2695 g_Sound_Delete('SOUND_GAME_BURNING');
2696 g_Sound_Delete('SOUND_GAME_SWITCH1');
2697 g_Sound_Delete('SOUND_GAME_SWITCH0');
2704 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2705 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2706 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2707 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2714 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2715 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2716 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2717 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2723 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2724 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2725 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2727 sound_get_flag
[0].Free();
2728 sound_get_flag
[1].Free();
2729 sound_lost_flag
[0].Free();
2730 sound_lost_flag
[1].Free();
2731 sound_ret_flag
[0].Free();
2732 sound_ret_flag
[1].Free();
2733 sound_cap_flag
[0].Free();
2734 sound_cap_flag
[1].Free();
2736 g_Sound_Delete('SOUND_CTF_GET1');
2737 g_Sound_Delete('SOUND_CTF_GET2');
2738 g_Sound_Delete('SOUND_CTF_LOST1');
2739 g_Sound_Delete('SOUND_CTF_LOST2');
2740 g_Sound_Delete('SOUND_CTF_RETURN1');
2741 g_Sound_Delete('SOUND_CTF_RETURN2');
2742 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2743 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2745 g_Game_FreeChatSounds();
2747 DataLoaded
:= False;
2750 procedure g_FatalError(Text: String);
2752 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2753 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2755 gExit
:= EXIT_SIMPLE
;
2756 if gGameOn
then EndGame
;
2759 procedure g_SimpleError(Text: String);
2761 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2762 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2765 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2767 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2768 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2771 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2774 if gPlayer1
= nil then
2776 if g_Game_IsClient
then
2778 if NetPlrUID1
> -1 then
2779 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2783 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2784 Team
:= gPlayer1Settings
.Team
;
2786 // Создание первого игрока:
2787 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2788 gPlayer1Settings
.Color
,
2790 if gPlayer1
= nil then
2791 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2794 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2795 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2796 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2797 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2798 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2799 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2800 if g_Game_IsServer
and g_Game_IsNet
then
2801 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2802 gPlayer1
.Respawn(False, True);
2803 g_Net_Slist_ServerPlayerComes();
2808 if gPlayer2
= nil then
2810 if g_Game_IsClient
then
2812 if NetPlrUID2
> -1 then
2813 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2817 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2818 Team
:= gPlayer2Settings
.Team
;
2820 // Создание второго игрока:
2821 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2822 gPlayer2Settings
.Color
,
2824 if gPlayer2
= nil then
2825 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2828 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2829 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2830 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2831 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2832 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2833 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2834 if g_Game_IsServer
and g_Game_IsNet
then
2835 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2836 gPlayer2
.Respawn(False, True);
2837 g_Net_Slist_ServerPlayerComes();
2844 procedure g_Game_RemovePlayer();
2848 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2849 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2854 if g_Game_IsServer
then
2857 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2858 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2859 g_Player_Remove(Pl
.UID
);
2860 g_Net_Slist_ServerPlayerLeaves();
2864 gSpectLatchPID2
:= Pl
.UID
;
2872 if g_Game_IsServer
then
2875 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2876 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2877 g_Player_Remove(Pl
.UID
);
2878 g_Net_Slist_ServerPlayerLeaves();
2881 gSpectLatchPID1
:= Pl
.UID
;
2883 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2887 g_Net_Slist_ServerPlayerLeaves();
2890 procedure g_Game_Spectate();
2892 g_Game_RemovePlayer();
2893 if gPlayer1
<> nil then
2894 g_Game_RemovePlayer();
2897 procedure g_Game_SpectateCenterView();
2899 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2900 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2903 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2910 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2912 g_Game_ClearLoading();
2915 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2918 gGameSettings
.GameType
:= GT_SINGLE
;
2919 gGameSettings
.MaxLives
:= 0;
2920 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2921 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2922 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2923 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2924 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2925 gSwitchGameMode
:= GM_SINGLE
;
2927 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2928 gLMSRespawnTime
:= 0;
2929 gSpectLatchPID1
:= 0;
2930 gSpectLatchPID2
:= 0;
2932 g_Game_ExecuteEvent('ongamestart');
2934 // Создание первого игрока:
2935 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2936 gPlayer1Settings
.Color
,
2937 gPlayer1Settings
.Team
, False));
2938 if gPlayer1
= nil then
2940 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2944 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2945 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2946 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2947 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2948 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2951 // Создание второго игрока, если есть:
2954 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2955 gPlayer2Settings
.Color
,
2956 gPlayer2Settings
.Team
, False));
2957 if gPlayer2
= nil then
2959 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2963 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2964 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2965 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2966 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2967 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2971 // Загрузка и запуск карты:
2972 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2974 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2975 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2979 // Настройки игроков и ботов:
2983 for i
:= nPl
+1 to nPlayers
do
2984 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2987 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2988 TimeLimit
, ScoreLimit
: Word;
2990 Options
: LongWord; nPlayers
: Byte);
2996 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2998 g_Game_ClearLoading();
3001 gGameSettings
.GameType
:= GT_CUSTOM
;
3002 gGameSettings
.GameMode
:= GameMode
;
3003 gSwitchGameMode
:= GameMode
;
3004 gGameSettings
.TimeLimit
:= TimeLimit
;
3005 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3006 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3007 gGameSettings
.Options
:= Options
;
3009 gCoopTotalMonstersKilled
:= 0;
3010 gCoopTotalSecretsFound
:= 0;
3011 gCoopTotalMonsters
:= 0;
3012 gCoopTotalSecrets
:= 0;
3016 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3017 gLMSRespawnTime
:= 0;
3018 gSpectLatchPID1
:= 0;
3019 gSpectLatchPID2
:= 0;
3021 g_Game_ExecuteEvent('ongamestart');
3023 // Режим наблюдателя:
3024 if nPlayers
= 0 then
3031 if nPlayers
>= 1 then
3033 // Создание первого игрока:
3034 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3035 gPlayer1Settings
.Color
,
3036 gPlayer1Settings
.Team
, False));
3037 if gPlayer1
= nil then
3039 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3043 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3044 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3045 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3046 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3047 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3051 if nPlayers
>= 2 then
3053 // Создание второго игрока:
3054 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3055 gPlayer2Settings
.Color
,
3056 gPlayer2Settings
.Team
, False));
3057 if gPlayer2
= nil then
3059 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3063 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3064 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3065 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3066 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3067 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3071 // Загрузка и запуск карты:
3072 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3074 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3078 // Нет точек появления:
3079 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3080 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3081 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3082 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3083 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3085 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3089 // Настройки игроков и ботов:
3093 for i
:= nPl
+1 to nPlayers
do
3094 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3097 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3098 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3099 Options
: LongWord; nPlayers
: Byte;
3100 IPAddr
: LongWord; Port
: Word);
3103 g_Net_Slist_ServerClosed();
3105 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3107 g_Game_ClearLoading();
3112 gGameSettings
.GameType
:= GT_SERVER
;
3113 gGameSettings
.GameMode
:= GameMode
;
3114 gSwitchGameMode
:= GameMode
;
3115 gGameSettings
.TimeLimit
:= TimeLimit
;
3116 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3117 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3118 gGameSettings
.Options
:= Options
;
3120 gCoopTotalMonstersKilled
:= 0;
3121 gCoopTotalSecretsFound
:= 0;
3122 gCoopTotalMonsters
:= 0;
3123 gCoopTotalSecrets
:= 0;
3127 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3128 gLMSRespawnTime
:= 0;
3129 gSpectLatchPID1
:= 0;
3130 gSpectLatchPID2
:= 0;
3132 g_Game_ExecuteEvent('ongamestart');
3134 // Режим наблюдателя:
3135 if nPlayers
= 0 then
3141 if nPlayers
>= 1 then
3143 // Создание первого игрока:
3144 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3145 gPlayer1Settings
.Color
,
3146 gPlayer1Settings
.Team
, False));
3147 if gPlayer1
= nil then
3149 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3153 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3154 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3155 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3156 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3157 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3160 if nPlayers
>= 2 then
3162 // Создание второго игрока:
3163 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3164 gPlayer2Settings
.Color
,
3165 gPlayer2Settings
.Team
, False));
3166 if gPlayer2
= nil then
3168 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3172 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3173 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3174 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3175 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3176 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3179 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3180 if NetForwardPorts
then
3181 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3184 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3186 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3190 g_Net_Slist_Set(NetMasterList
);
3192 g_Net_Slist_ServerStarted();
3194 // Загрузка и запуск карты:
3195 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3197 g_Net_Slist_ServerClosed();
3198 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3202 // Нет точек появления:
3203 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3204 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3205 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3206 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3207 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3209 g_Net_Slist_ServerClosed();
3210 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3214 // Настройки игроков и ботов:
3217 g_Net_Slist_ServerMapStarted();
3218 NetState
:= NET_STATE_GAME
;
3221 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3236 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3237 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3239 g_Game_ClearLoading();
3244 gGameSettings
.GameType
:= GT_CLIENT
;
3246 gCoopTotalMonstersKilled
:= 0;
3247 gCoopTotalSecretsFound
:= 0;
3248 gCoopTotalMonsters
:= 0;
3249 gCoopTotalSecrets
:= 0;
3253 g_Game_ExecuteEvent('ongamestart');
3255 NetState
:= NET_STATE_AUTH
;
3257 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3259 // create (or update) map/resource databases
3260 g_Res_CreateDatabases(true);
3262 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3263 gLMSRespawnTime
:= 0;
3264 gSpectLatchPID1
:= 0;
3265 gSpectLatchPID2
:= 0;
3268 if not g_Net_Connect(Addr
, Port
) then
3270 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3271 NetState
:= NET_STATE_NONE
;
3275 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3277 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3282 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3283 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3284 // thank you, enet. let's ignore failures altogether then.
3285 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3287 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3289 Ptr
:= NetEvent
.packet
^.data
;
3290 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3292 enet_packet_destroy(NetEvent
.packet
);
3296 InMsg
.ReadLongWord(); // skip size
3297 MID
:= InMsg
.ReadByte();
3299 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3301 NetMyID
:= InMsg
.ReadByte();
3302 NetPlrUID1
:= InMsg
.ReadWord();
3304 WadName
:= InMsg
.ReadString();
3305 Map
:= InMsg
.ReadString();
3307 gWADHash
:= InMsg
.ReadMD5();
3309 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3310 gSwitchGameMode
:= gGameSettings
.GameMode
;
3311 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3312 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3313 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3314 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3315 T
:= InMsg
.ReadLongWord();
3317 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3318 //if newResPath = '' then
3320 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3321 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3322 if newResPath
= '' then
3324 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3325 enet_packet_destroy(NetEvent
.packet
);
3326 NetState
:= NET_STATE_NONE
;
3329 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3331 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3334 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3335 gPlayer1Settings
.Color
,
3336 gPlayer1Settings
.Team
, False));
3338 if gPlayer1
= nil then
3340 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3342 enet_packet_destroy(NetEvent
.packet
);
3343 NetState
:= NET_STATE_NONE
;
3347 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3348 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3349 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3350 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3351 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3352 gPlayer1
.UID
:= NetPlrUID1
;
3353 gPlayer1
.Reset(True);
3355 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3357 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3359 enet_packet_destroy(NetEvent
.packet
);
3360 NetState
:= NET_STATE_NONE
;
3368 enet_packet_destroy(NetEvent
.packet
);
3372 enet_packet_destroy(NetEvent
.packet
);
3376 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3379 if (NetEvent
.data
<= NET_DISC_MAX
) then
3380 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3381 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3388 ProcessLoading(True);
3389 if g_Net_UserRequestExit() then
3398 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3399 NetState
:= NET_STATE_NONE
;
3404 NetState
:= NET_STATE_GAME
;
3405 MC_SEND_FullStateRequest
;
3406 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3410 lastAsMegaWad
: Boolean = false;
3412 procedure g_Game_ChangeMap(const MapPath
: String);
3416 g_Game_ClearLoading();
3418 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3419 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3420 if gExitByTrigger
then
3423 gExitByTrigger
:= False;
3425 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3426 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3429 procedure g_Game_Restart();
3433 if g_Game_IsClient
then
3435 map
:= g_ExtractFileName(gMapInfo
.Map
);
3436 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3440 g_Game_ClearLoading();
3441 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3444 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3446 NewWAD
, ResName
: String;
3450 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3452 {$IFDEF ENABLE_GIBS}
3455 {$IFDEF ENABLE_SHELLS}
3458 {$IFDEF ENABLE_CORPSES}
3459 g_Corpses_RemoveAll
;
3462 if (not g_Game_IsClient
) and
3463 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3464 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3466 if gSwitchGameMode
= GM_CTF
then
3467 gGameSettings
.MaxLives
:= 0;
3468 gGameSettings
.GameMode
:= gSwitchGameMode
;
3471 gSwitchGameMode
:= gGameSettings
.GameMode
;
3473 g_Player_ResetTeams();
3475 lastAsMegaWad
:= asMegawad
;
3476 if isWadPath(Map
) then
3478 NewWAD
:= g_ExtractWadName(Map
);
3479 ResName
:= g_ExtractFileName(Map
);
3480 if g_Game_IsServer
then
3482 nws
:= findDiskWad(NewWAD
);
3483 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3486 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3487 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3491 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3492 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3494 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3495 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3497 if (length(nws
) = 0) then
3499 ResName
:= ''; // failed
3504 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3505 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3506 g_Game_LoadWAD(NewWAD
);
3511 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3512 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3517 NewWAD
:= gGameSettings
.WAD
;
3523 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3525 if (ResName
<> '') and (NewWAD
<> '') then
3527 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3528 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3532 {$IFDEF ENABLE_RENDER}
3533 r_Render_LoadTextures
;
3536 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3538 gState
:= STATE_NONE
;
3539 {$IFDEF ENABLE_MENU}
3540 g_ActiveWindow
:= nil;
3545 wNeedTimeReset
:= True;
3547 if gGameSettings
.GameMode
= GM_CTF
then
3549 g_Map_ResetFlag(FLAG_RED
);
3550 g_Map_ResetFlag(FLAG_BLUE
);
3551 // CTF, а флагов нет:
3552 if not g_Map_HaveFlagPoints() then
3553 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3558 gState
:= STATE_MENU
;
3563 gPauseMain
:= false;
3564 gPauseHolmes
:= false;
3565 NetTimeToUpdate
:= 1;
3566 NetTimeToReliable
:= 0;
3567 NetTimeToMaster
:= NetMasterRate
;
3568 gSpectLatchPID1
:= 0;
3569 gSpectLatchPID2
:= 0;
3570 gMissionFailed
:= False;
3573 gCoopMonstersKilled
:= 0;
3574 gCoopSecretsFound
:= 0;
3576 gVoteInProgress
:= False;
3577 gVotePassed
:= False;
3583 if not gGameOn
then Exit
;
3585 g_Game_SpectateCenterView();
3587 if g_Game_IsServer
then
3589 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3591 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3592 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3593 gLMSSoftSpawn
:= True;
3594 if g_Game_IsNet
then
3595 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3599 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3600 gLMSRespawnTime
:= 0;
3604 if NetMode
= NET_SERVER
then
3606 // reset full state flags
3607 if NetClients
<> nil then
3608 for I
:= 0 to High(NetClients
) do
3609 NetClients
[I
].FullUpdateSent
:= False;
3611 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3614 g_Net_Slist_ServerMapStarted();
3616 if NetClients
<> nil then
3617 for I
:= 0 to High(NetClients
) do
3618 if NetClients
[I
].Used
then
3620 NetClients
[I
].Voted
:= False;
3621 if NetClients
[I
].RequestedFullUpdate
then
3623 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3624 NetClients
[I
].RequestedFullUpdate
:= False;
3628 g_Net_UnbanNonPermHosts();
3633 gCoopTotalMonstersKilled
:= 0;
3634 gCoopTotalSecretsFound
:= 0;
3635 gCoopTotalMonsters
:= 0;
3636 gCoopTotalSecrets
:= 0;
3640 g_Game_ExecuteEvent('onmapstart');
3643 procedure SetFirstLevel
;
3647 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3648 if MapList
= nil then
3651 SortSArray(MapList
);
3652 gNextMap
:= MapList
[Low(MapList
)];
3657 procedure g_Game_ExitLevel(const Map
: AnsiString);
3661 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3662 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3663 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3664 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3666 // Вышли в выход в Одиночной игре:
3667 if gGameSettings
.GameType
= GT_SINGLE
then
3668 gExit
:= EXIT_ENDLEVELSINGLE
3669 else // Вышли в выход в Своей игре
3671 gExit
:= EXIT_ENDLEVELCUSTOM
;
3672 if gGameSettings
.GameMode
= GM_COOP
then
3673 g_Player_RememberAll
;
3675 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3678 if gGameSettings
.GameMode
= GM_COOP
then
3681 gStatsPressed
:= True;
3682 gNextMap
:= 'MAP01';
3684 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3687 if g_Game_IsNet
then
3689 MH_SEND_GameStats();
3690 MH_SEND_CoopStats();
3696 procedure g_Game_RestartLevel();
3700 if gGameSettings
.GameMode
= GM_SINGLE
then
3705 gExit
:= EXIT_ENDLEVELCUSTOM
;
3706 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3710 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3712 gWAD
{, xwad}: String;
3715 if not g_Game_IsClient
then Exit
;
3716 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3718 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3723 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3727 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3730 g_Game_LoadWAD(NewWAD
);
3734 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3735 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3738 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3739 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3743 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3747 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3748 g_Game_LoadWAD(NewWAD);
3752 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3754 i
, n
, nb
, nr
: Integer;
3756 if not g_Game_IsServer
then Exit
;
3757 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3758 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3759 gLMSRespawnTime
:= 0;
3762 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3764 gMissionFailed
:= True;
3765 g_Game_RestartLevel
;
3769 n
:= 0; nb
:= 0; nr
:= 0;
3770 for i
:= Low(gPlayers
) to High(gPlayers
) do
3771 if (gPlayers
[i
] <> nil) and
3772 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3773 (gPlayers
[i
] is TBot
)) then
3776 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3777 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3780 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3782 // wait a second until the fuckers finally decide to join
3783 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3784 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3785 gLMSSoftSpawn
:= NoMapRestart
;
3786 if g_Game_IsNet
then
3787 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3791 {$IFDEF ENABLE_GIBS}
3794 {$IFDEF ENABLE_SHELLS}
3797 {$IFDEF ENABLE_CORPSES}
3798 g_Corpses_RemoveAll
;
3801 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3802 if g_Game_IsNet
then
3803 MH_SEND_GameEvent(NET_EV_LMS_START
);
3805 for i
:= Low(gPlayers
) to High(gPlayers
) do
3807 if gPlayers
[i
] = nil then continue
;
3808 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3809 // don't touch normal spectators
3810 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3812 gPlayers
[i
].FNoRespawn
:= True;
3813 gPlayers
[i
].Lives
:= 0;
3814 if g_Game_IsNet
then
3815 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3818 gPlayers
[i
].FNoRespawn
:= False;
3819 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3820 gPlayers
[i
].Respawn(False, True);
3821 if gGameSettings
.GameMode
= GM_COOP
then
3823 gPlayers
[i
].Frags
:= 0;
3824 gPlayers
[i
].RecallState
;
3826 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3827 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3828 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3829 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3832 g_Items_RestartRound();
3834 gLMSSoftSpawn
:= False;
3837 function g_Game_GetFirstMap(WAD
: String): String;
3841 MapList
:= g_Map_GetMapsList(WAD
);
3842 if MapList
= nil then
3845 SortSArray(MapList
);
3846 Result
:= MapList
[Low(MapList
)];
3848 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3854 function g_Game_GetNextMap(): String;
3861 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3862 if MapList
= nil then
3865 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3867 SortSArray(MapList
);
3869 for I
:= Low(MapList
) to High(MapList
) do
3870 if Map
= MapList
[I
] then
3876 if MapIndex
<> -255 then
3878 if MapIndex
= High(MapList
) then
3879 Result
:= MapList
[Low(MapList
)]
3881 Result
:= MapList
[MapIndex
+ 1];
3883 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3889 procedure g_Game_NextLevel();
3891 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3892 gExit
:= EXIT_ENDLEVELCUSTOM
3895 gExit
:= EXIT_ENDLEVELSINGLE
;
3899 if gNextMap
<> '' then Exit
;
3900 gNextMap
:= g_Game_GetNextMap();
3903 function g_Game_IsTestMap(): Boolean;
3905 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3908 procedure g_Game_DeleteTestMap();
3911 //MapName: AnsiString;
3919 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3920 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3921 if (a
= 0) then exit
;
3923 // Выделяем имя wad-файла и имя карты
3924 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3925 Delete(gMapToDelete
, 1, a
+5);
3926 gMapToDelete
:= UpperCase(gMapToDelete
);
3928 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3931 // Имя карты не стандартное тестовое:
3932 if MapName <> TEST_MAP_NAME then
3935 if not gTempDelete then
3937 time := g_GetFileTime(WadName);
3938 WAD := TWADFile.Create();
3941 if not WAD.ReadFile(WadName) then
3942 begin // Нет такого WAD-файла
3947 // Составляем список карт и ищем нужную:
3949 MapList := WAD.GetResourcesList('');
3951 if MapList <> nil then
3952 for a := 0 to High(MapList) do
3953 if MapList[a] = MapName then
3955 // Удаляем и сохраняем:
3956 WAD.RemoveResource('', MapName);
3957 WAD.SaveTo(WadName);
3962 g_SetFileTime(WadName, time);
3965 if gTempDelete
then DeleteFile(WadName
);
3968 procedure GameCVars(P
: SSArray
);
3971 stat
: TPlayerStatArray
;
3974 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3978 if Length(P
) > 1 then
3983 gsGameFlags
:= gsGameFlags
or Flag
3985 gsGameFlags
:= gsGameFlags
and (not Flag
);
3987 if g_Game_IsServer
then
3990 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3992 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3993 if g_Game_IsNet
then MH_SEND_GameSettings
;
3997 if LongBool(gsGameFlags
and Flag
) then
3998 g_Console_Add(_lc
[OnMsg
])
4000 g_Console_Add(_lc
[OffMsg
]);
4002 if OnMapChange
and g_Game_IsServer
then
4003 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4008 cmd
:= LowerCase(P
[0]);
4010 if cmd
= 'g_gamemode' then
4012 if (Length(P
) > 1) then
4014 a
:= g_Game_TextToMode(P
[1]);
4015 if a
= GM_SINGLE
then a
:= GM_COOP
;
4016 gsGameMode
:= g_Game_ModeToText(a
);
4017 if g_Game_IsServer
then
4019 gSwitchGameMode
:= a
;
4020 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4021 (gState
= STATE_INTERSINGLE
) then
4022 gSwitchGameMode
:= GM_SINGLE
;
4024 gGameSettings
.GameMode
:= gSwitchGameMode
;
4028 if gSwitchGameMode
= gGameSettings
.GameMode
then
4029 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4030 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4032 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4033 [g_Game_ModeToText(gGameSettings
.GameMode
),
4034 g_Game_ModeToText(gSwitchGameMode
)]));
4036 else if cmd
= 'g_friendlyfire' then
4038 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4040 else if cmd
= 'g_friendly_absorb_damage' then
4042 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
4044 else if cmd
= 'g_friendly_hit_trace' then
4046 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
4048 else if cmd
= 'g_friendly_hit_projectile' then
4050 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
4052 else if cmd
= 'g_weaponstay' then
4054 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
4056 else if cmd
= 'g_allow_exit' then
4058 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
4060 else if cmd
= 'g_allow_monsters' then
4062 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
4064 else if cmd
= 'g_allow_dropflag' then
4066 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
4068 else if cmd
= 'g_throw_flag' then
4070 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
4072 else if cmd
= 'g_bot_vsplayers' then
4074 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4076 else if cmd
= 'g_bot_vsmonsters' then
4078 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4080 else if cmd
= 'g_dm_keys' then
4082 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4084 else if cmd
= 'g_gameflags' then
4086 if Length(P
) > 1 then
4088 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4089 if g_Game_IsServer
then
4091 gGameSettings
.Options
:= gsGameFlags
;
4092 if g_Game_IsNet
then MH_SEND_GameSettings
;
4096 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4098 else if cmd
= 'g_warmup_time' then
4100 if Length(P
) > 1 then
4102 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4103 if g_Game_IsServer
then
4105 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4106 // extend warmup if it's already going
4107 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4109 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4110 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4112 if g_Game_IsNet
then MH_SEND_GameSettings
;
4116 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4117 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4119 else if cmd
= 'g_spawn_invul' then
4121 if Length(P
) > 1 then
4123 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4124 if g_Game_IsServer
then
4126 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4127 if g_Game_IsNet
then MH_SEND_GameSettings
;
4131 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4133 else if cmd
= 'g_item_respawn_time' then
4135 if Length(P
) > 1 then
4137 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4138 if g_Game_IsServer
then
4140 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4141 if g_Game_IsNet
then MH_SEND_GameSettings
;
4145 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4146 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4148 else if cmd
= 'sv_intertime' then
4150 if (Length(P
) > 1) then
4151 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4153 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4155 else if cmd
= 'g_max_particles' then
4157 if Length(p
) = 2 then
4160 a
:= Max(0, StrToIntDef(p
[1], 0));
4164 else if Length(p
) = 1 then
4167 e_LogWritefln('%s', [g_GFX_GetMax()])
4169 e_LogWritefln('%s', [0])
4174 e_LogWritefln('usage: %s <n>', [cmd
])
4177 else if cmd
= 'g_max_shells' then
4179 if Length(p
) = 2 then
4181 {$IFDEF ENABLE_SHELLS}
4182 a
:= Max(0, StrToIntDef(p
[1], 0));
4186 else if Length(p
) = 1 then
4188 {$IFDEF ENABLE_SHELLS}
4189 e_LogWritefln('%s', [g_Shells_GetMax()])
4191 e_LogWritefln('%s', [0])
4196 e_LogWritefln('usage: %s <n>', [cmd
])
4199 else if cmd
= 'g_max_gibs' then
4201 if Length(p
) = 2 then
4203 {$IFDEF ENABLE_GIBS}
4204 a
:= Max(0, StrToIntDef(p
[1], 0));
4208 else if Length(p
) = 1 then
4210 {$IFDEF ENABLE_GIBS}
4211 e_LogWritefln('%s', [g_Gibs_GetMax()])
4213 e_LogWritefln('%s', [0])
4218 e_LogWritefln('usage: %s <n>', [cmd
])
4221 else if cmd
= 'g_max_corpses' then
4223 if Length(p
) = 2 then
4225 {$IFDEF ENABLE_CORPSES}
4226 a
:= Max(0, StrToIntDef(p
[1], 0));
4230 else if Length(p
) = 1 then
4232 {$IFDEF ENABLE_CORPSES}
4233 e_LogWritefln('%s', [g_Corpses_GetMax()])
4235 e_LogWritefln('%s', [0])
4240 e_LogWritefln('usage: %s <n>', [cmd
])
4243 else if cmd
= 'g_force_model' then
4245 if Length(p
) = 2 then
4247 a
:= StrToIntDef(p
[1], 0);
4248 g_Force_Model_Set(a
);
4249 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4251 for a
:= Low(gPlayers
) to High(gPlayers
) do
4253 if (gPlayers
[a
] <> nil) then
4255 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4257 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4259 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4263 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4265 for a
:= Low(gPlayers
) to High(gPlayers
) do
4267 if (gPlayers
[a
] <> nil) then
4269 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4271 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4273 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4279 else if cmd
= 'g_force_model_name' then
4281 if (Length(P
) > 1) then
4283 cmd
:= b_Text_Unformat(P
[1]);
4284 g_Forced_Model_SetName(cmd
);
4285 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4287 for a
:= Low(gPlayers
) to High(gPlayers
) do
4289 if (gPlayers
[a
] <> nil) then
4291 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4293 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4295 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4301 else if cmd
= 'g_scorelimit' then
4303 if Length(P
) > 1 then
4305 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4307 if g_Game_IsServer
then
4310 if gGameSettings
.GameMode
= GM_DM
then
4312 stat
:= g_Player_GetStats();
4314 for a
:= 0 to High(stat
) do
4315 if stat
[a
].Frags
> b
then
4319 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4321 // if someone has a higher score, set it to that instead
4322 gsScoreLimit
:= max(gsScoreLimit
, b
);
4323 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4325 if g_Game_IsNet
then MH_SEND_GameSettings
;
4329 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4331 else if cmd
= 'g_timelimit' then
4333 if Length(P
) > 1 then
4335 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4336 if g_Game_IsServer
then
4338 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4339 if g_Game_IsNet
then MH_SEND_GameSettings
;
4342 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4343 [gsTimeLimit
div 3600,
4344 (gsTimeLimit
div 60) mod 60,
4345 gsTimeLimit
mod 60]));
4347 else if cmd
= 'g_max_bots' then
4349 if Length(P
) > 1 then
4350 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4351 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4353 else if cmd
= 'g_maxlives' then
4355 if Length(P
) > 1 then
4357 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4358 if g_Game_IsServer
then
4360 gGameSettings
.MaxLives
:= gsMaxLives
;
4361 if g_Game_IsNet
then MH_SEND_GameSettings
;
4365 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4369 procedure PlayerSettingsCVars(P
: SSArray
);
4374 function ParseTeam(s
: string): Byte;
4378 'red', '1': result
:= TEAM_RED
;
4379 'blue', '2': result
:= TEAM_BLUE
;
4380 else result
:= TEAM_NONE
;
4384 cmd
:= LowerCase(P
[0]);
4388 if (Length(P
) > 1) then
4390 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4391 if g_Game_IsClient
then
4392 MC_SEND_PlayerSettings
4393 else if gGameOn
and (gPlayer1
<> nil) then
4395 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4396 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4402 if (Length(P
) > 1) then
4404 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4405 if g_Game_IsClient
then
4406 MC_SEND_PlayerSettings
4407 else if gGameOn
and (gPlayer2
<> nil) then
4409 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4410 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4416 if Length(P
) > 3 then
4418 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4419 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4420 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4421 if g_Game_IsClient
then
4422 MC_SEND_PlayerSettings
4423 else if gGameOn
and (gPlayer1
<> nil) then
4425 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4426 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4432 if Length(P
) > 3 then
4434 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4435 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4436 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4437 if g_Game_IsClient
then
4438 MC_SEND_PlayerSettings
4439 else if gGameOn
and (gPlayer2
<> nil) then
4441 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4442 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4448 if (Length(P
) > 1) then
4450 gPlayer1Settings
.Model
:= P
[1];
4451 if g_Game_IsClient
then
4452 MC_SEND_PlayerSettings
4453 else if gGameOn
and (gPlayer1
<> nil) then
4455 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4456 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4457 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4463 if (Length(P
) > 1) then
4465 gPlayer2Settings
.Model
:= P
[1];
4466 if g_Game_IsClient
then
4467 MC_SEND_PlayerSettings
4468 else if gGameOn
and (gPlayer2
<> nil) then
4470 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4471 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4472 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4478 // TODO: switch teams if in game or store this separately
4479 if (Length(P
) > 1) then
4481 team
:= ParseTeam(P
[1]);
4482 if team
= TEAM_NONE
then
4483 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4484 else if not gGameOn
and not g_Game_IsNet
then
4485 gPlayer1Settings
.Team
:= team
4487 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4492 // TODO: switch teams if in game or store this separately
4493 if (Length(P
) > 1) then
4495 team
:= ParseTeam(P
[1]);
4496 if team
= TEAM_NONE
then
4497 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4498 else if not gGameOn
and not g_Game_IsNet
then
4499 gPlayer2Settings
.Team
:= team
4501 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4506 if (Length(P
) = 2) then
4507 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4511 if (Length(P
) = 2) then
4512 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4516 if (Length(P
) = 2) then
4517 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4521 if (Length(P
) = 2) then
4522 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4526 if (Length(P
) = 2) then
4527 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4531 if (Length(P
) = 2) then
4532 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4534 'p1_priority_kastet':
4536 if (Length(P
) = 2) then
4537 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4539 'p2_priority_kastet':
4541 if (Length(P
) = 2) then
4542 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4546 if (Length(P
) = 2) then
4547 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4551 if (Length(P
) = 2) then
4552 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4554 'p1_priority_pistol':
4556 if (Length(P
) = 2) then
4557 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4559 'p2_priority_pistol':
4561 if (Length(P
) = 2) then
4562 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4564 'p1_priority_shotgun1':
4566 if (Length(P
) = 2) then
4567 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4569 'p2_priority_shotgun1':
4571 if (Length(P
) = 2) then
4572 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4574 'p1_priority_shotgun2':
4576 if (Length(P
) = 2) then
4577 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4579 'p2_priority_shotgun2':
4581 if (Length(P
) = 2) then
4582 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4584 'p1_priority_chaingun':
4586 if (Length(P
) = 2) then
4587 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4589 'p2_priority_chaingun':
4591 if (Length(P
) = 2) then
4592 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4594 'p1_priority_rocketlauncher':
4596 if (Length(P
) = 2) then
4597 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4599 'p2_priority_rocketlauncher':
4601 if (Length(P
) = 2) then
4602 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4604 'p1_priority_plasma':
4606 if (Length(P
) = 2) then
4607 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4609 'p2_priority_plasma':
4611 if (Length(P
) = 2) then
4612 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4616 if (Length(P
) = 2) then
4617 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4621 if (Length(P
) = 2) then
4622 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4624 'p1_priority_super':
4626 if (Length(P
) = 2) then
4627 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4629 'p2_priority_super':
4631 if (Length(P
) = 2) then
4632 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4634 'p1_priority_flamethrower':
4636 if (Length(P
) = 2) then
4637 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4639 'p2_priority_flamethrower':
4641 if (Length(P
) = 2) then
4642 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4644 'p1_priority_berserk':
4646 if (Length(P
) = 2) then
4647 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4649 'p2_priority_berserk':
4651 if (Length(P
) = 2) then
4652 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4657 procedure PrintHeapStats();
4661 hs
:= GetFPCHeapStatus();
4662 e_LogWriteLn ('v===== heap status =====v');
4663 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4664 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4665 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4666 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4667 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4668 e_LogWriteLn ('^=======================^');
4671 procedure DebugCommands(P
: SSArray
);
4678 // Команды отладочного режима:
4679 if {gDebugMode}conIsCheatsEnabled
then
4681 cmd
:= LowerCase(P
[0]);
4682 if cmd
= 'd_window' then
4684 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4685 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4687 else if cmd
= 'd_winmsg' then
4689 if (Length(P
) > 1) and
4690 ((P
[1] = '1') or (P
[1] = '0')) then
4691 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4693 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4695 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4697 if (Length(P
) > 1) and
4698 ((P
[1] = '1') or (P
[1] = '0')) then
4699 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4701 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4703 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4705 if Length(P
) > 1 then
4707 '0': g_debug_BotAIOff
:= 0;
4708 '1': g_debug_BotAIOff
:= 1;
4709 '2': g_debug_BotAIOff
:= 2;
4710 '3': g_debug_BotAIOff
:= 3;
4713 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4715 else if cmd
= 'd_monster' then
4717 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4718 if Length(P
) < 2 then
4720 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4721 g_Console_Add('ID | Name');
4722 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4723 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4724 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4727 a
:= StrToIntDef(P
[1], 0);
4728 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4729 a
:= g_Mons_TypeIdByName(P
[1]);
4731 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4732 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4735 with gPlayer1
.Obj
do
4737 mon
:= g_Monsters_Create(a
,
4738 X
+ Rect
.X
+ (Rect
.Width
div 2),
4739 Y
+ Rect
.Y
+ Rect
.Height
,
4740 gPlayer1
.Direction
, True);
4742 if (Length(P
) > 2) and (mon
<> nil) then
4744 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4745 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4746 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4747 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4748 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4749 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4750 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4751 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4752 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4757 else if (cmd
= 'd_player') then
4759 if (Length(P
) > 1) and
4760 ((P
[1] = '1') or (P
[1] = '0')) then
4761 g_debug_Player
:= (P
[1][1] = '1');
4763 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4765 else if (cmd
= 'd_mem') then
4771 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4775 procedure GameCheats(P
: SSArray
);
4781 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4783 g_Console_Add('not available');
4789 g_Console_Add('where is the player?!');
4792 cmd
:= LowerCase(P
[0]);
4796 plr
.GodMode
:= not plr
.GodMode
;
4797 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4800 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4801 if cmd
= 'give' then
4803 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4804 for f
:= 1 to High(P
) do
4806 cmd
:= LowerCase(P
[f
]);
4807 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4808 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4809 if cmd
= 'exit' then
4811 if gTriggers
<> nil then
4813 for a
:= 0 to High(gTriggers
) do
4815 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4817 g_Console_Add('player left the map');
4818 gExitByTrigger
:= True;
4819 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4820 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4828 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4829 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4830 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4831 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4832 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4834 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4835 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4837 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4838 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;
4840 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4841 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4843 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4844 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4846 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4847 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4849 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4850 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4851 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4853 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4854 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4855 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4856 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;
4857 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4858 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4860 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;
4861 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;
4862 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;
4863 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;
4864 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;
4865 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;
4867 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4868 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;
4870 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;
4871 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;
4873 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4875 if cmd
= 'ammo' then
4877 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4878 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4879 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4880 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4881 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4882 g_Console_Add('player got some ammo');
4886 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4887 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4889 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4890 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4892 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4893 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4895 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4896 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4898 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4900 if cmd
= 'weapons' then
4902 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4903 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4904 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4905 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4906 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4907 plr
.GiveItem(ITEM_WEAPON_BFG
);
4908 g_Console_Add('player got weapons');
4912 if cmd
= 'keys' then
4914 plr
.GiveItem(ITEM_KEY_RED
);
4915 plr
.GiveItem(ITEM_KEY_GREEN
);
4916 plr
.GiveItem(ITEM_KEY_BLUE
);
4917 g_Console_Add('player got all keys');
4921 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4926 if cmd
= 'open' then
4928 g_Console_Add('player activated sesame');
4929 g_Triggers_OpenAll();
4936 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4940 if cmd
= 'noclip' then
4943 g_Console_Add('wall hardeness adjusted');
4947 if cmd
= 'notarget' then
4949 plr
.NoTarget
:= not plr
.NoTarget
;
4950 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4954 if cmd
= 'noreload' then
4956 plr
.NoReload
:= not plr
.NoReload
;
4957 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4961 if cmd
= 'speedy' then
4963 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4964 g_Console_Add('speed adjusted');
4968 if cmd
= 'jumpy' then
4970 VEL_JUMP
:= 30-VEL_JUMP
;
4971 g_Console_Add('jump height adjusted');
4975 if cmd
= 'automap' then
4977 gShowMap
:= not gShowMap
;
4978 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4982 if cmd
= 'aimline' then
4984 gAimLine
:= not gAimLine
;
4985 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4990 procedure GameCommands(P
: SSArray
);
4996 pl
: pTNetClient
= nil;
5004 cmd
:= LowerCase(P
[0]);
5006 if cmd
= 'pause' then
5008 {$IFDEF ENABLE_MENU}
5009 if (g_ActiveWindow
= nil) then
5010 g_Game_Pause(not gPauseMain
);
5012 g_Game_Pause(not gPauseMain
);
5015 else if cmd
= 'endgame' then
5016 gExit
:= EXIT_SIMPLE
5017 else if cmd
= 'restart' then
5019 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5021 if g_Game_IsClient
then
5023 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5028 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5030 else if cmd
= 'kick' then
5032 if g_Game_IsServer
then
5034 if Length(P
) < 2 then
5036 g_Console_Add('kick <name>');
5041 g_Console_Add('kick <name>');
5045 if g_Game_IsNet
then
5046 pl
:= g_Net_Client_ByName(P
[1]);
5049 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5050 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5051 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5052 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5053 g_Net_Slist_ServerPlayerLeaves();
5054 end else if gPlayers
<> nil then
5055 for a
:= Low(gPlayers
) to High(gPlayers
) do
5056 if gPlayers
[a
] <> nil then
5057 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5059 // Не отключать основных игроков в сингле
5060 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5062 gPlayers
[a
].Lives
:= 0;
5063 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5064 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5065 g_Player_Remove(gPlayers
[a
].UID
);
5066 g_Net_Slist_ServerPlayerLeaves();
5067 // Если не перемешать, при добавлении новых ботов появятся старые
5071 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5073 else if cmd
= 'kick_id' then
5075 if g_Game_IsServer
and g_Game_IsNet
then
5077 if Length(P
) < 2 then
5079 g_Console_Add('kick_id <client ID>');
5084 g_Console_Add('kick_id <client ID>');
5088 a
:= StrToIntDef(P
[1], 0);
5089 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5091 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5093 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5094 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
5095 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5096 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5097 g_Net_Slist_ServerPlayerLeaves();
5101 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5103 else if cmd
= 'kick_pid' then
5105 if g_Game_IsServer
and g_Game_IsNet
then
5107 if Length(P
) < 2 then
5109 g_Console_Add('kick_pid <player ID>');
5114 g_Console_Add('kick_pid <player ID>');
5118 a
:= StrToIntDef(P
[1], 0);
5119 pl
:= g_Net_Client_ByPlayer(a
);
5120 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5122 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5123 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5124 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5125 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5126 g_Net_Slist_ServerPlayerLeaves();
5129 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5131 else if cmd
= 'ban' then
5133 if g_Game_IsServer
and g_Game_IsNet
then
5135 if Length(P
) < 2 then
5137 g_Console_Add('ban <name>');
5142 g_Console_Add('ban <name>');
5146 pl
:= g_Net_Client_ByName(P
[1]);
5149 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5150 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5151 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5152 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5153 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5154 g_Net_Slist_ServerPlayerLeaves();
5156 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5158 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5160 else if cmd
= 'ban_id' then
5162 if g_Game_IsServer
and g_Game_IsNet
then
5164 if Length(P
) < 2 then
5166 g_Console_Add('ban_id <client ID>');
5171 g_Console_Add('ban_id <client ID>');
5175 a
:= StrToIntDef(P
[1], 0);
5176 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5177 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5179 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5180 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5181 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5182 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5183 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5184 g_Net_Slist_ServerPlayerLeaves();
5187 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5189 else if cmd
= 'ban_pid' then
5191 if g_Game_IsServer
and g_Game_IsNet
then
5193 if Length(P
) < 2 then
5195 g_Console_Add('ban_pid <player ID>');
5200 g_Console_Add('ban_pid <player ID>');
5204 a
:= StrToIntDef(P
[1], 0);
5205 pl
:= g_Net_Client_ByPlayer(a
);
5206 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5208 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5209 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5210 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5211 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5212 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5213 g_Net_Slist_ServerPlayerLeaves();
5216 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5218 else if cmd
= 'permban' then
5220 if g_Game_IsServer
and g_Game_IsNet
then
5222 if Length(P
) < 2 then
5224 g_Console_Add('permban <name>');
5229 g_Console_Add('permban <name>');
5233 pl
:= g_Net_Client_ByName(P
[1]);
5236 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5237 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5238 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5239 g_Net_SaveBanList();
5240 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5241 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5242 g_Net_Slist_ServerPlayerLeaves();
5244 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5246 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5248 else if cmd
= 'permban_id' then
5250 if g_Game_IsServer
and g_Game_IsNet
then
5252 if Length(P
) < 2 then
5254 g_Console_Add('permban_id <client ID>');
5259 g_Console_Add('permban_id <client ID>');
5263 a
:= StrToIntDef(P
[1], 0);
5264 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5265 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5267 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5268 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5269 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5270 g_Net_SaveBanList();
5271 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5272 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5273 g_Net_Slist_ServerPlayerLeaves();
5276 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5278 else if cmd
= 'permban_pid' then
5280 if g_Game_IsServer
and g_Game_IsNet
then
5282 if Length(P
) < 2 then
5284 g_Console_Add('permban_pid <player ID>');
5289 g_Console_Add('permban_pid <player ID>');
5293 a
:= StrToIntDef(P
[1], 0);
5294 pl
:= g_Net_Client_ByPlayer(a
);
5295 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5297 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5298 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5299 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5300 g_Net_SaveBanList();
5301 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5302 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5303 g_Net_Slist_ServerPlayerLeaves();
5306 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5308 else if cmd
= 'permban_ip' then
5310 if g_Game_IsServer
and g_Game_IsNet
then
5312 if Length(P
) < 2 then
5314 g_Console_Add('permban_ip <IP address>');
5319 g_Console_Add('permban_ip <IP address>');
5323 g_Net_BanHost(P
[1]);
5324 g_Net_SaveBanList();
5325 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5327 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5329 else if cmd
= 'unban' then
5331 if g_Game_IsServer
and g_Game_IsNet
then
5333 if Length(P
) < 2 then
5335 g_Console_Add('unban <IP Address>');
5340 g_Console_Add('unban <IP Address>');
5344 if g_Net_UnbanHost(P
[1]) then
5346 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5347 g_Net_SaveBanList();
5349 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5351 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5353 else if cmd
= 'clientlist' then
5355 if g_Game_IsServer
and g_Game_IsNet
then
5358 if NetClients
<> nil then
5359 for a
:= Low(NetClients
) to High(NetClients
) do
5360 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5362 plr
:= g_Player_Get(NetClients
[a
].Player
);
5363 if plr
= nil then continue
;
5365 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5366 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5369 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5371 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5373 else if cmd
= 'connect' then
5375 if (NetMode
= NET_NONE
) then
5377 if Length(P
) < 2 then
5379 g_Console_Add('connect <IP> [port] [password]');
5384 g_Console_Add('connect <IP> [port] [password]');
5388 if Length(P
) > 2 then
5389 prt
:= StrToIntDef(P
[2], 25666)
5393 if Length(P
) > 3 then
5398 g_Game_StartClient(P
[1], prt
, pw
);
5401 else if cmd
= 'disconnect' then
5403 if (NetMode
= NET_CLIENT
) then
5406 else if cmd
= 'reconnect' then
5408 if (NetMode
= NET_SERVER
) then
5411 if (NetMode
= NET_CLIENT
) then
5414 gExit
:= EXIT_SIMPLE
;
5418 //TODO: Use last successful password to reconnect, instead of ''
5419 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5421 else if (cmd
= 'addbot') or
5422 (cmd
= 'bot_add') then
5424 if Length(P
) > 2 then
5425 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5426 else if Length(P
) > 1 then
5427 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5429 g_Bot_Add(TEAM_NONE
, 2);
5431 else if cmd
= 'bot_addlist' then
5433 if Length(P
) > 1 then
5435 if Length(P
) = 2 then
5436 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5437 else if Length(P
) = 3 then
5438 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5440 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5443 else if cmd
= 'bot_removeall' then
5445 else if cmd
= 'chat' then
5447 if g_Game_IsNet
then
5449 if Length(P
) > 1 then
5451 for a
:= 1 to High(P
) do
5452 chstr
:= chstr
+ P
[a
] + ' ';
5454 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5456 if Length(chstr
) < 1 then
5458 g_Console_Add('chat <text>');
5462 chstr
:= b_Text_Format(chstr
);
5463 if g_Game_IsClient
then
5464 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5466 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5469 g_Console_Add('chat <text>');
5471 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5473 else if cmd
= 'teamchat' then
5475 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5477 if Length(P
) > 1 then
5479 for a
:= 1 to High(P
) do
5480 chstr
:= chstr
+ P
[a
] + ' ';
5482 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5484 if Length(chstr
) < 1 then
5486 g_Console_Add('teamchat <text>');
5490 chstr
:= b_Text_Format(chstr
);
5491 if g_Game_IsClient
then
5492 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5494 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5495 gPlayer1Settings
.Team
);
5498 g_Console_Add('teamchat <text>');
5500 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5502 else if (cmd
= 'an') or (cmd
= 'announce') then
5504 if g_Game_IsNet
then
5506 if Length(P
) > 1 then
5508 for a
:= 1 to High(P
) do
5509 chstr
:= chstr
+ P
[a
] + ' ';
5511 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5513 if Length(chstr
) < 1 then
5515 g_Console_Add('announce <text>');
5519 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5520 if g_Game_IsClient
then
5521 MC_SEND_RCONCommand(chstr
)
5523 g_Console_Process(chstr
, True);
5526 g_Console_Add('announce <text>');
5528 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5530 else if cmd
= 'game' then
5532 if gGameSettings
.GameType
<> GT_NONE
then
5534 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5537 if Length(P
) = 1 then
5539 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5542 // game not started yet, load fist map from some wad
5544 s
:= addWadExtension(P
[1]);
5545 found
:= e_FindResource(AllMapDirs
, s
);
5549 P
[1] := ExpandFileName(P
[1]);
5550 // if map not choosed then set first map
5551 if Length(P
) < 3 then
5554 P
[2] := g_Game_GetFirstMap(P
[1]);
5557 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5559 if g_Map_Exist(s
) then
5563 with gGameSettings
do
5565 Options
:= gsGameFlags
;
5566 GameMode
:= g_Game_TextToMode(gsGameMode
);
5567 if gSwitchGameMode
<> GM_NONE
then
5568 GameMode
:= gSwitchGameMode
;
5569 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5570 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5572 if Length(P
) >= 4 then
5573 b
:= StrToIntDef(P
[3], 1);
5574 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5575 ScoreLimit
, MaxLives
, Options
, b
);
5580 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5582 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5584 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5586 else if cmd
= 'host' then
5588 if gGameSettings
.GameType
<> GT_NONE
then
5590 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5593 if Length(P
) < 4 then
5595 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5598 if not StrToIp(P
[1], listen
) then
5600 prt
:= StrToIntDef(P
[2], 25666);
5602 s
:= addWadExtension(P
[3]);
5603 found
:= e_FindResource(AllMapDirs
, s
);
5607 // get first map in wad, if not specified
5608 if Length(P
) < 5 then
5611 P
[4] := g_Game_GetFirstMap(P
[1]);
5613 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5614 if g_Map_Exist(s
) then
5618 with gGameSettings
do
5620 Options
:= gsGameFlags
;
5621 GameMode
:= g_Game_TextToMode(gsGameMode
);
5622 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5623 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5624 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5626 if Length(P
) >= 6 then
5627 b
:= StrToIntDef(P
[5], 0);
5628 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5634 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5636 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5641 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5644 else if cmd
= 'map' then
5646 if Length(P
) = 1 then
5648 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5650 g_Console_Add(cmd
+ ' <MAP>');
5651 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5655 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5660 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5662 if Length(P
) < 3 then
5664 // first param is map or wad
5665 s
:= UpperCase(P
[1]);
5666 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5668 gExitByTrigger
:= False;
5671 // already in game, finish current map
5673 gExit
:= EXIT_ENDLEVELCUSTOM
;
5677 // intermission, so change map immediately
5684 found
:= e_FindResource(AllMapDirs
, s
);
5686 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5689 // no such map, found wad
5692 P
[1] := ExpandFileName(pw
);
5693 P
[2] := g_Game_GetFirstMap(P
[1]);
5694 s
:= P
[1] + ':\' + P
[2];
5695 if g_Map_Exist(s
) then
5697 gExitByTrigger
:= False;
5700 // already in game, finish current map
5702 gExit
:= EXIT_ENDLEVELCUSTOM
5706 // intermission, so change map immediately
5713 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5715 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5720 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5726 s
:= addWadExtension(P
[1]);
5727 found
:= e_FindResource(AllMapDirs
, s
);
5731 P
[2] := UpperCase(P
[2]);
5732 s
:= P
[1] + ':\' + P
[2];
5733 if g_Map_Exist(s
) then
5735 gExitByTrigger
:= False;
5739 gExit
:= EXIT_ENDLEVELCUSTOM
5748 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5753 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5759 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5763 else if cmd
= 'nextmap' then
5765 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5767 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5772 if Length(P
) = 1 then
5774 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5776 g_Console_Add(cmd
+ ' <MAP>');
5777 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5782 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5788 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5790 if Length(P
) < 3 then
5792 // first param is map or wad
5793 s
:= UpperCase(P
[1]);
5794 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5797 gExitByTrigger
:= False;
5803 // no such map, found wad
5804 pw
:= addWadExtension(P
[1]);
5805 found
:= e_FindResource(MapDirs
, pw
);
5807 found
:= e_FindResource(WadDirs
, pw
);
5809 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5812 // map not specified, select first map
5814 P
[2] := g_Game_GetFirstMap(P
[1]);
5815 s
:= P
[1] + ':\' + P
[2];
5816 if g_Map_Exist(s
) then
5818 gExitByTrigger
:= False;
5825 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5827 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5832 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5838 // specified two params wad + map
5839 pw
:= addWadExtension(P
[1]);
5840 found
:= e_FindResource(MapDirs
, pw
);
5842 found
:= e_FindResource(MapDirs
, pw
);
5846 P
[2] := UpperCase(P
[2]);
5847 s
:= P
[1] + ':\' + P
[2];
5848 if g_Map_Exist(s
) then
5850 gExitByTrigger
:= False;
5856 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5861 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5867 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5872 if gNextMap
= '' then
5873 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5875 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5879 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5883 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5887 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5889 gExitByTrigger
:= False;
5890 // next map not specified, try to find trigger EXIT
5891 if (gNextMap
= '') and (gTriggers
<> nil) then
5893 for a
:= 0 to High(gTriggers
) do
5895 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5897 gExitByTrigger
:= True;
5898 //gNextMap := gTriggers[a].Data.MapName;
5899 gNextMap
:= gTriggers
[a
].tgcMap
;
5904 if gNextMap
= '' then
5905 gNextMap
:= g_Game_GetNextMap();
5906 if not isWadPath(gNextMap
) then
5907 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5910 if g_Map_Exist(s
) then
5911 gExit
:= EXIT_ENDLEVELCUSTOM
5913 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5917 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5921 else if (cmd
= 'event') then
5923 if (Length(P
) <= 1) then
5925 for a
:= 0 to High(gEvents
) do
5926 if gEvents
[a
].Command
= '' then
5927 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5929 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5932 if (Length(P
) = 2) then
5934 for a
:= 0 to High(gEvents
) do
5935 if gEvents
[a
].Name
= P
[1] then
5936 if gEvents
[a
].Command
= '' then
5937 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5939 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5942 for a
:= 0 to High(gEvents
) do
5943 if gEvents
[a
].Name
= P
[1] then
5945 gEvents
[a
].Command
:= '';
5946 for b
:= 2 to High(P
) do
5947 if Pos(' ', P
[b
]) = 0 then
5948 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5950 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5951 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5955 else if cmd
= 'suicide' then
5959 if g_Game_IsClient
then
5960 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5963 if gPlayer1
<> nil then
5964 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5965 if gPlayer2
<> nil then
5966 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5970 else if cmd
= 'screenshot' then
5972 {$IFDEF ENABLE_RENDER}
5973 r_Render_RequestScreenShot
;
5976 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5978 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5980 gWeaponAction
[0, WP_PREV
] := True;
5982 gWeaponAction
[0, WP_NEXT
] := True;
5984 else if cmd
= 'weapon' then
5986 if Length(p
) = 2 then
5988 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5989 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5990 gSelectWeapon
[0, a
] := True
5993 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5994 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5996 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5997 b
:= ord(cmd
[2]) - ord('1');
5999 gWeaponAction
[b
, WP_PREV
] := True;
6001 gWeaponAction
[b
, WP_NEXT
] := True;
6003 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
6005 if Length(p
) = 2 then
6007 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
6008 b
:= ord(cmd
[2]) - ord('1');
6009 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6010 gSelectWeapon
[b
, a
] := True
6013 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
6015 b
:= ord(cmd
[2]) - ord('1');
6017 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
6019 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
6021 else if (cmd
= 'dropflag') then
6023 if g_Game_IsServer
then
6025 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
6026 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
6029 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6031 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
6033 b
:= ord(cmd
[2]) - ord('1');
6034 if g_Game_IsServer
then
6036 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
6037 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
6040 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6042 // Команды Своей игры:
6043 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6045 if cmd
= 'bot_addred' then
6047 if Length(P
) > 1 then
6048 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6050 g_Bot_Add(TEAM_RED
, 2);
6052 else if cmd
= 'bot_addblue' then
6054 if Length(P
) > 1 then
6055 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6057 g_Bot_Add(TEAM_BLUE
, 2);
6059 else if cmd
= 'spectate' then
6065 else if cmd
= 'say' then
6067 if g_Game_IsServer
and g_Game_IsNet
then
6069 if Length(P
) > 1 then
6072 for a
:= 1 to High(P
) do
6073 chstr
:= chstr
+ P
[a
] + ' ';
6075 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6077 if Length(chstr
) < 1 then
6079 g_Console_Add('say <text>');
6083 chstr
:= b_Text_Format(chstr
);
6084 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6086 else g_Console_Add('say <text>');
6088 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6090 else if cmd
= 'tell' then
6092 if g_Game_IsServer
and g_Game_IsNet
then
6094 if (Length(P
) > 2) and (P
[1] <> '') then
6097 for a
:= 2 to High(P
) do
6098 chstr
:= chstr
+ P
[a
] + ' ';
6100 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6102 if Length(chstr
) < 1 then
6104 g_Console_Add('tell <playername> <text>');
6108 pl
:= g_Net_Client_ByName(P
[1]);
6110 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6112 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6114 else g_Console_Add('tell <playername> <text>');
6116 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6118 else if cmd
= 'centerprint' then
6120 if (Length(P
) > 2) and (P
[1] <> '') then
6123 for a
:= 2 to High(P
) do
6124 chstr
:= chstr
+ P
[a
] + ' ';
6126 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6128 if Length(chstr
) < 1 then
6130 g_Console_Add('centerprint <timeout> <text>');
6134 a
:= StrToIntDef(P
[1], 100);
6135 chstr
:= b_Text_Format(chstr
);
6136 g_Game_Message(chstr
, a
);
6137 if g_Game_IsNet
and g_Game_IsServer
then
6138 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6140 else g_Console_Add('centerprint <timeout> <text>');
6142 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6144 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6146 // Дополнительное время:
6147 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6149 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6150 [gGameSettings
.TimeLimit
div 3600,
6151 (gGameSettings
.TimeLimit
div 60) mod 60,
6152 gGameSettings
.TimeLimit
mod 60]));
6153 if g_Game_IsNet
then MH_SEND_GameSettings
;
6155 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6157 if (Length(P
) <= 1) then
6158 g_Console_Add('rcon_password <password>')
6160 MC_SEND_RCONPassword(P
[1]);
6162 else if cmd
= 'rcon' then
6164 if g_Game_IsClient
then
6166 if Length(P
) > 1 then
6169 for a
:= 1 to High(P
) do
6170 chstr
:= chstr
+ P
[a
] + ' ';
6172 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6174 if Length(chstr
) < 1 then
6176 g_Console_Add('rcon <command>');
6180 MC_SEND_RCONCommand(chstr
);
6182 else g_Console_Add('rcon <command>');
6185 else if cmd
= 'ready' then
6187 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6188 gLMSRespawnTime
:= gTime
+ 100;
6190 else if (cmd
= 'callvote') and g_Game_IsNet
then
6192 if Length(P
) > 1 then
6195 for a
:= 1 to High(P
) do begin
6196 if a
> 1 then chstr
:= chstr
+ ' ';
6197 chstr
:= chstr
+ P
[a
];
6200 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6202 if Length(chstr
) < 1 then
6204 g_Console_Add('callvote <command>');
6208 if g_Game_IsClient
then
6209 MC_SEND_Vote(True, chstr
)
6211 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6212 g_Console_Process('vote', True);
6215 g_Console_Add('callvote <command>');
6217 else if (cmd
= 'vote') and g_Game_IsNet
then
6219 if g_Game_IsClient
then
6221 else if gVoteInProgress
then
6223 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6224 a
:= Floor((NetClientCount
+1)/2.0) + 1
6226 a
:= Floor(NetClientCount
/2.0) + 1;
6231 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6232 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6238 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6239 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6247 procedure SystemCommands(P
: SSArray
);
6251 cmd
:= LowerCase(P
[0]);
6258 {$IFDEF ENABLE_RENDER}
6264 if Length(p
) = 2 then
6266 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6268 gFrameTime
:= 1000 div gMaxFPS
6272 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6276 if Length(p
) = 2 then
6278 gAskLanguage
:= true;
6279 gLanguage
:= LANGUAGE_ENGLISH
;
6280 case LowerCase(p
[1]) of
6283 gAskLanguage
:= false;
6284 gLanguage
:= LANGUAGE_ENGLISH
;
6288 gAskLanguage
:= false;
6289 gLanguage
:= LANGUAGE_RUSSIAN
;
6293 gAskLanguage
:= true;
6294 gLanguage
:= LANGUAGE_ENGLISH
;
6297 g_Language_Set(gLanguage
);
6301 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6307 {$IFDEF ENABLE_MENU}
6308 procedure g_Game_InGameMenu(Show
: Boolean);
6310 if (g_ActiveWindow
= nil) and Show
then
6312 if gGameSettings
.GameType
= GT_SINGLE
then
6313 g_GUI_ShowWindow('GameSingleMenu')
6316 if g_Game_IsClient
then
6317 g_GUI_ShowWindow('GameClientMenu')
6319 if g_Game_IsNet
then
6320 g_GUI_ShowWindow('GameServerMenu')
6322 g_GUI_ShowWindow('GameCustomMenu');
6324 g_Sound_PlayEx('MENU_OPEN');
6326 // Пауза при меню только в одиночной игре:
6327 if (not g_Game_IsNet
) then
6331 if (g_ActiveWindow
<> nil) and (not Show
) then
6333 // Пауза при меню только в одиночной игре:
6334 if (not g_Game_IsNet
) then
6335 g_Game_Pause(False);
6340 procedure g_Game_Pause (Enable
: Boolean);
6344 if not gGameOn
then exit
;
6346 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6349 gPauseMain
:= Enable
;
6351 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6354 procedure g_Game_HolmesPause (Enable
: Boolean);
6358 if not gGameOn
then exit
;
6359 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6362 gPauseHolmes
:= Enable
;
6364 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6367 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6372 if gTriggers
<> nil then
6373 for i
:= 0 to High(gTriggers
) do
6374 with gTriggers
[i
] do
6375 if (TriggerType
= TRIGGER_SOUND
) and
6377 Sound
.IsPlaying() then
6379 Sound
.Pause(Enable
);
6383 if gPlayers
<> nil then
6384 for i
:= 0 to High(gPlayers
) do
6385 if gPlayers
[i
] <> nil then
6386 gPlayers
[i
].PauseSounds(Enable
);
6389 if gMusic
<> nil then
6390 gMusic
.Pause(Enable
);
6393 procedure g_Game_StopAllSounds(all
: Boolean);
6397 if gTriggers
<> nil then
6398 for i
:= 0 to High(gTriggers
) do
6399 with gTriggers
[i
] do
6400 if (TriggerType
= TRIGGER_SOUND
) and
6404 if gMusic
<> nil then
6411 procedure g_Game_UpdateTriggerSounds
;
6414 if gTriggers
<> nil then
6415 for i
:= 0 to High(gTriggers
) do
6416 with gTriggers
[i
] do
6417 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6418 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6421 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6424 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6429 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6434 if gSpectMode
<> SPECT_PLAYERS
then
6436 if gSpectPID1
= UID
then
6441 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6448 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6453 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6458 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6463 if gSpectMode
<> SPECT_PLAYERS
then
6465 Pl
:= g_Player_Get(gSpectPID1
);
6466 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6471 if gSpectViewTwo
then
6473 Pl
:= g_Player_Get(gSpectPID2
);
6474 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6482 procedure g_Game_Message (Msg
: string; Time
: Word);
6485 MessageTime
:= Time
;
6488 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6490 punct
: Array[0..13] of String =
6491 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6497 function IsPunctuation(S
: String): Boolean;
6502 if Length(S
) <> 1 then
6504 for i
:= Low(punct
) to High(punct
) do
6505 if S
= punct
[i
] then
6511 function FilterPunctuation(S
: String): String;
6515 for i
:= Low(punct
) to High(punct
) do
6516 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6522 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6524 // remove player name
6525 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6526 // for FullWord check
6527 Text := toLowerCase1251(' ' + Text + ' ');
6528 fpText
:= FilterPunctuation(Text);
6530 for i
:= 0 to Length(gChatSounds
) - 1 do
6533 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6535 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6536 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6538 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6544 gChatSounds
[i
].Sound
.Play();
6550 g_Sound_PlayEx('SOUND_GAME_RADIO');
6553 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6562 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6566 if goodsnd
[a
].IsPlaying() then
6569 goodsnd
[Random(4)].Play();
6572 procedure g_Game_Announce_KillCombo(Param
: Integer);
6579 UID
:= Param
and $FFFF;
6584 Pl
:= g_Player_Get(UID
);
6593 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6597 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6601 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6605 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6613 if not g_Game_IsWatchedPlayer(UID
) then
6616 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6620 if killsnd
[n
].IsPlaying() then
6625 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6633 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6637 if hahasnd
[a
].IsPlaying() then
6640 hahasnd
[Random(3)].Play();
6643 procedure g_Game_StartVote(Command
, Initiator
: string);
6647 if not gVotesEnabled
then Exit
;
6648 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6649 if gVoteInProgress
or gVotePassed
then
6651 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6652 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6655 gVoteInProgress
:= True;
6656 gVotePassed
:= False;
6657 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6660 gVoteCommand
:= Command
;
6662 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6663 Need
:= Floor((NetClientCount
+1)/2.0)+1
6665 Need
:= Floor(NetClientCount
/2.0)+1;
6666 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6667 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6670 procedure g_Game_CheckVote
;
6674 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6675 if not gVoteInProgress
then Exit
;
6677 if (gTime
>= gVoteTimer
) then
6679 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6680 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6682 Need
:= Floor(NetClientCount
/2.0) + 1;
6683 if gVoteCount
>= Need
then
6685 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6686 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6687 gVotePassed
:= True;
6688 gVoteCmdTimer
:= gTime
+ 5000;
6692 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6693 MH_SEND_VoteEvent(NET_VE_FAILED
);
6695 if NetClients
<> nil then
6696 for I
:= Low(NetClients
) to High(NetClients
) do
6697 if NetClients
[i
].Used
then
6698 NetClients
[i
].Voted
:= False;
6699 gVoteInProgress
:= False;
6705 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6706 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6708 Need
:= Floor(NetClientCount
/2.0) + 1;
6709 if gVoteCount
>= Need
then
6711 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6712 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6713 gVoteInProgress
:= False;
6714 gVotePassed
:= True;
6715 gVoteCmdTimer
:= gTime
+ 5000;
6718 if NetClients
<> nil then
6719 for I
:= Low(NetClients
) to High(NetClients
) do
6720 if NetClients
[i
].Used
then
6721 NetClients
[i
].Voted
:= False;
6726 procedure g_Game_LoadMapList(FileName
: string);
6734 if not FileExists(FileName
) then Exit
;
6736 AssignFile(ListFile
, FileName
);
6738 while not EOF(ListFile
) do
6740 ReadLn(ListFile
, s
);
6743 if s
= '' then Continue
;
6745 SetLength(MapList
, Length(MapList
)+1);
6746 MapList
[High(MapList
)] := s
;
6748 CloseFile(ListFile
);
6751 procedure g_Game_SetDebugMode();
6754 // Читы (даже в своей игре):
6758 procedure Parse_Params(var pars
: TParamStrValues
);
6765 while i
<= ParamCount
do
6768 if (Length(s
) > 1) and (s
[1] = '-') then
6770 if (Length(s
) > 2) and (s
[2] = '-') then
6771 begin // Одиночный параметр
6772 SetLength(pars
, Length(pars
) + 1);
6773 with pars
[High(pars
)] do
6775 Name
:= LowerCase(s
);
6780 if (i
< ParamCount
) then
6781 begin // Параметр со значением
6783 SetLength(pars
, Length(pars
) + 1);
6784 with pars
[High(pars
)] do
6786 Name
:= LowerCase(s
);
6787 Value
:= LowerCase(ParamStr(i
));
6796 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6801 for i
:= 0 to High(pars
) do
6802 if pars
[i
].Name
= aName
then
6804 Result
:= pars
[i
].Value
;
6809 procedure g_Game_Process_Params();
6811 pars
: TParamStrValues
;
6814 LimT
, LimS
: Integer;
6825 s
:= Find_Param_Value(pars
, '--debug');
6828 g_Game_SetDebugMode();
6829 s
:= Find_Param_Value(pars
, '--netdump');
6834 // Connect when game loads
6835 ip
:= Find_Param_Value(pars
, '-connect');
6839 s
:= Find_Param_Value(pars
, '-port');
6840 if (s
= '') or not TryStrToInt(s
, Port
) then
6843 s
:= Find_Param_Value(pars
, '-pw');
6845 g_Game_StartClient(ip
, Port
, s
);
6849 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6852 gDefaultMegawadStart
:= s
;
6855 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6856 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6858 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6861 // Start map when game loads:
6862 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6863 if isWadPath(map
) then
6866 s
:= Find_Param_Value(pars
, '-gm');
6867 GMode
:= g_Game_TextToMode(s
);
6868 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6869 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6872 s
:= Find_Param_Value(pars
, '-limt');
6873 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6879 s
:= Find_Param_Value(pars
, '-lims');
6880 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6886 s
:= Find_Param_Value(pars
, '-lives');
6887 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6893 s
:= Find_Param_Value(pars
, '-opt');
6897 Opt
:= StrToIntDef(s
, 0);
6900 s
:= Find_Param_Value(pars
, '--close');
6904 // Override map to test:
6905 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6908 if e_IsValidResourceName(s
) then
6909 e_FindResource(AllMapDirs
, s
);
6910 gTestMap
:= ExpandFileName(s
);
6913 // Delete test map after play:
6914 s
:= Find_Param_Value(pars
, '--testdelete');
6917 //gMapToDelete := MapsDir + map;
6918 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6922 // Delete temporary WAD after play:
6923 s
:= Find_Param_Value(pars
, '--tempdelete');
6924 if (s
<> '') and (gTestMap
<> '') then
6926 gMapToDelete
:= gTestMap
;
6927 gTempDelete
:= True;
6930 // Number of players:
6931 s
:= Find_Param_Value(pars
, '-pl');
6933 n
:= DEFAULT_PLAYERS
6935 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6938 s
:= Find_Param_Value(pars
, '-port');
6939 if (s
= '') or not TryStrToInt(s
, Port
) then
6940 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6942 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6945 // Execute script when game loads:
6946 s
:= Find_Param_Value(pars
, '-exec');
6949 // if not isWadPath(s) then
6950 // s := GameDir + '/' + s;
6955 if IOResult
<> 0 then
6957 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6958 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6962 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6963 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6968 if IOResult
<> 0 then
6970 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6971 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6975 if Pos('#', s
) <> 1 then // script comment
6976 g_Console_Process(s
, True);
6987 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6988 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6989 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6990 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6992 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6993 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6994 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6997 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6998 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7001 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7002 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7004 {$IFDEF ENABLE_HOLMES}
7005 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7008 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7010 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7011 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7013 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7014 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7016 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
7017 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
7018 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
7019 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
7020 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7021 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7022 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7023 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7024 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');