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_MonsterOff
: Boolean = False;
316 g_debug_BotAIOff
: Byte = 0;
317 g_Debug_Player
: Boolean = False;
318 gCoopMonstersKilled
: Word = 0;
319 gCoopSecretsFound
: Word = 0;
320 gCoopTotalMonstersKilled
: Word = 0;
321 gCoopTotalSecretsFound
: Word = 0;
322 gCoopTotalMonsters
: Word = 0;
323 gCoopTotalSecrets
: Word = 0;
324 gStatsOff
: Boolean = False;
325 gStatsPressed
: Boolean = False;
326 gExitByTrigger
: Boolean = False;
327 gNextMap
: String = '';
328 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
329 gLMSRespawnTime
: Cardinal = 0;
330 gLMSSoftSpawn
: Boolean = False;
331 gMissionFailed
: Boolean = False;
332 gVoteInProgress
: Boolean = False;
333 gVotePassed
: Boolean = False;
334 gVoteCommand
: string = '';
335 gVoteTimer
: Cardinal = 0;
336 gVoteCmdTimer
: Cardinal = 0;
337 gVoteCount
: Integer = 0;
338 gVoteTimeout
: Cardinal = 30;
339 gVoted
: Boolean = False;
340 gVotesEnabled
: Boolean = True;
341 gEvents
: Array of TGameEvent
;
342 gDelayedEvents
: Array of TDelayedEvent
;
343 gUseChatSounds
: Boolean = True;
344 gChatSounds
: Array of TChatSound
;
345 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
346 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
347 gInterReadyCount
: Integer = 0;
348 gMaxBots
: Integer = 127;
350 g_dbg_ignore_bounds
: Boolean = false;
351 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
352 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
354 // move button values:
355 // bits 0-1: l/r state:
356 // 0: neither left, nor right pressed
359 // bits 4-5: l/r state when strafe was pressed
360 P1MoveButton
: Byte = 0;
361 P2MoveButton
: Byte = 0;
363 g_profile_frame_update
: Boolean = false;
364 g_profile_frame_draw
: Boolean = false;
365 g_profile_collision
: Boolean = false;
366 g_profile_los
: Boolean = false;
367 g_profile_history_size
: Integer = 1000;
369 g_rlayer_back
: Boolean = true;
370 g_rlayer_step
: Boolean = true;
371 g_rlayer_wall
: Boolean = true;
372 g_rlayer_door
: Boolean = true;
373 g_rlayer_acid1
: Boolean = true;
374 g_rlayer_acid2
: Boolean = true;
375 g_rlayer_water
: Boolean = true;
376 g_rlayer_fore
: Boolean = true;
378 wNeedTimeReset
: Boolean = false;
380 procedure g_ResetDynlights ();
381 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
382 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
384 function conIsCheatsEnabled (): Boolean; inline;
385 function gPause (): Boolean; inline;
387 type (* private state *)
388 TEndCustomGameStat
= record
389 PlayerStat
: TPlayerStatArray
;
393 Map
, MapName
: String;
396 TEndSingleGameStat
= record
397 PlayerStat
: Array [0..1] of record
403 TotalSecrets
: Integer;
407 x
, y
, radius
: Integer;
410 exploRadius
: Integer;
413 var (* private state *)
414 CustomStat
: TEndCustomGameStat
;
415 StatShotDone
: Boolean;
416 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
417 SingleStat
: TEndSingleGameStat
;
420 EndingGameCounter
: Byte;
422 g_playerLight
: Boolean;
423 g_dynLights
: array of TDynLight
= nil;
424 g_dynLightCount
: Integer = 0;
425 EndPicPath
: AnsiString; // full path, used by render
430 {$IFDEF ENABLE_HOLMES}
442 {$IFDEF ENABLE_SHELLS}
445 {$IFDEF ENABLE_CORPSES}
448 {$IFDEF ENABLE_RENDER}
451 {$IFDEF ENABLE_SYSTEM}
455 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
456 g_playermodel
, g_options
, Math
,
457 g_triggers
, g_monsters
, e_sound
, CONFIG
,
458 g_language
, g_net
, g_phys
,
459 ENet
, e_msg
, g_netmsg
, g_netmaster
,
463 charbuff
: packed array [0..15] of AnsiChar = (
464 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
467 function Translit (const S
: AnsiString): AnsiString;
472 for i
:= 1 to Length(Result
) do
475 #
$C9: Result
[i
] := 'Q';
476 #
$D6: Result
[i
] := 'W';
477 #
$D3: Result
[i
] := 'E';
478 #
$CA: Result
[i
] := 'R';
479 #
$C5: Result
[i
] := 'T';
480 #
$CD: Result
[i
] := 'Y';
481 #
$C3: Result
[i
] := 'U';
482 #
$D8: Result
[i
] := 'I';
483 #
$D9: Result
[i
] := 'O';
484 #
$C7: Result
[i
] := 'P';
485 #
$D5: Result
[i
] := '['; //Chr(219);
486 #
$DA: Result
[i
] := ']'; //Chr(221);
487 #
$D4: Result
[i
] := 'A';
488 #
$DB: Result
[i
] := 'S';
489 #
$C2: Result
[i
] := 'D';
490 #
$C0: Result
[i
] := 'F';
491 #
$CF: Result
[i
] := 'G';
492 #
$D0: Result
[i
] := 'H';
493 #
$CE: Result
[i
] := 'J';
494 #
$CB: Result
[i
] := 'K';
495 #
$C4: Result
[i
] := 'L';
496 #
$C6: Result
[i
] := ';'; //Chr(186);
497 #
$DD: Result
[i
] := #39; //Chr(222);
498 #
$DF: Result
[i
] := 'Z';
499 #
$D7: Result
[i
] := 'X';
500 #
$D1: Result
[i
] := 'C';
501 #
$CC: Result
[i
] := 'V';
502 #
$C8: Result
[i
] := 'B';
503 #
$D2: Result
[i
] := 'N';
504 #
$DC: Result
[i
] := 'M';
505 #
$C1: Result
[i
] := ','; //Chr(188);
506 #
$DE: Result
[i
] := '.'; //Chr(190);
512 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
517 ls2
:= Translit(CheatRus
[ct
]);
518 if length(ls1
) = 0 then ls1
:= '~';
519 if length(ls2
) = 0 then ls2
:= '~';
521 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
522 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
523 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
524 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
526 if ct = I_GAME_CHEAT_JETPACK then
528 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
529 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
530 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
531 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
532 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
533 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
549 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
550 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
551 or g_Game_IsNet then Exit;
553 if not gGameOn
then exit
;
554 if not conIsCheatsEnabled
then exit
;
556 s
:= 'SOUND_GAME_RADIO';
559 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
561 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
562 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
566 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
568 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
569 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
573 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
575 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
576 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
580 if CheckCheat(I_GAME_CHEAT_DEATH
) then
582 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
583 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
584 s
:= 'SOUND_MONSTER_HAHA';
588 if CheckCheat(I_GAME_CHEAT_DOORS
) then
590 g_Triggers_OpenAll();
594 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
596 if gTriggers
<> nil then
597 for a
:= 0 to High(gTriggers
) do
598 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
600 gExitByTrigger
:= True;
601 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
602 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
608 s2
:= Copy(charbuff
, 15, 2);
609 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
611 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
619 if CheckCheat(I_GAME_CHEAT_FLY
) then
625 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
627 VEL_JUMP
:= 30-VEL_JUMP
;
631 if CheckCheat(I_GAME_CHEAT_SPEED
) then
633 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
637 if CheckCheat(I_GAME_CHEAT_SUIT
) then
639 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
640 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
644 if CheckCheat(I_GAME_CHEAT_AIR
) then
646 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
647 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
651 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
653 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
654 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
658 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
660 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
661 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
665 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
667 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
668 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
672 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
674 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
675 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
679 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
681 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
682 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
685 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
687 gAimLine
:= not gAimLine
;
690 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
692 gShowMap
:= not gShowMap
;
703 procedure KeyPress (K
: Word);
704 var Msg
: g_gui
.TMessage
;
709 if (g_ActiveWindow
<> nil) then
711 Msg
.Msg
:= WM_KEYDOWN
;
712 Msg
.WParam
:= VK_ESCAPE
;
713 g_ActiveWindow
.OnMessage(Msg
);
714 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
716 else if (gState
<> STATE_FOLD
) then
718 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
720 g_Game_InGameMenu(True);
722 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
724 if (gState
<> STATE_MENU
) then
726 if (NetMode
<> NET_NONE
) then
728 g_Game_StopAllSounds(True);
730 gState
:= STATE_MENU
;
734 g_GUI_ShowWindow('MainMenu');
735 g_Sound_PlayEx('MENU_OPEN');
740 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
741 begin // <F2> .. <F6> � <F12>
742 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
744 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
745 if (not g_Game_IsNet
) then g_Game_Pause(True);
747 IK_F2
: g_Menu_Show_SaveMenu();
748 IK_F3
: g_Menu_Show_LoadMenu();
749 IK_F4
: g_Menu_Show_GameSetGame();
750 IK_F5
: g_Menu_Show_OptionsVideo();
751 IK_F6
: g_Menu_Show_OptionsSound();
752 IK_F7
: g_Menu_Show_EndGameMenu();
753 IK_F10
: g_Menu_Show_QuitGameMenu();
760 gJustChatted
:= False;
761 if gConsoleShow
or gChatShow
then
763 g_Console_Control(K
);
765 else if (g_ActiveWindow
<> nil) then
767 Msg
.Msg
:= WM_KEYDOWN
;
769 g_ActiveWindow
.OnMessage(Msg
);
771 else if (gState
= STATE_MENU
) then
773 g_GUI_ShowWindow('MainMenu');
774 g_Sound_PlayEx('MENU_OPEN');
780 procedure KeyPress (K
: Word);
782 gJustChatted
:= False;
783 if gConsoleShow
or gChatShow
then
785 g_Console_Control(K
);
790 {$IFDEF ENABLE_SYSTEM}
791 procedure CharPress (C
: AnsiChar);
793 var Msg
: g_gui
.TMessage
;
797 if gConsoleShow
or gChatShow
then
802 else if g_ActiveWindow
<> nil then
805 Msg
.WParam
:= Ord(C
);
806 g_ActiveWindow
.OnMessage(Msg
);
813 charbuff
[a
] := charbuff
[a
+ 1];
815 charbuff
[15] := upcase1251(C
);
822 // ////////////////////////////////////////////////////////////////////////// //
823 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
825 procedure g_ResetDynlights ();
829 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
831 for idx
:= 0 to g_dynLightCount
-1 do
833 if g_dynLights
[idx
].exploCount
= -666 then
840 Inc(g_dynLights
[idx
].exploCount
);
841 if (g_dynLights
[idx
].exploCount
< 10) then
843 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
844 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
845 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
846 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
851 g_dynLightCount
:= lnum
;
854 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
856 if not gwin_has_stencil
then exit
;
857 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
858 g_dynLights
[g_dynLightCount
].x
:= x
;
859 g_dynLights
[g_dynLightCount
].y
:= y
;
860 g_dynLights
[g_dynLightCount
].radius
:= radius
;
861 g_dynLights
[g_dynLightCount
].r
:= r
;
862 g_dynLights
[g_dynLightCount
].g
:= g
;
863 g_dynLights
[g_dynLightCount
].b
:= b
;
864 g_dynLights
[g_dynLightCount
].a
:= a
;
865 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
866 Inc(g_dynLightCount
);
869 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
871 if not gwin_has_stencil
then exit
;
872 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
873 g_dynLights
[g_dynLightCount
].x
:= x
;
874 g_dynLights
[g_dynLightCount
].y
:= y
;
875 g_dynLights
[g_dynLightCount
].radius
:= 0;
876 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
877 g_dynLights
[g_dynLightCount
].r
:= r
;
878 g_dynLights
[g_dynLightCount
].g
:= g
;
879 g_dynLights
[g_dynLightCount
].b
:= b
;
880 g_dynLights
[g_dynLightCount
].a
:= 0;
881 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
882 Inc(g_dynLightCount
);
885 // ////////////////////////////////////////////////////////////////////////// //
886 function conIsCheatsEnabled (): Boolean; inline;
889 if g_Game_IsNet
then exit
;
890 if not gDebugMode
then
892 //if not gCheats then exit;
893 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
894 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
899 // ////////////////////////////////////////////////////////////////////////// //
901 TParamStrValue
= record
906 TParamStrValues
= Array of TParamStrValue
;
909 INTER_ACTION_TEXT
= 1;
910 INTER_ACTION_PIC
= 2;
911 INTER_ACTION_MUSIC
= 3;
916 DataLoaded
: Boolean = False;
918 MapList
: SSArray
= nil;
919 MapIndex
: Integer = -1;
920 InterReadyTime
: Integer = -1;
921 StatDate
: string = '';
936 function Compare(a
, b
: TPlayerStat
): Integer;
938 if a
.Spectator
then Result
:= 1
939 else if b
.Spectator
then Result
:= -1
940 else if a
.Frags
< b
.Frags
then Result
:= 1
941 else if a
.Frags
> b
.Frags
then Result
:= -1
942 else if a
.Deaths
< b
.Deaths
then Result
:= -1
943 else if a
.Deaths
> b
.Deaths
then Result
:= 1
944 else if a
.Kills
< b
.Kills
then Result
:= -1
948 procedure SortGameStat(var stat
: TPlayerStatArray
);
953 if stat
= nil then Exit
;
955 for I
:= High(stat
) downto Low(stat
) do
956 for J
:= Low(stat
) to High(stat
) - 1 do
957 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
960 stat
[J
] := stat
[J
+ 1];
965 // saves a shitty CSV containing the game stats passed to it
966 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
969 dir
, fname
, map
, mode
, etime
: String;
973 dir
:= e_GetWriteableDir(StatsDirs
);
974 // stats are placed in stats/yy/mm/dd/*.csv
975 fname
:= e_CatPath(dir
, Path
);
976 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
977 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
978 AssignFile(s
, fname
);
980 SetTextCodePage(s
, CP_UTF8
);
982 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
983 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
984 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
985 mode
:= g_Game_ModeToText(Stat
.GameMode
);
986 etime
:= Format('%d:%.2d:%.2d', [
987 Stat
.GameTime
div 1000 div 3600,
988 (Stat
.GameTime
div 1000 div 60) mod 60,
989 Stat
.GameTime
div 1000 mod 60
991 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
992 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
998 gGameSettings
.TimeLimit
,
999 gGameSettings
.ScoreLimit
,
1000 gGameSettings
.Options
,
1002 Length(Stat
.PlayerStat
)
1004 // line 2: game specific shit
1005 // if it's a team game: red score, blue score
1006 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1007 // otherwise nothing
1008 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1010 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
1011 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1013 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1014 // lines 3-...: team, player name, frags, deaths
1015 WriteLn(s
, 'team,name,frags,deaths');
1016 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1017 with Stat
.PlayerStat
[I
] do
1018 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1020 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1023 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1028 procedure ClearDebugCvars();
1030 g_debug_MonsterOff
:= False;
1031 g_debug_BotAIOff
:= 0;
1032 g_Debug_Player
:= False;
1035 function g_Game_ModeToText(Mode
: Byte): string;
1039 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1040 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1041 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1042 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1043 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1047 function g_Game_TextToMode(Mode
: string): Byte;
1050 Mode
:= UpperCase(Mode
);
1051 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1056 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1061 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1066 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1071 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1073 Result
:= GM_SINGLE
;
1078 function g_Game_IsNet(): Boolean;
1080 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1083 function g_Game_IsServer(): Boolean;
1085 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1088 function g_Game_IsClient(): Boolean;
1090 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1093 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1100 Result
.name
:= ExtractFileName(WAD
);
1101 Result
.description
:= '';
1102 Result
.author
:= '';
1104 w
:= TWADFile
.Create();
1107 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1113 cfg
:= TConfig
.CreateMem(p
, len
);
1114 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1115 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1116 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1117 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1123 procedure g_Game_FreeWAD
;
1126 g_Sound_Delete('MUSIC_endmus');
1127 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1128 gGameSettings
.WAD
:= '';
1131 procedure g_Game_LoadWAD(WAD
: string);
1140 gGameSettings
.WAD
:= WAD
;
1141 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1144 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1146 w
:= TWADFile
.Create();
1149 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1155 cfg
:= TConfig
.CreateMem(p
, len
);
1158 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1159 if MegaWAD
.endpic
<> '' then
1160 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1162 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1163 if MegaWAD
.endmus
<> '' then
1165 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1166 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1174 {procedure start_trigger(t: string);
1178 function next_trigger(): Boolean;
1182 procedure DisableCheats();
1188 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1189 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1190 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1191 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1193 {$IF DEFINED(D2F_DEBUG)}
1194 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1195 gAimLine
:= g_dbg_aimline_on
;
1199 procedure g_Game_ExecuteEvent(Name
: String);
1205 if gEvents
= nil then
1207 for a
:= 0 to High(gEvents
) do
1208 if gEvents
[a
].Name
= Name
then
1210 if gEvents
[a
].Command
<> '' then
1211 g_Console_Process(gEvents
[a
].Command
, True);
1216 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1221 if gDelayedEvents
<> nil then
1222 for a
:= 0 to High(gDelayedEvents
) do
1223 if not gDelayedEvents
[a
].Pending
then
1230 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1231 n
:= High(gDelayedEvents
);
1233 gDelayedEvents
[n
].Pending
:= True;
1234 gDelayedEvents
[n
].DEType
:= DEType
;
1235 gDelayedEvents
[n
].DENum
:= Num
;
1236 gDelayedEvents
[n
].DEStr
:= Str
;
1237 if DEType
= DE_GLOBEVENT
then
1238 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1240 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1244 procedure EndGame();
1250 if g_Game_IsNet
and g_Game_IsServer
then
1251 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1254 gPauseMain
:= false;
1255 gPauseHolmes
:= false;
1258 g_Game_StopAllSounds(False);
1263 EndingGameCounter
:= 0;
1265 {$IFDEF ENABLE_MENU}
1266 g_ActiveWindow
:= nil;
1269 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1270 gLMSRespawnTime
:= 0;
1273 EXIT_SIMPLE
: // Выход через меню или конец теста
1277 begin // Это был тест
1281 begin // Выход в главное меню
1282 {$IFDEF DISABLE_MENU}
1283 gState
:= STATE_MENU
; // ???
1285 gMusic
.SetByName('MUSIC_MENU');
1287 if gState
<> STATE_SLIST
then
1289 g_GUI_ShowWindow('MainMenu');
1290 gState
:= STATE_MENU
;
1294 // Обновляем список серверов
1295 slReturnPressed
:= True;
1296 if g_Net_Slist_Fetch(slCurrent
) then
1298 if slCurrent
= nil then
1299 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1302 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1303 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1306 g_Game_ExecuteEvent('ongameend');
1310 EXIT_RESTART
: // Начать уровень сначала
1312 if not g_Game_IsClient
then g_Game_Restart();
1315 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1317 // Статистика Своей игры:
1318 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1320 CustomStat
.GameTime
:= gTime
;
1321 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1322 CustomStat
.MapName
:= gMapInfo
.Name
;
1323 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1324 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1325 CustomStat
.TeamStat
:= gTeamStat
;
1327 CustomStat
.PlayerStat
:= nil;
1329 // Статистика игроков:
1330 if gPlayers
<> nil then
1332 for a
:= 0 to High(gPlayers
) do
1333 if gPlayers
[a
] <> nil then
1335 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1336 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1339 Name
:= gPlayers
[a
].Name
;
1340 Frags
:= gPlayers
[a
].Frags
;
1341 Deaths
:= gPlayers
[a
].Death
;
1342 Kills
:= gPlayers
[a
].Kills
;
1343 Team
:= gPlayers
[a
].Team
;
1344 Color
:= gPlayers
[a
].Model
.Color
;
1345 Spectator
:= gPlayers
[a
].FSpectator
;
1349 SortGameStat(CustomStat
.PlayerStat
);
1351 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1354 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1355 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1356 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1357 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1359 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1362 StatShotDone
:= False;
1365 g_Game_ExecuteEvent('onmapend');
1366 if not g_Game_IsClient
then g_Player_ResetReady
;
1367 gInterReadyCount
:= 0;
1369 // Затухающий экран:
1370 EndingGameCounter
:= 255;
1371 gState
:= STATE_FOLD
;
1373 if gDefInterTime
< 0 then
1374 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1376 gInterEndTime
:= gDefInterTime
* 1000;
1379 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1381 // Статистика Одиночной игры:
1382 SingleStat
.GameTime
:= gTime
;
1383 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1384 SingleStat
.TotalSecrets
:= gSecretsCount
;
1385 // Статистика первого игрока:
1386 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1387 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1388 // Статистика второго игрока (если есть):
1389 if SingleStat
.TwoPlayers
then
1391 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1392 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1395 g_Game_ExecuteEvent('onmapend');
1398 if gNextMap
<> '' then
1400 gMusic
.SetByName('MUSIC_INTERMUS');
1402 gState
:= STATE_INTERSINGLE
;
1405 g_Game_ExecuteEvent('oninter');
1407 else // Больше нет карт
1409 // Затухающий экран:
1410 EndingGameCounter
:= 255;
1411 gState
:= STATE_FOLD
;
1416 // Окончание обработано:
1417 if gExit
<> EXIT_QUIT
then
1421 procedure g_Game_Init();
1425 gTempDelete
:= False;
1427 sfsGCDisable(); // temporary disable removing of temporary volumes
1431 gPauseMain
:= false;
1432 gPauseHolmes
:= false;
1435 {e_MouseInfo.Accel := 1.0;}
1439 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1440 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1441 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1442 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1443 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1445 gMusic
:= TMusic
.Create();
1446 gMusic
.SetByName('MUSIC_MENU');
1449 gGameSettings
.WarmupTime
:= 30;
1451 gState
:= STATE_MENU
;
1453 SetLength(gEvents
, 6);
1454 gEvents
[0].Name
:= 'ongamestart';
1455 gEvents
[1].Name
:= 'ongameend';
1456 gEvents
[2].Name
:= 'onmapstart';
1457 gEvents
[3].Name
:= 'onmapend';
1458 gEvents
[4].Name
:= 'oninter';
1459 gEvents
[5].Name
:= 'onwadend';
1461 sfsGCEnable(); // enable releasing unused volumes
1465 procedure g_Game_Free(freeTextures
: Boolean=true);
1467 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1468 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1470 g_Map_Free(freeTextures
);
1473 {$IFDEF ENABLE_GIBS}
1476 {$IFDEF ENABLE_SHELLS}
1479 {$IFDEF ENABLE_CORPSES}
1480 g_Corpses_RemoveAll
;
1483 gGameSettings
.GameType
:= GT_NONE
;
1484 if gGameSettings
.GameMode
= GM_SINGLE
then
1485 gGameSettings
.GameMode
:= GM_DM
;
1486 gSwitchGameMode
:= gGameSettings
.GameMode
;
1489 gExitByTrigger
:= False;
1492 function IsActivePlayer(p
: TPlayer
): Boolean;
1497 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1500 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1506 if gPlayers
= nil then
1510 for a
:= Low(gPlayers
) to High(gPlayers
) do
1511 if IsActivePlayer(gPlayers
[a
]) then
1513 SetLength(ids
, Length(ids
) + 1);
1514 ids
[High(ids
)] := gPlayers
[a
].UID
;
1515 if gPlayers
[a
].UID
= Skip
then
1518 if Length(ids
) = 0 then
1523 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1526 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1532 if gPlayers
= nil then
1536 for a
:= Low(gPlayers
) to High(gPlayers
) do
1537 if IsActivePlayer(gPlayers
[a
]) then
1539 SetLength(ids
, Length(ids
) + 1);
1540 ids
[High(ids
)] := gPlayers
[a
].UID
;
1541 if gPlayers
[a
].UID
= Skip
then
1544 if Length(ids
) = 0 then
1547 Result
:= ids
[Length(ids
) - 1]
1549 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1552 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1558 if gPlayers
= nil then
1562 for a
:= Low(gPlayers
) to High(gPlayers
) do
1563 if IsActivePlayer(gPlayers
[a
]) then
1565 SetLength(ids
, Length(ids
) + 1);
1566 ids
[High(ids
)] := gPlayers
[a
].UID
;
1567 if gPlayers
[a
].UID
= Skip
then
1570 if Length(ids
) = 0 then
1572 if Length(ids
) = 1 then
1577 Result
:= ids
[Random(Length(ids
))];
1579 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1581 Result
:= ids
[Random(Length(ids
))];
1586 function GetRandomSpectMode(Current
: Byte): Byte;
1593 0: Result
:= SPECT_STATS
;
1594 1: Result
:= SPECT_MAPVIEW
;
1595 2: Result
:= SPECT_MAPVIEW
;
1596 3: Result
:= SPECT_PLAYERS
;
1597 4: Result
:= SPECT_PLAYERS
;
1598 5: Result
:= SPECT_PLAYERS
;
1599 6: Result
:= SPECT_PLAYERS
;
1601 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1605 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1611 if (plr
= nil) then exit
;
1612 if (p
= 2) then time
:= 1000 else time
:= 1;
1613 strafeDir
:= MoveButton
shr 4;
1614 MoveButton
:= MoveButton
and $0F;
1616 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1617 MoveButton
:= 1 // Нажата только "Влево"
1618 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1619 MoveButton
:= 2 // Нажата только "Вправо"
1620 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1621 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1623 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1624 if MoveButton
= 1 then
1625 plr
.PressKey(KEY_LEFT
, time
)
1626 else if MoveButton
= 2 then
1627 plr
.PressKey(KEY_RIGHT
, time
);
1629 // if we have "strafe" key, turn off old strafe mechanics
1630 if gPlayerAction
[p
, ACTION_STRAFE
] then
1632 // new strafe mechanics
1633 if (strafeDir
= 0) then
1634 strafeDir
:= MoveButton
; // start strafing
1635 // now set direction according to strafe (reversed)
1636 if (strafeDir
= 2) then
1637 plr
.SetDirection(TDirection
.D_LEFT
)
1638 else if (strafeDir
= 1) then
1639 plr
.SetDirection(TDirection
.D_RIGHT
)
1643 strafeDir
:= 0; // not strafing anymore
1644 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1645 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1646 plr
.SetDirection(TDirection
.D_LEFT
)
1647 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1648 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1649 plr
.SetDirection(TDirection
.D_RIGHT
)
1650 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1651 else if MoveButton
<> 0 then
1652 plr
.SetDirection(TDirection(MoveButton
-1))
1655 // fix movebutton state
1656 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1658 // Остальные клавиши:
1659 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1660 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1661 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1662 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1663 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1665 for i
:= WP_FACT
to WP_LACT
do
1667 if gWeaponAction
[p
, i
] then
1669 plr
.ProcessWeaponAction(i
);
1670 gWeaponAction
[p
, i
] := False
1674 for i
:= WP_FIRST
to WP_LAST
do
1676 if gSelectWeapon
[p
, i
] then
1678 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1679 gSelectWeapon
[p
, i
] := False
1683 {$IFDEF ENABLE_MENU}
1684 // HACK: add dynlight here
1685 if gwin_k8_enable_light_experiments
then
1687 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1689 g_playerLight
:= true;
1691 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1693 g_playerLight
:= false;
1697 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1701 // HACK: don't have a "key was pressed" function
1702 procedure InterReady();
1704 if InterReadyTime
> gTime
then Exit
;
1705 InterReadyTime
:= gTime
+ 3000;
1706 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1709 procedure g_Game_PreUpdate();
1711 // these are in separate PreUpdate functions because they can interact during Update()
1712 // and are synced over the net
1713 // we don't care that much about corpses and gibs
1714 g_Player_PreUpdate();
1715 g_Monsters_PreUpdate();
1716 g_Items_PreUpdate();
1717 g_Weapon_PreUpdate();
1720 procedure g_Game_SetupHearPoints
;
1721 var p1
, p2
: TPlayer
; a
, b
: Integer;
1725 gHearPoint1
.Active
:= false;
1726 gHearPoint2
.Active
:= false;
1727 if gSpectMode
= SPECT_MAPVIEW
then
1729 // TODO something better (render dependency)
1730 gHearPoint1
.Active
:= true;
1731 gHearPoint1
.Coords
.X
:= gSpectX
+ gScreenWidth
div 2;
1732 gHearPoint1
.Coords
.Y
:= gSpectY
+ gScreenHeight
div 2;
1734 else if gSpectMode
= SPECT_PLAYERS
then
1736 p1
:= g_Player_Get(gSpectPID1
);
1737 if gSpectViewTwo
then
1738 p2
:= g_Player_Get(gSpectPID2
);
1740 else if gSpectMode
= SPECT_NONE
then
1747 gHearPoint1
.Active
:= true;
1748 gHearPoint1
.Coords
.X
:= p1
.obj
.x
+ p1
.obj
.rect
.width
div 2;
1749 gHearPoint1
.Coords
.Y
:= p1
.obj
.y
+ p1
.obj
.rect
.height
div 2;
1751 if (p2
<> nil) and (p1
<> p2
) then
1753 gHearPoint2
.Active
:= true;
1754 gHearPoint2
.Coords
.X
:= p2
.obj
.x
+ p2
.obj
.rect
.width
div 2;
1755 gHearPoint2
.Coords
.Y
:= p2
.obj
.y
+ p2
.obj
.rect
.height
div 2;
1757 // TODO something better (render dependency)
1758 if (p1
<> nil) and (p2
<> nil) then
1760 gPlayerScreenSize
.X
:= gScreenWidth
- 196;
1761 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
1765 gPlayerScreenSize
.X
:= gScreenWidth
- 196;
1766 gPlayerScreenSize
.Y
:= gScreenHeight
;
1769 if gMapInfo
.Height
> gPlayerScreenSize
.Y
then a
:= gMapInfo
.Height
- gPlayerScreenSize
.Y
else a
:= gMapInfo
.Height
;
1770 if gMapInfo
.Width
> gPlayerScreenSize
.X
then b
:= gMapInfo
.Width
- gPlayerScreenSize
.X
else b
:= gMapInfo
.Width
;
1771 gMaxDist
:= Trunc(Hypot(a
, b
));
1774 procedure g_Game_Update();
1776 {$IFDEF ENABLE_MENU}
1777 Msg
: g_gui
.TMessage
;
1784 function sendMonsPos (mon
: TMonster
): Boolean;
1786 result
:= false; // don't stop
1787 // this will also reset "need-send" flag
1788 if mon
.gncNeedSend
then
1790 MH_SEND_MonsterPos(mon
.UID
);
1792 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1794 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1796 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1798 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1802 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1804 result
:= false; // don't stop
1805 // this will also reset "need-send" flag
1806 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1809 function sendItemPos (it
: PItem
): Boolean;
1811 result
:= false; // don't stop
1814 MH_SEND_ItemPos(it
.myId
);
1815 it
.needSend
:= False;
1820 reliableUpdate
: Boolean;
1821 rSpectX0
, rSpectY0
: Integer;
1822 rSpectX1
, rSpectY1
: Integer;
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
2101 {$IFDEF ENABLE_RENDER}
2102 r_Render_GetSpectatorLimits(rSpectX0
, rSpectY0
, rSpectX1
, rSpectY1
);
2104 rSpectX0
:= 0; rSpectY0
:= 0;
2105 rSpectX1
:= gMapInfo
.Width
- 1; rSpectY1
:= gMapInfo
.Height
- 1;
2108 if (gPlayer1
= nil) and (gPlayer2
= nil)
2109 and (not gConsoleShow
) and (not gChatShow
)
2110 {$IFDEF ENABLE_MENU}
2111 and (g_ActiveWindow
= nil)
2115 if not gSpectKeyPress
then
2117 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2119 // switch spect mode
2121 SPECT_NONE
: ; // not spectator
2123 SPECT_MAPVIEW
: Inc(gSpectMode
);
2124 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2126 gSpectKeyPress
:= True;
2128 if (gSpectMode
= SPECT_MAPVIEW
)
2129 and (not gSpectAuto
) then
2131 if gPlayerAction
[0, ACTION_MOVELEFT
] then gSpectX
:= gSpectX
- gSpectStep
;
2132 if gPlayerAction
[0, ACTION_MOVERIGHT
] then gSpectX
:= gSpectX
+ gSpectStep
;
2133 if gPlayerAction
[0, ACTION_LOOKUP
] then gSpectY
:= gSpectY
- gSpectStep
;
2134 if gPlayerAction
[0, ACTION_LOOKDOWN
] then gSpectY
:= gSpectY
+ gSpectStep
;
2135 if gWeaponAction
[0, WP_PREV
] then
2138 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2139 gWeaponAction
[0, WP_PREV
] := False;
2141 if gWeaponAction
[0, WP_NEXT
] then
2144 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2145 gWeaponAction
[0, WP_NEXT
] := False;
2148 if (gSpectMode
= SPECT_PLAYERS
)
2149 and (not gSpectAuto
) then
2151 if gPlayerAction
[0, ACTION_LOOKUP
] then
2154 gSpectViewTwo
:= True;
2155 gSpectKeyPress
:= True;
2157 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2159 // remove second view
2160 gSpectViewTwo
:= False;
2161 gSpectKeyPress
:= True;
2163 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2165 // prev player (view 1)
2166 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2167 gSpectKeyPress
:= True;
2169 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2171 // next player (view 1)
2172 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2173 gSpectKeyPress
:= True;
2175 if gWeaponAction
[0, WP_PREV
] then
2177 // prev player (view 2)
2178 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2179 gWeaponAction
[0, WP_PREV
] := False;
2181 if gWeaponAction
[0, WP_NEXT
] then
2183 // next player (view 2)
2184 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2185 gWeaponAction
[0, WP_NEXT
] := False;
2188 if gPlayerAction
[0, ACTION_ATTACK
] then
2190 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2193 gSpectAutoNext
:= 0;
2194 gSpectViewTwo
:= False;
2195 gSpectKeyPress
:= True;
2200 gSpectMode
:= SPECT_STATS
;
2201 gSpectAuto
:= False;
2202 gSpectKeyPress
:= True;
2207 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2208 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2209 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2210 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2211 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2212 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2213 gSpectKeyPress
:= False;
2217 if gSpectMode
= SPECT_MAPVIEW
then
2219 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, rSpectX0
), rSpectX1
);
2221 gSpectAutoNext
:= gTime
2224 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, rSpectY0
), rSpectY1
);
2226 gSpectAutoNext
:= gTime
2230 if gSpectAutoNext
<= gTime
then
2232 if gSpectAutoNext
> 0 then
2234 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2238 gSpectX
:= rSpectX0
+ Random(rSpectX1
- rSpectX0
);
2239 gSpectY
:= rSpectY0
+ Random(rSpectY1
- rSpectY0
);
2240 gSpectAutoStepX
:= Random(9) - 4;
2241 gSpectAutoStepY
:= Random(9) - 4;
2242 if ((gSpectX
< rSpectX0
) and (gSpectAutoStepX
< 0)) or
2243 ((gSpectX
> rSpectX1
) and (gSpectAutoStepX
> 0)) then
2244 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2245 if ((gSpectY
< rSpectY0
) and (gSpectAutoStepY
< 0)) or
2246 ((gSpectY
> rSpectY1
) and (gSpectAutoStepY
> 0)) then
2247 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2251 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2256 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2257 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2258 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2263 if gSpectMode
= SPECT_MAPVIEW
then
2265 gSpectX
:= Max(gSpectX
, rSpectX0
);
2266 gSpectX
:= Min(gSpectX
, rSpectX1
);
2267 gSpectY
:= Max(gSpectY
, rSpectY0
);
2268 gSpectY
:= Min(gSpectY
, rSpectY1
);
2272 (* spectator state check from render *)
2274 if (gPlayer1
= nil) and (gPlayer2
= nil) then
2276 (* no local players -> automatically enable to spectator mode *)
2277 if gSpectMode
= SPECT_NONE
then gSpectMode
:= SPECT_STATS
;
2281 (* at least one local player -> automatically disable spectator mode *)
2282 gSpectMode
:= SPECT_NONE
;
2285 if IsActivePlayer(g_Player_Get(gSpectPID1
)) = false then
2286 gSpectPID1
:= GetActivePlayerID_Next();
2288 if IsActivePlayer(g_Player_Get(gSpectPID2
)) = false then
2289 gSpectPID2
:= GetActivePlayerID_Next();
2291 g_Game_SetupHearPoints
;
2293 // Обновляем все остальное:
2296 g_Triggers_Update();
2298 g_Monsters_Update();
2302 g_Player_UpdateAll();
2303 {$IFDEF ENABLE_GIBS}
2306 {$IFDEF ENABLE_CORPSES}
2309 {$IFDEF ENABLE_SHELLS}
2313 // server: send newly spawned monsters unconditionally
2314 if (gGameSettings
.GameType
= GT_SERVER
) then
2316 if (Length(gMonstersSpawned
) > 0) then
2318 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2319 SetLength(gMonstersSpawned
, 0);
2323 if (gSoundTriggerTime
> 8) then
2325 g_Game_UpdateTriggerSounds();
2326 gSoundTriggerTime
:= 0;
2330 Inc(gSoundTriggerTime
);
2333 if (NetMode
= NET_SERVER
) then
2335 Inc(NetTimeToUpdate
);
2336 Inc(NetTimeToReliable
);
2338 // send monster updates
2339 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2341 // send all monsters (periodic sync)
2342 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2344 for I
:= 0 to High(gPlayers
) do
2346 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2349 g_Mons_ForEach(sendMonsPos
);
2351 // update flags that aren't stationary
2352 if gGameSettings
.GameMode
= GM_CTF
then
2353 for I
:= FLAG_RED
to FLAG_BLUE
do
2354 if gFlags
[I
].NeedSend
then
2356 gFlags
[I
].NeedSend
:= False;
2360 // update items that aren't stationary
2361 g_Items_ForEachAlive(sendItemPos
);
2363 if reliableUpdate
then
2365 NetTimeToReliable
:= 0;
2366 NetTimeToUpdate
:= NetUpdateRate
;
2370 NetTimeToUpdate
:= 0;
2375 // send only mosters with some unexpected changes
2376 g_Mons_ForEach(sendMonsPosUnexpected
);
2379 // send unexpected platform changes
2380 g_Map_NetSendInterestingPanels();
2382 g_Net_Slist_ServerUpdate();
2384 if NetUseMaster then
2386 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2388 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2390 NetTimeToMaster := gTime + NetMasterRate;
2395 else if (NetMode
= NET_CLIENT
) then
2397 MC_SEND_PlayerPos();
2399 end; // if gameOn ...
2401 // Активно окно интерфейса - передаем клавиши ему:
2402 {$IFDEF ENABLE_MENU}
2403 if g_ActiveWindow
<> nil then
2405 w
:= e_GetFirstKeyPressed();
2407 if (w
<> IK_INVALID
) then
2409 Msg
.Msg
:= MESSAGE_DIKEY
;
2411 g_ActiveWindow
.OnMessage(Msg
);
2414 // Если оно от этого не закрылось, то обновляем:
2415 if g_ActiveWindow
<> nil then
2416 g_ActiveWindow
.Update();
2418 // Нужно сменить разрешение:
2419 if gResolutionChange
then
2421 {$IFDEF ENABLE_RENDER}
2422 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2425 gResolutionChange
:= False;
2426 g_ActiveWindow
:= nil;
2429 // Нужно сменить язык:
2430 if gLanguageChange
then
2432 //e_WriteLog('Read language file', MSG_NOTIFY);
2433 //g_Language_Load(DataDir + gLanguage + '.txt');
2434 g_Language_Set(gLanguage
);
2436 gLanguageChange
:= False;
2440 // Горячая клавиша для вызова меню выхода из игры (F10):
2441 if e_KeyPressed(IK_F10
) and
2443 (not gConsoleShow
) and
2444 (g_ActiveWindow
= nil) then
2450 Time
:= GetTickCount64() {div 1000};
2452 // Обработка отложенных событий:
2453 if gDelayedEvents
<> nil then
2454 for a
:= 0 to High(gDelayedEvents
) do
2455 if gDelayedEvents
[a
].Pending
and
2457 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2458 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2461 case gDelayedEvents
[a
].DEType
of
2463 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2466 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2470 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2471 if g_Game_IsNet
and g_Game_IsServer
then
2472 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2476 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2478 gDelayedEvents
[a
].Pending
:= False;
2481 // Каждую секунду обновляем счетчик обновлений:
2482 UPSCounter
:= UPSCounter
+ 1;
2483 if Time
- UPSTime
>= 1000 then
2492 g_Weapon_AddDynLights();
2493 g_Items_AddDynLights();
2497 procedure g_Game_LoadChatSounds(Resource
: string);
2500 FileName
, Snd
: string;
2502 len
, cnt
, tags
, i
, j
: Integer;
2505 FileName
:= g_ExtractWadName(Resource
);
2507 WAD
:= TWADFile
.Create();
2508 WAD
.ReadFile(FileName
);
2510 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2517 cfg
:= TConfig
.CreateMem(p
, len
);
2518 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2520 SetLength(gChatSounds
, cnt
);
2521 for i
:= 0 to Length(gChatSounds
) - 1 do
2523 gChatSounds
[i
].Sound
:= nil;
2524 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2525 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2526 if (Snd
= '') or (Tags
<= 0) then
2528 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2529 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2530 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2531 SetLength(gChatSounds
[i
].Tags
, tags
);
2532 for j
:= 0 to tags
- 1 do
2533 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2534 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2541 procedure g_Game_FreeChatSounds();
2545 for i
:= 0 to Length(gChatSounds
) - 1 do
2547 gChatSounds
[i
].Sound
.Free();
2548 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2550 SetLength(gChatSounds
, 0);
2554 procedure g_Game_LoadData();
2556 if DataLoaded
then Exit
;
2558 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2559 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
2561 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2562 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2563 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2564 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2565 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2566 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2567 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2568 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2569 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2570 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2571 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2572 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2573 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2574 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2575 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2576 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2577 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2578 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2579 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2580 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2581 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2582 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2583 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2584 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2585 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2586 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2587 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2588 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2589 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2590 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2591 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2592 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2594 goodsnd
[0] := TPlayableSound
.Create();
2595 goodsnd
[1] := TPlayableSound
.Create();
2596 goodsnd
[2] := TPlayableSound
.Create();
2597 goodsnd
[3] := TPlayableSound
.Create();
2599 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2600 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2601 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2602 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2604 killsnd
[0] := TPlayableSound
.Create();
2605 killsnd
[1] := TPlayableSound
.Create();
2606 killsnd
[2] := TPlayableSound
.Create();
2607 killsnd
[3] := TPlayableSound
.Create();
2609 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2610 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2611 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2612 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2614 hahasnd
[0] := TPlayableSound
.Create();
2615 hahasnd
[1] := TPlayableSound
.Create();
2616 hahasnd
[2] := TPlayableSound
.Create();
2618 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2619 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2620 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2622 sound_get_flag
[0] := TPlayableSound
.Create();
2623 sound_get_flag
[1] := TPlayableSound
.Create();
2624 sound_lost_flag
[0] := TPlayableSound
.Create();
2625 sound_lost_flag
[1] := TPlayableSound
.Create();
2626 sound_ret_flag
[0] := TPlayableSound
.Create();
2627 sound_ret_flag
[1] := TPlayableSound
.Create();
2628 sound_cap_flag
[0] := TPlayableSound
.Create();
2629 sound_cap_flag
[1] := TPlayableSound
.Create();
2631 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2632 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2633 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2634 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2635 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2636 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2637 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2638 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2640 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2644 g_Weapon_LoadData();
2646 g_Monsters_LoadData();
2651 procedure g_Game_Quit();
2653 g_Game_StopAllSounds(True);
2656 g_PlayerModel_FreeData();
2657 {$IFDEF ENABLE_MENU}
2658 // g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2661 if NetInitDone
then g_Net_Free
;
2663 // remove map after test
2664 if gMapToDelete
<> '' then
2665 g_Game_DeleteTestMap();
2669 {$IFDEF ENABLE_SYSTEM}
2674 procedure g_Game_FreeData();
2676 if not DataLoaded
then Exit
;
2679 g_Weapon_FreeData();
2680 g_Monsters_FreeData();
2682 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2684 g_Sound_Delete('SOUND_GAME_TELEPORT');
2685 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2686 g_Sound_Delete('SOUND_GAME_SECRET');
2687 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2688 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2689 g_Sound_Delete('SOUND_GAME_BULK1');
2690 g_Sound_Delete('SOUND_GAME_BULK2');
2691 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2692 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2693 g_Sound_Delete('SOUND_GAME_BURNING');
2694 g_Sound_Delete('SOUND_GAME_SWITCH1');
2695 g_Sound_Delete('SOUND_GAME_SWITCH0');
2702 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2703 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2704 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2705 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2712 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2713 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2714 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2715 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2721 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2722 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2723 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2725 sound_get_flag
[0].Free();
2726 sound_get_flag
[1].Free();
2727 sound_lost_flag
[0].Free();
2728 sound_lost_flag
[1].Free();
2729 sound_ret_flag
[0].Free();
2730 sound_ret_flag
[1].Free();
2731 sound_cap_flag
[0].Free();
2732 sound_cap_flag
[1].Free();
2734 g_Sound_Delete('SOUND_CTF_GET1');
2735 g_Sound_Delete('SOUND_CTF_GET2');
2736 g_Sound_Delete('SOUND_CTF_LOST1');
2737 g_Sound_Delete('SOUND_CTF_LOST2');
2738 g_Sound_Delete('SOUND_CTF_RETURN1');
2739 g_Sound_Delete('SOUND_CTF_RETURN2');
2740 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2741 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2743 g_Game_FreeChatSounds();
2745 DataLoaded
:= False;
2748 procedure g_FatalError(Text: String);
2750 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2751 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2753 gExit
:= EXIT_SIMPLE
;
2754 if gGameOn
then EndGame
;
2757 procedure g_SimpleError(Text: String);
2759 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2760 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2763 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2765 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2766 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2769 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2772 if gPlayer1
= nil then
2774 if g_Game_IsClient
then
2776 if NetPlrUID1
> -1 then
2777 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2781 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2782 Team
:= gPlayer1Settings
.Team
;
2784 // Создание первого игрока:
2785 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2786 gPlayer1Settings
.Color
,
2788 if gPlayer1
= nil then
2789 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2792 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2793 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2794 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2795 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2796 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2797 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2798 if g_Game_IsServer
and g_Game_IsNet
then
2799 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2800 gPlayer1
.Respawn(False, True);
2801 g_Net_Slist_ServerPlayerComes();
2806 if gPlayer2
= nil then
2808 if g_Game_IsClient
then
2810 if NetPlrUID2
> -1 then
2811 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2815 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2816 Team
:= gPlayer2Settings
.Team
;
2818 // Создание второго игрока:
2819 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2820 gPlayer2Settings
.Color
,
2822 if gPlayer2
= nil then
2823 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2826 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2827 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2828 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2829 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2830 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2831 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2832 if g_Game_IsServer
and g_Game_IsNet
then
2833 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2834 gPlayer2
.Respawn(False, True);
2835 g_Net_Slist_ServerPlayerComes();
2842 procedure g_Game_RemovePlayer();
2846 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2847 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2852 if g_Game_IsServer
then
2855 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2856 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2857 g_Player_Remove(Pl
.UID
);
2858 g_Net_Slist_ServerPlayerLeaves();
2862 gSpectLatchPID2
:= Pl
.UID
;
2870 if g_Game_IsServer
then
2873 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2874 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2875 g_Player_Remove(Pl
.UID
);
2876 g_Net_Slist_ServerPlayerLeaves();
2879 gSpectLatchPID1
:= Pl
.UID
;
2881 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2885 g_Net_Slist_ServerPlayerLeaves();
2888 procedure g_Game_Spectate();
2890 g_Game_RemovePlayer();
2891 if gPlayer1
<> nil then
2892 g_Game_RemovePlayer();
2895 procedure g_Game_SpectateCenterView();
2897 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2898 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2901 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2908 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2910 g_Game_ClearLoading();
2913 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2916 gGameSettings
.GameType
:= GT_SINGLE
;
2917 gGameSettings
.MaxLives
:= 0;
2918 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2919 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2920 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2921 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2922 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2923 gSwitchGameMode
:= GM_SINGLE
;
2925 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2926 gLMSRespawnTime
:= 0;
2927 gSpectLatchPID1
:= 0;
2928 gSpectLatchPID2
:= 0;
2930 g_Game_ExecuteEvent('ongamestart');
2932 // Создание первого игрока:
2933 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2934 gPlayer1Settings
.Color
,
2935 gPlayer1Settings
.Team
, False));
2936 if gPlayer1
= nil then
2938 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2942 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2943 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2944 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2945 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2946 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2949 // Создание второго игрока, если есть:
2952 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2953 gPlayer2Settings
.Color
,
2954 gPlayer2Settings
.Team
, False));
2955 if gPlayer2
= nil then
2957 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2961 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2962 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2963 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2964 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2965 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2969 // Загрузка и запуск карты:
2970 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2972 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2973 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2977 // Настройки игроков и ботов:
2981 for i
:= nPl
+1 to nPlayers
do
2982 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2985 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2986 TimeLimit
, ScoreLimit
: Word;
2988 Options
: LongWord; nPlayers
: Byte);
2994 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2996 g_Game_ClearLoading();
2999 gGameSettings
.GameType
:= GT_CUSTOM
;
3000 gGameSettings
.GameMode
:= GameMode
;
3001 gSwitchGameMode
:= GameMode
;
3002 gGameSettings
.TimeLimit
:= TimeLimit
;
3003 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3004 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3005 gGameSettings
.Options
:= Options
;
3007 gCoopTotalMonstersKilled
:= 0;
3008 gCoopTotalSecretsFound
:= 0;
3009 gCoopTotalMonsters
:= 0;
3010 gCoopTotalSecrets
:= 0;
3014 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3015 gLMSRespawnTime
:= 0;
3016 gSpectLatchPID1
:= 0;
3017 gSpectLatchPID2
:= 0;
3019 g_Game_ExecuteEvent('ongamestart');
3021 // Режим наблюдателя:
3022 if nPlayers
= 0 then
3029 if nPlayers
>= 1 then
3031 // Создание первого игрока:
3032 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3033 gPlayer1Settings
.Color
,
3034 gPlayer1Settings
.Team
, False));
3035 if gPlayer1
= nil then
3037 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3041 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3042 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3043 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3044 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3045 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3049 if nPlayers
>= 2 then
3051 // Создание второго игрока:
3052 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3053 gPlayer2Settings
.Color
,
3054 gPlayer2Settings
.Team
, False));
3055 if gPlayer2
= nil then
3057 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3061 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3062 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3063 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3064 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3065 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3069 // Загрузка и запуск карты:
3070 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3072 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3076 // Нет точек появления:
3077 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3078 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3079 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3080 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3081 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3083 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3087 // Настройки игроков и ботов:
3091 for i
:= nPl
+1 to nPlayers
do
3092 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3095 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3096 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3097 Options
: LongWord; nPlayers
: Byte;
3098 IPAddr
: LongWord; Port
: Word);
3101 g_Net_Slist_ServerClosed();
3103 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3105 g_Game_ClearLoading();
3110 gGameSettings
.GameType
:= GT_SERVER
;
3111 gGameSettings
.GameMode
:= GameMode
;
3112 gSwitchGameMode
:= GameMode
;
3113 gGameSettings
.TimeLimit
:= TimeLimit
;
3114 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3115 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3116 gGameSettings
.Options
:= Options
;
3118 gCoopTotalMonstersKilled
:= 0;
3119 gCoopTotalSecretsFound
:= 0;
3120 gCoopTotalMonsters
:= 0;
3121 gCoopTotalSecrets
:= 0;
3125 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3126 gLMSRespawnTime
:= 0;
3127 gSpectLatchPID1
:= 0;
3128 gSpectLatchPID2
:= 0;
3130 g_Game_ExecuteEvent('ongamestart');
3132 // Режим наблюдателя:
3133 if nPlayers
= 0 then
3139 if nPlayers
>= 1 then
3141 // Создание первого игрока:
3142 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3143 gPlayer1Settings
.Color
,
3144 gPlayer1Settings
.Team
, False));
3145 if gPlayer1
= nil then
3147 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3151 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3152 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3153 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3154 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3155 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3158 if nPlayers
>= 2 then
3160 // Создание второго игрока:
3161 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3162 gPlayer2Settings
.Color
,
3163 gPlayer2Settings
.Team
, False));
3164 if gPlayer2
= nil then
3166 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3170 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3171 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3172 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3173 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3174 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3177 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3178 if NetForwardPorts
then
3179 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3182 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3184 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3188 g_Net_Slist_Set(NetMasterList
);
3190 g_Net_Slist_ServerStarted();
3192 // Загрузка и запуск карты:
3193 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3195 g_Net_Slist_ServerClosed();
3196 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3200 // Нет точек появления:
3201 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3202 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3203 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3204 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3205 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3207 g_Net_Slist_ServerClosed();
3208 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3212 // Настройки игроков и ботов:
3215 g_Net_Slist_ServerMapStarted();
3216 NetState
:= NET_STATE_GAME
;
3219 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3234 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3235 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3237 g_Game_ClearLoading();
3242 gGameSettings
.GameType
:= GT_CLIENT
;
3244 gCoopTotalMonstersKilled
:= 0;
3245 gCoopTotalSecretsFound
:= 0;
3246 gCoopTotalMonsters
:= 0;
3247 gCoopTotalSecrets
:= 0;
3251 g_Game_ExecuteEvent('ongamestart');
3253 NetState
:= NET_STATE_AUTH
;
3255 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3257 // create (or update) map/resource databases
3258 g_Res_CreateDatabases(true);
3260 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3261 gLMSRespawnTime
:= 0;
3262 gSpectLatchPID1
:= 0;
3263 gSpectLatchPID2
:= 0;
3266 if not g_Net_Connect(Addr
, Port
) then
3268 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3269 NetState
:= NET_STATE_NONE
;
3273 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3275 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3280 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3281 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3282 // thank you, enet. let's ignore failures altogether then.
3283 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3285 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3287 Ptr
:= NetEvent
.packet
^.data
;
3288 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3290 enet_packet_destroy(NetEvent
.packet
);
3294 InMsg
.ReadLongWord(); // skip size
3295 MID
:= InMsg
.ReadByte();
3297 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3299 NetMyID
:= InMsg
.ReadByte();
3300 NetPlrUID1
:= InMsg
.ReadWord();
3302 WadName
:= InMsg
.ReadString();
3303 Map
:= InMsg
.ReadString();
3305 gWADHash
:= InMsg
.ReadMD5();
3307 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3308 gSwitchGameMode
:= gGameSettings
.GameMode
;
3309 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3310 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3311 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3312 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3313 T
:= InMsg
.ReadLongWord();
3315 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3316 //if newResPath = '' then
3318 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3319 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3320 if newResPath
= '' then
3322 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3323 enet_packet_destroy(NetEvent
.packet
);
3324 NetState
:= NET_STATE_NONE
;
3327 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3329 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3332 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3333 gPlayer1Settings
.Color
,
3334 gPlayer1Settings
.Team
, False));
3336 if gPlayer1
= nil then
3338 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3340 enet_packet_destroy(NetEvent
.packet
);
3341 NetState
:= NET_STATE_NONE
;
3345 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3346 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3347 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3348 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3349 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3350 gPlayer1
.UID
:= NetPlrUID1
;
3351 gPlayer1
.Reset(True);
3353 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3355 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3357 enet_packet_destroy(NetEvent
.packet
);
3358 NetState
:= NET_STATE_NONE
;
3366 enet_packet_destroy(NetEvent
.packet
);
3370 enet_packet_destroy(NetEvent
.packet
);
3374 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3377 if (NetEvent
.data
<= NET_DISC_MAX
) then
3378 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3379 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3386 ProcessLoading(True);
3387 if g_Net_UserRequestExit() then
3396 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3397 NetState
:= NET_STATE_NONE
;
3402 NetState
:= NET_STATE_GAME
;
3403 MC_SEND_FullStateRequest
;
3404 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3408 lastAsMegaWad
: Boolean = false;
3410 procedure g_Game_ChangeMap(const MapPath
: String);
3414 g_Game_ClearLoading();
3416 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3417 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3418 if gExitByTrigger
then
3421 gExitByTrigger
:= False;
3423 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3424 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3427 procedure g_Game_Restart();
3431 if g_Game_IsClient
then
3433 map
:= g_ExtractFileName(gMapInfo
.Map
);
3434 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3438 g_Game_ClearLoading();
3439 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3442 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3444 NewWAD
, ResName
: String;
3448 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3450 {$IFDEF ENABLE_GIBS}
3453 {$IFDEF ENABLE_SHELLS}
3456 {$IFDEF ENABLE_CORPSES}
3457 g_Corpses_RemoveAll
;
3460 if (not g_Game_IsClient
) and
3461 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3462 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3464 if gSwitchGameMode
= GM_CTF
then
3465 gGameSettings
.MaxLives
:= 0;
3466 gGameSettings
.GameMode
:= gSwitchGameMode
;
3469 gSwitchGameMode
:= gGameSettings
.GameMode
;
3471 g_Player_ResetTeams();
3473 lastAsMegaWad
:= asMegawad
;
3474 if isWadPath(Map
) then
3476 NewWAD
:= g_ExtractWadName(Map
);
3477 ResName
:= g_ExtractFileName(Map
);
3478 if g_Game_IsServer
then
3480 nws
:= findDiskWad(NewWAD
);
3481 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3484 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3485 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3489 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3490 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3492 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3493 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3495 if (length(nws
) = 0) then
3497 ResName
:= ''; // failed
3502 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3503 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3504 g_Game_LoadWAD(NewWAD
);
3509 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3510 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3515 NewWAD
:= gGameSettings
.WAD
;
3521 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3523 if (ResName
<> '') and (NewWAD
<> '') then
3525 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3526 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3530 {$IFDEF ENABLE_RENDER}
3531 r_Render_LoadTextures
;
3534 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3536 gState
:= STATE_NONE
;
3537 {$IFDEF ENABLE_MENU}
3538 g_ActiveWindow
:= nil;
3543 wNeedTimeReset
:= True;
3545 if gGameSettings
.GameMode
= GM_CTF
then
3547 g_Map_ResetFlag(FLAG_RED
);
3548 g_Map_ResetFlag(FLAG_BLUE
);
3549 // CTF, а флагов нет:
3550 if not g_Map_HaveFlagPoints() then
3551 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3556 gState
:= STATE_MENU
;
3561 gPauseMain
:= false;
3562 gPauseHolmes
:= false;
3563 NetTimeToUpdate
:= 1;
3564 NetTimeToReliable
:= 0;
3565 NetTimeToMaster
:= NetMasterRate
;
3566 gSpectLatchPID1
:= 0;
3567 gSpectLatchPID2
:= 0;
3568 gMissionFailed
:= False;
3571 gCoopMonstersKilled
:= 0;
3572 gCoopSecretsFound
:= 0;
3574 gVoteInProgress
:= False;
3575 gVotePassed
:= False;
3581 if not gGameOn
then Exit
;
3583 g_Game_SpectateCenterView();
3585 if g_Game_IsServer
then
3587 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3589 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3590 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3591 gLMSSoftSpawn
:= True;
3592 if g_Game_IsNet
then
3593 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3597 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3598 gLMSRespawnTime
:= 0;
3602 if NetMode
= NET_SERVER
then
3604 // reset full state flags
3605 if NetClients
<> nil then
3606 for I
:= 0 to High(NetClients
) do
3607 NetClients
[I
].FullUpdateSent
:= False;
3609 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3612 g_Net_Slist_ServerMapStarted();
3614 if NetClients
<> nil then
3615 for I
:= 0 to High(NetClients
) do
3616 if NetClients
[I
].Used
then
3618 NetClients
[I
].Voted
:= False;
3619 if NetClients
[I
].RequestedFullUpdate
then
3621 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3622 NetClients
[I
].RequestedFullUpdate
:= False;
3626 g_Net_UnbanNonPermHosts();
3631 gCoopTotalMonstersKilled
:= 0;
3632 gCoopTotalSecretsFound
:= 0;
3633 gCoopTotalMonsters
:= 0;
3634 gCoopTotalSecrets
:= 0;
3638 g_Game_ExecuteEvent('onmapstart');
3641 procedure SetFirstLevel
;
3645 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3646 if MapList
= nil then
3649 SortSArray(MapList
);
3650 gNextMap
:= MapList
[Low(MapList
)];
3655 procedure g_Game_ExitLevel(const Map
: AnsiString);
3659 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3660 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3661 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3662 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3664 // Вышли в выход в Одиночной игре:
3665 if gGameSettings
.GameType
= GT_SINGLE
then
3666 gExit
:= EXIT_ENDLEVELSINGLE
3667 else // Вышли в выход в Своей игре
3669 gExit
:= EXIT_ENDLEVELCUSTOM
;
3670 if gGameSettings
.GameMode
= GM_COOP
then
3671 g_Player_RememberAll
;
3673 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3676 if gGameSettings
.GameMode
= GM_COOP
then
3679 gStatsPressed
:= True;
3680 gNextMap
:= 'MAP01';
3682 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3685 if g_Game_IsNet
then
3687 MH_SEND_GameStats();
3688 MH_SEND_CoopStats();
3694 procedure g_Game_RestartLevel();
3698 if gGameSettings
.GameMode
= GM_SINGLE
then
3703 gExit
:= EXIT_ENDLEVELCUSTOM
;
3704 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3708 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3710 gWAD
{, xwad}: String;
3713 if not g_Game_IsClient
then Exit
;
3714 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3716 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3721 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3725 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3728 g_Game_LoadWAD(NewWAD
);
3732 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3733 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3736 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3737 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3741 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3745 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3746 g_Game_LoadWAD(NewWAD);
3750 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3752 i
, n
, nb
, nr
: Integer;
3754 if not g_Game_IsServer
then Exit
;
3755 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3756 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3757 gLMSRespawnTime
:= 0;
3760 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3762 gMissionFailed
:= True;
3763 g_Game_RestartLevel
;
3767 n
:= 0; nb
:= 0; nr
:= 0;
3768 for i
:= Low(gPlayers
) to High(gPlayers
) do
3769 if (gPlayers
[i
] <> nil) and
3770 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3771 (gPlayers
[i
] is TBot
)) then
3774 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3775 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3778 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3780 // wait a second until the fuckers finally decide to join
3781 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3782 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3783 gLMSSoftSpawn
:= NoMapRestart
;
3784 if g_Game_IsNet
then
3785 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3789 {$IFDEF ENABLE_GIBS}
3792 {$IFDEF ENABLE_SHELLS}
3795 {$IFDEF ENABLE_CORPSES}
3796 g_Corpses_RemoveAll
;
3799 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3800 if g_Game_IsNet
then
3801 MH_SEND_GameEvent(NET_EV_LMS_START
);
3803 for i
:= Low(gPlayers
) to High(gPlayers
) do
3805 if gPlayers
[i
] = nil then continue
;
3806 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3807 // don't touch normal spectators
3808 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3810 gPlayers
[i
].FNoRespawn
:= True;
3811 gPlayers
[i
].Lives
:= 0;
3812 if g_Game_IsNet
then
3813 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3816 gPlayers
[i
].FNoRespawn
:= False;
3817 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3818 gPlayers
[i
].Respawn(False, True);
3819 if gGameSettings
.GameMode
= GM_COOP
then
3821 gPlayers
[i
].Frags
:= 0;
3822 gPlayers
[i
].RecallState
;
3824 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3825 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3826 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3827 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3830 g_Items_RestartRound();
3832 gLMSSoftSpawn
:= False;
3835 function g_Game_GetFirstMap(WAD
: String): String;
3839 MapList
:= g_Map_GetMapsList(WAD
);
3840 if MapList
= nil then
3843 SortSArray(MapList
);
3844 Result
:= MapList
[Low(MapList
)];
3846 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3852 function g_Game_GetNextMap(): String;
3859 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3860 if MapList
= nil then
3863 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3865 SortSArray(MapList
);
3867 for I
:= Low(MapList
) to High(MapList
) do
3868 if Map
= MapList
[I
] then
3874 if MapIndex
<> -255 then
3876 if MapIndex
= High(MapList
) then
3877 Result
:= MapList
[Low(MapList
)]
3879 Result
:= MapList
[MapIndex
+ 1];
3881 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3887 procedure g_Game_NextLevel();
3889 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3890 gExit
:= EXIT_ENDLEVELCUSTOM
3893 gExit
:= EXIT_ENDLEVELSINGLE
;
3897 if gNextMap
<> '' then Exit
;
3898 gNextMap
:= g_Game_GetNextMap();
3901 function g_Game_IsTestMap(): Boolean;
3903 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3906 procedure g_Game_DeleteTestMap();
3909 //MapName: AnsiString;
3917 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3918 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3919 if (a
= 0) then exit
;
3921 // Выделяем имя wad-файла и имя карты
3922 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3923 Delete(gMapToDelete
, 1, a
+5);
3924 gMapToDelete
:= UpperCase(gMapToDelete
);
3926 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3929 // Имя карты не стандартное тестовое:
3930 if MapName <> TEST_MAP_NAME then
3933 if not gTempDelete then
3935 time := g_GetFileTime(WadName);
3936 WAD := TWADFile.Create();
3939 if not WAD.ReadFile(WadName) then
3940 begin // Нет такого WAD-файла
3945 // Составляем список карт и ищем нужную:
3947 MapList := WAD.GetResourcesList('');
3949 if MapList <> nil then
3950 for a := 0 to High(MapList) do
3951 if MapList[a] = MapName then
3953 // Удаляем и сохраняем:
3954 WAD.RemoveResource('', MapName);
3955 WAD.SaveTo(WadName);
3960 g_SetFileTime(WadName, time);
3963 if gTempDelete
then DeleteFile(WadName
);
3966 procedure GameCVars(P
: SSArray
);
3969 stat
: TPlayerStatArray
;
3972 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3976 if Length(P
) > 1 then
3981 gsGameFlags
:= gsGameFlags
or Flag
3983 gsGameFlags
:= gsGameFlags
and (not Flag
);
3985 if g_Game_IsServer
then
3988 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3990 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3991 if g_Game_IsNet
then MH_SEND_GameSettings
;
3995 if LongBool(gsGameFlags
and Flag
) then
3996 g_Console_Add(_lc
[OnMsg
])
3998 g_Console_Add(_lc
[OffMsg
]);
4000 if OnMapChange
and g_Game_IsServer
then
4001 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4006 cmd
:= LowerCase(P
[0]);
4008 if cmd
= 'g_gamemode' then
4010 if (Length(P
) > 1) then
4012 a
:= g_Game_TextToMode(P
[1]);
4013 if a
= GM_SINGLE
then a
:= GM_COOP
;
4014 gsGameMode
:= g_Game_ModeToText(a
);
4015 if g_Game_IsServer
then
4017 gSwitchGameMode
:= a
;
4018 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4019 (gState
= STATE_INTERSINGLE
) then
4020 gSwitchGameMode
:= GM_SINGLE
;
4022 gGameSettings
.GameMode
:= gSwitchGameMode
;
4026 if gSwitchGameMode
= gGameSettings
.GameMode
then
4027 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4028 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4030 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4031 [g_Game_ModeToText(gGameSettings
.GameMode
),
4032 g_Game_ModeToText(gSwitchGameMode
)]));
4034 else if cmd
= 'g_friendlyfire' then
4036 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4038 else if cmd
= 'g_friendly_absorb_damage' then
4040 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
4042 else if cmd
= 'g_friendly_hit_trace' then
4044 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
4046 else if cmd
= 'g_friendly_hit_projectile' then
4048 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
4050 else if cmd
= 'g_weaponstay' then
4052 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
4054 else if cmd
= 'g_allow_exit' then
4056 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
4058 else if cmd
= 'g_allow_monsters' then
4060 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
4062 else if cmd
= 'g_allow_dropflag' then
4064 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
4066 else if cmd
= 'g_throw_flag' then
4068 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
4070 else if cmd
= 'g_bot_vsplayers' then
4072 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4074 else if cmd
= 'g_bot_vsmonsters' then
4076 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4078 else if cmd
= 'g_dm_keys' then
4080 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4082 else if cmd
= 'g_gameflags' then
4084 if Length(P
) > 1 then
4086 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4087 if g_Game_IsServer
then
4089 gGameSettings
.Options
:= gsGameFlags
;
4090 if g_Game_IsNet
then MH_SEND_GameSettings
;
4094 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4096 else if cmd
= 'g_warmup_time' then
4098 if Length(P
) > 1 then
4100 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4101 if g_Game_IsServer
then
4103 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4104 // extend warmup if it's already going
4105 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4107 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4108 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4110 if g_Game_IsNet
then MH_SEND_GameSettings
;
4114 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4115 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4117 else if cmd
= 'g_spawn_invul' then
4119 if Length(P
) > 1 then
4121 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4122 if g_Game_IsServer
then
4124 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4125 if g_Game_IsNet
then MH_SEND_GameSettings
;
4129 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4131 else if cmd
= 'g_item_respawn_time' then
4133 if Length(P
) > 1 then
4135 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4136 if g_Game_IsServer
then
4138 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4139 if g_Game_IsNet
then MH_SEND_GameSettings
;
4143 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4144 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4146 else if cmd
= 'sv_intertime' then
4148 if (Length(P
) > 1) then
4149 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4151 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4153 else if cmd
= 'g_max_particles' then
4155 if Length(p
) = 2 then
4158 a
:= Max(0, StrToIntDef(p
[1], 0));
4162 else if Length(p
) = 1 then
4165 e_LogWritefln('%s', [g_GFX_GetMax()])
4167 e_LogWritefln('%s', [0])
4172 e_LogWritefln('usage: %s <n>', [cmd
])
4175 else if cmd
= 'g_max_shells' then
4177 if Length(p
) = 2 then
4179 {$IFDEF ENABLE_SHELLS}
4180 a
:= Max(0, StrToIntDef(p
[1], 0));
4184 else if Length(p
) = 1 then
4186 {$IFDEF ENABLE_SHELLS}
4187 e_LogWritefln('%s', [g_Shells_GetMax()])
4189 e_LogWritefln('%s', [0])
4194 e_LogWritefln('usage: %s <n>', [cmd
])
4197 else if cmd
= 'g_max_gibs' then
4199 if Length(p
) = 2 then
4201 {$IFDEF ENABLE_GIBS}
4202 a
:= Max(0, StrToIntDef(p
[1], 0));
4206 else if Length(p
) = 1 then
4208 {$IFDEF ENABLE_GIBS}
4209 e_LogWritefln('%s', [g_Gibs_GetMax()])
4211 e_LogWritefln('%s', [0])
4216 e_LogWritefln('usage: %s <n>', [cmd
])
4219 else if cmd
= 'g_max_corpses' then
4221 if Length(p
) = 2 then
4223 {$IFDEF ENABLE_CORPSES}
4224 a
:= Max(0, StrToIntDef(p
[1], 0));
4228 else if Length(p
) = 1 then
4230 {$IFDEF ENABLE_CORPSES}
4231 e_LogWritefln('%s', [g_Corpses_GetMax()])
4233 e_LogWritefln('%s', [0])
4238 e_LogWritefln('usage: %s <n>', [cmd
])
4241 else if cmd
= 'g_force_model' then
4243 if Length(p
) = 2 then
4245 a
:= StrToIntDef(p
[1], 0);
4246 g_Force_Model_Set(a
);
4247 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4249 for a
:= Low(gPlayers
) to High(gPlayers
) do
4251 if (gPlayers
[a
] <> nil) then
4253 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4255 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4257 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4261 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4263 for a
:= Low(gPlayers
) to High(gPlayers
) do
4265 if (gPlayers
[a
] <> nil) then
4267 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4269 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4271 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4277 else if cmd
= 'g_force_model_name' then
4279 if (Length(P
) > 1) then
4281 cmd
:= b_Text_Unformat(P
[1]);
4282 g_Forced_Model_SetName(cmd
);
4283 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4285 for a
:= Low(gPlayers
) to High(gPlayers
) do
4287 if (gPlayers
[a
] <> nil) then
4289 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4291 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4293 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4299 else if cmd
= 'g_scorelimit' then
4301 if Length(P
) > 1 then
4303 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4305 if g_Game_IsServer
then
4308 if gGameSettings
.GameMode
= GM_DM
then
4310 stat
:= g_Player_GetStats();
4312 for a
:= 0 to High(stat
) do
4313 if stat
[a
].Frags
> b
then
4317 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4319 // if someone has a higher score, set it to that instead
4320 gsScoreLimit
:= max(gsScoreLimit
, b
);
4321 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4323 if g_Game_IsNet
then MH_SEND_GameSettings
;
4327 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4329 else if cmd
= 'g_timelimit' then
4331 if Length(P
) > 1 then
4333 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4334 if g_Game_IsServer
then
4336 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4337 if g_Game_IsNet
then MH_SEND_GameSettings
;
4340 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4341 [gsTimeLimit
div 3600,
4342 (gsTimeLimit
div 60) mod 60,
4343 gsTimeLimit
mod 60]));
4345 else if cmd
= 'g_max_bots' then
4347 if Length(P
) > 1 then
4348 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4349 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4351 else if cmd
= 'g_maxlives' then
4353 if Length(P
) > 1 then
4355 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4356 if g_Game_IsServer
then
4358 gGameSettings
.MaxLives
:= gsMaxLives
;
4359 if g_Game_IsNet
then MH_SEND_GameSettings
;
4363 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4367 procedure PlayerSettingsCVars(P
: SSArray
);
4372 function ParseTeam(s
: string): Byte;
4376 'red', '1': result
:= TEAM_RED
;
4377 'blue', '2': result
:= TEAM_BLUE
;
4378 else result
:= TEAM_NONE
;
4382 cmd
:= LowerCase(P
[0]);
4386 if (Length(P
) > 1) then
4388 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4389 if g_Game_IsClient
then
4390 MC_SEND_PlayerSettings
4391 else if gGameOn
and (gPlayer1
<> nil) then
4393 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4394 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4400 if (Length(P
) > 1) then
4402 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4403 if g_Game_IsClient
then
4404 MC_SEND_PlayerSettings
4405 else if gGameOn
and (gPlayer2
<> nil) then
4407 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4408 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4414 if Length(P
) > 3 then
4416 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4417 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4418 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4419 if g_Game_IsClient
then
4420 MC_SEND_PlayerSettings
4421 else if gGameOn
and (gPlayer1
<> nil) then
4423 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4424 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4430 if Length(P
) > 3 then
4432 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4433 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4434 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4435 if g_Game_IsClient
then
4436 MC_SEND_PlayerSettings
4437 else if gGameOn
and (gPlayer2
<> nil) then
4439 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4440 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4446 if (Length(P
) > 1) then
4448 gPlayer1Settings
.Model
:= P
[1];
4449 if g_Game_IsClient
then
4450 MC_SEND_PlayerSettings
4451 else if gGameOn
and (gPlayer1
<> nil) then
4453 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4454 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4455 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4461 if (Length(P
) > 1) then
4463 gPlayer2Settings
.Model
:= P
[1];
4464 if g_Game_IsClient
then
4465 MC_SEND_PlayerSettings
4466 else if gGameOn
and (gPlayer2
<> nil) then
4468 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4469 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4470 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4476 // TODO: switch teams if in game or store this separately
4477 if (Length(P
) > 1) then
4479 team
:= ParseTeam(P
[1]);
4480 if team
= TEAM_NONE
then
4481 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4482 else if not gGameOn
and not g_Game_IsNet
then
4483 gPlayer1Settings
.Team
:= team
4485 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4490 // TODO: switch teams if in game or store this separately
4491 if (Length(P
) > 1) then
4493 team
:= ParseTeam(P
[1]);
4494 if team
= TEAM_NONE
then
4495 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4496 else if not gGameOn
and not g_Game_IsNet
then
4497 gPlayer2Settings
.Team
:= team
4499 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4504 if (Length(P
) = 2) then
4505 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4509 if (Length(P
) = 2) then
4510 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4514 if (Length(P
) = 2) then
4515 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4519 if (Length(P
) = 2) then
4520 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4524 if (Length(P
) = 2) then
4525 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4529 if (Length(P
) = 2) then
4530 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4532 'p1_priority_kastet':
4534 if (Length(P
) = 2) then
4535 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4537 'p2_priority_kastet':
4539 if (Length(P
) = 2) then
4540 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4544 if (Length(P
) = 2) then
4545 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4549 if (Length(P
) = 2) then
4550 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4552 'p1_priority_pistol':
4554 if (Length(P
) = 2) then
4555 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4557 'p2_priority_pistol':
4559 if (Length(P
) = 2) then
4560 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4562 'p1_priority_shotgun1':
4564 if (Length(P
) = 2) then
4565 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4567 'p2_priority_shotgun1':
4569 if (Length(P
) = 2) then
4570 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4572 'p1_priority_shotgun2':
4574 if (Length(P
) = 2) then
4575 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4577 'p2_priority_shotgun2':
4579 if (Length(P
) = 2) then
4580 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4582 'p1_priority_chaingun':
4584 if (Length(P
) = 2) then
4585 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4587 'p2_priority_chaingun':
4589 if (Length(P
) = 2) then
4590 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4592 'p1_priority_rocketlauncher':
4594 if (Length(P
) = 2) then
4595 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4597 'p2_priority_rocketlauncher':
4599 if (Length(P
) = 2) then
4600 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4602 'p1_priority_plasma':
4604 if (Length(P
) = 2) then
4605 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4607 'p2_priority_plasma':
4609 if (Length(P
) = 2) then
4610 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4614 if (Length(P
) = 2) then
4615 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4619 if (Length(P
) = 2) then
4620 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4622 'p1_priority_super':
4624 if (Length(P
) = 2) then
4625 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4627 'p2_priority_super':
4629 if (Length(P
) = 2) then
4630 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4632 'p1_priority_flamethrower':
4634 if (Length(P
) = 2) then
4635 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4637 'p2_priority_flamethrower':
4639 if (Length(P
) = 2) then
4640 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4642 'p1_priority_berserk':
4644 if (Length(P
) = 2) then
4645 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4647 'p2_priority_berserk':
4649 if (Length(P
) = 2) then
4650 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4655 procedure PrintHeapStats();
4659 hs
:= GetFPCHeapStatus();
4660 e_LogWriteLn ('v===== heap status =====v');
4661 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4662 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4663 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4664 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4665 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4666 e_LogWriteLn ('^=======================^');
4669 procedure DebugCommands(P
: SSArray
);
4676 // Команды отладочного режима:
4677 if {gDebugMode}conIsCheatsEnabled
then
4679 cmd
:= LowerCase(P
[0]);
4680 if cmd
= 'd_window' then
4682 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4683 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4685 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4687 if (Length(P
) > 1) and
4688 ((P
[1] = '1') or (P
[1] = '0')) then
4689 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4691 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4693 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4695 if Length(P
) > 1 then
4697 '0': g_debug_BotAIOff
:= 0;
4698 '1': g_debug_BotAIOff
:= 1;
4699 '2': g_debug_BotAIOff
:= 2;
4700 '3': g_debug_BotAIOff
:= 3;
4703 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4705 else if cmd
= 'd_monster' then
4707 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4708 if Length(P
) < 2 then
4710 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4711 g_Console_Add('ID | Name');
4712 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4713 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4714 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4717 a
:= StrToIntDef(P
[1], 0);
4718 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4719 a
:= g_Mons_TypeIdByName(P
[1]);
4721 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4722 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4725 with gPlayer1
.Obj
do
4727 mon
:= g_Monsters_Create(a
,
4728 X
+ Rect
.X
+ (Rect
.Width
div 2),
4729 Y
+ Rect
.Y
+ Rect
.Height
,
4730 gPlayer1
.Direction
, True);
4732 if (Length(P
) > 2) and (mon
<> nil) then
4734 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4735 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4736 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4737 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4738 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4739 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4740 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4741 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4742 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4747 else if (cmd
= 'd_player') then
4749 if (Length(P
) > 1) and
4750 ((P
[1] = '1') or (P
[1] = '0')) then
4751 g_debug_Player
:= (P
[1][1] = '1');
4753 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4755 else if (cmd
= 'd_mem') then
4761 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4765 procedure GameCheats(P
: SSArray
);
4771 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4773 g_Console_Add('not available');
4779 g_Console_Add('where is the player?!');
4782 cmd
:= LowerCase(P
[0]);
4786 plr
.GodMode
:= not plr
.GodMode
;
4787 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4790 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4791 if cmd
= 'give' then
4793 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4794 for f
:= 1 to High(P
) do
4796 cmd
:= LowerCase(P
[f
]);
4797 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4798 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4799 if cmd
= 'exit' then
4801 if gTriggers
<> nil then
4803 for a
:= 0 to High(gTriggers
) do
4805 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4807 g_Console_Add('player left the map');
4808 gExitByTrigger
:= True;
4809 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4810 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4818 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4819 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4820 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4821 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4822 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4824 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4825 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4827 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4828 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;
4830 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4831 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4833 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4834 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4836 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4837 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4839 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4840 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4841 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4843 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4844 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4845 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4846 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;
4847 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4848 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4850 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;
4851 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;
4852 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;
4853 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;
4854 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;
4855 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;
4857 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4858 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;
4860 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;
4861 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;
4863 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4865 if cmd
= 'ammo' then
4867 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4868 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4869 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4870 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4871 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4872 g_Console_Add('player got some ammo');
4876 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4877 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4879 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4880 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4882 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4883 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4885 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4886 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4888 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4890 if cmd
= 'weapons' then
4892 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4893 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4894 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4895 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4896 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4897 plr
.GiveItem(ITEM_WEAPON_BFG
);
4898 g_Console_Add('player got weapons');
4902 if cmd
= 'keys' then
4904 plr
.GiveItem(ITEM_KEY_RED
);
4905 plr
.GiveItem(ITEM_KEY_GREEN
);
4906 plr
.GiveItem(ITEM_KEY_BLUE
);
4907 g_Console_Add('player got all keys');
4911 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4916 if cmd
= 'open' then
4918 g_Console_Add('player activated sesame');
4919 g_Triggers_OpenAll();
4926 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4930 if cmd
= 'noclip' then
4933 g_Console_Add('wall hardeness adjusted');
4937 if cmd
= 'notarget' then
4939 plr
.NoTarget
:= not plr
.NoTarget
;
4940 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4944 if cmd
= 'noreload' then
4946 plr
.NoReload
:= not plr
.NoReload
;
4947 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4951 if cmd
= 'speedy' then
4953 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4954 g_Console_Add('speed adjusted');
4958 if cmd
= 'jumpy' then
4960 VEL_JUMP
:= 30-VEL_JUMP
;
4961 g_Console_Add('jump height adjusted');
4965 if cmd
= 'automap' then
4967 gShowMap
:= not gShowMap
;
4968 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4972 if cmd
= 'aimline' then
4974 gAimLine
:= not gAimLine
;
4975 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4980 procedure GameCommands(P
: SSArray
);
4986 pl
: pTNetClient
= nil;
4994 cmd
:= LowerCase(P
[0]);
4996 if cmd
= 'pause' then
4998 {$IFDEF ENABLE_MENU}
4999 if (g_ActiveWindow
= nil) then
5000 g_Game_Pause(not gPauseMain
);
5002 g_Game_Pause(not gPauseMain
);
5005 else if cmd
= 'endgame' then
5006 gExit
:= EXIT_SIMPLE
5007 else if cmd
= 'restart' then
5009 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5011 if g_Game_IsClient
then
5013 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5018 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5020 else if cmd
= 'kick' then
5022 if g_Game_IsServer
then
5024 if Length(P
) < 2 then
5026 g_Console_Add('kick <name>');
5031 g_Console_Add('kick <name>');
5035 if g_Game_IsNet
then
5036 pl
:= g_Net_Client_ByName(P
[1]);
5039 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5040 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5041 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5042 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5043 g_Net_Slist_ServerPlayerLeaves();
5044 end else if gPlayers
<> nil then
5045 for a
:= Low(gPlayers
) to High(gPlayers
) do
5046 if gPlayers
[a
] <> nil then
5047 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5049 // Не отключать основных игроков в сингле
5050 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5052 gPlayers
[a
].Lives
:= 0;
5053 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5054 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5055 g_Player_Remove(gPlayers
[a
].UID
);
5056 g_Net_Slist_ServerPlayerLeaves();
5057 // Если не перемешать, при добавлении новых ботов появятся старые
5061 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5063 else if cmd
= 'kick_id' then
5065 if g_Game_IsServer
and g_Game_IsNet
then
5067 if Length(P
) < 2 then
5069 g_Console_Add('kick_id <client ID>');
5074 g_Console_Add('kick_id <client ID>');
5078 a
:= StrToIntDef(P
[1], 0);
5079 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5081 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5083 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5084 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
5085 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5086 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5087 g_Net_Slist_ServerPlayerLeaves();
5091 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5093 else if cmd
= 'kick_pid' then
5095 if g_Game_IsServer
and g_Game_IsNet
then
5097 if Length(P
) < 2 then
5099 g_Console_Add('kick_pid <player ID>');
5104 g_Console_Add('kick_pid <player ID>');
5108 a
:= StrToIntDef(P
[1], 0);
5109 pl
:= g_Net_Client_ByPlayer(a
);
5110 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5112 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5113 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5114 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5115 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5116 g_Net_Slist_ServerPlayerLeaves();
5119 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5121 else if cmd
= 'ban' then
5123 if g_Game_IsServer
and g_Game_IsNet
then
5125 if Length(P
) < 2 then
5127 g_Console_Add('ban <name>');
5132 g_Console_Add('ban <name>');
5136 pl
:= g_Net_Client_ByName(P
[1]);
5139 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5140 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5141 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5142 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5143 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5144 g_Net_Slist_ServerPlayerLeaves();
5146 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5148 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5150 else if cmd
= 'ban_id' then
5152 if g_Game_IsServer
and g_Game_IsNet
then
5154 if Length(P
) < 2 then
5156 g_Console_Add('ban_id <client ID>');
5161 g_Console_Add('ban_id <client ID>');
5165 a
:= StrToIntDef(P
[1], 0);
5166 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5167 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5169 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5170 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5171 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5172 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5173 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5174 g_Net_Slist_ServerPlayerLeaves();
5177 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5179 else if cmd
= 'ban_pid' then
5181 if g_Game_IsServer
and g_Game_IsNet
then
5183 if Length(P
) < 2 then
5185 g_Console_Add('ban_pid <player ID>');
5190 g_Console_Add('ban_pid <player ID>');
5194 a
:= StrToIntDef(P
[1], 0);
5195 pl
:= g_Net_Client_ByPlayer(a
);
5196 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5198 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5199 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5200 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5201 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5202 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5203 g_Net_Slist_ServerPlayerLeaves();
5206 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5208 else if cmd
= 'permban' then
5210 if g_Game_IsServer
and g_Game_IsNet
then
5212 if Length(P
) < 2 then
5214 g_Console_Add('permban <name>');
5219 g_Console_Add('permban <name>');
5223 pl
:= g_Net_Client_ByName(P
[1]);
5226 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5227 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5228 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5229 g_Net_SaveBanList();
5230 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5231 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5232 g_Net_Slist_ServerPlayerLeaves();
5234 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5236 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5238 else if cmd
= 'permban_id' then
5240 if g_Game_IsServer
and g_Game_IsNet
then
5242 if Length(P
) < 2 then
5244 g_Console_Add('permban_id <client ID>');
5249 g_Console_Add('permban_id <client ID>');
5253 a
:= StrToIntDef(P
[1], 0);
5254 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5255 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5257 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5258 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5259 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5260 g_Net_SaveBanList();
5261 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5262 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5263 g_Net_Slist_ServerPlayerLeaves();
5266 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5268 else if cmd
= 'permban_pid' then
5270 if g_Game_IsServer
and g_Game_IsNet
then
5272 if Length(P
) < 2 then
5274 g_Console_Add('permban_pid <player ID>');
5279 g_Console_Add('permban_pid <player ID>');
5283 a
:= StrToIntDef(P
[1], 0);
5284 pl
:= g_Net_Client_ByPlayer(a
);
5285 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5287 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5288 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5289 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5290 g_Net_SaveBanList();
5291 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5292 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5293 g_Net_Slist_ServerPlayerLeaves();
5296 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5298 else if cmd
= 'permban_ip' then
5300 if g_Game_IsServer
and g_Game_IsNet
then
5302 if Length(P
) < 2 then
5304 g_Console_Add('permban_ip <IP address>');
5309 g_Console_Add('permban_ip <IP address>');
5313 g_Net_BanHost(P
[1]);
5314 g_Net_SaveBanList();
5315 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5317 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5319 else if cmd
= 'unban' then
5321 if g_Game_IsServer
and g_Game_IsNet
then
5323 if Length(P
) < 2 then
5325 g_Console_Add('unban <IP Address>');
5330 g_Console_Add('unban <IP Address>');
5334 if g_Net_UnbanHost(P
[1]) then
5336 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5337 g_Net_SaveBanList();
5339 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5341 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5343 else if cmd
= 'clientlist' then
5345 if g_Game_IsServer
and g_Game_IsNet
then
5348 if NetClients
<> nil then
5349 for a
:= Low(NetClients
) to High(NetClients
) do
5350 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5352 plr
:= g_Player_Get(NetClients
[a
].Player
);
5353 if plr
= nil then continue
;
5355 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5356 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5359 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5361 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5363 else if cmd
= 'connect' then
5365 if (NetMode
= NET_NONE
) then
5367 if Length(P
) < 2 then
5369 g_Console_Add('connect <IP> [port] [password]');
5374 g_Console_Add('connect <IP> [port] [password]');
5378 if Length(P
) > 2 then
5379 prt
:= StrToIntDef(P
[2], 25666)
5383 if Length(P
) > 3 then
5388 g_Game_StartClient(P
[1], prt
, pw
);
5391 else if cmd
= 'disconnect' then
5393 if (NetMode
= NET_CLIENT
) then
5396 else if cmd
= 'reconnect' then
5398 if (NetMode
= NET_SERVER
) then
5401 if (NetMode
= NET_CLIENT
) then
5404 gExit
:= EXIT_SIMPLE
;
5408 //TODO: Use last successful password to reconnect, instead of ''
5409 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5411 else if (cmd
= 'addbot') or
5412 (cmd
= 'bot_add') then
5414 if Length(P
) > 2 then
5415 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5416 else if Length(P
) > 1 then
5417 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5419 g_Bot_Add(TEAM_NONE
, 2);
5421 else if cmd
= 'bot_addlist' then
5423 if Length(P
) > 1 then
5425 if Length(P
) = 2 then
5426 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5427 else if Length(P
) = 3 then
5428 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5430 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5433 else if cmd
= 'bot_removeall' then
5435 else if cmd
= 'chat' then
5437 if g_Game_IsNet
then
5439 if Length(P
) > 1 then
5441 for a
:= 1 to High(P
) do
5442 chstr
:= chstr
+ P
[a
] + ' ';
5444 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5446 if Length(chstr
) < 1 then
5448 g_Console_Add('chat <text>');
5452 chstr
:= b_Text_Format(chstr
);
5453 if g_Game_IsClient
then
5454 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5456 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5459 g_Console_Add('chat <text>');
5461 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5463 else if cmd
= 'teamchat' then
5465 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5467 if Length(P
) > 1 then
5469 for a
:= 1 to High(P
) do
5470 chstr
:= chstr
+ P
[a
] + ' ';
5472 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5474 if Length(chstr
) < 1 then
5476 g_Console_Add('teamchat <text>');
5480 chstr
:= b_Text_Format(chstr
);
5481 if g_Game_IsClient
then
5482 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5484 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5485 gPlayer1Settings
.Team
);
5488 g_Console_Add('teamchat <text>');
5490 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5492 else if (cmd
= 'an') or (cmd
= 'announce') then
5494 if g_Game_IsNet
then
5496 if Length(P
) > 1 then
5498 for a
:= 1 to High(P
) do
5499 chstr
:= chstr
+ P
[a
] + ' ';
5501 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5503 if Length(chstr
) < 1 then
5505 g_Console_Add('announce <text>');
5509 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5510 if g_Game_IsClient
then
5511 MC_SEND_RCONCommand(chstr
)
5513 g_Console_Process(chstr
, True);
5516 g_Console_Add('announce <text>');
5518 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5520 else if cmd
= 'game' then
5522 if gGameSettings
.GameType
<> GT_NONE
then
5524 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5527 if Length(P
) = 1 then
5529 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5532 // game not started yet, load fist map from some wad
5534 s
:= addWadExtension(P
[1]);
5535 found
:= e_FindResource(AllMapDirs
, s
);
5539 P
[1] := ExpandFileName(P
[1]);
5540 // if map not choosed then set first map
5541 if Length(P
) < 3 then
5544 P
[2] := g_Game_GetFirstMap(P
[1]);
5547 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5549 if g_Map_Exist(s
) then
5553 with gGameSettings
do
5555 Options
:= gsGameFlags
;
5556 GameMode
:= g_Game_TextToMode(gsGameMode
);
5557 if gSwitchGameMode
<> GM_NONE
then
5558 GameMode
:= gSwitchGameMode
;
5559 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5560 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5562 if Length(P
) >= 4 then
5563 b
:= StrToIntDef(P
[3], 1);
5564 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5565 ScoreLimit
, MaxLives
, Options
, b
);
5570 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5572 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5574 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5576 else if cmd
= 'host' then
5578 if gGameSettings
.GameType
<> GT_NONE
then
5580 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5583 if Length(P
) < 4 then
5585 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5588 if not StrToIp(P
[1], listen
) then
5590 prt
:= StrToIntDef(P
[2], 25666);
5592 s
:= addWadExtension(P
[3]);
5593 found
:= e_FindResource(AllMapDirs
, s
);
5597 // get first map in wad, if not specified
5598 if Length(P
) < 5 then
5601 P
[4] := g_Game_GetFirstMap(P
[1]);
5603 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5604 if g_Map_Exist(s
) then
5608 with gGameSettings
do
5610 Options
:= gsGameFlags
;
5611 GameMode
:= g_Game_TextToMode(gsGameMode
);
5612 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5613 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5614 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5616 if Length(P
) >= 6 then
5617 b
:= StrToIntDef(P
[5], 0);
5618 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5624 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5626 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5631 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5634 else if cmd
= 'map' then
5636 if Length(P
) = 1 then
5638 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5640 g_Console_Add(cmd
+ ' <MAP>');
5641 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5645 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5650 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5652 if Length(P
) < 3 then
5654 // first param is map or wad
5655 s
:= UpperCase(P
[1]);
5656 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5658 gExitByTrigger
:= False;
5661 // already in game, finish current map
5663 gExit
:= EXIT_ENDLEVELCUSTOM
;
5667 // intermission, so change map immediately
5674 found
:= e_FindResource(AllMapDirs
, s
);
5676 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5679 // no such map, found wad
5682 P
[1] := ExpandFileName(pw
);
5683 P
[2] := g_Game_GetFirstMap(P
[1]);
5684 s
:= P
[1] + ':\' + P
[2];
5685 if g_Map_Exist(s
) then
5687 gExitByTrigger
:= False;
5690 // already in game, finish current map
5692 gExit
:= EXIT_ENDLEVELCUSTOM
5696 // intermission, so change map immediately
5703 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5705 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5710 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5716 s
:= addWadExtension(P
[1]);
5717 found
:= e_FindResource(AllMapDirs
, s
);
5721 P
[2] := UpperCase(P
[2]);
5722 s
:= P
[1] + ':\' + P
[2];
5723 if g_Map_Exist(s
) then
5725 gExitByTrigger
:= False;
5729 gExit
:= EXIT_ENDLEVELCUSTOM
5738 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5743 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5749 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5753 else if cmd
= 'nextmap' then
5755 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5757 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5762 if Length(P
) = 1 then
5764 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5766 g_Console_Add(cmd
+ ' <MAP>');
5767 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5772 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5778 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5780 if Length(P
) < 3 then
5782 // first param is map or wad
5783 s
:= UpperCase(P
[1]);
5784 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5787 gExitByTrigger
:= False;
5793 // no such map, found wad
5794 pw
:= addWadExtension(P
[1]);
5795 found
:= e_FindResource(MapDirs
, pw
);
5797 found
:= e_FindResource(WadDirs
, pw
);
5799 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5802 // map not specified, select first map
5804 P
[2] := g_Game_GetFirstMap(P
[1]);
5805 s
:= P
[1] + ':\' + P
[2];
5806 if g_Map_Exist(s
) then
5808 gExitByTrigger
:= False;
5815 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5817 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5822 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5828 // specified two params wad + map
5829 pw
:= addWadExtension(P
[1]);
5830 found
:= e_FindResource(MapDirs
, pw
);
5832 found
:= e_FindResource(MapDirs
, pw
);
5836 P
[2] := UpperCase(P
[2]);
5837 s
:= P
[1] + ':\' + P
[2];
5838 if g_Map_Exist(s
) then
5840 gExitByTrigger
:= False;
5846 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5851 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5857 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5862 if gNextMap
= '' then
5863 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5865 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5869 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5873 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5877 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5879 gExitByTrigger
:= False;
5880 // next map not specified, try to find trigger EXIT
5881 if (gNextMap
= '') and (gTriggers
<> nil) then
5883 for a
:= 0 to High(gTriggers
) do
5885 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5887 gExitByTrigger
:= True;
5888 //gNextMap := gTriggers[a].Data.MapName;
5889 gNextMap
:= gTriggers
[a
].tgcMap
;
5894 if gNextMap
= '' then
5895 gNextMap
:= g_Game_GetNextMap();
5896 if not isWadPath(gNextMap
) then
5897 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5900 if g_Map_Exist(s
) then
5901 gExit
:= EXIT_ENDLEVELCUSTOM
5903 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5907 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5911 else if (cmd
= 'event') then
5913 if (Length(P
) <= 1) then
5915 for a
:= 0 to High(gEvents
) do
5916 if gEvents
[a
].Command
= '' then
5917 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5919 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5922 if (Length(P
) = 2) then
5924 for a
:= 0 to High(gEvents
) do
5925 if gEvents
[a
].Name
= P
[1] then
5926 if gEvents
[a
].Command
= '' then
5927 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5929 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5932 for a
:= 0 to High(gEvents
) do
5933 if gEvents
[a
].Name
= P
[1] then
5935 gEvents
[a
].Command
:= '';
5936 for b
:= 2 to High(P
) do
5937 if Pos(' ', P
[b
]) = 0 then
5938 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5940 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5941 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5945 else if cmd
= 'suicide' then
5949 if g_Game_IsClient
then
5950 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5953 if gPlayer1
<> nil then
5954 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5955 if gPlayer2
<> nil then
5956 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5960 else if cmd
= 'screenshot' then
5962 {$IFDEF ENABLE_RENDER}
5963 r_Render_RequestScreenShot
;
5966 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5968 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5970 gWeaponAction
[0, WP_PREV
] := True;
5972 gWeaponAction
[0, WP_NEXT
] := True;
5974 else if cmd
= 'weapon' then
5976 if Length(p
) = 2 then
5978 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5979 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5980 gSelectWeapon
[0, a
] := True
5983 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5984 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5986 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5987 b
:= ord(cmd
[2]) - ord('1');
5989 gWeaponAction
[b
, WP_PREV
] := True;
5991 gWeaponAction
[b
, WP_NEXT
] := True;
5993 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5995 if Length(p
) = 2 then
5997 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5998 b
:= ord(cmd
[2]) - ord('1');
5999 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6000 gSelectWeapon
[b
, a
] := True
6003 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
6005 b
:= ord(cmd
[2]) - ord('1');
6007 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
6009 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
6011 else if (cmd
= 'dropflag') then
6013 if g_Game_IsServer
then
6015 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
6016 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
6019 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6021 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
6023 b
:= ord(cmd
[2]) - ord('1');
6024 if g_Game_IsServer
then
6026 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
6027 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
6030 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6032 // Команды Своей игры:
6033 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6035 if cmd
= 'bot_addred' then
6037 if Length(P
) > 1 then
6038 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6040 g_Bot_Add(TEAM_RED
, 2);
6042 else if cmd
= 'bot_addblue' then
6044 if Length(P
) > 1 then
6045 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6047 g_Bot_Add(TEAM_BLUE
, 2);
6049 else if cmd
= 'spectate' then
6055 else if cmd
= 'say' then
6057 if g_Game_IsServer
and g_Game_IsNet
then
6059 if Length(P
) > 1 then
6062 for a
:= 1 to High(P
) do
6063 chstr
:= chstr
+ P
[a
] + ' ';
6065 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6067 if Length(chstr
) < 1 then
6069 g_Console_Add('say <text>');
6073 chstr
:= b_Text_Format(chstr
);
6074 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6076 else g_Console_Add('say <text>');
6078 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6080 else if cmd
= 'tell' then
6082 if g_Game_IsServer
and g_Game_IsNet
then
6084 if (Length(P
) > 2) and (P
[1] <> '') then
6087 for a
:= 2 to High(P
) do
6088 chstr
:= chstr
+ P
[a
] + ' ';
6090 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6092 if Length(chstr
) < 1 then
6094 g_Console_Add('tell <playername> <text>');
6098 pl
:= g_Net_Client_ByName(P
[1]);
6100 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6102 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6104 else g_Console_Add('tell <playername> <text>');
6106 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6108 else if cmd
= 'centerprint' then
6110 if (Length(P
) > 2) and (P
[1] <> '') then
6113 for a
:= 2 to High(P
) do
6114 chstr
:= chstr
+ P
[a
] + ' ';
6116 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6118 if Length(chstr
) < 1 then
6120 g_Console_Add('centerprint <timeout> <text>');
6124 a
:= StrToIntDef(P
[1], 100);
6125 chstr
:= b_Text_Format(chstr
);
6126 g_Game_Message(chstr
, a
);
6127 if g_Game_IsNet
and g_Game_IsServer
then
6128 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6130 else g_Console_Add('centerprint <timeout> <text>');
6132 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6134 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6136 // Дополнительное время:
6137 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6139 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6140 [gGameSettings
.TimeLimit
div 3600,
6141 (gGameSettings
.TimeLimit
div 60) mod 60,
6142 gGameSettings
.TimeLimit
mod 60]));
6143 if g_Game_IsNet
then MH_SEND_GameSettings
;
6145 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6147 if (Length(P
) <= 1) then
6148 g_Console_Add('rcon_password <password>')
6150 MC_SEND_RCONPassword(P
[1]);
6152 else if cmd
= 'rcon' then
6154 if g_Game_IsClient
then
6156 if Length(P
) > 1 then
6159 for a
:= 1 to High(P
) do
6160 chstr
:= chstr
+ P
[a
] + ' ';
6162 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6164 if Length(chstr
) < 1 then
6166 g_Console_Add('rcon <command>');
6170 MC_SEND_RCONCommand(chstr
);
6172 else g_Console_Add('rcon <command>');
6175 else if cmd
= 'ready' then
6177 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6178 gLMSRespawnTime
:= gTime
+ 100;
6180 else if (cmd
= 'callvote') and g_Game_IsNet
then
6182 if Length(P
) > 1 then
6185 for a
:= 1 to High(P
) do begin
6186 if a
> 1 then chstr
:= chstr
+ ' ';
6187 chstr
:= chstr
+ P
[a
];
6190 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6192 if Length(chstr
) < 1 then
6194 g_Console_Add('callvote <command>');
6198 if g_Game_IsClient
then
6199 MC_SEND_Vote(True, chstr
)
6201 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6202 g_Console_Process('vote', True);
6205 g_Console_Add('callvote <command>');
6207 else if (cmd
= 'vote') and g_Game_IsNet
then
6209 if g_Game_IsClient
then
6211 else if gVoteInProgress
then
6213 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6214 a
:= Floor((NetClientCount
+1)/2.0) + 1
6216 a
:= Floor(NetClientCount
/2.0) + 1;
6221 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6222 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6228 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6229 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6237 procedure SystemCommands(P
: SSArray
);
6241 cmd
:= LowerCase(P
[0]);
6248 {$IFDEF ENABLE_RENDER}
6254 if Length(p
) = 2 then
6256 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6258 gFrameTime
:= 1000 div gMaxFPS
6262 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6266 if Length(p
) = 2 then
6268 gAskLanguage
:= true;
6269 gLanguage
:= LANGUAGE_ENGLISH
;
6270 case LowerCase(p
[1]) of
6273 gAskLanguage
:= false;
6274 gLanguage
:= LANGUAGE_ENGLISH
;
6278 gAskLanguage
:= false;
6279 gLanguage
:= LANGUAGE_RUSSIAN
;
6283 gAskLanguage
:= true;
6284 gLanguage
:= LANGUAGE_ENGLISH
;
6287 g_Language_Set(gLanguage
);
6291 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6297 {$IFDEF ENABLE_MENU}
6298 procedure g_Game_InGameMenu(Show
: Boolean);
6300 if (g_ActiveWindow
= nil) and Show
then
6302 if gGameSettings
.GameType
= GT_SINGLE
then
6303 g_GUI_ShowWindow('GameSingleMenu')
6306 if g_Game_IsClient
then
6307 g_GUI_ShowWindow('GameClientMenu')
6309 if g_Game_IsNet
then
6310 g_GUI_ShowWindow('GameServerMenu')
6312 g_GUI_ShowWindow('GameCustomMenu');
6314 g_Sound_PlayEx('MENU_OPEN');
6316 // Пауза при меню только в одиночной игре:
6317 if (not g_Game_IsNet
) then
6321 if (g_ActiveWindow
<> nil) and (not Show
) then
6323 // Пауза при меню только в одиночной игре:
6324 if (not g_Game_IsNet
) then
6325 g_Game_Pause(False);
6330 procedure g_Game_Pause (Enable
: Boolean);
6334 if not gGameOn
then exit
;
6336 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6339 gPauseMain
:= Enable
;
6341 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6344 procedure g_Game_HolmesPause (Enable
: Boolean);
6348 if not gGameOn
then exit
;
6349 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6352 gPauseHolmes
:= Enable
;
6354 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6357 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6362 if gTriggers
<> nil then
6363 for i
:= 0 to High(gTriggers
) do
6364 with gTriggers
[i
] do
6365 if (TriggerType
= TRIGGER_SOUND
) and
6367 Sound
.IsPlaying() then
6369 Sound
.Pause(Enable
);
6373 if gPlayers
<> nil then
6374 for i
:= 0 to High(gPlayers
) do
6375 if gPlayers
[i
] <> nil then
6376 gPlayers
[i
].PauseSounds(Enable
);
6379 if gMusic
<> nil then
6380 gMusic
.Pause(Enable
);
6383 procedure g_Game_StopAllSounds(all
: Boolean);
6387 if gTriggers
<> nil then
6388 for i
:= 0 to High(gTriggers
) do
6389 with gTriggers
[i
] do
6390 if (TriggerType
= TRIGGER_SOUND
) and
6394 if gMusic
<> nil then
6401 procedure g_Game_UpdateTriggerSounds
;
6404 if gTriggers
<> nil then
6405 for i
:= 0 to High(gTriggers
) do
6406 with gTriggers
[i
] do
6407 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6408 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6411 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6414 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6419 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6424 if gSpectMode
<> SPECT_PLAYERS
then
6426 if gSpectPID1
= UID
then
6431 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6438 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6443 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6448 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6453 if gSpectMode
<> SPECT_PLAYERS
then
6455 Pl
:= g_Player_Get(gSpectPID1
);
6456 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6461 if gSpectViewTwo
then
6463 Pl
:= g_Player_Get(gSpectPID2
);
6464 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6472 procedure g_Game_Message (Msg
: string; Time
: Word);
6475 MessageTime
:= Time
;
6478 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6480 punct
: Array[0..13] of String =
6481 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6487 function IsPunctuation(S
: String): Boolean;
6492 if Length(S
) <> 1 then
6494 for i
:= Low(punct
) to High(punct
) do
6495 if S
= punct
[i
] then
6501 function FilterPunctuation(S
: String): String;
6505 for i
:= Low(punct
) to High(punct
) do
6506 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6512 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6514 // remove player name
6515 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6516 // for FullWord check
6517 Text := toLowerCase1251(' ' + Text + ' ');
6518 fpText
:= FilterPunctuation(Text);
6520 for i
:= 0 to Length(gChatSounds
) - 1 do
6523 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6525 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6526 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6528 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6534 gChatSounds
[i
].Sound
.Play();
6540 g_Sound_PlayEx('SOUND_GAME_RADIO');
6543 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6552 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6556 if goodsnd
[a
].IsPlaying() then
6559 goodsnd
[Random(4)].Play();
6562 procedure g_Game_Announce_KillCombo(Param
: Integer);
6569 UID
:= Param
and $FFFF;
6574 Pl
:= g_Player_Get(UID
);
6583 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6587 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6591 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6595 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6603 if not g_Game_IsWatchedPlayer(UID
) then
6606 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6610 if killsnd
[n
].IsPlaying() then
6615 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6623 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6627 if hahasnd
[a
].IsPlaying() then
6630 hahasnd
[Random(3)].Play();
6633 procedure g_Game_StartVote(Command
, Initiator
: string);
6637 if not gVotesEnabled
then Exit
;
6638 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6639 if gVoteInProgress
or gVotePassed
then
6641 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6642 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6645 gVoteInProgress
:= True;
6646 gVotePassed
:= False;
6647 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6650 gVoteCommand
:= Command
;
6652 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6653 Need
:= Floor((NetClientCount
+1)/2.0)+1
6655 Need
:= Floor(NetClientCount
/2.0)+1;
6656 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6657 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6660 procedure g_Game_CheckVote
;
6664 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6665 if not gVoteInProgress
then Exit
;
6667 if (gTime
>= gVoteTimer
) then
6669 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6670 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6672 Need
:= Floor(NetClientCount
/2.0) + 1;
6673 if gVoteCount
>= Need
then
6675 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6676 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6677 gVotePassed
:= True;
6678 gVoteCmdTimer
:= gTime
+ 5000;
6682 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6683 MH_SEND_VoteEvent(NET_VE_FAILED
);
6685 if NetClients
<> nil then
6686 for I
:= Low(NetClients
) to High(NetClients
) do
6687 if NetClients
[i
].Used
then
6688 NetClients
[i
].Voted
:= False;
6689 gVoteInProgress
:= False;
6695 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6696 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6698 Need
:= Floor(NetClientCount
/2.0) + 1;
6699 if gVoteCount
>= Need
then
6701 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6702 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6703 gVoteInProgress
:= False;
6704 gVotePassed
:= True;
6705 gVoteCmdTimer
:= gTime
+ 5000;
6708 if NetClients
<> nil then
6709 for I
:= Low(NetClients
) to High(NetClients
) do
6710 if NetClients
[i
].Used
then
6711 NetClients
[i
].Voted
:= False;
6716 procedure g_Game_LoadMapList(FileName
: string);
6724 if not FileExists(FileName
) then Exit
;
6726 AssignFile(ListFile
, FileName
);
6728 while not EOF(ListFile
) do
6730 ReadLn(ListFile
, s
);
6733 if s
= '' then Continue
;
6735 SetLength(MapList
, Length(MapList
)+1);
6736 MapList
[High(MapList
)] := s
;
6738 CloseFile(ListFile
);
6741 procedure g_Game_SetDebugMode();
6744 // Читы (даже в своей игре):
6748 procedure Parse_Params(var pars
: TParamStrValues
);
6755 while i
<= ParamCount
do
6758 if (Length(s
) > 1) and (s
[1] = '-') then
6760 if (Length(s
) > 2) and (s
[2] = '-') then
6761 begin // Одиночный параметр
6762 SetLength(pars
, Length(pars
) + 1);
6763 with pars
[High(pars
)] do
6765 Name
:= LowerCase(s
);
6770 if (i
< ParamCount
) then
6771 begin // Параметр со значением
6773 SetLength(pars
, Length(pars
) + 1);
6774 with pars
[High(pars
)] do
6776 Name
:= LowerCase(s
);
6777 Value
:= LowerCase(ParamStr(i
));
6786 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6791 for i
:= 0 to High(pars
) do
6792 if pars
[i
].Name
= aName
then
6794 Result
:= pars
[i
].Value
;
6799 procedure g_Game_Process_Params();
6801 pars
: TParamStrValues
;
6804 LimT
, LimS
: Integer;
6815 s
:= Find_Param_Value(pars
, '--debug');
6818 g_Game_SetDebugMode();
6819 s
:= Find_Param_Value(pars
, '--netdump');
6824 // Connect when game loads
6825 ip
:= Find_Param_Value(pars
, '-connect');
6829 s
:= Find_Param_Value(pars
, '-port');
6830 if (s
= '') or not TryStrToInt(s
, Port
) then
6833 s
:= Find_Param_Value(pars
, '-pw');
6835 g_Game_StartClient(ip
, Port
, s
);
6839 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6842 gDefaultMegawadStart
:= s
;
6845 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6846 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6848 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6851 // Start map when game loads:
6852 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6853 if isWadPath(map
) then
6856 s
:= Find_Param_Value(pars
, '-gm');
6857 GMode
:= g_Game_TextToMode(s
);
6858 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6859 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6862 s
:= Find_Param_Value(pars
, '-limt');
6863 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6869 s
:= Find_Param_Value(pars
, '-lims');
6870 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6876 s
:= Find_Param_Value(pars
, '-lives');
6877 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6883 s
:= Find_Param_Value(pars
, '-opt');
6887 Opt
:= StrToIntDef(s
, 0);
6890 s
:= Find_Param_Value(pars
, '--close');
6894 // Override map to test:
6895 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6898 if e_IsValidResourceName(s
) then
6899 e_FindResource(AllMapDirs
, s
);
6900 gTestMap
:= ExpandFileName(s
);
6903 // Delete test map after play:
6904 s
:= Find_Param_Value(pars
, '--testdelete');
6907 //gMapToDelete := MapsDir + map;
6908 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6912 // Delete temporary WAD after play:
6913 s
:= Find_Param_Value(pars
, '--tempdelete');
6914 if (s
<> '') and (gTestMap
<> '') then
6916 gMapToDelete
:= gTestMap
;
6917 gTempDelete
:= True;
6920 // Number of players:
6921 s
:= Find_Param_Value(pars
, '-pl');
6923 n
:= DEFAULT_PLAYERS
6925 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6928 s
:= Find_Param_Value(pars
, '-port');
6929 if (s
= '') or not TryStrToInt(s
, Port
) then
6930 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6932 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6935 // Execute script when game loads:
6936 s
:= Find_Param_Value(pars
, '-exec');
6939 // if not isWadPath(s) then
6940 // s := GameDir + '/' + s;
6945 if IOResult
<> 0 then
6947 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6948 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6952 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6953 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6958 if IOResult
<> 0 then
6960 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6961 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6965 if Pos('#', s
) <> 1 then // script comment
6966 g_Console_Process(s
, True);
6977 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6978 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6979 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6980 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6982 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6983 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6984 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6987 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6988 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6991 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6992 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6994 {$IFDEF ENABLE_HOLMES}
6995 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6998 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7000 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7001 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7003 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7004 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7006 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
7007 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
7008 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
7009 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
7010 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7011 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7012 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7013 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7014 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');