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;
1827 // Пора выключать игру:
1828 if gExit
= EXIT_QUIT
then
1830 // Игра закончилась - обрабатываем:
1834 if gExit
= EXIT_QUIT
then
1838 // Читаем клавиатуру и джойстик, если окно активно
1839 // no need to, as we'll do it in event handler
1841 // Обновляем консоль (движение и сообщения):
1844 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1846 gExit
:= EXIT_SIMPLE
;
1851 // process master server communications
1852 g_Net_Slist_Pulse();
1855 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1856 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1857 STATE_INTERTEXT
, // Текст между уровнями
1858 STATE_INTERPIC
: // Картинка между уровнями
1860 if g_Game_IsNet
and g_Game_IsServer
then
1862 gInterTime
:= gInterTime
+ GAME_TICK
;
1863 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1864 if a
<> gServInterTime
then
1866 gServInterTime
:= a
;
1867 MH_SEND_TimeSync(gServInterTime
);
1871 if (not g_Game_IsClient
) and
1875 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1876 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1877 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1878 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1880 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1881 {$IFDEF ENABLE_MENU}
1882 and (g_ActiveWindow
= nil)
1885 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1888 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1889 g_Game_StopAllSounds(True);
1891 if gMapOnce
then // Это был тест
1892 gExit
:= EXIT_SIMPLE
1894 if gNextMap
<> '' then // Переходим на следующую карту
1895 g_Game_ChangeMap(gNextMap
)
1896 else // Следующей карты нет
1898 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1900 // Выход в главное меню:
1902 {$IFDEF ENABLE_MENU}
1903 g_GUI_ShowWindow('MainMenu');
1904 gMusic
.SetByName('MUSIC_MENU');
1907 gState
:= STATE_MENU
;
1910 // Финальная картинка:
1911 g_Game_ExecuteEvent('onwadend');
1913 if not gMusic
.SetByName('MUSIC_endmus') then
1914 gMusic
.SetByName('MUSIC_STDENDMUS');
1916 gState
:= STATE_ENDPIC
;
1918 g_Game_ExecuteEvent('ongameend');
1923 else if g_Game_IsClient
and
1926 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1927 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1928 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1929 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1931 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1932 {$IFDEF ENABLE_MENU}
1933 and (g_ActiveWindow
= nil)
1942 if gState
= STATE_INTERTEXT
then
1943 if InterText
.counter
> 0 then
1944 InterText
.counter
:= InterText
.counter
- 1;
1947 STATE_FOLD
: // Затухание экрана
1949 if EndingGameCounter
= 0 then
1951 // Закончился уровень в Своей игре:
1952 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1954 gState
:= STATE_INTERCUSTOM
;
1955 InterReadyTime
:= -1;
1956 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1958 g_Game_ExecuteEvent('onwadend');
1959 if not gMusic
.SetByName('MUSIC_endmus') then
1960 gMusic
.SetByName('MUSIC_STDENDMUS');
1963 gMusic
.SetByName('MUSIC_ROUNDMUS');
1967 else // Закончилась последняя карта в Одиночной игре
1969 gMusic
.SetByName('MUSIC_INTERMUS');
1971 gState
:= STATE_INTERSINGLE
;
1974 g_Game_ExecuteEvent('oninter');
1977 DecMin(EndingGameCounter
, 6, 0);
1980 STATE_ENDPIC
: // Картинка окончания мегаВада
1982 if gMapOnce
then // Это был тест
1984 gExit
:= EXIT_SIMPLE
;
1990 g_Serverlist_Control(slCurrent
, slTable
);
1993 // Статистика по Tab:
1996 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
2000 if g_Console_Action(ACTION_SCORES
) then
2002 if not gStatsPressed
then
2004 gStatsOff
:= not gStatsOff
;
2005 gStatsPressed
:= True;
2009 gStatsPressed
:= False;
2013 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
2015 // Время += 28 миллисекунд:
2016 gTime
:= gTime
+ GAME_TICK
;
2018 // Сообщение посередине экрана:
2019 if MessageTime
= 0 then
2021 if MessageTime
> 0 then
2022 MessageTime
:= MessageTime
- 1;
2024 if (g_Game_IsServer
) then
2026 // Был задан лимит времени:
2027 if (gGameSettings
.TimeLimit
> 0) then
2028 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
2029 begin // Он прошел => конец уровня
2034 // Надо респавнить игроков в LMS:
2035 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
2036 g_Game_RestartRound(gLMSSoftSpawn
);
2038 // Проверим результат голосования, если время прошло
2039 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2041 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2043 g_Console_Process(gVoteCommand
);
2045 gVotePassed
:= False;
2048 // Замеряем время захвата флагов
2049 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2050 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2051 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2052 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2054 // Был задан лимит побед:
2055 if (gGameSettings
.ScoreLimit
> 0) then
2059 if gGameSettings
.GameMode
= GM_DM
then
2060 begin // В DM ищем игрока с max фрагами
2061 for i
:= 0 to High(gPlayers
) do
2062 if gPlayers
[i
] <> nil then
2063 if gPlayers
[i
].Frags
> b
then
2064 b
:= gPlayers
[i
].Frags
;
2067 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2068 begin // В CTF/TDM выбираем команду с наибольшим счетом
2069 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2072 // Лимит побед набран => конец уровня:
2073 if b
>= gGameSettings
.ScoreLimit
then
2080 // Обрабатываем клавиши игроков:
2081 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2082 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2083 {$IFDEF DISABLE_MENU}
2084 if (not gConsoleShow
) and (not gChatShow
) then
2086 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2089 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2090 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2091 end // if not console
2094 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2096 // process weapon switch queue
2100 if (gPlayer1
= nil) and (gPlayer2
= nil)
2101 and (not gConsoleShow
) and (not gChatShow
)
2102 {$IFDEF ENABLE_MENU}
2103 and (g_ActiveWindow
= nil)
2107 if not gSpectKeyPress
then
2109 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2111 // switch spect mode
2113 SPECT_NONE
: ; // not spectator
2115 SPECT_MAPVIEW
: Inc(gSpectMode
);
2116 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2118 gSpectKeyPress
:= True;
2120 if (gSpectMode
= SPECT_MAPVIEW
)
2121 and (not gSpectAuto
) then
2123 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2124 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2125 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2126 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2127 if gPlayerAction
[0, ACTION_LOOKUP
] then
2128 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2129 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2130 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2131 if gWeaponAction
[0, WP_PREV
] then
2134 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2135 gWeaponAction
[0, WP_PREV
] := False;
2137 if gWeaponAction
[0, WP_NEXT
] then
2140 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2141 gWeaponAction
[0, WP_NEXT
] := False;
2144 if (gSpectMode
= SPECT_PLAYERS
)
2145 and (not gSpectAuto
) then
2147 if gPlayerAction
[0, ACTION_LOOKUP
] then
2150 gSpectViewTwo
:= True;
2151 gSpectKeyPress
:= True;
2153 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2155 // remove second view
2156 gSpectViewTwo
:= False;
2157 gSpectKeyPress
:= True;
2159 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2161 // prev player (view 1)
2162 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2163 gSpectKeyPress
:= True;
2165 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2167 // next player (view 1)
2168 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2169 gSpectKeyPress
:= True;
2171 if gWeaponAction
[0, WP_PREV
] then
2173 // prev player (view 2)
2174 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2175 gWeaponAction
[0, WP_PREV
] := False;
2177 if gWeaponAction
[0, WP_NEXT
] then
2179 // next player (view 2)
2180 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2181 gWeaponAction
[0, WP_NEXT
] := False;
2184 if gPlayerAction
[0, ACTION_ATTACK
] then
2186 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2189 gSpectAutoNext
:= 0;
2190 gSpectViewTwo
:= False;
2191 gSpectKeyPress
:= True;
2196 gSpectMode
:= SPECT_STATS
;
2197 gSpectAuto
:= False;
2198 gSpectKeyPress
:= True;
2203 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2204 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2205 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2206 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2207 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2208 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2209 gSpectKeyPress
:= False;
2213 if gSpectMode
= SPECT_MAPVIEW
then
2215 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2217 gSpectAutoNext
:= gTime
2220 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2222 gSpectAutoNext
:= gTime
2226 if gSpectAutoNext
<= gTime
then
2228 if gSpectAutoNext
> 0 then
2230 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2234 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2235 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2236 gSpectAutoStepX
:= Random(9) - 4;
2237 gSpectAutoStepY
:= Random(9) - 4;
2238 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2239 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2240 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2241 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2242 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2243 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2247 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2252 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2253 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2254 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2260 (* spectator state check from render *)
2262 if (gPlayer1
= nil) and (gPlayer2
= nil) and (gSpectMode
= SPECT_NONE
) then
2263 gSpectMode
:= SPECT_STATS
;
2265 if IsActivePlayer(g_Player_Get(gSpectPID1
)) = false then
2266 gSpectPID1
:= GetActivePlayerID_Next();
2268 if IsActivePlayer(g_Player_Get(gSpectPID2
)) = false then
2269 gSpectPID2
:= GetActivePlayerID_Next();
2271 g_Game_SetupHearPoints
;
2273 // Обновляем все остальное:
2276 g_Triggers_Update();
2278 g_Monsters_Update();
2282 g_Player_UpdateAll();
2283 {$IFDEF ENABLE_GIBS}
2286 {$IFDEF ENABLE_CORPSES}
2289 {$IFDEF ENABLE_SHELLS}
2293 // server: send newly spawned monsters unconditionally
2294 if (gGameSettings
.GameType
= GT_SERVER
) then
2296 if (Length(gMonstersSpawned
) > 0) then
2298 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2299 SetLength(gMonstersSpawned
, 0);
2303 if (gSoundTriggerTime
> 8) then
2305 g_Game_UpdateTriggerSounds();
2306 gSoundTriggerTime
:= 0;
2310 Inc(gSoundTriggerTime
);
2313 if (NetMode
= NET_SERVER
) then
2315 Inc(NetTimeToUpdate
);
2316 Inc(NetTimeToReliable
);
2318 // send monster updates
2319 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2321 // send all monsters (periodic sync)
2322 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2324 for I
:= 0 to High(gPlayers
) do
2326 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2329 g_Mons_ForEach(sendMonsPos
);
2331 // update flags that aren't stationary
2332 if gGameSettings
.GameMode
= GM_CTF
then
2333 for I
:= FLAG_RED
to FLAG_BLUE
do
2334 if gFlags
[I
].NeedSend
then
2336 gFlags
[I
].NeedSend
:= False;
2340 // update items that aren't stationary
2341 g_Items_ForEachAlive(sendItemPos
);
2343 if reliableUpdate
then
2345 NetTimeToReliable
:= 0;
2346 NetTimeToUpdate
:= NetUpdateRate
;
2350 NetTimeToUpdate
:= 0;
2355 // send only mosters with some unexpected changes
2356 g_Mons_ForEach(sendMonsPosUnexpected
);
2359 // send unexpected platform changes
2360 g_Map_NetSendInterestingPanels();
2362 g_Net_Slist_ServerUpdate();
2364 if NetUseMaster then
2366 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2368 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2370 NetTimeToMaster := gTime + NetMasterRate;
2375 else if (NetMode
= NET_CLIENT
) then
2377 MC_SEND_PlayerPos();
2379 end; // if gameOn ...
2381 // Активно окно интерфейса - передаем клавиши ему:
2382 {$IFDEF ENABLE_MENU}
2383 if g_ActiveWindow
<> nil then
2385 w
:= e_GetFirstKeyPressed();
2387 if (w
<> IK_INVALID
) then
2389 Msg
.Msg
:= MESSAGE_DIKEY
;
2391 g_ActiveWindow
.OnMessage(Msg
);
2394 // Если оно от этого не закрылось, то обновляем:
2395 if g_ActiveWindow
<> nil then
2396 g_ActiveWindow
.Update();
2398 // Нужно сменить разрешение:
2399 if gResolutionChange
then
2401 {$IFDEF ENABLE_RENDER}
2402 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2405 gResolutionChange
:= False;
2406 g_ActiveWindow
:= nil;
2409 // Нужно сменить язык:
2410 if gLanguageChange
then
2412 //e_WriteLog('Read language file', MSG_NOTIFY);
2413 //g_Language_Load(DataDir + gLanguage + '.txt');
2414 g_Language_Set(gLanguage
);
2416 gLanguageChange
:= False;
2420 // Горячая клавиша для вызова меню выхода из игры (F10):
2421 if e_KeyPressed(IK_F10
) and
2423 (not gConsoleShow
) and
2424 (g_ActiveWindow
= nil) then
2430 Time
:= GetTickCount64() {div 1000};
2432 // Обработка отложенных событий:
2433 if gDelayedEvents
<> nil then
2434 for a
:= 0 to High(gDelayedEvents
) do
2435 if gDelayedEvents
[a
].Pending
and
2437 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2438 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2441 case gDelayedEvents
[a
].DEType
of
2443 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2446 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2450 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2451 if g_Game_IsNet
and g_Game_IsServer
then
2452 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2456 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2458 gDelayedEvents
[a
].Pending
:= False;
2461 // Каждую секунду обновляем счетчик обновлений:
2462 UPSCounter
:= UPSCounter
+ 1;
2463 if Time
- UPSTime
>= 1000 then
2472 g_Weapon_AddDynLights();
2473 g_Items_AddDynLights();
2477 procedure g_Game_LoadChatSounds(Resource
: string);
2480 FileName
, Snd
: string;
2482 len
, cnt
, tags
, i
, j
: Integer;
2485 FileName
:= g_ExtractWadName(Resource
);
2487 WAD
:= TWADFile
.Create();
2488 WAD
.ReadFile(FileName
);
2490 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2497 cfg
:= TConfig
.CreateMem(p
, len
);
2498 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2500 SetLength(gChatSounds
, cnt
);
2501 for i
:= 0 to Length(gChatSounds
) - 1 do
2503 gChatSounds
[i
].Sound
:= nil;
2504 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2505 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2506 if (Snd
= '') or (Tags
<= 0) then
2508 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2509 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2510 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2511 SetLength(gChatSounds
[i
].Tags
, tags
);
2512 for j
:= 0 to tags
- 1 do
2513 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2514 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2521 procedure g_Game_FreeChatSounds();
2525 for i
:= 0 to Length(gChatSounds
) - 1 do
2527 gChatSounds
[i
].Sound
.Free();
2528 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2530 SetLength(gChatSounds
, 0);
2534 procedure g_Game_LoadData();
2536 if DataLoaded
then Exit
;
2538 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2539 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
2541 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2542 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2543 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2544 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2545 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2546 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2547 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2548 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2549 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2550 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2551 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2552 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2553 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2554 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2555 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2556 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2557 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2558 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2559 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2560 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2561 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2562 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2563 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2564 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2565 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2566 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2567 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2568 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2569 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2570 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2571 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2572 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2574 goodsnd
[0] := TPlayableSound
.Create();
2575 goodsnd
[1] := TPlayableSound
.Create();
2576 goodsnd
[2] := TPlayableSound
.Create();
2577 goodsnd
[3] := TPlayableSound
.Create();
2579 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2580 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2581 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2582 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2584 killsnd
[0] := TPlayableSound
.Create();
2585 killsnd
[1] := TPlayableSound
.Create();
2586 killsnd
[2] := TPlayableSound
.Create();
2587 killsnd
[3] := TPlayableSound
.Create();
2589 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2590 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2591 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2592 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2594 hahasnd
[0] := TPlayableSound
.Create();
2595 hahasnd
[1] := TPlayableSound
.Create();
2596 hahasnd
[2] := TPlayableSound
.Create();
2598 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2599 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2600 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2602 sound_get_flag
[0] := TPlayableSound
.Create();
2603 sound_get_flag
[1] := TPlayableSound
.Create();
2604 sound_lost_flag
[0] := TPlayableSound
.Create();
2605 sound_lost_flag
[1] := TPlayableSound
.Create();
2606 sound_ret_flag
[0] := TPlayableSound
.Create();
2607 sound_ret_flag
[1] := TPlayableSound
.Create();
2608 sound_cap_flag
[0] := TPlayableSound
.Create();
2609 sound_cap_flag
[1] := TPlayableSound
.Create();
2611 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2612 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2613 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2614 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2615 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2616 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2617 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2618 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2620 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2624 g_Weapon_LoadData();
2626 g_Monsters_LoadData();
2631 procedure g_Game_Quit();
2633 g_Game_StopAllSounds(True);
2636 g_PlayerModel_FreeData();
2637 {$IFDEF ENABLE_MENU}
2638 // g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2641 if NetInitDone
then g_Net_Free
;
2643 // remove map after test
2644 if gMapToDelete
<> '' then
2645 g_Game_DeleteTestMap();
2649 {$IFDEF ENABLE_SYSTEM}
2654 procedure g_Game_FreeData();
2656 if not DataLoaded
then Exit
;
2659 g_Weapon_FreeData();
2660 g_Monsters_FreeData();
2662 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2664 g_Sound_Delete('SOUND_GAME_TELEPORT');
2665 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2666 g_Sound_Delete('SOUND_GAME_SECRET');
2667 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2668 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2669 g_Sound_Delete('SOUND_GAME_BULK1');
2670 g_Sound_Delete('SOUND_GAME_BULK2');
2671 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2672 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2673 g_Sound_Delete('SOUND_GAME_BURNING');
2674 g_Sound_Delete('SOUND_GAME_SWITCH1');
2675 g_Sound_Delete('SOUND_GAME_SWITCH0');
2682 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2683 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2684 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2685 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2692 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2693 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2694 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2695 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2701 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2702 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2703 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2705 sound_get_flag
[0].Free();
2706 sound_get_flag
[1].Free();
2707 sound_lost_flag
[0].Free();
2708 sound_lost_flag
[1].Free();
2709 sound_ret_flag
[0].Free();
2710 sound_ret_flag
[1].Free();
2711 sound_cap_flag
[0].Free();
2712 sound_cap_flag
[1].Free();
2714 g_Sound_Delete('SOUND_CTF_GET1');
2715 g_Sound_Delete('SOUND_CTF_GET2');
2716 g_Sound_Delete('SOUND_CTF_LOST1');
2717 g_Sound_Delete('SOUND_CTF_LOST2');
2718 g_Sound_Delete('SOUND_CTF_RETURN1');
2719 g_Sound_Delete('SOUND_CTF_RETURN2');
2720 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2721 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2723 g_Game_FreeChatSounds();
2725 DataLoaded
:= False;
2728 procedure g_FatalError(Text: String);
2730 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2731 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2733 gExit
:= EXIT_SIMPLE
;
2734 if gGameOn
then EndGame
;
2737 procedure g_SimpleError(Text: String);
2739 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2740 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2743 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2745 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2746 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2749 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2752 if gPlayer1
= nil then
2754 if g_Game_IsClient
then
2756 if NetPlrUID1
> -1 then
2757 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2761 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2762 Team
:= gPlayer1Settings
.Team
;
2764 // Создание первого игрока:
2765 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2766 gPlayer1Settings
.Color
,
2768 if gPlayer1
= nil then
2769 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2772 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2773 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2774 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2775 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2776 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2777 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2778 if g_Game_IsServer
and g_Game_IsNet
then
2779 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2780 gPlayer1
.Respawn(False, True);
2781 g_Net_Slist_ServerPlayerComes();
2786 if gPlayer2
= nil then
2788 if g_Game_IsClient
then
2790 if NetPlrUID2
> -1 then
2791 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2795 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2796 Team
:= gPlayer2Settings
.Team
;
2798 // Создание второго игрока:
2799 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2800 gPlayer2Settings
.Color
,
2802 if gPlayer2
= nil then
2803 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2806 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2807 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2808 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2809 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2810 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2811 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2812 if g_Game_IsServer
and g_Game_IsNet
then
2813 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2814 gPlayer2
.Respawn(False, True);
2815 g_Net_Slist_ServerPlayerComes();
2822 procedure g_Game_RemovePlayer();
2826 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2827 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2832 if g_Game_IsServer
then
2835 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2836 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2837 g_Player_Remove(Pl
.UID
);
2838 g_Net_Slist_ServerPlayerLeaves();
2842 gSpectLatchPID2
:= Pl
.UID
;
2850 if g_Game_IsServer
then
2853 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2854 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2855 g_Player_Remove(Pl
.UID
);
2856 g_Net_Slist_ServerPlayerLeaves();
2859 gSpectLatchPID1
:= Pl
.UID
;
2861 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2865 g_Net_Slist_ServerPlayerLeaves();
2868 procedure g_Game_Spectate();
2870 g_Game_RemovePlayer();
2871 if gPlayer1
<> nil then
2872 g_Game_RemovePlayer();
2875 procedure g_Game_SpectateCenterView();
2877 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2878 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2881 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2888 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2890 g_Game_ClearLoading();
2893 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2896 gGameSettings
.GameType
:= GT_SINGLE
;
2897 gGameSettings
.MaxLives
:= 0;
2898 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2899 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2900 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2901 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2902 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2903 gSwitchGameMode
:= GM_SINGLE
;
2905 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2906 gLMSRespawnTime
:= 0;
2907 gSpectLatchPID1
:= 0;
2908 gSpectLatchPID2
:= 0;
2910 g_Game_ExecuteEvent('ongamestart');
2912 // Создание первого игрока:
2913 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2914 gPlayer1Settings
.Color
,
2915 gPlayer1Settings
.Team
, False));
2916 if gPlayer1
= nil then
2918 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2922 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2923 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2924 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2925 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2926 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2929 // Создание второго игрока, если есть:
2932 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2933 gPlayer2Settings
.Color
,
2934 gPlayer2Settings
.Team
, False));
2935 if gPlayer2
= nil then
2937 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2941 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2942 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2943 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2944 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2945 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2949 // Загрузка и запуск карты:
2950 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2952 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2953 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2957 // Настройки игроков и ботов:
2961 for i
:= nPl
+1 to nPlayers
do
2962 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2965 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2966 TimeLimit
, ScoreLimit
: Word;
2968 Options
: LongWord; nPlayers
: Byte);
2974 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2976 g_Game_ClearLoading();
2979 gGameSettings
.GameType
:= GT_CUSTOM
;
2980 gGameSettings
.GameMode
:= GameMode
;
2981 gSwitchGameMode
:= GameMode
;
2982 gGameSettings
.TimeLimit
:= TimeLimit
;
2983 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2984 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2985 gGameSettings
.Options
:= Options
;
2987 gCoopTotalMonstersKilled
:= 0;
2988 gCoopTotalSecretsFound
:= 0;
2989 gCoopTotalMonsters
:= 0;
2990 gCoopTotalSecrets
:= 0;
2994 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2995 gLMSRespawnTime
:= 0;
2996 gSpectLatchPID1
:= 0;
2997 gSpectLatchPID2
:= 0;
2999 g_Game_ExecuteEvent('ongamestart');
3001 // Режим наблюдателя:
3002 if nPlayers
= 0 then
3009 if nPlayers
>= 1 then
3011 // Создание первого игрока:
3012 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3013 gPlayer1Settings
.Color
,
3014 gPlayer1Settings
.Team
, False));
3015 if gPlayer1
= nil then
3017 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3021 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3022 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3023 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3024 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3025 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3029 if nPlayers
>= 2 then
3031 // Создание второго игрока:
3032 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3033 gPlayer2Settings
.Color
,
3034 gPlayer2Settings
.Team
, False));
3035 if gPlayer2
= nil then
3037 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3041 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3042 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3043 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3044 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3045 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3049 // Загрузка и запуск карты:
3050 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3052 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3056 // Нет точек появления:
3057 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3058 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3059 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3060 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3061 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3063 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3067 // Настройки игроков и ботов:
3071 for i
:= nPl
+1 to nPlayers
do
3072 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3075 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3076 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3077 Options
: LongWord; nPlayers
: Byte;
3078 IPAddr
: LongWord; Port
: Word);
3081 g_Net_Slist_ServerClosed();
3083 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3085 g_Game_ClearLoading();
3090 gGameSettings
.GameType
:= GT_SERVER
;
3091 gGameSettings
.GameMode
:= GameMode
;
3092 gSwitchGameMode
:= GameMode
;
3093 gGameSettings
.TimeLimit
:= TimeLimit
;
3094 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3095 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3096 gGameSettings
.Options
:= Options
;
3098 gCoopTotalMonstersKilled
:= 0;
3099 gCoopTotalSecretsFound
:= 0;
3100 gCoopTotalMonsters
:= 0;
3101 gCoopTotalSecrets
:= 0;
3105 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3106 gLMSRespawnTime
:= 0;
3107 gSpectLatchPID1
:= 0;
3108 gSpectLatchPID2
:= 0;
3110 g_Game_ExecuteEvent('ongamestart');
3112 // Режим наблюдателя:
3113 if nPlayers
= 0 then
3119 if nPlayers
>= 1 then
3121 // Создание первого игрока:
3122 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3123 gPlayer1Settings
.Color
,
3124 gPlayer1Settings
.Team
, False));
3125 if gPlayer1
= nil then
3127 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3131 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3132 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3133 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3134 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3135 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3138 if nPlayers
>= 2 then
3140 // Создание второго игрока:
3141 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3142 gPlayer2Settings
.Color
,
3143 gPlayer2Settings
.Team
, False));
3144 if gPlayer2
= nil then
3146 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3150 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3151 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3152 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3153 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3154 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3157 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3158 if NetForwardPorts
then
3159 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3162 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3164 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3168 g_Net_Slist_Set(NetMasterList
);
3170 g_Net_Slist_ServerStarted();
3172 // Загрузка и запуск карты:
3173 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3175 g_Net_Slist_ServerClosed();
3176 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3180 // Нет точек появления:
3181 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3182 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3183 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3184 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3185 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3187 g_Net_Slist_ServerClosed();
3188 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3192 // Настройки игроков и ботов:
3195 g_Net_Slist_ServerMapStarted();
3196 NetState
:= NET_STATE_GAME
;
3199 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3214 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3215 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3217 g_Game_ClearLoading();
3222 gGameSettings
.GameType
:= GT_CLIENT
;
3224 gCoopTotalMonstersKilled
:= 0;
3225 gCoopTotalSecretsFound
:= 0;
3226 gCoopTotalMonsters
:= 0;
3227 gCoopTotalSecrets
:= 0;
3231 g_Game_ExecuteEvent('ongamestart');
3233 NetState
:= NET_STATE_AUTH
;
3235 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3237 // create (or update) map/resource databases
3238 g_Res_CreateDatabases(true);
3240 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3241 gLMSRespawnTime
:= 0;
3242 gSpectLatchPID1
:= 0;
3243 gSpectLatchPID2
:= 0;
3246 if not g_Net_Connect(Addr
, Port
) then
3248 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3249 NetState
:= NET_STATE_NONE
;
3253 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3255 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3260 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3261 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3262 // thank you, enet. let's ignore failures altogether then.
3263 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3265 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3267 Ptr
:= NetEvent
.packet
^.data
;
3268 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3270 enet_packet_destroy(NetEvent
.packet
);
3274 InMsg
.ReadLongWord(); // skip size
3275 MID
:= InMsg
.ReadByte();
3277 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3279 NetMyID
:= InMsg
.ReadByte();
3280 NetPlrUID1
:= InMsg
.ReadWord();
3282 WadName
:= InMsg
.ReadString();
3283 Map
:= InMsg
.ReadString();
3285 gWADHash
:= InMsg
.ReadMD5();
3287 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3288 gSwitchGameMode
:= gGameSettings
.GameMode
;
3289 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3290 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3291 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3292 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3293 T
:= InMsg
.ReadLongWord();
3295 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3296 //if newResPath = '' then
3298 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3299 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3300 if newResPath
= '' then
3302 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3303 enet_packet_destroy(NetEvent
.packet
);
3304 NetState
:= NET_STATE_NONE
;
3307 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3309 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3312 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3313 gPlayer1Settings
.Color
,
3314 gPlayer1Settings
.Team
, False));
3316 if gPlayer1
= nil then
3318 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3320 enet_packet_destroy(NetEvent
.packet
);
3321 NetState
:= NET_STATE_NONE
;
3325 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3326 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3327 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3328 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3329 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3330 gPlayer1
.UID
:= NetPlrUID1
;
3331 gPlayer1
.Reset(True);
3333 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3335 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3337 enet_packet_destroy(NetEvent
.packet
);
3338 NetState
:= NET_STATE_NONE
;
3346 enet_packet_destroy(NetEvent
.packet
);
3350 enet_packet_destroy(NetEvent
.packet
);
3354 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3357 if (NetEvent
.data
<= NET_DISC_MAX
) then
3358 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3359 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3366 ProcessLoading(True);
3367 if g_Net_UserRequestExit() then
3376 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3377 NetState
:= NET_STATE_NONE
;
3382 NetState
:= NET_STATE_GAME
;
3383 MC_SEND_FullStateRequest
;
3384 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3388 lastAsMegaWad
: Boolean = false;
3390 procedure g_Game_ChangeMap(const MapPath
: String);
3394 g_Game_ClearLoading();
3396 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3397 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3398 if gExitByTrigger
then
3401 gExitByTrigger
:= False;
3403 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3404 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3407 procedure g_Game_Restart();
3411 if g_Game_IsClient
then
3413 map
:= g_ExtractFileName(gMapInfo
.Map
);
3414 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3418 g_Game_ClearLoading();
3419 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3422 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3424 NewWAD
, ResName
: String;
3428 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3430 {$IFDEF ENABLE_GIBS}
3433 {$IFDEF ENABLE_SHELLS}
3436 {$IFDEF ENABLE_CORPSES}
3437 g_Corpses_RemoveAll
;
3440 if (not g_Game_IsClient
) and
3441 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3442 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3444 if gSwitchGameMode
= GM_CTF
then
3445 gGameSettings
.MaxLives
:= 0;
3446 gGameSettings
.GameMode
:= gSwitchGameMode
;
3449 gSwitchGameMode
:= gGameSettings
.GameMode
;
3451 g_Player_ResetTeams();
3453 lastAsMegaWad
:= asMegawad
;
3454 if isWadPath(Map
) then
3456 NewWAD
:= g_ExtractWadName(Map
);
3457 ResName
:= g_ExtractFileName(Map
);
3458 if g_Game_IsServer
then
3460 nws
:= findDiskWad(NewWAD
);
3461 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3464 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3465 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3469 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3470 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3472 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3473 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3475 if (length(nws
) = 0) then
3477 ResName
:= ''; // failed
3482 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3483 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3484 g_Game_LoadWAD(NewWAD
);
3489 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3490 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3495 NewWAD
:= gGameSettings
.WAD
;
3501 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3503 if (ResName
<> '') and (NewWAD
<> '') then
3505 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3506 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3510 {$IFDEF ENABLE_RENDER}
3511 r_Render_LoadTextures
;
3514 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3516 gState
:= STATE_NONE
;
3517 {$IFDEF ENABLE_MENU}
3518 g_ActiveWindow
:= nil;
3523 wNeedTimeReset
:= True;
3525 if gGameSettings
.GameMode
= GM_CTF
then
3527 g_Map_ResetFlag(FLAG_RED
);
3528 g_Map_ResetFlag(FLAG_BLUE
);
3529 // CTF, а флагов нет:
3530 if not g_Map_HaveFlagPoints() then
3531 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3536 gState
:= STATE_MENU
;
3541 gPauseMain
:= false;
3542 gPauseHolmes
:= false;
3543 NetTimeToUpdate
:= 1;
3544 NetTimeToReliable
:= 0;
3545 NetTimeToMaster
:= NetMasterRate
;
3546 gSpectLatchPID1
:= 0;
3547 gSpectLatchPID2
:= 0;
3548 gMissionFailed
:= False;
3551 gCoopMonstersKilled
:= 0;
3552 gCoopSecretsFound
:= 0;
3554 gVoteInProgress
:= False;
3555 gVotePassed
:= False;
3561 if not gGameOn
then Exit
;
3563 g_Game_SpectateCenterView();
3565 if g_Game_IsServer
then
3567 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3569 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3570 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3571 gLMSSoftSpawn
:= True;
3572 if g_Game_IsNet
then
3573 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3577 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3578 gLMSRespawnTime
:= 0;
3582 if NetMode
= NET_SERVER
then
3584 // reset full state flags
3585 if NetClients
<> nil then
3586 for I
:= 0 to High(NetClients
) do
3587 NetClients
[I
].FullUpdateSent
:= False;
3589 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3592 g_Net_Slist_ServerMapStarted();
3594 if NetClients
<> nil then
3595 for I
:= 0 to High(NetClients
) do
3596 if NetClients
[I
].Used
then
3598 NetClients
[I
].Voted
:= False;
3599 if NetClients
[I
].RequestedFullUpdate
then
3601 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3602 NetClients
[I
].RequestedFullUpdate
:= False;
3606 g_Net_UnbanNonPermHosts();
3611 gCoopTotalMonstersKilled
:= 0;
3612 gCoopTotalSecretsFound
:= 0;
3613 gCoopTotalMonsters
:= 0;
3614 gCoopTotalSecrets
:= 0;
3618 g_Game_ExecuteEvent('onmapstart');
3621 procedure SetFirstLevel
;
3625 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3626 if MapList
= nil then
3629 SortSArray(MapList
);
3630 gNextMap
:= MapList
[Low(MapList
)];
3635 procedure g_Game_ExitLevel(const Map
: AnsiString);
3639 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3640 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3641 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3642 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3644 // Вышли в выход в Одиночной игре:
3645 if gGameSettings
.GameType
= GT_SINGLE
then
3646 gExit
:= EXIT_ENDLEVELSINGLE
3647 else // Вышли в выход в Своей игре
3649 gExit
:= EXIT_ENDLEVELCUSTOM
;
3650 if gGameSettings
.GameMode
= GM_COOP
then
3651 g_Player_RememberAll
;
3653 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3656 if gGameSettings
.GameMode
= GM_COOP
then
3659 gStatsPressed
:= True;
3660 gNextMap
:= 'MAP01';
3662 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3665 if g_Game_IsNet
then
3667 MH_SEND_GameStats();
3668 MH_SEND_CoopStats();
3674 procedure g_Game_RestartLevel();
3678 if gGameSettings
.GameMode
= GM_SINGLE
then
3683 gExit
:= EXIT_ENDLEVELCUSTOM
;
3684 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3688 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3690 gWAD
{, xwad}: String;
3693 if not g_Game_IsClient
then Exit
;
3694 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3696 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3701 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3705 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3708 g_Game_LoadWAD(NewWAD
);
3712 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3713 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3716 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3717 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3721 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3725 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3726 g_Game_LoadWAD(NewWAD);
3730 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3732 i
, n
, nb
, nr
: Integer;
3734 if not g_Game_IsServer
then Exit
;
3735 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3736 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3737 gLMSRespawnTime
:= 0;
3740 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3742 gMissionFailed
:= True;
3743 g_Game_RestartLevel
;
3747 n
:= 0; nb
:= 0; nr
:= 0;
3748 for i
:= Low(gPlayers
) to High(gPlayers
) do
3749 if (gPlayers
[i
] <> nil) and
3750 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3751 (gPlayers
[i
] is TBot
)) then
3754 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3755 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3758 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3760 // wait a second until the fuckers finally decide to join
3761 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3762 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3763 gLMSSoftSpawn
:= NoMapRestart
;
3764 if g_Game_IsNet
then
3765 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3769 {$IFDEF ENABLE_GIBS}
3772 {$IFDEF ENABLE_SHELLS}
3775 {$IFDEF ENABLE_CORPSES}
3776 g_Corpses_RemoveAll
;
3779 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3780 if g_Game_IsNet
then
3781 MH_SEND_GameEvent(NET_EV_LMS_START
);
3783 for i
:= Low(gPlayers
) to High(gPlayers
) do
3785 if gPlayers
[i
] = nil then continue
;
3786 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3787 // don't touch normal spectators
3788 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3790 gPlayers
[i
].FNoRespawn
:= True;
3791 gPlayers
[i
].Lives
:= 0;
3792 if g_Game_IsNet
then
3793 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3796 gPlayers
[i
].FNoRespawn
:= False;
3797 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3798 gPlayers
[i
].Respawn(False, True);
3799 if gGameSettings
.GameMode
= GM_COOP
then
3801 gPlayers
[i
].Frags
:= 0;
3802 gPlayers
[i
].RecallState
;
3804 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3805 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3806 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3807 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3810 g_Items_RestartRound();
3812 gLMSSoftSpawn
:= False;
3815 function g_Game_GetFirstMap(WAD
: String): String;
3819 MapList
:= g_Map_GetMapsList(WAD
);
3820 if MapList
= nil then
3823 SortSArray(MapList
);
3824 Result
:= MapList
[Low(MapList
)];
3826 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3832 function g_Game_GetNextMap(): String;
3839 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3840 if MapList
= nil then
3843 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3845 SortSArray(MapList
);
3847 for I
:= Low(MapList
) to High(MapList
) do
3848 if Map
= MapList
[I
] then
3854 if MapIndex
<> -255 then
3856 if MapIndex
= High(MapList
) then
3857 Result
:= MapList
[Low(MapList
)]
3859 Result
:= MapList
[MapIndex
+ 1];
3861 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3867 procedure g_Game_NextLevel();
3869 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3870 gExit
:= EXIT_ENDLEVELCUSTOM
3873 gExit
:= EXIT_ENDLEVELSINGLE
;
3877 if gNextMap
<> '' then Exit
;
3878 gNextMap
:= g_Game_GetNextMap();
3881 function g_Game_IsTestMap(): Boolean;
3883 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3886 procedure g_Game_DeleteTestMap();
3889 //MapName: AnsiString;
3897 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3898 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3899 if (a
= 0) then exit
;
3901 // Выделяем имя wad-файла и имя карты
3902 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3903 Delete(gMapToDelete
, 1, a
+5);
3904 gMapToDelete
:= UpperCase(gMapToDelete
);
3906 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3909 // Имя карты не стандартное тестовое:
3910 if MapName <> TEST_MAP_NAME then
3913 if not gTempDelete then
3915 time := g_GetFileTime(WadName);
3916 WAD := TWADFile.Create();
3919 if not WAD.ReadFile(WadName) then
3920 begin // Нет такого WAD-файла
3925 // Составляем список карт и ищем нужную:
3927 MapList := WAD.GetResourcesList('');
3929 if MapList <> nil then
3930 for a := 0 to High(MapList) do
3931 if MapList[a] = MapName then
3933 // Удаляем и сохраняем:
3934 WAD.RemoveResource('', MapName);
3935 WAD.SaveTo(WadName);
3940 g_SetFileTime(WadName, time);
3943 if gTempDelete
then DeleteFile(WadName
);
3946 procedure GameCVars(P
: SSArray
);
3949 stat
: TPlayerStatArray
;
3952 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3956 if Length(P
) > 1 then
3961 gsGameFlags
:= gsGameFlags
or Flag
3963 gsGameFlags
:= gsGameFlags
and (not Flag
);
3965 if g_Game_IsServer
then
3968 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3970 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3971 if g_Game_IsNet
then MH_SEND_GameSettings
;
3975 if LongBool(gsGameFlags
and Flag
) then
3976 g_Console_Add(_lc
[OnMsg
])
3978 g_Console_Add(_lc
[OffMsg
]);
3980 if OnMapChange
and g_Game_IsServer
then
3981 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3986 cmd
:= LowerCase(P
[0]);
3988 if cmd
= 'g_gamemode' then
3990 if (Length(P
) > 1) then
3992 a
:= g_Game_TextToMode(P
[1]);
3993 if a
= GM_SINGLE
then a
:= GM_COOP
;
3994 gsGameMode
:= g_Game_ModeToText(a
);
3995 if g_Game_IsServer
then
3997 gSwitchGameMode
:= a
;
3998 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3999 (gState
= STATE_INTERSINGLE
) then
4000 gSwitchGameMode
:= GM_SINGLE
;
4002 gGameSettings
.GameMode
:= gSwitchGameMode
;
4006 if gSwitchGameMode
= gGameSettings
.GameMode
then
4007 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4008 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4010 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4011 [g_Game_ModeToText(gGameSettings
.GameMode
),
4012 g_Game_ModeToText(gSwitchGameMode
)]));
4014 else if cmd
= 'g_friendlyfire' then
4016 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4018 else if cmd
= 'g_friendly_absorb_damage' then
4020 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
4022 else if cmd
= 'g_friendly_hit_trace' then
4024 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
4026 else if cmd
= 'g_friendly_hit_projectile' then
4028 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
4030 else if cmd
= 'g_weaponstay' then
4032 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
4034 else if cmd
= 'g_allow_exit' then
4036 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
4038 else if cmd
= 'g_allow_monsters' then
4040 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
4042 else if cmd
= 'g_allow_dropflag' then
4044 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
4046 else if cmd
= 'g_throw_flag' then
4048 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
4050 else if cmd
= 'g_bot_vsplayers' then
4052 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4054 else if cmd
= 'g_bot_vsmonsters' then
4056 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4058 else if cmd
= 'g_dm_keys' then
4060 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4062 else if cmd
= 'g_gameflags' then
4064 if Length(P
) > 1 then
4066 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4067 if g_Game_IsServer
then
4069 gGameSettings
.Options
:= gsGameFlags
;
4070 if g_Game_IsNet
then MH_SEND_GameSettings
;
4074 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4076 else if cmd
= 'g_warmup_time' then
4078 if Length(P
) > 1 then
4080 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4081 if g_Game_IsServer
then
4083 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4084 // extend warmup if it's already going
4085 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4087 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4088 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4090 if g_Game_IsNet
then MH_SEND_GameSettings
;
4094 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4095 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4097 else if cmd
= 'g_spawn_invul' then
4099 if Length(P
) > 1 then
4101 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4102 if g_Game_IsServer
then
4104 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4105 if g_Game_IsNet
then MH_SEND_GameSettings
;
4109 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4111 else if cmd
= 'g_item_respawn_time' then
4113 if Length(P
) > 1 then
4115 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4116 if g_Game_IsServer
then
4118 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4119 if g_Game_IsNet
then MH_SEND_GameSettings
;
4123 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4124 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4126 else if cmd
= 'sv_intertime' then
4128 if (Length(P
) > 1) then
4129 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4131 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4133 else if cmd
= 'g_max_particles' then
4135 if Length(p
) = 2 then
4138 a
:= Max(0, StrToIntDef(p
[1], 0));
4142 else if Length(p
) = 1 then
4145 e_LogWritefln('%s', [g_GFX_GetMax()])
4147 e_LogWritefln('%s', [0])
4152 e_LogWritefln('usage: %s <n>', [cmd
])
4155 else if cmd
= 'g_max_shells' then
4157 if Length(p
) = 2 then
4159 {$IFDEF ENABLE_SHELLS}
4160 a
:= Max(0, StrToIntDef(p
[1], 0));
4164 else if Length(p
) = 1 then
4166 {$IFDEF ENABLE_SHELLS}
4167 e_LogWritefln('%s', [g_Shells_GetMax()])
4169 e_LogWritefln('%s', [0])
4174 e_LogWritefln('usage: %s <n>', [cmd
])
4177 else if cmd
= 'g_max_gibs' then
4179 if Length(p
) = 2 then
4181 {$IFDEF ENABLE_GIBS}
4182 a
:= Max(0, StrToIntDef(p
[1], 0));
4186 else if Length(p
) = 1 then
4188 {$IFDEF ENABLE_GIBS}
4189 e_LogWritefln('%s', [g_Gibs_GetMax()])
4191 e_LogWritefln('%s', [0])
4196 e_LogWritefln('usage: %s <n>', [cmd
])
4199 else if cmd
= 'g_max_corpses' then
4201 if Length(p
) = 2 then
4203 {$IFDEF ENABLE_CORPSES}
4204 a
:= Max(0, StrToIntDef(p
[1], 0));
4208 else if Length(p
) = 1 then
4210 {$IFDEF ENABLE_CORPSES}
4211 e_LogWritefln('%s', [g_Corpses_GetMax()])
4213 e_LogWritefln('%s', [0])
4218 e_LogWritefln('usage: %s <n>', [cmd
])
4221 else if cmd
= 'g_force_model' then
4223 if Length(p
) = 2 then
4225 a
:= StrToIntDef(p
[1], 0);
4226 g_Force_Model_Set(a
);
4227 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4229 for a
:= Low(gPlayers
) to High(gPlayers
) do
4231 if (gPlayers
[a
] <> nil) then
4233 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4235 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4237 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4241 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4243 for a
:= Low(gPlayers
) to High(gPlayers
) do
4245 if (gPlayers
[a
] <> nil) then
4247 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4249 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4251 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4257 else if cmd
= 'g_force_model_name' then
4259 if (Length(P
) > 1) then
4261 cmd
:= b_Text_Unformat(P
[1]);
4262 g_Forced_Model_SetName(cmd
);
4263 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(g_Forced_Model_GetName());
4279 else if cmd
= 'g_scorelimit' then
4281 if Length(P
) > 1 then
4283 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4285 if g_Game_IsServer
then
4288 if gGameSettings
.GameMode
= GM_DM
then
4290 stat
:= g_Player_GetStats();
4292 for a
:= 0 to High(stat
) do
4293 if stat
[a
].Frags
> b
then
4297 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4299 // if someone has a higher score, set it to that instead
4300 gsScoreLimit
:= max(gsScoreLimit
, b
);
4301 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4303 if g_Game_IsNet
then MH_SEND_GameSettings
;
4307 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4309 else if cmd
= 'g_timelimit' then
4311 if Length(P
) > 1 then
4313 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4314 if g_Game_IsServer
then
4316 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4317 if g_Game_IsNet
then MH_SEND_GameSettings
;
4320 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4321 [gsTimeLimit
div 3600,
4322 (gsTimeLimit
div 60) mod 60,
4323 gsTimeLimit
mod 60]));
4325 else if cmd
= 'g_max_bots' then
4327 if Length(P
) > 1 then
4328 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4329 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4331 else if cmd
= 'g_maxlives' then
4333 if Length(P
) > 1 then
4335 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4336 if g_Game_IsServer
then
4338 gGameSettings
.MaxLives
:= gsMaxLives
;
4339 if g_Game_IsNet
then MH_SEND_GameSettings
;
4343 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4347 procedure PlayerSettingsCVars(P
: SSArray
);
4352 function ParseTeam(s
: string): Byte;
4356 'red', '1': result
:= TEAM_RED
;
4357 'blue', '2': result
:= TEAM_BLUE
;
4358 else result
:= TEAM_NONE
;
4362 cmd
:= LowerCase(P
[0]);
4366 if (Length(P
) > 1) then
4368 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4369 if g_Game_IsClient
then
4370 MC_SEND_PlayerSettings
4371 else if gGameOn
and (gPlayer1
<> nil) then
4373 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4374 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4380 if (Length(P
) > 1) then
4382 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4383 if g_Game_IsClient
then
4384 MC_SEND_PlayerSettings
4385 else if gGameOn
and (gPlayer2
<> nil) then
4387 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4388 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4394 if Length(P
) > 3 then
4396 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4397 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4398 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4399 if g_Game_IsClient
then
4400 MC_SEND_PlayerSettings
4401 else if gGameOn
and (gPlayer1
<> nil) then
4403 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4404 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4410 if Length(P
) > 3 then
4412 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4413 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4414 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4415 if g_Game_IsClient
then
4416 MC_SEND_PlayerSettings
4417 else if gGameOn
and (gPlayer2
<> nil) then
4419 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4420 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4426 if (Length(P
) > 1) then
4428 gPlayer1Settings
.Model
:= P
[1];
4429 if g_Game_IsClient
then
4430 MC_SEND_PlayerSettings
4431 else if gGameOn
and (gPlayer1
<> nil) then
4433 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4434 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4435 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4441 if (Length(P
) > 1) then
4443 gPlayer2Settings
.Model
:= P
[1];
4444 if g_Game_IsClient
then
4445 MC_SEND_PlayerSettings
4446 else if gGameOn
and (gPlayer2
<> nil) then
4448 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4449 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4450 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4456 // TODO: switch teams if in game or store this separately
4457 if (Length(P
) > 1) then
4459 team
:= ParseTeam(P
[1]);
4460 if team
= TEAM_NONE
then
4461 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4462 else if not gGameOn
and not g_Game_IsNet
then
4463 gPlayer1Settings
.Team
:= team
4465 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4470 // TODO: switch teams if in game or store this separately
4471 if (Length(P
) > 1) then
4473 team
:= ParseTeam(P
[1]);
4474 if team
= TEAM_NONE
then
4475 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4476 else if not gGameOn
and not g_Game_IsNet
then
4477 gPlayer2Settings
.Team
:= team
4479 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4484 if (Length(P
) = 2) then
4485 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4489 if (Length(P
) = 2) then
4490 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4494 if (Length(P
) = 2) then
4495 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4499 if (Length(P
) = 2) then
4500 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4504 if (Length(P
) = 2) then
4505 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4509 if (Length(P
) = 2) then
4510 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4512 'p1_priority_kastet':
4514 if (Length(P
) = 2) then
4515 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4517 'p2_priority_kastet':
4519 if (Length(P
) = 2) then
4520 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4524 if (Length(P
) = 2) then
4525 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4529 if (Length(P
) = 2) then
4530 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4532 'p1_priority_pistol':
4534 if (Length(P
) = 2) then
4535 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4537 'p2_priority_pistol':
4539 if (Length(P
) = 2) then
4540 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4542 'p1_priority_shotgun1':
4544 if (Length(P
) = 2) then
4545 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4547 'p2_priority_shotgun1':
4549 if (Length(P
) = 2) then
4550 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4552 'p1_priority_shotgun2':
4554 if (Length(P
) = 2) then
4555 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4557 'p2_priority_shotgun2':
4559 if (Length(P
) = 2) then
4560 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4562 'p1_priority_chaingun':
4564 if (Length(P
) = 2) then
4565 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4567 'p2_priority_chaingun':
4569 if (Length(P
) = 2) then
4570 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4572 'p1_priority_rocketlauncher':
4574 if (Length(P
) = 2) then
4575 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4577 'p2_priority_rocketlauncher':
4579 if (Length(P
) = 2) then
4580 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4582 'p1_priority_plasma':
4584 if (Length(P
) = 2) then
4585 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4587 'p2_priority_plasma':
4589 if (Length(P
) = 2) then
4590 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4594 if (Length(P
) = 2) then
4595 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4599 if (Length(P
) = 2) then
4600 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4602 'p1_priority_super':
4604 if (Length(P
) = 2) then
4605 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4607 'p2_priority_super':
4609 if (Length(P
) = 2) then
4610 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4612 'p1_priority_flamethrower':
4614 if (Length(P
) = 2) then
4615 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4617 'p2_priority_flamethrower':
4619 if (Length(P
) = 2) then
4620 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4622 'p1_priority_berserk':
4624 if (Length(P
) = 2) then
4625 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4627 'p2_priority_berserk':
4629 if (Length(P
) = 2) then
4630 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4635 procedure PrintHeapStats();
4639 hs
:= GetFPCHeapStatus();
4640 e_LogWriteLn ('v===== heap status =====v');
4641 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4642 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4643 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4644 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4645 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4646 e_LogWriteLn ('^=======================^');
4649 procedure DebugCommands(P
: SSArray
);
4656 // Команды отладочного режима:
4657 if {gDebugMode}conIsCheatsEnabled
then
4659 cmd
:= LowerCase(P
[0]);
4660 if cmd
= 'd_window' then
4662 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4663 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4665 else if cmd
= 'd_winmsg' then
4667 if (Length(P
) > 1) and
4668 ((P
[1] = '1') or (P
[1] = '0')) then
4669 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4671 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4673 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4675 if (Length(P
) > 1) and
4676 ((P
[1] = '1') or (P
[1] = '0')) then
4677 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4679 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4681 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4683 if Length(P
) > 1 then
4685 '0': g_debug_BotAIOff
:= 0;
4686 '1': g_debug_BotAIOff
:= 1;
4687 '2': g_debug_BotAIOff
:= 2;
4688 '3': g_debug_BotAIOff
:= 3;
4691 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4693 else if cmd
= 'd_monster' then
4695 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4696 if Length(P
) < 2 then
4698 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4699 g_Console_Add('ID | Name');
4700 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4701 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4702 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4705 a
:= StrToIntDef(P
[1], 0);
4706 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4707 a
:= g_Mons_TypeIdByName(P
[1]);
4709 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4710 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4713 with gPlayer1
.Obj
do
4715 mon
:= g_Monsters_Create(a
,
4716 X
+ Rect
.X
+ (Rect
.Width
div 2),
4717 Y
+ Rect
.Y
+ Rect
.Height
,
4718 gPlayer1
.Direction
, True);
4720 if (Length(P
) > 2) and (mon
<> nil) then
4722 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4723 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4724 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4725 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4726 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4727 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4728 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4729 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4730 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4735 else if (cmd
= 'd_player') then
4737 if (Length(P
) > 1) and
4738 ((P
[1] = '1') or (P
[1] = '0')) then
4739 g_debug_Player
:= (P
[1][1] = '1');
4741 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4743 else if (cmd
= 'd_mem') then
4749 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4753 procedure GameCheats(P
: SSArray
);
4759 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4761 g_Console_Add('not available');
4767 g_Console_Add('where is the player?!');
4770 cmd
:= LowerCase(P
[0]);
4774 plr
.GodMode
:= not plr
.GodMode
;
4775 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4778 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4779 if cmd
= 'give' then
4781 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4782 for f
:= 1 to High(P
) do
4784 cmd
:= LowerCase(P
[f
]);
4785 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4786 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4787 if cmd
= 'exit' then
4789 if gTriggers
<> nil then
4791 for a
:= 0 to High(gTriggers
) do
4793 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4795 g_Console_Add('player left the map');
4796 gExitByTrigger
:= True;
4797 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4798 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4806 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4807 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4808 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4809 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4810 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4812 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4813 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4815 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4816 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;
4818 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4819 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4821 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4822 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4824 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4825 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4827 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4828 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4829 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4831 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4832 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4833 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4834 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;
4835 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4836 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4838 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;
4839 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;
4840 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;
4841 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;
4842 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;
4843 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;
4845 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4846 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;
4848 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;
4849 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;
4851 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4853 if cmd
= 'ammo' then
4855 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4856 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4857 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4858 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4859 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4860 g_Console_Add('player got some ammo');
4864 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4865 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4867 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4868 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4870 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4871 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4873 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4874 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4876 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4878 if cmd
= 'weapons' then
4880 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4881 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4882 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4883 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4884 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4885 plr
.GiveItem(ITEM_WEAPON_BFG
);
4886 g_Console_Add('player got weapons');
4890 if cmd
= 'keys' then
4892 plr
.GiveItem(ITEM_KEY_RED
);
4893 plr
.GiveItem(ITEM_KEY_GREEN
);
4894 plr
.GiveItem(ITEM_KEY_BLUE
);
4895 g_Console_Add('player got all keys');
4899 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4904 if cmd
= 'open' then
4906 g_Console_Add('player activated sesame');
4907 g_Triggers_OpenAll();
4914 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4918 if cmd
= 'noclip' then
4921 g_Console_Add('wall hardeness adjusted');
4925 if cmd
= 'notarget' then
4927 plr
.NoTarget
:= not plr
.NoTarget
;
4928 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4932 if cmd
= 'noreload' then
4934 plr
.NoReload
:= not plr
.NoReload
;
4935 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4939 if cmd
= 'speedy' then
4941 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4942 g_Console_Add('speed adjusted');
4946 if cmd
= 'jumpy' then
4948 VEL_JUMP
:= 30-VEL_JUMP
;
4949 g_Console_Add('jump height adjusted');
4953 if cmd
= 'automap' then
4955 gShowMap
:= not gShowMap
;
4956 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4960 if cmd
= 'aimline' then
4962 gAimLine
:= not gAimLine
;
4963 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4968 procedure GameCommands(P
: SSArray
);
4974 pl
: pTNetClient
= nil;
4982 cmd
:= LowerCase(P
[0]);
4984 if cmd
= 'pause' then
4986 {$IFDEF ENABLE_MENU}
4987 if (g_ActiveWindow
= nil) then
4988 g_Game_Pause(not gPauseMain
);
4990 g_Game_Pause(not gPauseMain
);
4993 else if cmd
= 'endgame' then
4994 gExit
:= EXIT_SIMPLE
4995 else if cmd
= 'restart' then
4997 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4999 if g_Game_IsClient
then
5001 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5006 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5008 else if cmd
= 'kick' then
5010 if g_Game_IsServer
then
5012 if Length(P
) < 2 then
5014 g_Console_Add('kick <name>');
5019 g_Console_Add('kick <name>');
5023 if g_Game_IsNet
then
5024 pl
:= g_Net_Client_ByName(P
[1]);
5027 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5028 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5029 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5030 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5031 g_Net_Slist_ServerPlayerLeaves();
5032 end else if gPlayers
<> nil then
5033 for a
:= Low(gPlayers
) to High(gPlayers
) do
5034 if gPlayers
[a
] <> nil then
5035 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5037 // Не отключать основных игроков в сингле
5038 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5040 gPlayers
[a
].Lives
:= 0;
5041 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5042 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5043 g_Player_Remove(gPlayers
[a
].UID
);
5044 g_Net_Slist_ServerPlayerLeaves();
5045 // Если не перемешать, при добавлении новых ботов появятся старые
5049 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5051 else if cmd
= 'kick_id' then
5053 if g_Game_IsServer
and g_Game_IsNet
then
5055 if Length(P
) < 2 then
5057 g_Console_Add('kick_id <client ID>');
5062 g_Console_Add('kick_id <client ID>');
5066 a
:= StrToIntDef(P
[1], 0);
5067 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5069 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5071 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5072 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
5073 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5074 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5075 g_Net_Slist_ServerPlayerLeaves();
5079 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5081 else if cmd
= 'kick_pid' then
5083 if g_Game_IsServer
and g_Game_IsNet
then
5085 if Length(P
) < 2 then
5087 g_Console_Add('kick_pid <player ID>');
5092 g_Console_Add('kick_pid <player ID>');
5096 a
:= StrToIntDef(P
[1], 0);
5097 pl
:= g_Net_Client_ByPlayer(a
);
5098 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5100 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5101 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5102 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5103 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5104 g_Net_Slist_ServerPlayerLeaves();
5107 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5109 else if cmd
= 'ban' then
5111 if g_Game_IsServer
and g_Game_IsNet
then
5113 if Length(P
) < 2 then
5115 g_Console_Add('ban <name>');
5120 g_Console_Add('ban <name>');
5124 pl
:= g_Net_Client_ByName(P
[1]);
5127 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5128 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5129 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5130 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5131 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5132 g_Net_Slist_ServerPlayerLeaves();
5134 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5136 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5138 else if cmd
= 'ban_id' then
5140 if g_Game_IsServer
and g_Game_IsNet
then
5142 if Length(P
) < 2 then
5144 g_Console_Add('ban_id <client ID>');
5149 g_Console_Add('ban_id <client ID>');
5153 a
:= StrToIntDef(P
[1], 0);
5154 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5155 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5157 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5158 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5159 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5160 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5161 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5162 g_Net_Slist_ServerPlayerLeaves();
5165 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5167 else if cmd
= 'ban_pid' then
5169 if g_Game_IsServer
and g_Game_IsNet
then
5171 if Length(P
) < 2 then
5173 g_Console_Add('ban_pid <player ID>');
5178 g_Console_Add('ban_pid <player ID>');
5182 a
:= StrToIntDef(P
[1], 0);
5183 pl
:= g_Net_Client_ByPlayer(a
);
5184 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5186 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5187 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5188 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5189 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5190 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5191 g_Net_Slist_ServerPlayerLeaves();
5194 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5196 else if cmd
= 'permban' then
5198 if g_Game_IsServer
and g_Game_IsNet
then
5200 if Length(P
) < 2 then
5202 g_Console_Add('permban <name>');
5207 g_Console_Add('permban <name>');
5211 pl
:= g_Net_Client_ByName(P
[1]);
5214 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5215 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5216 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5217 g_Net_SaveBanList();
5218 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5219 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5220 g_Net_Slist_ServerPlayerLeaves();
5222 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5224 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5226 else if cmd
= 'permban_id' then
5228 if g_Game_IsServer
and g_Game_IsNet
then
5230 if Length(P
) < 2 then
5232 g_Console_Add('permban_id <client ID>');
5237 g_Console_Add('permban_id <client ID>');
5241 a
:= StrToIntDef(P
[1], 0);
5242 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5243 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5245 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5246 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5247 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5248 g_Net_SaveBanList();
5249 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5250 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5251 g_Net_Slist_ServerPlayerLeaves();
5254 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5256 else if cmd
= 'permban_pid' then
5258 if g_Game_IsServer
and g_Game_IsNet
then
5260 if Length(P
) < 2 then
5262 g_Console_Add('permban_pid <player ID>');
5267 g_Console_Add('permban_pid <player ID>');
5271 a
:= StrToIntDef(P
[1], 0);
5272 pl
:= g_Net_Client_ByPlayer(a
);
5273 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5275 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5276 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5277 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5278 g_Net_SaveBanList();
5279 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5280 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5281 g_Net_Slist_ServerPlayerLeaves();
5284 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5286 else if cmd
= 'permban_ip' then
5288 if g_Game_IsServer
and g_Game_IsNet
then
5290 if Length(P
) < 2 then
5292 g_Console_Add('permban_ip <IP address>');
5297 g_Console_Add('permban_ip <IP address>');
5301 g_Net_BanHost(P
[1]);
5302 g_Net_SaveBanList();
5303 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5305 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5307 else if cmd
= 'unban' then
5309 if g_Game_IsServer
and g_Game_IsNet
then
5311 if Length(P
) < 2 then
5313 g_Console_Add('unban <IP Address>');
5318 g_Console_Add('unban <IP Address>');
5322 if g_Net_UnbanHost(P
[1]) then
5324 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5325 g_Net_SaveBanList();
5327 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5329 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5331 else if cmd
= 'clientlist' then
5333 if g_Game_IsServer
and g_Game_IsNet
then
5336 if NetClients
<> nil then
5337 for a
:= Low(NetClients
) to High(NetClients
) do
5338 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5340 plr
:= g_Player_Get(NetClients
[a
].Player
);
5341 if plr
= nil then continue
;
5343 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5344 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5347 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5349 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5351 else if cmd
= 'connect' then
5353 if (NetMode
= NET_NONE
) then
5355 if Length(P
) < 2 then
5357 g_Console_Add('connect <IP> [port] [password]');
5362 g_Console_Add('connect <IP> [port] [password]');
5366 if Length(P
) > 2 then
5367 prt
:= StrToIntDef(P
[2], 25666)
5371 if Length(P
) > 3 then
5376 g_Game_StartClient(P
[1], prt
, pw
);
5379 else if cmd
= 'disconnect' then
5381 if (NetMode
= NET_CLIENT
) then
5384 else if cmd
= 'reconnect' then
5386 if (NetMode
= NET_SERVER
) then
5389 if (NetMode
= NET_CLIENT
) then
5392 gExit
:= EXIT_SIMPLE
;
5396 //TODO: Use last successful password to reconnect, instead of ''
5397 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5399 else if (cmd
= 'addbot') or
5400 (cmd
= 'bot_add') then
5402 if Length(P
) > 2 then
5403 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5404 else if Length(P
) > 1 then
5405 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5407 g_Bot_Add(TEAM_NONE
, 2);
5409 else if cmd
= 'bot_addlist' then
5411 if Length(P
) > 1 then
5413 if Length(P
) = 2 then
5414 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5415 else if Length(P
) = 3 then
5416 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5418 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5421 else if cmd
= 'bot_removeall' then
5423 else if cmd
= 'chat' then
5425 if g_Game_IsNet
then
5427 if Length(P
) > 1 then
5429 for a
:= 1 to High(P
) do
5430 chstr
:= chstr
+ P
[a
] + ' ';
5432 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5434 if Length(chstr
) < 1 then
5436 g_Console_Add('chat <text>');
5440 chstr
:= b_Text_Format(chstr
);
5441 if g_Game_IsClient
then
5442 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5444 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5447 g_Console_Add('chat <text>');
5449 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5451 else if cmd
= 'teamchat' then
5453 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5455 if Length(P
) > 1 then
5457 for a
:= 1 to High(P
) do
5458 chstr
:= chstr
+ P
[a
] + ' ';
5460 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5462 if Length(chstr
) < 1 then
5464 g_Console_Add('teamchat <text>');
5468 chstr
:= b_Text_Format(chstr
);
5469 if g_Game_IsClient
then
5470 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5472 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5473 gPlayer1Settings
.Team
);
5476 g_Console_Add('teamchat <text>');
5478 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5480 else if (cmd
= 'an') or (cmd
= 'announce') then
5482 if g_Game_IsNet
then
5484 if Length(P
) > 1 then
5486 for a
:= 1 to High(P
) do
5487 chstr
:= chstr
+ P
[a
] + ' ';
5489 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5491 if Length(chstr
) < 1 then
5493 g_Console_Add('announce <text>');
5497 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5498 if g_Game_IsClient
then
5499 MC_SEND_RCONCommand(chstr
)
5501 g_Console_Process(chstr
, True);
5504 g_Console_Add('announce <text>');
5506 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5508 else if cmd
= 'game' then
5510 if gGameSettings
.GameType
<> GT_NONE
then
5512 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5515 if Length(P
) = 1 then
5517 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5520 // game not started yet, load fist map from some wad
5522 s
:= addWadExtension(P
[1]);
5523 found
:= e_FindResource(AllMapDirs
, s
);
5527 P
[1] := ExpandFileName(P
[1]);
5528 // if map not choosed then set first map
5529 if Length(P
) < 3 then
5532 P
[2] := g_Game_GetFirstMap(P
[1]);
5535 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5537 if g_Map_Exist(s
) then
5541 with gGameSettings
do
5543 Options
:= gsGameFlags
;
5544 GameMode
:= g_Game_TextToMode(gsGameMode
);
5545 if gSwitchGameMode
<> GM_NONE
then
5546 GameMode
:= gSwitchGameMode
;
5547 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5548 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5550 if Length(P
) >= 4 then
5551 b
:= StrToIntDef(P
[3], 1);
5552 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5553 ScoreLimit
, MaxLives
, Options
, b
);
5558 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5560 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5562 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5564 else if cmd
= 'host' then
5566 if gGameSettings
.GameType
<> GT_NONE
then
5568 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5571 if Length(P
) < 4 then
5573 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5576 if not StrToIp(P
[1], listen
) then
5578 prt
:= StrToIntDef(P
[2], 25666);
5580 s
:= addWadExtension(P
[3]);
5581 found
:= e_FindResource(AllMapDirs
, s
);
5585 // get first map in wad, if not specified
5586 if Length(P
) < 5 then
5589 P
[4] := g_Game_GetFirstMap(P
[1]);
5591 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5592 if g_Map_Exist(s
) then
5596 with gGameSettings
do
5598 Options
:= gsGameFlags
;
5599 GameMode
:= g_Game_TextToMode(gsGameMode
);
5600 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5601 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5602 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5604 if Length(P
) >= 6 then
5605 b
:= StrToIntDef(P
[5], 0);
5606 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5612 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5614 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5619 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5622 else if cmd
= 'map' then
5624 if Length(P
) = 1 then
5626 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5628 g_Console_Add(cmd
+ ' <MAP>');
5629 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5633 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5638 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5640 if Length(P
) < 3 then
5642 // first param is map or wad
5643 s
:= UpperCase(P
[1]);
5644 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5646 gExitByTrigger
:= False;
5649 // already in game, finish current map
5651 gExit
:= EXIT_ENDLEVELCUSTOM
;
5655 // intermission, so change map immediately
5662 found
:= e_FindResource(AllMapDirs
, s
);
5664 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5667 // no such map, found wad
5670 P
[1] := ExpandFileName(pw
);
5671 P
[2] := g_Game_GetFirstMap(P
[1]);
5672 s
:= P
[1] + ':\' + P
[2];
5673 if g_Map_Exist(s
) then
5675 gExitByTrigger
:= False;
5678 // already in game, finish current map
5680 gExit
:= EXIT_ENDLEVELCUSTOM
5684 // intermission, so change map immediately
5691 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5693 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5698 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5704 s
:= addWadExtension(P
[1]);
5705 found
:= e_FindResource(AllMapDirs
, s
);
5709 P
[2] := UpperCase(P
[2]);
5710 s
:= P
[1] + ':\' + P
[2];
5711 if g_Map_Exist(s
) then
5713 gExitByTrigger
:= False;
5717 gExit
:= EXIT_ENDLEVELCUSTOM
5726 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5731 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5737 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5741 else if cmd
= 'nextmap' then
5743 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5745 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5750 if Length(P
) = 1 then
5752 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5754 g_Console_Add(cmd
+ ' <MAP>');
5755 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5760 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5766 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5768 if Length(P
) < 3 then
5770 // first param is map or wad
5771 s
:= UpperCase(P
[1]);
5772 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5775 gExitByTrigger
:= False;
5781 // no such map, found wad
5782 pw
:= addWadExtension(P
[1]);
5783 found
:= e_FindResource(MapDirs
, pw
);
5785 found
:= e_FindResource(WadDirs
, pw
);
5787 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5790 // map not specified, select first map
5792 P
[2] := g_Game_GetFirstMap(P
[1]);
5793 s
:= P
[1] + ':\' + P
[2];
5794 if g_Map_Exist(s
) then
5796 gExitByTrigger
:= False;
5803 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5805 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5810 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5816 // specified two params wad + map
5817 pw
:= addWadExtension(P
[1]);
5818 found
:= e_FindResource(MapDirs
, pw
);
5820 found
:= e_FindResource(MapDirs
, pw
);
5824 P
[2] := UpperCase(P
[2]);
5825 s
:= P
[1] + ':\' + P
[2];
5826 if g_Map_Exist(s
) then
5828 gExitByTrigger
:= False;
5834 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5839 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5845 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5850 if gNextMap
= '' then
5851 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5853 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5857 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5861 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5865 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5867 gExitByTrigger
:= False;
5868 // next map not specified, try to find trigger EXIT
5869 if (gNextMap
= '') and (gTriggers
<> nil) then
5871 for a
:= 0 to High(gTriggers
) do
5873 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5875 gExitByTrigger
:= True;
5876 //gNextMap := gTriggers[a].Data.MapName;
5877 gNextMap
:= gTriggers
[a
].tgcMap
;
5882 if gNextMap
= '' then
5883 gNextMap
:= g_Game_GetNextMap();
5884 if not isWadPath(gNextMap
) then
5885 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5888 if g_Map_Exist(s
) then
5889 gExit
:= EXIT_ENDLEVELCUSTOM
5891 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5895 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5899 else if (cmd
= 'event') then
5901 if (Length(P
) <= 1) then
5903 for a
:= 0 to High(gEvents
) do
5904 if gEvents
[a
].Command
= '' then
5905 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5907 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5910 if (Length(P
) = 2) then
5912 for a
:= 0 to High(gEvents
) do
5913 if gEvents
[a
].Name
= P
[1] then
5914 if gEvents
[a
].Command
= '' then
5915 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5917 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5920 for a
:= 0 to High(gEvents
) do
5921 if gEvents
[a
].Name
= P
[1] then
5923 gEvents
[a
].Command
:= '';
5924 for b
:= 2 to High(P
) do
5925 if Pos(' ', P
[b
]) = 0 then
5926 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5928 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5929 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5933 else if cmd
= 'suicide' then
5937 if g_Game_IsClient
then
5938 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5941 if gPlayer1
<> nil then
5942 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5943 if gPlayer2
<> nil then
5944 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5948 else if cmd
= 'screenshot' then
5950 {$IFDEF ENABLE_RENDER}
5951 r_Render_RequestScreenShot
;
5954 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5956 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5958 gWeaponAction
[0, WP_PREV
] := True;
5960 gWeaponAction
[0, WP_NEXT
] := True;
5962 else if cmd
= 'weapon' then
5964 if Length(p
) = 2 then
5966 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5967 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5968 gSelectWeapon
[0, a
] := True
5971 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5972 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5974 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5975 b
:= ord(cmd
[2]) - ord('1');
5977 gWeaponAction
[b
, WP_PREV
] := True;
5979 gWeaponAction
[b
, WP_NEXT
] := True;
5981 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5983 if Length(p
) = 2 then
5985 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5986 b
:= ord(cmd
[2]) - ord('1');
5987 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5988 gSelectWeapon
[b
, a
] := True
5991 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
5993 b
:= ord(cmd
[2]) - ord('1');
5995 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
5997 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
5999 else if (cmd
= 'dropflag') then
6001 if g_Game_IsServer
then
6003 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
6004 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
6007 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6009 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
6011 b
:= ord(cmd
[2]) - ord('1');
6012 if g_Game_IsServer
then
6014 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
6015 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
6018 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6020 // Команды Своей игры:
6021 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6023 if cmd
= 'bot_addred' then
6025 if Length(P
) > 1 then
6026 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6028 g_Bot_Add(TEAM_RED
, 2);
6030 else if cmd
= 'bot_addblue' then
6032 if Length(P
) > 1 then
6033 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6035 g_Bot_Add(TEAM_BLUE
, 2);
6037 else if cmd
= 'spectate' then
6043 else if cmd
= 'say' then
6045 if g_Game_IsServer
and g_Game_IsNet
then
6047 if Length(P
) > 1 then
6050 for a
:= 1 to High(P
) do
6051 chstr
:= chstr
+ P
[a
] + ' ';
6053 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6055 if Length(chstr
) < 1 then
6057 g_Console_Add('say <text>');
6061 chstr
:= b_Text_Format(chstr
);
6062 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6064 else g_Console_Add('say <text>');
6066 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6068 else if cmd
= 'tell' then
6070 if g_Game_IsServer
and g_Game_IsNet
then
6072 if (Length(P
) > 2) and (P
[1] <> '') then
6075 for a
:= 2 to High(P
) do
6076 chstr
:= chstr
+ P
[a
] + ' ';
6078 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6080 if Length(chstr
) < 1 then
6082 g_Console_Add('tell <playername> <text>');
6086 pl
:= g_Net_Client_ByName(P
[1]);
6088 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6090 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6092 else g_Console_Add('tell <playername> <text>');
6094 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6096 else if cmd
= 'centerprint' then
6098 if (Length(P
) > 2) and (P
[1] <> '') then
6101 for a
:= 2 to High(P
) do
6102 chstr
:= chstr
+ P
[a
] + ' ';
6104 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6106 if Length(chstr
) < 1 then
6108 g_Console_Add('centerprint <timeout> <text>');
6112 a
:= StrToIntDef(P
[1], 100);
6113 chstr
:= b_Text_Format(chstr
);
6114 g_Game_Message(chstr
, a
);
6115 if g_Game_IsNet
and g_Game_IsServer
then
6116 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6118 else g_Console_Add('centerprint <timeout> <text>');
6120 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6122 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6124 // Дополнительное время:
6125 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6127 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6128 [gGameSettings
.TimeLimit
div 3600,
6129 (gGameSettings
.TimeLimit
div 60) mod 60,
6130 gGameSettings
.TimeLimit
mod 60]));
6131 if g_Game_IsNet
then MH_SEND_GameSettings
;
6133 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6135 if (Length(P
) <= 1) then
6136 g_Console_Add('rcon_password <password>')
6138 MC_SEND_RCONPassword(P
[1]);
6140 else if cmd
= 'rcon' then
6142 if g_Game_IsClient
then
6144 if Length(P
) > 1 then
6147 for a
:= 1 to High(P
) do
6148 chstr
:= chstr
+ P
[a
] + ' ';
6150 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6152 if Length(chstr
) < 1 then
6154 g_Console_Add('rcon <command>');
6158 MC_SEND_RCONCommand(chstr
);
6160 else g_Console_Add('rcon <command>');
6163 else if cmd
= 'ready' then
6165 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6166 gLMSRespawnTime
:= gTime
+ 100;
6168 else if (cmd
= 'callvote') and g_Game_IsNet
then
6170 if Length(P
) > 1 then
6173 for a
:= 1 to High(P
) do begin
6174 if a
> 1 then chstr
:= chstr
+ ' ';
6175 chstr
:= chstr
+ P
[a
];
6178 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6180 if Length(chstr
) < 1 then
6182 g_Console_Add('callvote <command>');
6186 if g_Game_IsClient
then
6187 MC_SEND_Vote(True, chstr
)
6189 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6190 g_Console_Process('vote', True);
6193 g_Console_Add('callvote <command>');
6195 else if (cmd
= 'vote') and g_Game_IsNet
then
6197 if g_Game_IsClient
then
6199 else if gVoteInProgress
then
6201 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6202 a
:= Floor((NetClientCount
+1)/2.0) + 1
6204 a
:= Floor(NetClientCount
/2.0) + 1;
6209 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6210 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6216 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6217 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6225 procedure SystemCommands(P
: SSArray
);
6229 cmd
:= LowerCase(P
[0]);
6236 {$IFDEF ENABLE_RENDER}
6242 if Length(p
) = 2 then
6244 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6246 gFrameTime
:= 1000 div gMaxFPS
6250 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6254 if Length(p
) = 2 then
6256 gAskLanguage
:= true;
6257 gLanguage
:= LANGUAGE_ENGLISH
;
6258 case LowerCase(p
[1]) of
6261 gAskLanguage
:= false;
6262 gLanguage
:= LANGUAGE_ENGLISH
;
6266 gAskLanguage
:= false;
6267 gLanguage
:= LANGUAGE_RUSSIAN
;
6271 gAskLanguage
:= true;
6272 gLanguage
:= LANGUAGE_ENGLISH
;
6275 g_Language_Set(gLanguage
);
6279 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6285 {$IFDEF ENABLE_MENU}
6286 procedure g_Game_InGameMenu(Show
: Boolean);
6288 if (g_ActiveWindow
= nil) and Show
then
6290 if gGameSettings
.GameType
= GT_SINGLE
then
6291 g_GUI_ShowWindow('GameSingleMenu')
6294 if g_Game_IsClient
then
6295 g_GUI_ShowWindow('GameClientMenu')
6297 if g_Game_IsNet
then
6298 g_GUI_ShowWindow('GameServerMenu')
6300 g_GUI_ShowWindow('GameCustomMenu');
6302 g_Sound_PlayEx('MENU_OPEN');
6304 // Пауза при меню только в одиночной игре:
6305 if (not g_Game_IsNet
) then
6309 if (g_ActiveWindow
<> nil) and (not Show
) then
6311 // Пауза при меню только в одиночной игре:
6312 if (not g_Game_IsNet
) then
6313 g_Game_Pause(False);
6318 procedure g_Game_Pause (Enable
: Boolean);
6322 if not gGameOn
then exit
;
6324 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6327 gPauseMain
:= Enable
;
6329 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6332 procedure g_Game_HolmesPause (Enable
: Boolean);
6336 if not gGameOn
then exit
;
6337 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6340 gPauseHolmes
:= Enable
;
6342 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6345 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6350 if gTriggers
<> nil then
6351 for i
:= 0 to High(gTriggers
) do
6352 with gTriggers
[i
] do
6353 if (TriggerType
= TRIGGER_SOUND
) and
6355 Sound
.IsPlaying() then
6357 Sound
.Pause(Enable
);
6361 if gPlayers
<> nil then
6362 for i
:= 0 to High(gPlayers
) do
6363 if gPlayers
[i
] <> nil then
6364 gPlayers
[i
].PauseSounds(Enable
);
6367 if gMusic
<> nil then
6368 gMusic
.Pause(Enable
);
6371 procedure g_Game_StopAllSounds(all
: Boolean);
6375 if gTriggers
<> nil then
6376 for i
:= 0 to High(gTriggers
) do
6377 with gTriggers
[i
] do
6378 if (TriggerType
= TRIGGER_SOUND
) and
6382 if gMusic
<> nil then
6389 procedure g_Game_UpdateTriggerSounds
;
6392 if gTriggers
<> nil then
6393 for i
:= 0 to High(gTriggers
) do
6394 with gTriggers
[i
] do
6395 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6396 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6399 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6402 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6407 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6412 if gSpectMode
<> SPECT_PLAYERS
then
6414 if gSpectPID1
= UID
then
6419 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6426 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6431 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6436 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6441 if gSpectMode
<> SPECT_PLAYERS
then
6443 Pl
:= g_Player_Get(gSpectPID1
);
6444 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6449 if gSpectViewTwo
then
6451 Pl
:= g_Player_Get(gSpectPID2
);
6452 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6460 procedure g_Game_Message (Msg
: string; Time
: Word);
6463 MessageTime
:= Time
;
6466 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6468 punct
: Array[0..13] of String =
6469 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6475 function IsPunctuation(S
: String): Boolean;
6480 if Length(S
) <> 1 then
6482 for i
:= Low(punct
) to High(punct
) do
6483 if S
= punct
[i
] then
6489 function FilterPunctuation(S
: String): String;
6493 for i
:= Low(punct
) to High(punct
) do
6494 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6500 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6502 // remove player name
6503 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6504 // for FullWord check
6505 Text := toLowerCase1251(' ' + Text + ' ');
6506 fpText
:= FilterPunctuation(Text);
6508 for i
:= 0 to Length(gChatSounds
) - 1 do
6511 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6513 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6514 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6516 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6522 gChatSounds
[i
].Sound
.Play();
6528 g_Sound_PlayEx('SOUND_GAME_RADIO');
6531 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6540 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6544 if goodsnd
[a
].IsPlaying() then
6547 goodsnd
[Random(4)].Play();
6550 procedure g_Game_Announce_KillCombo(Param
: Integer);
6557 UID
:= Param
and $FFFF;
6562 Pl
:= g_Player_Get(UID
);
6571 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6575 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6579 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6583 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6591 if not g_Game_IsWatchedPlayer(UID
) then
6594 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6598 if killsnd
[n
].IsPlaying() then
6603 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6611 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6615 if hahasnd
[a
].IsPlaying() then
6618 hahasnd
[Random(3)].Play();
6621 procedure g_Game_StartVote(Command
, Initiator
: string);
6625 if not gVotesEnabled
then Exit
;
6626 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6627 if gVoteInProgress
or gVotePassed
then
6629 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6630 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6633 gVoteInProgress
:= True;
6634 gVotePassed
:= False;
6635 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6638 gVoteCommand
:= Command
;
6640 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6641 Need
:= Floor((NetClientCount
+1)/2.0)+1
6643 Need
:= Floor(NetClientCount
/2.0)+1;
6644 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6645 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6648 procedure g_Game_CheckVote
;
6652 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6653 if not gVoteInProgress
then Exit
;
6655 if (gTime
>= gVoteTimer
) then
6657 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6658 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6660 Need
:= Floor(NetClientCount
/2.0) + 1;
6661 if gVoteCount
>= Need
then
6663 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6664 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6665 gVotePassed
:= True;
6666 gVoteCmdTimer
:= gTime
+ 5000;
6670 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6671 MH_SEND_VoteEvent(NET_VE_FAILED
);
6673 if NetClients
<> nil then
6674 for I
:= Low(NetClients
) to High(NetClients
) do
6675 if NetClients
[i
].Used
then
6676 NetClients
[i
].Voted
:= False;
6677 gVoteInProgress
:= False;
6683 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6684 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6686 Need
:= Floor(NetClientCount
/2.0) + 1;
6687 if gVoteCount
>= Need
then
6689 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6690 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6691 gVoteInProgress
:= False;
6692 gVotePassed
:= True;
6693 gVoteCmdTimer
:= gTime
+ 5000;
6696 if NetClients
<> nil then
6697 for I
:= Low(NetClients
) to High(NetClients
) do
6698 if NetClients
[i
].Used
then
6699 NetClients
[i
].Voted
:= False;
6704 procedure g_Game_LoadMapList(FileName
: string);
6712 if not FileExists(FileName
) then Exit
;
6714 AssignFile(ListFile
, FileName
);
6716 while not EOF(ListFile
) do
6718 ReadLn(ListFile
, s
);
6721 if s
= '' then Continue
;
6723 SetLength(MapList
, Length(MapList
)+1);
6724 MapList
[High(MapList
)] := s
;
6726 CloseFile(ListFile
);
6729 procedure g_Game_SetDebugMode();
6732 // Читы (даже в своей игре):
6736 procedure Parse_Params(var pars
: TParamStrValues
);
6743 while i
<= ParamCount
do
6746 if (Length(s
) > 1) and (s
[1] = '-') then
6748 if (Length(s
) > 2) and (s
[2] = '-') then
6749 begin // Одиночный параметр
6750 SetLength(pars
, Length(pars
) + 1);
6751 with pars
[High(pars
)] do
6753 Name
:= LowerCase(s
);
6758 if (i
< ParamCount
) then
6759 begin // Параметр со значением
6761 SetLength(pars
, Length(pars
) + 1);
6762 with pars
[High(pars
)] do
6764 Name
:= LowerCase(s
);
6765 Value
:= LowerCase(ParamStr(i
));
6774 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6779 for i
:= 0 to High(pars
) do
6780 if pars
[i
].Name
= aName
then
6782 Result
:= pars
[i
].Value
;
6787 procedure g_Game_Process_Params();
6789 pars
: TParamStrValues
;
6792 LimT
, LimS
: Integer;
6803 s
:= Find_Param_Value(pars
, '--debug');
6806 g_Game_SetDebugMode();
6807 s
:= Find_Param_Value(pars
, '--netdump');
6812 // Connect when game loads
6813 ip
:= Find_Param_Value(pars
, '-connect');
6817 s
:= Find_Param_Value(pars
, '-port');
6818 if (s
= '') or not TryStrToInt(s
, Port
) then
6821 s
:= Find_Param_Value(pars
, '-pw');
6823 g_Game_StartClient(ip
, Port
, s
);
6827 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6830 gDefaultMegawadStart
:= s
;
6833 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6834 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6836 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6839 // Start map when game loads:
6840 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6841 if isWadPath(map
) then
6844 s
:= Find_Param_Value(pars
, '-gm');
6845 GMode
:= g_Game_TextToMode(s
);
6846 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6847 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6850 s
:= Find_Param_Value(pars
, '-limt');
6851 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6857 s
:= Find_Param_Value(pars
, '-lims');
6858 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6864 s
:= Find_Param_Value(pars
, '-lives');
6865 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6871 s
:= Find_Param_Value(pars
, '-opt');
6875 Opt
:= StrToIntDef(s
, 0);
6878 s
:= Find_Param_Value(pars
, '--close');
6882 // Override map to test:
6883 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6886 if e_IsValidResourceName(s
) then
6887 e_FindResource(AllMapDirs
, s
);
6888 gTestMap
:= ExpandFileName(s
);
6891 // Delete test map after play:
6892 s
:= Find_Param_Value(pars
, '--testdelete');
6895 //gMapToDelete := MapsDir + map;
6896 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6900 // Delete temporary WAD after play:
6901 s
:= Find_Param_Value(pars
, '--tempdelete');
6902 if (s
<> '') and (gTestMap
<> '') then
6904 gMapToDelete
:= gTestMap
;
6905 gTempDelete
:= True;
6908 // Number of players:
6909 s
:= Find_Param_Value(pars
, '-pl');
6911 n
:= DEFAULT_PLAYERS
6913 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6916 s
:= Find_Param_Value(pars
, '-port');
6917 if (s
= '') or not TryStrToInt(s
, Port
) then
6918 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6920 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6923 // Execute script when game loads:
6924 s
:= Find_Param_Value(pars
, '-exec');
6927 // if not isWadPath(s) then
6928 // s := GameDir + '/' + s;
6933 if IOResult
<> 0 then
6935 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6936 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6940 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6941 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6946 if IOResult
<> 0 then
6948 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6949 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6953 if Pos('#', s
) <> 1 then // script comment
6954 g_Console_Process(s
, True);
6965 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6966 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6967 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6968 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6970 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6971 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6972 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6973 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6976 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6977 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6980 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6981 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6983 {$IFDEF ENABLE_HOLMES}
6984 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6987 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6989 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6990 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6992 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6993 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6995 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6996 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6997 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6998 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
6999 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7000 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7001 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7002 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7003 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');