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) then
2264 (* no local players -> automatically enable to spectator mode *)
2265 if gSpectMode
= SPECT_NONE
then gSpectMode
:= SPECT_STATS
;
2269 (* at least one local player -> automatically disable spectator mode *)
2270 gSpectMode
:= SPECT_NONE
;
2273 if IsActivePlayer(g_Player_Get(gSpectPID1
)) = false then
2274 gSpectPID1
:= GetActivePlayerID_Next();
2276 if IsActivePlayer(g_Player_Get(gSpectPID2
)) = false then
2277 gSpectPID2
:= GetActivePlayerID_Next();
2279 g_Game_SetupHearPoints
;
2281 // Обновляем все остальное:
2284 g_Triggers_Update();
2286 g_Monsters_Update();
2290 g_Player_UpdateAll();
2291 {$IFDEF ENABLE_GIBS}
2294 {$IFDEF ENABLE_CORPSES}
2297 {$IFDEF ENABLE_SHELLS}
2301 // server: send newly spawned monsters unconditionally
2302 if (gGameSettings
.GameType
= GT_SERVER
) then
2304 if (Length(gMonstersSpawned
) > 0) then
2306 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2307 SetLength(gMonstersSpawned
, 0);
2311 if (gSoundTriggerTime
> 8) then
2313 g_Game_UpdateTriggerSounds();
2314 gSoundTriggerTime
:= 0;
2318 Inc(gSoundTriggerTime
);
2321 if (NetMode
= NET_SERVER
) then
2323 Inc(NetTimeToUpdate
);
2324 Inc(NetTimeToReliable
);
2326 // send monster updates
2327 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2329 // send all monsters (periodic sync)
2330 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2332 for I
:= 0 to High(gPlayers
) do
2334 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2337 g_Mons_ForEach(sendMonsPos
);
2339 // update flags that aren't stationary
2340 if gGameSettings
.GameMode
= GM_CTF
then
2341 for I
:= FLAG_RED
to FLAG_BLUE
do
2342 if gFlags
[I
].NeedSend
then
2344 gFlags
[I
].NeedSend
:= False;
2348 // update items that aren't stationary
2349 g_Items_ForEachAlive(sendItemPos
);
2351 if reliableUpdate
then
2353 NetTimeToReliable
:= 0;
2354 NetTimeToUpdate
:= NetUpdateRate
;
2358 NetTimeToUpdate
:= 0;
2363 // send only mosters with some unexpected changes
2364 g_Mons_ForEach(sendMonsPosUnexpected
);
2367 // send unexpected platform changes
2368 g_Map_NetSendInterestingPanels();
2370 g_Net_Slist_ServerUpdate();
2372 if NetUseMaster then
2374 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2376 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2378 NetTimeToMaster := gTime + NetMasterRate;
2383 else if (NetMode
= NET_CLIENT
) then
2385 MC_SEND_PlayerPos();
2387 end; // if gameOn ...
2389 // Активно окно интерфейса - передаем клавиши ему:
2390 {$IFDEF ENABLE_MENU}
2391 if g_ActiveWindow
<> nil then
2393 w
:= e_GetFirstKeyPressed();
2395 if (w
<> IK_INVALID
) then
2397 Msg
.Msg
:= MESSAGE_DIKEY
;
2399 g_ActiveWindow
.OnMessage(Msg
);
2402 // Если оно от этого не закрылось, то обновляем:
2403 if g_ActiveWindow
<> nil then
2404 g_ActiveWindow
.Update();
2406 // Нужно сменить разрешение:
2407 if gResolutionChange
then
2409 {$IFDEF ENABLE_RENDER}
2410 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2413 gResolutionChange
:= False;
2414 g_ActiveWindow
:= nil;
2417 // Нужно сменить язык:
2418 if gLanguageChange
then
2420 //e_WriteLog('Read language file', MSG_NOTIFY);
2421 //g_Language_Load(DataDir + gLanguage + '.txt');
2422 g_Language_Set(gLanguage
);
2424 gLanguageChange
:= False;
2428 // Горячая клавиша для вызова меню выхода из игры (F10):
2429 if e_KeyPressed(IK_F10
) and
2431 (not gConsoleShow
) and
2432 (g_ActiveWindow
= nil) then
2438 Time
:= GetTickCount64() {div 1000};
2440 // Обработка отложенных событий:
2441 if gDelayedEvents
<> nil then
2442 for a
:= 0 to High(gDelayedEvents
) do
2443 if gDelayedEvents
[a
].Pending
and
2445 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2446 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2449 case gDelayedEvents
[a
].DEType
of
2451 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2454 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2458 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2459 if g_Game_IsNet
and g_Game_IsServer
then
2460 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2464 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2466 gDelayedEvents
[a
].Pending
:= False;
2469 // Каждую секунду обновляем счетчик обновлений:
2470 UPSCounter
:= UPSCounter
+ 1;
2471 if Time
- UPSTime
>= 1000 then
2480 g_Weapon_AddDynLights();
2481 g_Items_AddDynLights();
2485 procedure g_Game_LoadChatSounds(Resource
: string);
2488 FileName
, Snd
: string;
2490 len
, cnt
, tags
, i
, j
: Integer;
2493 FileName
:= g_ExtractWadName(Resource
);
2495 WAD
:= TWADFile
.Create();
2496 WAD
.ReadFile(FileName
);
2498 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2505 cfg
:= TConfig
.CreateMem(p
, len
);
2506 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2508 SetLength(gChatSounds
, cnt
);
2509 for i
:= 0 to Length(gChatSounds
) - 1 do
2511 gChatSounds
[i
].Sound
:= nil;
2512 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2513 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2514 if (Snd
= '') or (Tags
<= 0) then
2516 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2517 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2518 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2519 SetLength(gChatSounds
[i
].Tags
, tags
);
2520 for j
:= 0 to tags
- 1 do
2521 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2522 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2529 procedure g_Game_FreeChatSounds();
2533 for i
:= 0 to Length(gChatSounds
) - 1 do
2535 gChatSounds
[i
].Sound
.Free();
2536 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2538 SetLength(gChatSounds
, 0);
2542 procedure g_Game_LoadData();
2544 if DataLoaded
then Exit
;
2546 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2547 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
2549 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2550 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2551 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2552 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2553 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2554 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2555 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2556 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2557 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2558 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2559 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2560 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2561 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2562 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2563 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2564 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2565 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2566 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2567 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2568 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2569 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2570 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2571 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2572 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2573 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2574 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2575 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2576 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2577 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2578 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2579 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2580 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2582 goodsnd
[0] := TPlayableSound
.Create();
2583 goodsnd
[1] := TPlayableSound
.Create();
2584 goodsnd
[2] := TPlayableSound
.Create();
2585 goodsnd
[3] := TPlayableSound
.Create();
2587 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2588 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2589 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2590 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2592 killsnd
[0] := TPlayableSound
.Create();
2593 killsnd
[1] := TPlayableSound
.Create();
2594 killsnd
[2] := TPlayableSound
.Create();
2595 killsnd
[3] := TPlayableSound
.Create();
2597 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2598 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2599 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2600 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2602 hahasnd
[0] := TPlayableSound
.Create();
2603 hahasnd
[1] := TPlayableSound
.Create();
2604 hahasnd
[2] := TPlayableSound
.Create();
2606 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2607 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2608 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2610 sound_get_flag
[0] := TPlayableSound
.Create();
2611 sound_get_flag
[1] := TPlayableSound
.Create();
2612 sound_lost_flag
[0] := TPlayableSound
.Create();
2613 sound_lost_flag
[1] := TPlayableSound
.Create();
2614 sound_ret_flag
[0] := TPlayableSound
.Create();
2615 sound_ret_flag
[1] := TPlayableSound
.Create();
2616 sound_cap_flag
[0] := TPlayableSound
.Create();
2617 sound_cap_flag
[1] := TPlayableSound
.Create();
2619 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2620 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2621 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2622 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2623 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2624 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2625 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2626 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2628 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2632 g_Weapon_LoadData();
2634 g_Monsters_LoadData();
2639 procedure g_Game_Quit();
2641 g_Game_StopAllSounds(True);
2644 g_PlayerModel_FreeData();
2645 {$IFDEF ENABLE_MENU}
2646 // g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2649 if NetInitDone
then g_Net_Free
;
2651 // remove map after test
2652 if gMapToDelete
<> '' then
2653 g_Game_DeleteTestMap();
2657 {$IFDEF ENABLE_SYSTEM}
2662 procedure g_Game_FreeData();
2664 if not DataLoaded
then Exit
;
2667 g_Weapon_FreeData();
2668 g_Monsters_FreeData();
2670 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2672 g_Sound_Delete('SOUND_GAME_TELEPORT');
2673 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2674 g_Sound_Delete('SOUND_GAME_SECRET');
2675 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2676 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2677 g_Sound_Delete('SOUND_GAME_BULK1');
2678 g_Sound_Delete('SOUND_GAME_BULK2');
2679 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2680 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2681 g_Sound_Delete('SOUND_GAME_BURNING');
2682 g_Sound_Delete('SOUND_GAME_SWITCH1');
2683 g_Sound_Delete('SOUND_GAME_SWITCH0');
2690 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2691 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2692 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2693 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2700 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2701 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2702 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2703 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2709 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2710 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2711 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2713 sound_get_flag
[0].Free();
2714 sound_get_flag
[1].Free();
2715 sound_lost_flag
[0].Free();
2716 sound_lost_flag
[1].Free();
2717 sound_ret_flag
[0].Free();
2718 sound_ret_flag
[1].Free();
2719 sound_cap_flag
[0].Free();
2720 sound_cap_flag
[1].Free();
2722 g_Sound_Delete('SOUND_CTF_GET1');
2723 g_Sound_Delete('SOUND_CTF_GET2');
2724 g_Sound_Delete('SOUND_CTF_LOST1');
2725 g_Sound_Delete('SOUND_CTF_LOST2');
2726 g_Sound_Delete('SOUND_CTF_RETURN1');
2727 g_Sound_Delete('SOUND_CTF_RETURN2');
2728 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2729 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2731 g_Game_FreeChatSounds();
2733 DataLoaded
:= False;
2736 procedure g_FatalError(Text: String);
2738 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2739 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2741 gExit
:= EXIT_SIMPLE
;
2742 if gGameOn
then EndGame
;
2745 procedure g_SimpleError(Text: String);
2747 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2748 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2751 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2753 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2754 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2757 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2760 if gPlayer1
= nil then
2762 if g_Game_IsClient
then
2764 if NetPlrUID1
> -1 then
2765 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2769 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2770 Team
:= gPlayer1Settings
.Team
;
2772 // Создание первого игрока:
2773 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2774 gPlayer1Settings
.Color
,
2776 if gPlayer1
= nil then
2777 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2780 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2781 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2782 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2783 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2784 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2785 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2786 if g_Game_IsServer
and g_Game_IsNet
then
2787 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2788 gPlayer1
.Respawn(False, True);
2789 g_Net_Slist_ServerPlayerComes();
2794 if gPlayer2
= nil then
2796 if g_Game_IsClient
then
2798 if NetPlrUID2
> -1 then
2799 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2803 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2804 Team
:= gPlayer2Settings
.Team
;
2806 // Создание второго игрока:
2807 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2808 gPlayer2Settings
.Color
,
2810 if gPlayer2
= nil then
2811 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2814 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2815 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2816 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2817 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2818 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2819 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2820 if g_Game_IsServer
and g_Game_IsNet
then
2821 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2822 gPlayer2
.Respawn(False, True);
2823 g_Net_Slist_ServerPlayerComes();
2830 procedure g_Game_RemovePlayer();
2834 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2835 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2840 if g_Game_IsServer
then
2843 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2844 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2845 g_Player_Remove(Pl
.UID
);
2846 g_Net_Slist_ServerPlayerLeaves();
2850 gSpectLatchPID2
:= Pl
.UID
;
2858 if g_Game_IsServer
then
2861 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2862 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2863 g_Player_Remove(Pl
.UID
);
2864 g_Net_Slist_ServerPlayerLeaves();
2867 gSpectLatchPID1
:= Pl
.UID
;
2869 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2873 g_Net_Slist_ServerPlayerLeaves();
2876 procedure g_Game_Spectate();
2878 g_Game_RemovePlayer();
2879 if gPlayer1
<> nil then
2880 g_Game_RemovePlayer();
2883 procedure g_Game_SpectateCenterView();
2885 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2886 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2889 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2896 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2898 g_Game_ClearLoading();
2901 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2904 gGameSettings
.GameType
:= GT_SINGLE
;
2905 gGameSettings
.MaxLives
:= 0;
2906 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2907 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2908 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2909 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2910 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2911 gSwitchGameMode
:= GM_SINGLE
;
2913 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2914 gLMSRespawnTime
:= 0;
2915 gSpectLatchPID1
:= 0;
2916 gSpectLatchPID2
:= 0;
2918 g_Game_ExecuteEvent('ongamestart');
2920 // Создание первого игрока:
2921 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2922 gPlayer1Settings
.Color
,
2923 gPlayer1Settings
.Team
, False));
2924 if gPlayer1
= nil then
2926 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2930 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2931 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2932 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2933 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2934 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2937 // Создание второго игрока, если есть:
2940 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2941 gPlayer2Settings
.Color
,
2942 gPlayer2Settings
.Team
, False));
2943 if gPlayer2
= nil then
2945 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2949 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2950 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2951 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2952 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2953 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2957 // Загрузка и запуск карты:
2958 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2960 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2961 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2965 // Настройки игроков и ботов:
2969 for i
:= nPl
+1 to nPlayers
do
2970 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2973 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2974 TimeLimit
, ScoreLimit
: Word;
2976 Options
: LongWord; nPlayers
: Byte);
2982 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2984 g_Game_ClearLoading();
2987 gGameSettings
.GameType
:= GT_CUSTOM
;
2988 gGameSettings
.GameMode
:= GameMode
;
2989 gSwitchGameMode
:= GameMode
;
2990 gGameSettings
.TimeLimit
:= TimeLimit
;
2991 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2992 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2993 gGameSettings
.Options
:= Options
;
2995 gCoopTotalMonstersKilled
:= 0;
2996 gCoopTotalSecretsFound
:= 0;
2997 gCoopTotalMonsters
:= 0;
2998 gCoopTotalSecrets
:= 0;
3002 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3003 gLMSRespawnTime
:= 0;
3004 gSpectLatchPID1
:= 0;
3005 gSpectLatchPID2
:= 0;
3007 g_Game_ExecuteEvent('ongamestart');
3009 // Режим наблюдателя:
3010 if nPlayers
= 0 then
3017 if nPlayers
>= 1 then
3019 // Создание первого игрока:
3020 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3021 gPlayer1Settings
.Color
,
3022 gPlayer1Settings
.Team
, False));
3023 if gPlayer1
= nil then
3025 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3029 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3030 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3031 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3032 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3033 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3037 if nPlayers
>= 2 then
3039 // Создание второго игрока:
3040 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3041 gPlayer2Settings
.Color
,
3042 gPlayer2Settings
.Team
, False));
3043 if gPlayer2
= nil then
3045 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3049 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3050 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3051 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3052 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3053 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3057 // Загрузка и запуск карты:
3058 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3060 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3064 // Нет точек появления:
3065 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3066 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3067 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3068 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3069 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3071 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3075 // Настройки игроков и ботов:
3079 for i
:= nPl
+1 to nPlayers
do
3080 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3083 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3084 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3085 Options
: LongWord; nPlayers
: Byte;
3086 IPAddr
: LongWord; Port
: Word);
3089 g_Net_Slist_ServerClosed();
3091 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3093 g_Game_ClearLoading();
3098 gGameSettings
.GameType
:= GT_SERVER
;
3099 gGameSettings
.GameMode
:= GameMode
;
3100 gSwitchGameMode
:= GameMode
;
3101 gGameSettings
.TimeLimit
:= TimeLimit
;
3102 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3103 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3104 gGameSettings
.Options
:= Options
;
3106 gCoopTotalMonstersKilled
:= 0;
3107 gCoopTotalSecretsFound
:= 0;
3108 gCoopTotalMonsters
:= 0;
3109 gCoopTotalSecrets
:= 0;
3113 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3114 gLMSRespawnTime
:= 0;
3115 gSpectLatchPID1
:= 0;
3116 gSpectLatchPID2
:= 0;
3118 g_Game_ExecuteEvent('ongamestart');
3120 // Режим наблюдателя:
3121 if nPlayers
= 0 then
3127 if nPlayers
>= 1 then
3129 // Создание первого игрока:
3130 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3131 gPlayer1Settings
.Color
,
3132 gPlayer1Settings
.Team
, False));
3133 if gPlayer1
= nil then
3135 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3139 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3140 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3141 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3142 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3143 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3146 if nPlayers
>= 2 then
3148 // Создание второго игрока:
3149 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3150 gPlayer2Settings
.Color
,
3151 gPlayer2Settings
.Team
, False));
3152 if gPlayer2
= nil then
3154 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3158 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3159 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3160 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3161 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3162 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3165 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3166 if NetForwardPorts
then
3167 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3170 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3172 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3176 g_Net_Slist_Set(NetMasterList
);
3178 g_Net_Slist_ServerStarted();
3180 // Загрузка и запуск карты:
3181 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3183 g_Net_Slist_ServerClosed();
3184 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3188 // Нет точек появления:
3189 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3190 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3191 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3192 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3193 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3195 g_Net_Slist_ServerClosed();
3196 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3200 // Настройки игроков и ботов:
3203 g_Net_Slist_ServerMapStarted();
3204 NetState
:= NET_STATE_GAME
;
3207 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3222 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3223 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3225 g_Game_ClearLoading();
3230 gGameSettings
.GameType
:= GT_CLIENT
;
3232 gCoopTotalMonstersKilled
:= 0;
3233 gCoopTotalSecretsFound
:= 0;
3234 gCoopTotalMonsters
:= 0;
3235 gCoopTotalSecrets
:= 0;
3239 g_Game_ExecuteEvent('ongamestart');
3241 NetState
:= NET_STATE_AUTH
;
3243 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3245 // create (or update) map/resource databases
3246 g_Res_CreateDatabases(true);
3248 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3249 gLMSRespawnTime
:= 0;
3250 gSpectLatchPID1
:= 0;
3251 gSpectLatchPID2
:= 0;
3254 if not g_Net_Connect(Addr
, Port
) then
3256 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3257 NetState
:= NET_STATE_NONE
;
3261 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3263 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3268 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3269 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3270 // thank you, enet. let's ignore failures altogether then.
3271 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3273 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3275 Ptr
:= NetEvent
.packet
^.data
;
3276 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3278 enet_packet_destroy(NetEvent
.packet
);
3282 InMsg
.ReadLongWord(); // skip size
3283 MID
:= InMsg
.ReadByte();
3285 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3287 NetMyID
:= InMsg
.ReadByte();
3288 NetPlrUID1
:= InMsg
.ReadWord();
3290 WadName
:= InMsg
.ReadString();
3291 Map
:= InMsg
.ReadString();
3293 gWADHash
:= InMsg
.ReadMD5();
3295 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3296 gSwitchGameMode
:= gGameSettings
.GameMode
;
3297 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3298 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3299 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3300 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3301 T
:= InMsg
.ReadLongWord();
3303 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3304 //if newResPath = '' then
3306 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3307 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3308 if newResPath
= '' then
3310 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3311 enet_packet_destroy(NetEvent
.packet
);
3312 NetState
:= NET_STATE_NONE
;
3315 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3317 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3320 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3321 gPlayer1Settings
.Color
,
3322 gPlayer1Settings
.Team
, False));
3324 if gPlayer1
= nil then
3326 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3328 enet_packet_destroy(NetEvent
.packet
);
3329 NetState
:= NET_STATE_NONE
;
3333 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3334 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3335 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3336 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3337 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3338 gPlayer1
.UID
:= NetPlrUID1
;
3339 gPlayer1
.Reset(True);
3341 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3343 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3345 enet_packet_destroy(NetEvent
.packet
);
3346 NetState
:= NET_STATE_NONE
;
3354 enet_packet_destroy(NetEvent
.packet
);
3358 enet_packet_destroy(NetEvent
.packet
);
3362 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3365 if (NetEvent
.data
<= NET_DISC_MAX
) then
3366 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3367 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3374 ProcessLoading(True);
3375 if g_Net_UserRequestExit() then
3384 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3385 NetState
:= NET_STATE_NONE
;
3390 NetState
:= NET_STATE_GAME
;
3391 MC_SEND_FullStateRequest
;
3392 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3396 lastAsMegaWad
: Boolean = false;
3398 procedure g_Game_ChangeMap(const MapPath
: String);
3402 g_Game_ClearLoading();
3404 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3405 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3406 if gExitByTrigger
then
3409 gExitByTrigger
:= False;
3411 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3412 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3415 procedure g_Game_Restart();
3419 if g_Game_IsClient
then
3421 map
:= g_ExtractFileName(gMapInfo
.Map
);
3422 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3426 g_Game_ClearLoading();
3427 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3430 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3432 NewWAD
, ResName
: String;
3436 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3438 {$IFDEF ENABLE_GIBS}
3441 {$IFDEF ENABLE_SHELLS}
3444 {$IFDEF ENABLE_CORPSES}
3445 g_Corpses_RemoveAll
;
3448 if (not g_Game_IsClient
) and
3449 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3450 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3452 if gSwitchGameMode
= GM_CTF
then
3453 gGameSettings
.MaxLives
:= 0;
3454 gGameSettings
.GameMode
:= gSwitchGameMode
;
3457 gSwitchGameMode
:= gGameSettings
.GameMode
;
3459 g_Player_ResetTeams();
3461 lastAsMegaWad
:= asMegawad
;
3462 if isWadPath(Map
) then
3464 NewWAD
:= g_ExtractWadName(Map
);
3465 ResName
:= g_ExtractFileName(Map
);
3466 if g_Game_IsServer
then
3468 nws
:= findDiskWad(NewWAD
);
3469 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3472 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3473 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3477 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3478 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3480 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3481 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3483 if (length(nws
) = 0) then
3485 ResName
:= ''; // failed
3490 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3491 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3492 g_Game_LoadWAD(NewWAD
);
3497 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3498 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3503 NewWAD
:= gGameSettings
.WAD
;
3509 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3511 if (ResName
<> '') and (NewWAD
<> '') then
3513 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3514 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3518 {$IFDEF ENABLE_RENDER}
3519 r_Render_LoadTextures
;
3522 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3524 gState
:= STATE_NONE
;
3525 {$IFDEF ENABLE_MENU}
3526 g_ActiveWindow
:= nil;
3531 wNeedTimeReset
:= True;
3533 if gGameSettings
.GameMode
= GM_CTF
then
3535 g_Map_ResetFlag(FLAG_RED
);
3536 g_Map_ResetFlag(FLAG_BLUE
);
3537 // CTF, а флагов нет:
3538 if not g_Map_HaveFlagPoints() then
3539 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3544 gState
:= STATE_MENU
;
3549 gPauseMain
:= false;
3550 gPauseHolmes
:= false;
3551 NetTimeToUpdate
:= 1;
3552 NetTimeToReliable
:= 0;
3553 NetTimeToMaster
:= NetMasterRate
;
3554 gSpectLatchPID1
:= 0;
3555 gSpectLatchPID2
:= 0;
3556 gMissionFailed
:= False;
3559 gCoopMonstersKilled
:= 0;
3560 gCoopSecretsFound
:= 0;
3562 gVoteInProgress
:= False;
3563 gVotePassed
:= False;
3569 if not gGameOn
then Exit
;
3571 g_Game_SpectateCenterView();
3573 if g_Game_IsServer
then
3575 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3577 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3578 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3579 gLMSSoftSpawn
:= True;
3580 if g_Game_IsNet
then
3581 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3585 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3586 gLMSRespawnTime
:= 0;
3590 if NetMode
= NET_SERVER
then
3592 // reset full state flags
3593 if NetClients
<> nil then
3594 for I
:= 0 to High(NetClients
) do
3595 NetClients
[I
].FullUpdateSent
:= False;
3597 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3600 g_Net_Slist_ServerMapStarted();
3602 if NetClients
<> nil then
3603 for I
:= 0 to High(NetClients
) do
3604 if NetClients
[I
].Used
then
3606 NetClients
[I
].Voted
:= False;
3607 if NetClients
[I
].RequestedFullUpdate
then
3609 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3610 NetClients
[I
].RequestedFullUpdate
:= False;
3614 g_Net_UnbanNonPermHosts();
3619 gCoopTotalMonstersKilled
:= 0;
3620 gCoopTotalSecretsFound
:= 0;
3621 gCoopTotalMonsters
:= 0;
3622 gCoopTotalSecrets
:= 0;
3626 g_Game_ExecuteEvent('onmapstart');
3629 procedure SetFirstLevel
;
3633 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3634 if MapList
= nil then
3637 SortSArray(MapList
);
3638 gNextMap
:= MapList
[Low(MapList
)];
3643 procedure g_Game_ExitLevel(const Map
: AnsiString);
3647 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3648 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3649 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3650 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3652 // Вышли в выход в Одиночной игре:
3653 if gGameSettings
.GameType
= GT_SINGLE
then
3654 gExit
:= EXIT_ENDLEVELSINGLE
3655 else // Вышли в выход в Своей игре
3657 gExit
:= EXIT_ENDLEVELCUSTOM
;
3658 if gGameSettings
.GameMode
= GM_COOP
then
3659 g_Player_RememberAll
;
3661 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3664 if gGameSettings
.GameMode
= GM_COOP
then
3667 gStatsPressed
:= True;
3668 gNextMap
:= 'MAP01';
3670 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3673 if g_Game_IsNet
then
3675 MH_SEND_GameStats();
3676 MH_SEND_CoopStats();
3682 procedure g_Game_RestartLevel();
3686 if gGameSettings
.GameMode
= GM_SINGLE
then
3691 gExit
:= EXIT_ENDLEVELCUSTOM
;
3692 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3696 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3698 gWAD
{, xwad}: String;
3701 if not g_Game_IsClient
then Exit
;
3702 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3704 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3709 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3713 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3716 g_Game_LoadWAD(NewWAD
);
3720 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3721 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3724 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3725 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3729 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3733 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3734 g_Game_LoadWAD(NewWAD);
3738 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3740 i
, n
, nb
, nr
: Integer;
3742 if not g_Game_IsServer
then Exit
;
3743 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3744 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3745 gLMSRespawnTime
:= 0;
3748 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3750 gMissionFailed
:= True;
3751 g_Game_RestartLevel
;
3755 n
:= 0; nb
:= 0; nr
:= 0;
3756 for i
:= Low(gPlayers
) to High(gPlayers
) do
3757 if (gPlayers
[i
] <> nil) and
3758 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3759 (gPlayers
[i
] is TBot
)) then
3762 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3763 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3766 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3768 // wait a second until the fuckers finally decide to join
3769 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3770 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3771 gLMSSoftSpawn
:= NoMapRestart
;
3772 if g_Game_IsNet
then
3773 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3777 {$IFDEF ENABLE_GIBS}
3780 {$IFDEF ENABLE_SHELLS}
3783 {$IFDEF ENABLE_CORPSES}
3784 g_Corpses_RemoveAll
;
3787 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3788 if g_Game_IsNet
then
3789 MH_SEND_GameEvent(NET_EV_LMS_START
);
3791 for i
:= Low(gPlayers
) to High(gPlayers
) do
3793 if gPlayers
[i
] = nil then continue
;
3794 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3795 // don't touch normal spectators
3796 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3798 gPlayers
[i
].FNoRespawn
:= True;
3799 gPlayers
[i
].Lives
:= 0;
3800 if g_Game_IsNet
then
3801 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3804 gPlayers
[i
].FNoRespawn
:= False;
3805 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3806 gPlayers
[i
].Respawn(False, True);
3807 if gGameSettings
.GameMode
= GM_COOP
then
3809 gPlayers
[i
].Frags
:= 0;
3810 gPlayers
[i
].RecallState
;
3812 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3813 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3814 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3815 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3818 g_Items_RestartRound();
3820 gLMSSoftSpawn
:= False;
3823 function g_Game_GetFirstMap(WAD
: String): String;
3827 MapList
:= g_Map_GetMapsList(WAD
);
3828 if MapList
= nil then
3831 SortSArray(MapList
);
3832 Result
:= MapList
[Low(MapList
)];
3834 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3840 function g_Game_GetNextMap(): String;
3847 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3848 if MapList
= nil then
3851 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3853 SortSArray(MapList
);
3855 for I
:= Low(MapList
) to High(MapList
) do
3856 if Map
= MapList
[I
] then
3862 if MapIndex
<> -255 then
3864 if MapIndex
= High(MapList
) then
3865 Result
:= MapList
[Low(MapList
)]
3867 Result
:= MapList
[MapIndex
+ 1];
3869 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3875 procedure g_Game_NextLevel();
3877 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3878 gExit
:= EXIT_ENDLEVELCUSTOM
3881 gExit
:= EXIT_ENDLEVELSINGLE
;
3885 if gNextMap
<> '' then Exit
;
3886 gNextMap
:= g_Game_GetNextMap();
3889 function g_Game_IsTestMap(): Boolean;
3891 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3894 procedure g_Game_DeleteTestMap();
3897 //MapName: AnsiString;
3905 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3906 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3907 if (a
= 0) then exit
;
3909 // Выделяем имя wad-файла и имя карты
3910 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3911 Delete(gMapToDelete
, 1, a
+5);
3912 gMapToDelete
:= UpperCase(gMapToDelete
);
3914 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3917 // Имя карты не стандартное тестовое:
3918 if MapName <> TEST_MAP_NAME then
3921 if not gTempDelete then
3923 time := g_GetFileTime(WadName);
3924 WAD := TWADFile.Create();
3927 if not WAD.ReadFile(WadName) then
3928 begin // Нет такого WAD-файла
3933 // Составляем список карт и ищем нужную:
3935 MapList := WAD.GetResourcesList('');
3937 if MapList <> nil then
3938 for a := 0 to High(MapList) do
3939 if MapList[a] = MapName then
3941 // Удаляем и сохраняем:
3942 WAD.RemoveResource('', MapName);
3943 WAD.SaveTo(WadName);
3948 g_SetFileTime(WadName, time);
3951 if gTempDelete
then DeleteFile(WadName
);
3954 procedure GameCVars(P
: SSArray
);
3957 stat
: TPlayerStatArray
;
3960 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3964 if Length(P
) > 1 then
3969 gsGameFlags
:= gsGameFlags
or Flag
3971 gsGameFlags
:= gsGameFlags
and (not Flag
);
3973 if g_Game_IsServer
then
3976 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3978 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3979 if g_Game_IsNet
then MH_SEND_GameSettings
;
3983 if LongBool(gsGameFlags
and Flag
) then
3984 g_Console_Add(_lc
[OnMsg
])
3986 g_Console_Add(_lc
[OffMsg
]);
3988 if OnMapChange
and g_Game_IsServer
then
3989 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3994 cmd
:= LowerCase(P
[0]);
3996 if cmd
= 'g_gamemode' then
3998 if (Length(P
) > 1) then
4000 a
:= g_Game_TextToMode(P
[1]);
4001 if a
= GM_SINGLE
then a
:= GM_COOP
;
4002 gsGameMode
:= g_Game_ModeToText(a
);
4003 if g_Game_IsServer
then
4005 gSwitchGameMode
:= a
;
4006 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4007 (gState
= STATE_INTERSINGLE
) then
4008 gSwitchGameMode
:= GM_SINGLE
;
4010 gGameSettings
.GameMode
:= gSwitchGameMode
;
4014 if gSwitchGameMode
= gGameSettings
.GameMode
then
4015 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4016 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4018 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4019 [g_Game_ModeToText(gGameSettings
.GameMode
),
4020 g_Game_ModeToText(gSwitchGameMode
)]));
4022 else if cmd
= 'g_friendlyfire' then
4024 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4026 else if cmd
= 'g_friendly_absorb_damage' then
4028 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
4030 else if cmd
= 'g_friendly_hit_trace' then
4032 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
4034 else if cmd
= 'g_friendly_hit_projectile' then
4036 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
4038 else if cmd
= 'g_weaponstay' then
4040 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
4042 else if cmd
= 'g_allow_exit' then
4044 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
4046 else if cmd
= 'g_allow_monsters' then
4048 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
4050 else if cmd
= 'g_allow_dropflag' then
4052 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
4054 else if cmd
= 'g_throw_flag' then
4056 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
4058 else if cmd
= 'g_bot_vsplayers' then
4060 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4062 else if cmd
= 'g_bot_vsmonsters' then
4064 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4066 else if cmd
= 'g_dm_keys' then
4068 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4070 else if cmd
= 'g_gameflags' then
4072 if Length(P
) > 1 then
4074 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4075 if g_Game_IsServer
then
4077 gGameSettings
.Options
:= gsGameFlags
;
4078 if g_Game_IsNet
then MH_SEND_GameSettings
;
4082 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4084 else if cmd
= 'g_warmup_time' then
4086 if Length(P
) > 1 then
4088 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4089 if g_Game_IsServer
then
4091 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4092 // extend warmup if it's already going
4093 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4095 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4096 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4098 if g_Game_IsNet
then MH_SEND_GameSettings
;
4102 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4103 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4105 else if cmd
= 'g_spawn_invul' then
4107 if Length(P
) > 1 then
4109 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4110 if g_Game_IsServer
then
4112 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4113 if g_Game_IsNet
then MH_SEND_GameSettings
;
4117 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4119 else if cmd
= 'g_item_respawn_time' then
4121 if Length(P
) > 1 then
4123 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4124 if g_Game_IsServer
then
4126 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4127 if g_Game_IsNet
then MH_SEND_GameSettings
;
4131 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4132 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4134 else if cmd
= 'sv_intertime' then
4136 if (Length(P
) > 1) then
4137 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4139 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4141 else if cmd
= 'g_max_particles' then
4143 if Length(p
) = 2 then
4146 a
:= Max(0, StrToIntDef(p
[1], 0));
4150 else if Length(p
) = 1 then
4153 e_LogWritefln('%s', [g_GFX_GetMax()])
4155 e_LogWritefln('%s', [0])
4160 e_LogWritefln('usage: %s <n>', [cmd
])
4163 else if cmd
= 'g_max_shells' then
4165 if Length(p
) = 2 then
4167 {$IFDEF ENABLE_SHELLS}
4168 a
:= Max(0, StrToIntDef(p
[1], 0));
4172 else if Length(p
) = 1 then
4174 {$IFDEF ENABLE_SHELLS}
4175 e_LogWritefln('%s', [g_Shells_GetMax()])
4177 e_LogWritefln('%s', [0])
4182 e_LogWritefln('usage: %s <n>', [cmd
])
4185 else if cmd
= 'g_max_gibs' then
4187 if Length(p
) = 2 then
4189 {$IFDEF ENABLE_GIBS}
4190 a
:= Max(0, StrToIntDef(p
[1], 0));
4194 else if Length(p
) = 1 then
4196 {$IFDEF ENABLE_GIBS}
4197 e_LogWritefln('%s', [g_Gibs_GetMax()])
4199 e_LogWritefln('%s', [0])
4204 e_LogWritefln('usage: %s <n>', [cmd
])
4207 else if cmd
= 'g_max_corpses' then
4209 if Length(p
) = 2 then
4211 {$IFDEF ENABLE_CORPSES}
4212 a
:= Max(0, StrToIntDef(p
[1], 0));
4216 else if Length(p
) = 1 then
4218 {$IFDEF ENABLE_CORPSES}
4219 e_LogWritefln('%s', [g_Corpses_GetMax()])
4221 e_LogWritefln('%s', [0])
4226 e_LogWritefln('usage: %s <n>', [cmd
])
4229 else if cmd
= 'g_force_model' then
4231 if Length(p
) = 2 then
4233 a
:= StrToIntDef(p
[1], 0);
4234 g_Force_Model_Set(a
);
4235 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4237 for a
:= Low(gPlayers
) to High(gPlayers
) do
4239 if (gPlayers
[a
] <> nil) then
4241 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4243 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4245 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4249 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4251 for a
:= Low(gPlayers
) to High(gPlayers
) do
4253 if (gPlayers
[a
] <> nil) then
4255 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4257 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4259 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4265 else if cmd
= 'g_force_model_name' then
4267 if (Length(P
) > 1) then
4269 cmd
:= b_Text_Unformat(P
[1]);
4270 g_Forced_Model_SetName(cmd
);
4271 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4273 for a
:= Low(gPlayers
) to High(gPlayers
) do
4275 if (gPlayers
[a
] <> nil) then
4277 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4279 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4281 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4287 else if cmd
= 'g_scorelimit' then
4289 if Length(P
) > 1 then
4291 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4293 if g_Game_IsServer
then
4296 if gGameSettings
.GameMode
= GM_DM
then
4298 stat
:= g_Player_GetStats();
4300 for a
:= 0 to High(stat
) do
4301 if stat
[a
].Frags
> b
then
4305 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4307 // if someone has a higher score, set it to that instead
4308 gsScoreLimit
:= max(gsScoreLimit
, b
);
4309 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4311 if g_Game_IsNet
then MH_SEND_GameSettings
;
4315 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4317 else if cmd
= 'g_timelimit' then
4319 if Length(P
) > 1 then
4321 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4322 if g_Game_IsServer
then
4324 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4325 if g_Game_IsNet
then MH_SEND_GameSettings
;
4328 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4329 [gsTimeLimit
div 3600,
4330 (gsTimeLimit
div 60) mod 60,
4331 gsTimeLimit
mod 60]));
4333 else if cmd
= 'g_max_bots' then
4335 if Length(P
) > 1 then
4336 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4337 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4339 else if cmd
= 'g_maxlives' then
4341 if Length(P
) > 1 then
4343 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4344 if g_Game_IsServer
then
4346 gGameSettings
.MaxLives
:= gsMaxLives
;
4347 if g_Game_IsNet
then MH_SEND_GameSettings
;
4351 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4355 procedure PlayerSettingsCVars(P
: SSArray
);
4360 function ParseTeam(s
: string): Byte;
4364 'red', '1': result
:= TEAM_RED
;
4365 'blue', '2': result
:= TEAM_BLUE
;
4366 else result
:= TEAM_NONE
;
4370 cmd
:= LowerCase(P
[0]);
4374 if (Length(P
) > 1) then
4376 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4377 if g_Game_IsClient
then
4378 MC_SEND_PlayerSettings
4379 else if gGameOn
and (gPlayer1
<> nil) then
4381 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4382 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4388 if (Length(P
) > 1) then
4390 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4391 if g_Game_IsClient
then
4392 MC_SEND_PlayerSettings
4393 else if gGameOn
and (gPlayer2
<> nil) then
4395 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4396 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4402 if Length(P
) > 3 then
4404 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4405 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4406 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4407 if g_Game_IsClient
then
4408 MC_SEND_PlayerSettings
4409 else if gGameOn
and (gPlayer1
<> nil) then
4411 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4412 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4418 if Length(P
) > 3 then
4420 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4421 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4422 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4423 if g_Game_IsClient
then
4424 MC_SEND_PlayerSettings
4425 else if gGameOn
and (gPlayer2
<> nil) then
4427 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4428 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4434 if (Length(P
) > 1) then
4436 gPlayer1Settings
.Model
:= P
[1];
4437 if g_Game_IsClient
then
4438 MC_SEND_PlayerSettings
4439 else if gGameOn
and (gPlayer1
<> nil) then
4441 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4442 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4443 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4449 if (Length(P
) > 1) then
4451 gPlayer2Settings
.Model
:= P
[1];
4452 if g_Game_IsClient
then
4453 MC_SEND_PlayerSettings
4454 else if gGameOn
and (gPlayer2
<> nil) then
4456 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4457 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4458 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4464 // TODO: switch teams if in game or store this separately
4465 if (Length(P
) > 1) then
4467 team
:= ParseTeam(P
[1]);
4468 if team
= TEAM_NONE
then
4469 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4470 else if not gGameOn
and not g_Game_IsNet
then
4471 gPlayer1Settings
.Team
:= team
4473 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4478 // TODO: switch teams if in game or store this separately
4479 if (Length(P
) > 1) then
4481 team
:= ParseTeam(P
[1]);
4482 if team
= TEAM_NONE
then
4483 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4484 else if not gGameOn
and not g_Game_IsNet
then
4485 gPlayer2Settings
.Team
:= team
4487 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4492 if (Length(P
) = 2) then
4493 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4497 if (Length(P
) = 2) then
4498 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4502 if (Length(P
) = 2) then
4503 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4507 if (Length(P
) = 2) then
4508 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4512 if (Length(P
) = 2) then
4513 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4517 if (Length(P
) = 2) then
4518 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4520 'p1_priority_kastet':
4522 if (Length(P
) = 2) then
4523 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4525 'p2_priority_kastet':
4527 if (Length(P
) = 2) then
4528 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4532 if (Length(P
) = 2) then
4533 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4537 if (Length(P
) = 2) then
4538 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4540 'p1_priority_pistol':
4542 if (Length(P
) = 2) then
4543 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4545 'p2_priority_pistol':
4547 if (Length(P
) = 2) then
4548 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4550 'p1_priority_shotgun1':
4552 if (Length(P
) = 2) then
4553 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4555 'p2_priority_shotgun1':
4557 if (Length(P
) = 2) then
4558 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4560 'p1_priority_shotgun2':
4562 if (Length(P
) = 2) then
4563 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4565 'p2_priority_shotgun2':
4567 if (Length(P
) = 2) then
4568 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4570 'p1_priority_chaingun':
4572 if (Length(P
) = 2) then
4573 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4575 'p2_priority_chaingun':
4577 if (Length(P
) = 2) then
4578 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4580 'p1_priority_rocketlauncher':
4582 if (Length(P
) = 2) then
4583 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4585 'p2_priority_rocketlauncher':
4587 if (Length(P
) = 2) then
4588 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4590 'p1_priority_plasma':
4592 if (Length(P
) = 2) then
4593 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4595 'p2_priority_plasma':
4597 if (Length(P
) = 2) then
4598 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4602 if (Length(P
) = 2) then
4603 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4607 if (Length(P
) = 2) then
4608 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4610 'p1_priority_super':
4612 if (Length(P
) = 2) then
4613 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4615 'p2_priority_super':
4617 if (Length(P
) = 2) then
4618 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4620 'p1_priority_flamethrower':
4622 if (Length(P
) = 2) then
4623 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4625 'p2_priority_flamethrower':
4627 if (Length(P
) = 2) then
4628 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4630 'p1_priority_berserk':
4632 if (Length(P
) = 2) then
4633 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4635 'p2_priority_berserk':
4637 if (Length(P
) = 2) then
4638 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4643 procedure PrintHeapStats();
4647 hs
:= GetFPCHeapStatus();
4648 e_LogWriteLn ('v===== heap status =====v');
4649 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4650 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4651 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4652 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4653 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4654 e_LogWriteLn ('^=======================^');
4657 procedure DebugCommands(P
: SSArray
);
4664 // Команды отладочного режима:
4665 if {gDebugMode}conIsCheatsEnabled
then
4667 cmd
:= LowerCase(P
[0]);
4668 if cmd
= 'd_window' then
4670 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4671 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4673 else if cmd
= 'd_winmsg' then
4675 if (Length(P
) > 1) and
4676 ((P
[1] = '1') or (P
[1] = '0')) then
4677 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4679 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4681 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4683 if (Length(P
) > 1) and
4684 ((P
[1] = '1') or (P
[1] = '0')) then
4685 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4687 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4689 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4691 if Length(P
) > 1 then
4693 '0': g_debug_BotAIOff
:= 0;
4694 '1': g_debug_BotAIOff
:= 1;
4695 '2': g_debug_BotAIOff
:= 2;
4696 '3': g_debug_BotAIOff
:= 3;
4699 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4701 else if cmd
= 'd_monster' then
4703 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4704 if Length(P
) < 2 then
4706 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4707 g_Console_Add('ID | Name');
4708 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4709 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4710 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4713 a
:= StrToIntDef(P
[1], 0);
4714 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4715 a
:= g_Mons_TypeIdByName(P
[1]);
4717 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4718 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4721 with gPlayer1
.Obj
do
4723 mon
:= g_Monsters_Create(a
,
4724 X
+ Rect
.X
+ (Rect
.Width
div 2),
4725 Y
+ Rect
.Y
+ Rect
.Height
,
4726 gPlayer1
.Direction
, True);
4728 if (Length(P
) > 2) and (mon
<> nil) then
4730 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4731 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4732 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4733 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4734 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4735 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4736 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4737 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4738 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4743 else if (cmd
= 'd_player') then
4745 if (Length(P
) > 1) and
4746 ((P
[1] = '1') or (P
[1] = '0')) then
4747 g_debug_Player
:= (P
[1][1] = '1');
4749 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4751 else if (cmd
= 'd_mem') then
4757 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4761 procedure GameCheats(P
: SSArray
);
4767 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4769 g_Console_Add('not available');
4775 g_Console_Add('where is the player?!');
4778 cmd
:= LowerCase(P
[0]);
4782 plr
.GodMode
:= not plr
.GodMode
;
4783 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4786 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4787 if cmd
= 'give' then
4789 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4790 for f
:= 1 to High(P
) do
4792 cmd
:= LowerCase(P
[f
]);
4793 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4794 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4795 if cmd
= 'exit' then
4797 if gTriggers
<> nil then
4799 for a
:= 0 to High(gTriggers
) do
4801 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4803 g_Console_Add('player left the map');
4804 gExitByTrigger
:= True;
4805 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4806 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4814 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4815 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4816 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4817 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4818 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4820 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4821 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4823 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4824 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;
4826 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4827 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4829 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4830 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4832 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4833 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4835 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4836 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4837 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4839 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4840 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4841 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4842 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;
4843 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4844 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4846 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;
4847 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;
4848 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;
4849 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;
4850 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;
4851 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;
4853 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4854 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;
4856 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;
4857 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;
4859 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4861 if cmd
= 'ammo' then
4863 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4864 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4865 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4866 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4867 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4868 g_Console_Add('player got some ammo');
4872 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4873 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4875 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4876 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4878 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4879 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4881 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4882 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4884 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4886 if cmd
= 'weapons' then
4888 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4889 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4890 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4891 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4892 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4893 plr
.GiveItem(ITEM_WEAPON_BFG
);
4894 g_Console_Add('player got weapons');
4898 if cmd
= 'keys' then
4900 plr
.GiveItem(ITEM_KEY_RED
);
4901 plr
.GiveItem(ITEM_KEY_GREEN
);
4902 plr
.GiveItem(ITEM_KEY_BLUE
);
4903 g_Console_Add('player got all keys');
4907 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4912 if cmd
= 'open' then
4914 g_Console_Add('player activated sesame');
4915 g_Triggers_OpenAll();
4922 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4926 if cmd
= 'noclip' then
4929 g_Console_Add('wall hardeness adjusted');
4933 if cmd
= 'notarget' then
4935 plr
.NoTarget
:= not plr
.NoTarget
;
4936 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4940 if cmd
= 'noreload' then
4942 plr
.NoReload
:= not plr
.NoReload
;
4943 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4947 if cmd
= 'speedy' then
4949 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4950 g_Console_Add('speed adjusted');
4954 if cmd
= 'jumpy' then
4956 VEL_JUMP
:= 30-VEL_JUMP
;
4957 g_Console_Add('jump height adjusted');
4961 if cmd
= 'automap' then
4963 gShowMap
:= not gShowMap
;
4964 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4968 if cmd
= 'aimline' then
4970 gAimLine
:= not gAimLine
;
4971 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4976 procedure GameCommands(P
: SSArray
);
4982 pl
: pTNetClient
= nil;
4990 cmd
:= LowerCase(P
[0]);
4992 if cmd
= 'pause' then
4994 {$IFDEF ENABLE_MENU}
4995 if (g_ActiveWindow
= nil) then
4996 g_Game_Pause(not gPauseMain
);
4998 g_Game_Pause(not gPauseMain
);
5001 else if cmd
= 'endgame' then
5002 gExit
:= EXIT_SIMPLE
5003 else if cmd
= 'restart' then
5005 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5007 if g_Game_IsClient
then
5009 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5014 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5016 else if cmd
= 'kick' then
5018 if g_Game_IsServer
then
5020 if Length(P
) < 2 then
5022 g_Console_Add('kick <name>');
5027 g_Console_Add('kick <name>');
5031 if g_Game_IsNet
then
5032 pl
:= g_Net_Client_ByName(P
[1]);
5035 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5036 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5037 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5038 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5039 g_Net_Slist_ServerPlayerLeaves();
5040 end else if gPlayers
<> nil then
5041 for a
:= Low(gPlayers
) to High(gPlayers
) do
5042 if gPlayers
[a
] <> nil then
5043 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5045 // Не отключать основных игроков в сингле
5046 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5048 gPlayers
[a
].Lives
:= 0;
5049 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5050 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5051 g_Player_Remove(gPlayers
[a
].UID
);
5052 g_Net_Slist_ServerPlayerLeaves();
5053 // Если не перемешать, при добавлении новых ботов появятся старые
5057 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5059 else if cmd
= 'kick_id' then
5061 if g_Game_IsServer
and g_Game_IsNet
then
5063 if Length(P
) < 2 then
5065 g_Console_Add('kick_id <client ID>');
5070 g_Console_Add('kick_id <client ID>');
5074 a
:= StrToIntDef(P
[1], 0);
5075 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5077 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5079 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5080 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
5081 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5082 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5083 g_Net_Slist_ServerPlayerLeaves();
5087 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5089 else if cmd
= 'kick_pid' then
5091 if g_Game_IsServer
and g_Game_IsNet
then
5093 if Length(P
) < 2 then
5095 g_Console_Add('kick_pid <player ID>');
5100 g_Console_Add('kick_pid <player ID>');
5104 a
:= StrToIntDef(P
[1], 0);
5105 pl
:= g_Net_Client_ByPlayer(a
);
5106 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5108 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5109 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5110 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5111 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5112 g_Net_Slist_ServerPlayerLeaves();
5115 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5117 else if cmd
= 'ban' then
5119 if g_Game_IsServer
and g_Game_IsNet
then
5121 if Length(P
) < 2 then
5123 g_Console_Add('ban <name>');
5128 g_Console_Add('ban <name>');
5132 pl
:= g_Net_Client_ByName(P
[1]);
5135 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5136 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5137 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5138 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5139 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5140 g_Net_Slist_ServerPlayerLeaves();
5142 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5144 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5146 else if cmd
= 'ban_id' then
5148 if g_Game_IsServer
and g_Game_IsNet
then
5150 if Length(P
) < 2 then
5152 g_Console_Add('ban_id <client ID>');
5157 g_Console_Add('ban_id <client ID>');
5161 a
:= StrToIntDef(P
[1], 0);
5162 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5163 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5165 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5166 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5167 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5168 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5169 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5170 g_Net_Slist_ServerPlayerLeaves();
5173 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5175 else if cmd
= 'ban_pid' then
5177 if g_Game_IsServer
and g_Game_IsNet
then
5179 if Length(P
) < 2 then
5181 g_Console_Add('ban_pid <player ID>');
5186 g_Console_Add('ban_pid <player ID>');
5190 a
:= StrToIntDef(P
[1], 0);
5191 pl
:= g_Net_Client_ByPlayer(a
);
5192 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5194 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5195 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5196 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5197 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5198 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5199 g_Net_Slist_ServerPlayerLeaves();
5202 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5204 else if cmd
= 'permban' then
5206 if g_Game_IsServer
and g_Game_IsNet
then
5208 if Length(P
) < 2 then
5210 g_Console_Add('permban <name>');
5215 g_Console_Add('permban <name>');
5219 pl
:= g_Net_Client_ByName(P
[1]);
5222 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5223 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5224 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5225 g_Net_SaveBanList();
5226 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5227 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5228 g_Net_Slist_ServerPlayerLeaves();
5230 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5232 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5234 else if cmd
= 'permban_id' then
5236 if g_Game_IsServer
and g_Game_IsNet
then
5238 if Length(P
) < 2 then
5240 g_Console_Add('permban_id <client ID>');
5245 g_Console_Add('permban_id <client ID>');
5249 a
:= StrToIntDef(P
[1], 0);
5250 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5251 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5253 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5254 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5255 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5256 g_Net_SaveBanList();
5257 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5258 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5259 g_Net_Slist_ServerPlayerLeaves();
5262 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5264 else if cmd
= 'permban_pid' then
5266 if g_Game_IsServer
and g_Game_IsNet
then
5268 if Length(P
) < 2 then
5270 g_Console_Add('permban_pid <player ID>');
5275 g_Console_Add('permban_pid <player ID>');
5279 a
:= StrToIntDef(P
[1], 0);
5280 pl
:= g_Net_Client_ByPlayer(a
);
5281 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5283 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5284 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5285 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5286 g_Net_SaveBanList();
5287 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5288 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5289 g_Net_Slist_ServerPlayerLeaves();
5292 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5294 else if cmd
= 'permban_ip' then
5296 if g_Game_IsServer
and g_Game_IsNet
then
5298 if Length(P
) < 2 then
5300 g_Console_Add('permban_ip <IP address>');
5305 g_Console_Add('permban_ip <IP address>');
5309 g_Net_BanHost(P
[1]);
5310 g_Net_SaveBanList();
5311 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5313 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5315 else if cmd
= 'unban' then
5317 if g_Game_IsServer
and g_Game_IsNet
then
5319 if Length(P
) < 2 then
5321 g_Console_Add('unban <IP Address>');
5326 g_Console_Add('unban <IP Address>');
5330 if g_Net_UnbanHost(P
[1]) then
5332 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5333 g_Net_SaveBanList();
5335 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5337 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5339 else if cmd
= 'clientlist' then
5341 if g_Game_IsServer
and g_Game_IsNet
then
5344 if NetClients
<> nil then
5345 for a
:= Low(NetClients
) to High(NetClients
) do
5346 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5348 plr
:= g_Player_Get(NetClients
[a
].Player
);
5349 if plr
= nil then continue
;
5351 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5352 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5355 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5357 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5359 else if cmd
= 'connect' then
5361 if (NetMode
= NET_NONE
) then
5363 if Length(P
) < 2 then
5365 g_Console_Add('connect <IP> [port] [password]');
5370 g_Console_Add('connect <IP> [port] [password]');
5374 if Length(P
) > 2 then
5375 prt
:= StrToIntDef(P
[2], 25666)
5379 if Length(P
) > 3 then
5384 g_Game_StartClient(P
[1], prt
, pw
);
5387 else if cmd
= 'disconnect' then
5389 if (NetMode
= NET_CLIENT
) then
5392 else if cmd
= 'reconnect' then
5394 if (NetMode
= NET_SERVER
) then
5397 if (NetMode
= NET_CLIENT
) then
5400 gExit
:= EXIT_SIMPLE
;
5404 //TODO: Use last successful password to reconnect, instead of ''
5405 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5407 else if (cmd
= 'addbot') or
5408 (cmd
= 'bot_add') then
5410 if Length(P
) > 2 then
5411 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5412 else if Length(P
) > 1 then
5413 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5415 g_Bot_Add(TEAM_NONE
, 2);
5417 else if cmd
= 'bot_addlist' then
5419 if Length(P
) > 1 then
5421 if Length(P
) = 2 then
5422 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5423 else if Length(P
) = 3 then
5424 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5426 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5429 else if cmd
= 'bot_removeall' then
5431 else if cmd
= 'chat' then
5433 if g_Game_IsNet
then
5435 if Length(P
) > 1 then
5437 for a
:= 1 to High(P
) do
5438 chstr
:= chstr
+ P
[a
] + ' ';
5440 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5442 if Length(chstr
) < 1 then
5444 g_Console_Add('chat <text>');
5448 chstr
:= b_Text_Format(chstr
);
5449 if g_Game_IsClient
then
5450 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5452 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5455 g_Console_Add('chat <text>');
5457 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5459 else if cmd
= 'teamchat' then
5461 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5463 if Length(P
) > 1 then
5465 for a
:= 1 to High(P
) do
5466 chstr
:= chstr
+ P
[a
] + ' ';
5468 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5470 if Length(chstr
) < 1 then
5472 g_Console_Add('teamchat <text>');
5476 chstr
:= b_Text_Format(chstr
);
5477 if g_Game_IsClient
then
5478 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5480 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5481 gPlayer1Settings
.Team
);
5484 g_Console_Add('teamchat <text>');
5486 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5488 else if (cmd
= 'an') or (cmd
= 'announce') then
5490 if g_Game_IsNet
then
5492 if Length(P
) > 1 then
5494 for a
:= 1 to High(P
) do
5495 chstr
:= chstr
+ P
[a
] + ' ';
5497 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5499 if Length(chstr
) < 1 then
5501 g_Console_Add('announce <text>');
5505 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5506 if g_Game_IsClient
then
5507 MC_SEND_RCONCommand(chstr
)
5509 g_Console_Process(chstr
, True);
5512 g_Console_Add('announce <text>');
5514 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5516 else if cmd
= 'game' then
5518 if gGameSettings
.GameType
<> GT_NONE
then
5520 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5523 if Length(P
) = 1 then
5525 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5528 // game not started yet, load fist map from some wad
5530 s
:= addWadExtension(P
[1]);
5531 found
:= e_FindResource(AllMapDirs
, s
);
5535 P
[1] := ExpandFileName(P
[1]);
5536 // if map not choosed then set first map
5537 if Length(P
) < 3 then
5540 P
[2] := g_Game_GetFirstMap(P
[1]);
5543 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5545 if g_Map_Exist(s
) then
5549 with gGameSettings
do
5551 Options
:= gsGameFlags
;
5552 GameMode
:= g_Game_TextToMode(gsGameMode
);
5553 if gSwitchGameMode
<> GM_NONE
then
5554 GameMode
:= gSwitchGameMode
;
5555 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5556 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5558 if Length(P
) >= 4 then
5559 b
:= StrToIntDef(P
[3], 1);
5560 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5561 ScoreLimit
, MaxLives
, Options
, b
);
5566 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5568 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5570 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5572 else if cmd
= 'host' then
5574 if gGameSettings
.GameType
<> GT_NONE
then
5576 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5579 if Length(P
) < 4 then
5581 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5584 if not StrToIp(P
[1], listen
) then
5586 prt
:= StrToIntDef(P
[2], 25666);
5588 s
:= addWadExtension(P
[3]);
5589 found
:= e_FindResource(AllMapDirs
, s
);
5593 // get first map in wad, if not specified
5594 if Length(P
) < 5 then
5597 P
[4] := g_Game_GetFirstMap(P
[1]);
5599 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5600 if g_Map_Exist(s
) then
5604 with gGameSettings
do
5606 Options
:= gsGameFlags
;
5607 GameMode
:= g_Game_TextToMode(gsGameMode
);
5608 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5609 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5610 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5612 if Length(P
) >= 6 then
5613 b
:= StrToIntDef(P
[5], 0);
5614 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5620 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5622 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5627 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5630 else if cmd
= 'map' then
5632 if Length(P
) = 1 then
5634 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5636 g_Console_Add(cmd
+ ' <MAP>');
5637 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5641 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5646 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5648 if Length(P
) < 3 then
5650 // first param is map or wad
5651 s
:= UpperCase(P
[1]);
5652 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5654 gExitByTrigger
:= False;
5657 // already in game, finish current map
5659 gExit
:= EXIT_ENDLEVELCUSTOM
;
5663 // intermission, so change map immediately
5670 found
:= e_FindResource(AllMapDirs
, s
);
5672 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5675 // no such map, found wad
5678 P
[1] := ExpandFileName(pw
);
5679 P
[2] := g_Game_GetFirstMap(P
[1]);
5680 s
:= P
[1] + ':\' + P
[2];
5681 if g_Map_Exist(s
) then
5683 gExitByTrigger
:= False;
5686 // already in game, finish current map
5688 gExit
:= EXIT_ENDLEVELCUSTOM
5692 // intermission, so change map immediately
5699 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5701 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5706 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5712 s
:= addWadExtension(P
[1]);
5713 found
:= e_FindResource(AllMapDirs
, s
);
5717 P
[2] := UpperCase(P
[2]);
5718 s
:= P
[1] + ':\' + P
[2];
5719 if g_Map_Exist(s
) then
5721 gExitByTrigger
:= False;
5725 gExit
:= EXIT_ENDLEVELCUSTOM
5734 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5739 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5745 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5749 else if cmd
= 'nextmap' then
5751 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5753 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5758 if Length(P
) = 1 then
5760 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5762 g_Console_Add(cmd
+ ' <MAP>');
5763 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5768 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5774 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5776 if Length(P
) < 3 then
5778 // first param is map or wad
5779 s
:= UpperCase(P
[1]);
5780 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5783 gExitByTrigger
:= False;
5789 // no such map, found wad
5790 pw
:= addWadExtension(P
[1]);
5791 found
:= e_FindResource(MapDirs
, pw
);
5793 found
:= e_FindResource(WadDirs
, pw
);
5795 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5798 // map not specified, select first map
5800 P
[2] := g_Game_GetFirstMap(P
[1]);
5801 s
:= P
[1] + ':\' + P
[2];
5802 if g_Map_Exist(s
) then
5804 gExitByTrigger
:= False;
5811 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5813 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5818 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5824 // specified two params wad + map
5825 pw
:= addWadExtension(P
[1]);
5826 found
:= e_FindResource(MapDirs
, pw
);
5828 found
:= e_FindResource(MapDirs
, pw
);
5832 P
[2] := UpperCase(P
[2]);
5833 s
:= P
[1] + ':\' + P
[2];
5834 if g_Map_Exist(s
) then
5836 gExitByTrigger
:= False;
5842 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5847 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5853 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5858 if gNextMap
= '' then
5859 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5861 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5865 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5869 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5873 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5875 gExitByTrigger
:= False;
5876 // next map not specified, try to find trigger EXIT
5877 if (gNextMap
= '') and (gTriggers
<> nil) then
5879 for a
:= 0 to High(gTriggers
) do
5881 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5883 gExitByTrigger
:= True;
5884 //gNextMap := gTriggers[a].Data.MapName;
5885 gNextMap
:= gTriggers
[a
].tgcMap
;
5890 if gNextMap
= '' then
5891 gNextMap
:= g_Game_GetNextMap();
5892 if not isWadPath(gNextMap
) then
5893 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5896 if g_Map_Exist(s
) then
5897 gExit
:= EXIT_ENDLEVELCUSTOM
5899 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5903 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5907 else if (cmd
= 'event') then
5909 if (Length(P
) <= 1) then
5911 for a
:= 0 to High(gEvents
) do
5912 if gEvents
[a
].Command
= '' then
5913 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5915 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5918 if (Length(P
) = 2) then
5920 for a
:= 0 to High(gEvents
) do
5921 if gEvents
[a
].Name
= P
[1] then
5922 if gEvents
[a
].Command
= '' then
5923 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5925 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5928 for a
:= 0 to High(gEvents
) do
5929 if gEvents
[a
].Name
= P
[1] then
5931 gEvents
[a
].Command
:= '';
5932 for b
:= 2 to High(P
) do
5933 if Pos(' ', P
[b
]) = 0 then
5934 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5936 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5937 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5941 else if cmd
= 'suicide' then
5945 if g_Game_IsClient
then
5946 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5949 if gPlayer1
<> nil then
5950 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5951 if gPlayer2
<> nil then
5952 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5956 else if cmd
= 'screenshot' then
5958 {$IFDEF ENABLE_RENDER}
5959 r_Render_RequestScreenShot
;
5962 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5964 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5966 gWeaponAction
[0, WP_PREV
] := True;
5968 gWeaponAction
[0, WP_NEXT
] := True;
5970 else if cmd
= 'weapon' then
5972 if Length(p
) = 2 then
5974 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5975 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5976 gSelectWeapon
[0, a
] := True
5979 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5980 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5982 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5983 b
:= ord(cmd
[2]) - ord('1');
5985 gWeaponAction
[b
, WP_PREV
] := True;
5987 gWeaponAction
[b
, WP_NEXT
] := True;
5989 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5991 if Length(p
) = 2 then
5993 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5994 b
:= ord(cmd
[2]) - ord('1');
5995 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5996 gSelectWeapon
[b
, a
] := True
5999 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
6001 b
:= ord(cmd
[2]) - ord('1');
6003 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
6005 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
6007 else if (cmd
= 'dropflag') then
6009 if g_Game_IsServer
then
6011 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
6012 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
6015 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6017 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
6019 b
:= ord(cmd
[2]) - ord('1');
6020 if g_Game_IsServer
then
6022 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
6023 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
6026 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6028 // Команды Своей игры:
6029 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6031 if cmd
= 'bot_addred' then
6033 if Length(P
) > 1 then
6034 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6036 g_Bot_Add(TEAM_RED
, 2);
6038 else if cmd
= 'bot_addblue' then
6040 if Length(P
) > 1 then
6041 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6043 g_Bot_Add(TEAM_BLUE
, 2);
6045 else if cmd
= 'spectate' then
6051 else if cmd
= 'say' then
6053 if g_Game_IsServer
and g_Game_IsNet
then
6055 if Length(P
) > 1 then
6058 for a
:= 1 to High(P
) do
6059 chstr
:= chstr
+ P
[a
] + ' ';
6061 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6063 if Length(chstr
) < 1 then
6065 g_Console_Add('say <text>');
6069 chstr
:= b_Text_Format(chstr
);
6070 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6072 else g_Console_Add('say <text>');
6074 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6076 else if cmd
= 'tell' then
6078 if g_Game_IsServer
and g_Game_IsNet
then
6080 if (Length(P
) > 2) and (P
[1] <> '') then
6083 for a
:= 2 to High(P
) do
6084 chstr
:= chstr
+ P
[a
] + ' ';
6086 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6088 if Length(chstr
) < 1 then
6090 g_Console_Add('tell <playername> <text>');
6094 pl
:= g_Net_Client_ByName(P
[1]);
6096 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6098 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6100 else g_Console_Add('tell <playername> <text>');
6102 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6104 else if cmd
= 'centerprint' then
6106 if (Length(P
) > 2) and (P
[1] <> '') then
6109 for a
:= 2 to High(P
) do
6110 chstr
:= chstr
+ P
[a
] + ' ';
6112 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6114 if Length(chstr
) < 1 then
6116 g_Console_Add('centerprint <timeout> <text>');
6120 a
:= StrToIntDef(P
[1], 100);
6121 chstr
:= b_Text_Format(chstr
);
6122 g_Game_Message(chstr
, a
);
6123 if g_Game_IsNet
and g_Game_IsServer
then
6124 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6126 else g_Console_Add('centerprint <timeout> <text>');
6128 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6130 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6132 // Дополнительное время:
6133 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6135 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6136 [gGameSettings
.TimeLimit
div 3600,
6137 (gGameSettings
.TimeLimit
div 60) mod 60,
6138 gGameSettings
.TimeLimit
mod 60]));
6139 if g_Game_IsNet
then MH_SEND_GameSettings
;
6141 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6143 if (Length(P
) <= 1) then
6144 g_Console_Add('rcon_password <password>')
6146 MC_SEND_RCONPassword(P
[1]);
6148 else if cmd
= 'rcon' then
6150 if g_Game_IsClient
then
6152 if Length(P
) > 1 then
6155 for a
:= 1 to High(P
) do
6156 chstr
:= chstr
+ P
[a
] + ' ';
6158 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6160 if Length(chstr
) < 1 then
6162 g_Console_Add('rcon <command>');
6166 MC_SEND_RCONCommand(chstr
);
6168 else g_Console_Add('rcon <command>');
6171 else if cmd
= 'ready' then
6173 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6174 gLMSRespawnTime
:= gTime
+ 100;
6176 else if (cmd
= 'callvote') and g_Game_IsNet
then
6178 if Length(P
) > 1 then
6181 for a
:= 1 to High(P
) do begin
6182 if a
> 1 then chstr
:= chstr
+ ' ';
6183 chstr
:= chstr
+ P
[a
];
6186 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6188 if Length(chstr
) < 1 then
6190 g_Console_Add('callvote <command>');
6194 if g_Game_IsClient
then
6195 MC_SEND_Vote(True, chstr
)
6197 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6198 g_Console_Process('vote', True);
6201 g_Console_Add('callvote <command>');
6203 else if (cmd
= 'vote') and g_Game_IsNet
then
6205 if g_Game_IsClient
then
6207 else if gVoteInProgress
then
6209 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6210 a
:= Floor((NetClientCount
+1)/2.0) + 1
6212 a
:= Floor(NetClientCount
/2.0) + 1;
6217 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6218 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6224 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6225 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6233 procedure SystemCommands(P
: SSArray
);
6237 cmd
:= LowerCase(P
[0]);
6244 {$IFDEF ENABLE_RENDER}
6250 if Length(p
) = 2 then
6252 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6254 gFrameTime
:= 1000 div gMaxFPS
6258 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6262 if Length(p
) = 2 then
6264 gAskLanguage
:= true;
6265 gLanguage
:= LANGUAGE_ENGLISH
;
6266 case LowerCase(p
[1]) of
6269 gAskLanguage
:= false;
6270 gLanguage
:= LANGUAGE_ENGLISH
;
6274 gAskLanguage
:= false;
6275 gLanguage
:= LANGUAGE_RUSSIAN
;
6279 gAskLanguage
:= true;
6280 gLanguage
:= LANGUAGE_ENGLISH
;
6283 g_Language_Set(gLanguage
);
6287 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6293 {$IFDEF ENABLE_MENU}
6294 procedure g_Game_InGameMenu(Show
: Boolean);
6296 if (g_ActiveWindow
= nil) and Show
then
6298 if gGameSettings
.GameType
= GT_SINGLE
then
6299 g_GUI_ShowWindow('GameSingleMenu')
6302 if g_Game_IsClient
then
6303 g_GUI_ShowWindow('GameClientMenu')
6305 if g_Game_IsNet
then
6306 g_GUI_ShowWindow('GameServerMenu')
6308 g_GUI_ShowWindow('GameCustomMenu');
6310 g_Sound_PlayEx('MENU_OPEN');
6312 // Пауза при меню только в одиночной игре:
6313 if (not g_Game_IsNet
) then
6317 if (g_ActiveWindow
<> nil) and (not Show
) then
6319 // Пауза при меню только в одиночной игре:
6320 if (not g_Game_IsNet
) then
6321 g_Game_Pause(False);
6326 procedure g_Game_Pause (Enable
: Boolean);
6330 if not gGameOn
then exit
;
6332 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6335 gPauseMain
:= Enable
;
6337 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6340 procedure g_Game_HolmesPause (Enable
: Boolean);
6344 if not gGameOn
then exit
;
6345 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6348 gPauseHolmes
:= Enable
;
6350 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6353 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6358 if gTriggers
<> nil then
6359 for i
:= 0 to High(gTriggers
) do
6360 with gTriggers
[i
] do
6361 if (TriggerType
= TRIGGER_SOUND
) and
6363 Sound
.IsPlaying() then
6365 Sound
.Pause(Enable
);
6369 if gPlayers
<> nil then
6370 for i
:= 0 to High(gPlayers
) do
6371 if gPlayers
[i
] <> nil then
6372 gPlayers
[i
].PauseSounds(Enable
);
6375 if gMusic
<> nil then
6376 gMusic
.Pause(Enable
);
6379 procedure g_Game_StopAllSounds(all
: Boolean);
6383 if gTriggers
<> nil then
6384 for i
:= 0 to High(gTriggers
) do
6385 with gTriggers
[i
] do
6386 if (TriggerType
= TRIGGER_SOUND
) and
6390 if gMusic
<> nil then
6397 procedure g_Game_UpdateTriggerSounds
;
6400 if gTriggers
<> nil then
6401 for i
:= 0 to High(gTriggers
) do
6402 with gTriggers
[i
] do
6403 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6404 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6407 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6410 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6415 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6420 if gSpectMode
<> SPECT_PLAYERS
then
6422 if gSpectPID1
= UID
then
6427 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6434 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6439 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6444 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6449 if gSpectMode
<> SPECT_PLAYERS
then
6451 Pl
:= g_Player_Get(gSpectPID1
);
6452 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6457 if gSpectViewTwo
then
6459 Pl
:= g_Player_Get(gSpectPID2
);
6460 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6468 procedure g_Game_Message (Msg
: string; Time
: Word);
6471 MessageTime
:= Time
;
6474 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6476 punct
: Array[0..13] of String =
6477 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6483 function IsPunctuation(S
: String): Boolean;
6488 if Length(S
) <> 1 then
6490 for i
:= Low(punct
) to High(punct
) do
6491 if S
= punct
[i
] then
6497 function FilterPunctuation(S
: String): String;
6501 for i
:= Low(punct
) to High(punct
) do
6502 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6508 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6510 // remove player name
6511 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6512 // for FullWord check
6513 Text := toLowerCase1251(' ' + Text + ' ');
6514 fpText
:= FilterPunctuation(Text);
6516 for i
:= 0 to Length(gChatSounds
) - 1 do
6519 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6521 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6522 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6524 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6530 gChatSounds
[i
].Sound
.Play();
6536 g_Sound_PlayEx('SOUND_GAME_RADIO');
6539 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6548 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6552 if goodsnd
[a
].IsPlaying() then
6555 goodsnd
[Random(4)].Play();
6558 procedure g_Game_Announce_KillCombo(Param
: Integer);
6565 UID
:= Param
and $FFFF;
6570 Pl
:= g_Player_Get(UID
);
6579 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6583 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6587 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6591 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6599 if not g_Game_IsWatchedPlayer(UID
) then
6602 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6606 if killsnd
[n
].IsPlaying() then
6611 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6619 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6623 if hahasnd
[a
].IsPlaying() then
6626 hahasnd
[Random(3)].Play();
6629 procedure g_Game_StartVote(Command
, Initiator
: string);
6633 if not gVotesEnabled
then Exit
;
6634 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6635 if gVoteInProgress
or gVotePassed
then
6637 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6638 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6641 gVoteInProgress
:= True;
6642 gVotePassed
:= False;
6643 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6646 gVoteCommand
:= Command
;
6648 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6649 Need
:= Floor((NetClientCount
+1)/2.0)+1
6651 Need
:= Floor(NetClientCount
/2.0)+1;
6652 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6653 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6656 procedure g_Game_CheckVote
;
6660 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6661 if not gVoteInProgress
then Exit
;
6663 if (gTime
>= gVoteTimer
) then
6665 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6666 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6668 Need
:= Floor(NetClientCount
/2.0) + 1;
6669 if gVoteCount
>= Need
then
6671 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6672 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6673 gVotePassed
:= True;
6674 gVoteCmdTimer
:= gTime
+ 5000;
6678 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6679 MH_SEND_VoteEvent(NET_VE_FAILED
);
6681 if NetClients
<> nil then
6682 for I
:= Low(NetClients
) to High(NetClients
) do
6683 if NetClients
[i
].Used
then
6684 NetClients
[i
].Voted
:= False;
6685 gVoteInProgress
:= False;
6691 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6692 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6694 Need
:= Floor(NetClientCount
/2.0) + 1;
6695 if gVoteCount
>= Need
then
6697 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6698 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6699 gVoteInProgress
:= False;
6700 gVotePassed
:= True;
6701 gVoteCmdTimer
:= gTime
+ 5000;
6704 if NetClients
<> nil then
6705 for I
:= Low(NetClients
) to High(NetClients
) do
6706 if NetClients
[i
].Used
then
6707 NetClients
[i
].Voted
:= False;
6712 procedure g_Game_LoadMapList(FileName
: string);
6720 if not FileExists(FileName
) then Exit
;
6722 AssignFile(ListFile
, FileName
);
6724 while not EOF(ListFile
) do
6726 ReadLn(ListFile
, s
);
6729 if s
= '' then Continue
;
6731 SetLength(MapList
, Length(MapList
)+1);
6732 MapList
[High(MapList
)] := s
;
6734 CloseFile(ListFile
);
6737 procedure g_Game_SetDebugMode();
6740 // Читы (даже в своей игре):
6744 procedure Parse_Params(var pars
: TParamStrValues
);
6751 while i
<= ParamCount
do
6754 if (Length(s
) > 1) and (s
[1] = '-') then
6756 if (Length(s
) > 2) and (s
[2] = '-') then
6757 begin // Одиночный параметр
6758 SetLength(pars
, Length(pars
) + 1);
6759 with pars
[High(pars
)] do
6761 Name
:= LowerCase(s
);
6766 if (i
< ParamCount
) then
6767 begin // Параметр со значением
6769 SetLength(pars
, Length(pars
) + 1);
6770 with pars
[High(pars
)] do
6772 Name
:= LowerCase(s
);
6773 Value
:= LowerCase(ParamStr(i
));
6782 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6787 for i
:= 0 to High(pars
) do
6788 if pars
[i
].Name
= aName
then
6790 Result
:= pars
[i
].Value
;
6795 procedure g_Game_Process_Params();
6797 pars
: TParamStrValues
;
6800 LimT
, LimS
: Integer;
6811 s
:= Find_Param_Value(pars
, '--debug');
6814 g_Game_SetDebugMode();
6815 s
:= Find_Param_Value(pars
, '--netdump');
6820 // Connect when game loads
6821 ip
:= Find_Param_Value(pars
, '-connect');
6825 s
:= Find_Param_Value(pars
, '-port');
6826 if (s
= '') or not TryStrToInt(s
, Port
) then
6829 s
:= Find_Param_Value(pars
, '-pw');
6831 g_Game_StartClient(ip
, Port
, s
);
6835 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6838 gDefaultMegawadStart
:= s
;
6841 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6842 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6844 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6847 // Start map when game loads:
6848 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6849 if isWadPath(map
) then
6852 s
:= Find_Param_Value(pars
, '-gm');
6853 GMode
:= g_Game_TextToMode(s
);
6854 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6855 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6858 s
:= Find_Param_Value(pars
, '-limt');
6859 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6865 s
:= Find_Param_Value(pars
, '-lims');
6866 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6872 s
:= Find_Param_Value(pars
, '-lives');
6873 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6879 s
:= Find_Param_Value(pars
, '-opt');
6883 Opt
:= StrToIntDef(s
, 0);
6886 s
:= Find_Param_Value(pars
, '--close');
6890 // Override map to test:
6891 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6894 if e_IsValidResourceName(s
) then
6895 e_FindResource(AllMapDirs
, s
);
6896 gTestMap
:= ExpandFileName(s
);
6899 // Delete test map after play:
6900 s
:= Find_Param_Value(pars
, '--testdelete');
6903 //gMapToDelete := MapsDir + map;
6904 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6908 // Delete temporary WAD after play:
6909 s
:= Find_Param_Value(pars
, '--tempdelete');
6910 if (s
<> '') and (gTestMap
<> '') then
6912 gMapToDelete
:= gTestMap
;
6913 gTempDelete
:= True;
6916 // Number of players:
6917 s
:= Find_Param_Value(pars
, '-pl');
6919 n
:= DEFAULT_PLAYERS
6921 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6924 s
:= Find_Param_Value(pars
, '-port');
6925 if (s
= '') or not TryStrToInt(s
, Port
) then
6926 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6928 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6931 // Execute script when game loads:
6932 s
:= Find_Param_Value(pars
, '-exec');
6935 // if not isWadPath(s) then
6936 // s := GameDir + '/' + s;
6941 if IOResult
<> 0 then
6943 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6944 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6948 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6949 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6954 if IOResult
<> 0 then
6956 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6957 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6961 if Pos('#', s
) <> 1 then // script comment
6962 g_Console_Process(s
, True);
6973 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6974 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6975 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6976 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6978 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6979 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6980 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6983 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6984 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6987 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6988 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6990 {$IFDEF ENABLE_HOLMES}
6991 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6994 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6996 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6997 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6999 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7000 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7002 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
7003 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
7004 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
7005 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
7006 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7007 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7008 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7009 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7010 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');