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_Sounds
: Boolean = False;
316 g_debug_WinMsgs
: Boolean = False;
317 g_debug_MonsterOff
: Boolean = False;
318 g_debug_BotAIOff
: Byte = 0;
319 g_debug_HealthBar
: Boolean = False;
320 g_Debug_Player
: Boolean = False;
321 gCoopMonstersKilled
: Word = 0;
322 gCoopSecretsFound
: Word = 0;
323 gCoopTotalMonstersKilled
: Word = 0;
324 gCoopTotalSecretsFound
: Word = 0;
325 gCoopTotalMonsters
: Word = 0;
326 gCoopTotalSecrets
: Word = 0;
327 gStatsOff
: Boolean = False;
328 gStatsPressed
: Boolean = False;
329 gExitByTrigger
: Boolean = False;
330 gNextMap
: String = '';
331 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
332 gLMSRespawnTime
: Cardinal = 0;
333 gLMSSoftSpawn
: Boolean = False;
334 gMissionFailed
: Boolean = False;
335 gVoteInProgress
: Boolean = False;
336 gVotePassed
: Boolean = False;
337 gVoteCommand
: string = '';
338 gVoteTimer
: Cardinal = 0;
339 gVoteCmdTimer
: Cardinal = 0;
340 gVoteCount
: Integer = 0;
341 gVoteTimeout
: Cardinal = 30;
342 gVoted
: Boolean = False;
343 gVotesEnabled
: Boolean = True;
344 gEvents
: Array of TGameEvent
;
345 gDelayedEvents
: Array of TDelayedEvent
;
346 gUseChatSounds
: Boolean = True;
347 gChatSounds
: Array of TChatSound
;
348 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
349 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
350 gInterReadyCount
: Integer = 0;
351 gMaxBots
: Integer = 127;
353 g_dbg_ignore_bounds
: Boolean = false;
354 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
355 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
357 // move button values:
358 // bits 0-1: l/r state:
359 // 0: neither left, nor right pressed
362 // bits 4-5: l/r state when strafe was pressed
363 P1MoveButton
: Byte = 0;
364 P2MoveButton
: Byte = 0;
366 g_profile_frame_update
: Boolean = false;
367 g_profile_frame_draw
: Boolean = false;
368 g_profile_collision
: Boolean = false;
369 g_profile_los
: Boolean = false;
370 g_profile_history_size
: Integer = 1000;
372 g_rlayer_back
: Boolean = true;
373 g_rlayer_step
: Boolean = true;
374 g_rlayer_wall
: Boolean = true;
375 g_rlayer_door
: Boolean = true;
376 g_rlayer_acid1
: Boolean = true;
377 g_rlayer_acid2
: Boolean = true;
378 g_rlayer_water
: Boolean = true;
379 g_rlayer_fore
: Boolean = true;
381 wNeedTimeReset
: Boolean = false;
383 procedure g_ResetDynlights ();
384 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
385 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
387 function conIsCheatsEnabled (): Boolean; inline;
388 function gPause (): Boolean; inline;
390 type (* private state *)
391 TEndCustomGameStat
= record
392 PlayerStat
: TPlayerStatArray
;
396 Map
, MapName
: String;
399 TEndSingleGameStat
= record
400 PlayerStat
: Array [0..1] of record
406 TotalSecrets
: Integer;
410 x
, y
, radius
: Integer;
413 exploRadius
: Integer;
416 var (* private state *)
417 CustomStat
: TEndCustomGameStat
;
418 StatShotDone
: Boolean;
419 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
420 SingleStat
: TEndSingleGameStat
;
423 EndingGameCounter
: Byte;
425 g_playerLight
: Boolean;
426 g_dynLights
: array of TDynLight
= nil;
427 g_dynLightCount
: Integer = 0;
428 EndPicPath
: AnsiString; // full path, used by render
433 {$IFDEF ENABLE_HOLMES}
445 {$IFDEF ENABLE_SHELLS}
448 {$IFDEF ENABLE_CORPSES}
451 {$IFDEF ENABLE_RENDER}
454 {$IFDEF ENABLE_SYSTEM}
458 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
459 g_playermodel
, g_options
, Math
,
460 g_triggers
, g_monsters
, e_sound
, CONFIG
,
461 g_language
, g_net
, g_phys
,
462 ENet
, e_msg
, g_netmsg
, g_netmaster
,
466 charbuff
: packed array [0..15] of AnsiChar = (
467 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
470 function Translit (const S
: AnsiString): AnsiString;
475 for i
:= 1 to Length(Result
) do
478 #
$C9: Result
[i
] := 'Q';
479 #
$D6: Result
[i
] := 'W';
480 #
$D3: Result
[i
] := 'E';
481 #
$CA: Result
[i
] := 'R';
482 #
$C5: Result
[i
] := 'T';
483 #
$CD: Result
[i
] := 'Y';
484 #
$C3: Result
[i
] := 'U';
485 #
$D8: Result
[i
] := 'I';
486 #
$D9: Result
[i
] := 'O';
487 #
$C7: Result
[i
] := 'P';
488 #
$D5: Result
[i
] := '['; //Chr(219);
489 #
$DA: Result
[i
] := ']'; //Chr(221);
490 #
$D4: Result
[i
] := 'A';
491 #
$DB: Result
[i
] := 'S';
492 #
$C2: Result
[i
] := 'D';
493 #
$C0: Result
[i
] := 'F';
494 #
$CF: Result
[i
] := 'G';
495 #
$D0: Result
[i
] := 'H';
496 #
$CE: Result
[i
] := 'J';
497 #
$CB: Result
[i
] := 'K';
498 #
$C4: Result
[i
] := 'L';
499 #
$C6: Result
[i
] := ';'; //Chr(186);
500 #
$DD: Result
[i
] := #39; //Chr(222);
501 #
$DF: Result
[i
] := 'Z';
502 #
$D7: Result
[i
] := 'X';
503 #
$D1: Result
[i
] := 'C';
504 #
$CC: Result
[i
] := 'V';
505 #
$C8: Result
[i
] := 'B';
506 #
$D2: Result
[i
] := 'N';
507 #
$DC: Result
[i
] := 'M';
508 #
$C1: Result
[i
] := ','; //Chr(188);
509 #
$DE: Result
[i
] := '.'; //Chr(190);
515 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
520 ls2
:= Translit(CheatRus
[ct
]);
521 if length(ls1
) = 0 then ls1
:= '~';
522 if length(ls2
) = 0 then ls2
:= '~';
524 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
525 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
526 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
527 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
529 if ct = I_GAME_CHEAT_JETPACK then
531 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
532 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
533 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
534 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
535 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
536 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
552 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
553 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
554 or g_Game_IsNet then Exit;
556 if not gGameOn
then exit
;
557 if not conIsCheatsEnabled
then exit
;
559 s
:= 'SOUND_GAME_RADIO';
562 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
564 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
565 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
569 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
571 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
572 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
576 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
578 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
579 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
583 if CheckCheat(I_GAME_CHEAT_DEATH
) then
585 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
586 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
587 s
:= 'SOUND_MONSTER_HAHA';
591 if CheckCheat(I_GAME_CHEAT_DOORS
) then
593 g_Triggers_OpenAll();
597 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
599 if gTriggers
<> nil then
600 for a
:= 0 to High(gTriggers
) do
601 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
603 gExitByTrigger
:= True;
604 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
605 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
611 s2
:= Copy(charbuff
, 15, 2);
612 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
614 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
622 if CheckCheat(I_GAME_CHEAT_FLY
) then
628 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
630 VEL_JUMP
:= 30-VEL_JUMP
;
634 if CheckCheat(I_GAME_CHEAT_SPEED
) then
636 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
640 if CheckCheat(I_GAME_CHEAT_SUIT
) then
642 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
643 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
647 if CheckCheat(I_GAME_CHEAT_AIR
) then
649 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
650 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
654 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
656 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
657 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
661 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
663 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
664 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
668 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
670 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
671 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
675 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
677 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
678 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
682 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
684 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
685 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
688 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
690 gAimLine
:= not gAimLine
;
693 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
695 gShowMap
:= not gShowMap
;
706 procedure KeyPress (K
: Word);
707 var Msg
: g_gui
.TMessage
;
712 if (g_ActiveWindow
<> nil) then
714 Msg
.Msg
:= WM_KEYDOWN
;
715 Msg
.WParam
:= VK_ESCAPE
;
716 g_ActiveWindow
.OnMessage(Msg
);
717 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
719 else if (gState
<> STATE_FOLD
) then
721 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
723 g_Game_InGameMenu(True);
725 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
727 if (gState
<> STATE_MENU
) then
729 if (NetMode
<> NET_NONE
) then
731 g_Game_StopAllSounds(True);
733 gState
:= STATE_MENU
;
737 g_GUI_ShowWindow('MainMenu');
738 g_Sound_PlayEx('MENU_OPEN');
743 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
744 begin // <F2> .. <F6> � <F12>
745 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
747 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
748 if (not g_Game_IsNet
) then g_Game_Pause(True);
750 IK_F2
: g_Menu_Show_SaveMenu();
751 IK_F3
: g_Menu_Show_LoadMenu();
752 IK_F4
: g_Menu_Show_GameSetGame();
753 IK_F5
: g_Menu_Show_OptionsVideo();
754 IK_F6
: g_Menu_Show_OptionsSound();
755 IK_F7
: g_Menu_Show_EndGameMenu();
756 IK_F10
: g_Menu_Show_QuitGameMenu();
763 gJustChatted
:= False;
764 if gConsoleShow
or gChatShow
then
766 g_Console_Control(K
);
768 else if (g_ActiveWindow
<> nil) then
770 Msg
.Msg
:= WM_KEYDOWN
;
772 g_ActiveWindow
.OnMessage(Msg
);
774 else if (gState
= STATE_MENU
) then
776 g_GUI_ShowWindow('MainMenu');
777 g_Sound_PlayEx('MENU_OPEN');
783 procedure KeyPress (K
: Word);
785 gJustChatted
:= False;
786 if gConsoleShow
or gChatShow
then
788 g_Console_Control(K
);
793 {$IFDEF ENABLE_SYSTEM}
794 procedure CharPress (C
: AnsiChar);
796 var Msg
: g_gui
.TMessage
;
800 if gConsoleShow
or gChatShow
then
805 else if g_ActiveWindow
<> nil then
808 Msg
.WParam
:= Ord(C
);
809 g_ActiveWindow
.OnMessage(Msg
);
816 charbuff
[a
] := charbuff
[a
+ 1];
818 charbuff
[15] := upcase1251(C
);
825 // ////////////////////////////////////////////////////////////////////////// //
826 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
828 procedure g_ResetDynlights ();
832 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
834 for idx
:= 0 to g_dynLightCount
-1 do
836 if g_dynLights
[idx
].exploCount
= -666 then
843 Inc(g_dynLights
[idx
].exploCount
);
844 if (g_dynLights
[idx
].exploCount
< 10) then
846 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
847 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
848 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
849 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
854 g_dynLightCount
:= lnum
;
857 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
859 if not gwin_has_stencil
then exit
;
860 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
861 g_dynLights
[g_dynLightCount
].x
:= x
;
862 g_dynLights
[g_dynLightCount
].y
:= y
;
863 g_dynLights
[g_dynLightCount
].radius
:= radius
;
864 g_dynLights
[g_dynLightCount
].r
:= r
;
865 g_dynLights
[g_dynLightCount
].g
:= g
;
866 g_dynLights
[g_dynLightCount
].b
:= b
;
867 g_dynLights
[g_dynLightCount
].a
:= a
;
868 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
869 Inc(g_dynLightCount
);
872 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
874 if not gwin_has_stencil
then exit
;
875 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
876 g_dynLights
[g_dynLightCount
].x
:= x
;
877 g_dynLights
[g_dynLightCount
].y
:= y
;
878 g_dynLights
[g_dynLightCount
].radius
:= 0;
879 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
880 g_dynLights
[g_dynLightCount
].r
:= r
;
881 g_dynLights
[g_dynLightCount
].g
:= g
;
882 g_dynLights
[g_dynLightCount
].b
:= b
;
883 g_dynLights
[g_dynLightCount
].a
:= 0;
884 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
885 Inc(g_dynLightCount
);
888 // ////////////////////////////////////////////////////////////////////////// //
889 function conIsCheatsEnabled (): Boolean; inline;
892 if g_Game_IsNet
then exit
;
893 if not gDebugMode
then
895 //if not gCheats then exit;
896 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
897 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
902 // ////////////////////////////////////////////////////////////////////////// //
904 TParamStrValue
= record
909 TParamStrValues
= Array of TParamStrValue
;
912 INTER_ACTION_TEXT
= 1;
913 INTER_ACTION_PIC
= 2;
914 INTER_ACTION_MUSIC
= 3;
919 DataLoaded
: Boolean = False;
921 MapList
: SSArray
= nil;
922 MapIndex
: Integer = -1;
923 InterReadyTime
: Integer = -1;
924 StatDate
: string = '';
939 function Compare(a
, b
: TPlayerStat
): Integer;
941 if a
.Spectator
then Result
:= 1
942 else if b
.Spectator
then Result
:= -1
943 else if a
.Frags
< b
.Frags
then Result
:= 1
944 else if a
.Frags
> b
.Frags
then Result
:= -1
945 else if a
.Deaths
< b
.Deaths
then Result
:= -1
946 else if a
.Deaths
> b
.Deaths
then Result
:= 1
947 else if a
.Kills
< b
.Kills
then Result
:= -1
951 procedure SortGameStat(var stat
: TPlayerStatArray
);
956 if stat
= nil then Exit
;
958 for I
:= High(stat
) downto Low(stat
) do
959 for J
:= Low(stat
) to High(stat
) - 1 do
960 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
963 stat
[J
] := stat
[J
+ 1];
968 // saves a shitty CSV containing the game stats passed to it
969 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
972 dir
, fname
, map
, mode
, etime
: String;
976 dir
:= e_GetWriteableDir(StatsDirs
);
977 // stats are placed in stats/yy/mm/dd/*.csv
978 fname
:= e_CatPath(dir
, Path
);
979 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
980 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
981 AssignFile(s
, fname
);
983 SetTextCodePage(s
, CP_UTF8
);
985 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
986 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
987 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
988 mode
:= g_Game_ModeToText(Stat
.GameMode
);
989 etime
:= Format('%d:%.2d:%.2d', [
990 Stat
.GameTime
div 1000 div 3600,
991 (Stat
.GameTime
div 1000 div 60) mod 60,
992 Stat
.GameTime
div 1000 mod 60
994 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
995 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
1001 gGameSettings
.TimeLimit
,
1002 gGameSettings
.ScoreLimit
,
1003 gGameSettings
.Options
,
1005 Length(Stat
.PlayerStat
)
1007 // line 2: game specific shit
1008 // if it's a team game: red score, blue score
1009 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1010 // otherwise nothing
1011 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1013 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
1014 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1016 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1017 // lines 3-...: team, player name, frags, deaths
1018 WriteLn(s
, 'team,name,frags,deaths');
1019 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1020 with Stat
.PlayerStat
[I
] do
1021 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1023 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1026 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1031 procedure ClearDebugCvars();
1033 g_debug_Sounds
:= False;
1034 g_debug_WinMsgs
:= False;
1035 g_debug_MonsterOff
:= False;
1036 g_debug_BotAIOff
:= 0;
1037 g_debug_HealthBar
:= False;
1038 g_Debug_Player
:= False;
1041 function g_Game_ModeToText(Mode
: Byte): string;
1045 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1046 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1047 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1048 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1049 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1053 function g_Game_TextToMode(Mode
: string): Byte;
1056 Mode
:= UpperCase(Mode
);
1057 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1062 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1067 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1072 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1077 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1079 Result
:= GM_SINGLE
;
1084 function g_Game_IsNet(): Boolean;
1086 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1089 function g_Game_IsServer(): Boolean;
1091 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1094 function g_Game_IsClient(): Boolean;
1096 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1099 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1106 Result
.name
:= ExtractFileName(WAD
);
1107 Result
.description
:= '';
1108 Result
.author
:= '';
1110 w
:= TWADFile
.Create();
1113 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1119 cfg
:= TConfig
.CreateMem(p
, len
);
1120 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1121 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1122 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1123 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1129 procedure g_Game_FreeWAD
;
1132 g_Sound_Delete('MUSIC_endmus');
1133 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1134 gGameSettings
.WAD
:= '';
1137 procedure g_Game_LoadWAD(WAD
: string);
1146 gGameSettings
.WAD
:= WAD
;
1147 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1150 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1152 w
:= TWADFile
.Create();
1155 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1161 cfg
:= TConfig
.CreateMem(p
, len
);
1164 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1165 if MegaWAD
.endpic
<> '' then
1166 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1168 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1169 if MegaWAD
.endmus
<> '' then
1171 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1172 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1180 {procedure start_trigger(t: string);
1184 function next_trigger(): Boolean;
1188 procedure DisableCheats();
1194 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1195 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1196 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1197 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1199 {$IF DEFINED(D2F_DEBUG)}
1200 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1201 gAimLine
:= g_dbg_aimline_on
;
1205 procedure g_Game_ExecuteEvent(Name
: String);
1211 if gEvents
= nil then
1213 for a
:= 0 to High(gEvents
) do
1214 if gEvents
[a
].Name
= Name
then
1216 if gEvents
[a
].Command
<> '' then
1217 g_Console_Process(gEvents
[a
].Command
, True);
1222 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1227 if gDelayedEvents
<> nil then
1228 for a
:= 0 to High(gDelayedEvents
) do
1229 if not gDelayedEvents
[a
].Pending
then
1236 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1237 n
:= High(gDelayedEvents
);
1239 gDelayedEvents
[n
].Pending
:= True;
1240 gDelayedEvents
[n
].DEType
:= DEType
;
1241 gDelayedEvents
[n
].DENum
:= Num
;
1242 gDelayedEvents
[n
].DEStr
:= Str
;
1243 if DEType
= DE_GLOBEVENT
then
1244 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1246 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1250 procedure EndGame();
1256 if g_Game_IsNet
and g_Game_IsServer
then
1257 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1260 gPauseMain
:= false;
1261 gPauseHolmes
:= false;
1264 g_Game_StopAllSounds(False);
1269 EndingGameCounter
:= 0;
1271 {$IFDEF ENABLE_MENU}
1272 g_ActiveWindow
:= nil;
1275 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1276 gLMSRespawnTime
:= 0;
1279 EXIT_SIMPLE
: // Выход через меню или конец теста
1283 begin // Это был тест
1287 begin // Выход в главное меню
1288 {$IFDEF DISABLE_MENU}
1289 gState
:= STATE_MENU
; // ???
1291 gMusic
.SetByName('MUSIC_MENU');
1293 if gState
<> STATE_SLIST
then
1295 g_GUI_ShowWindow('MainMenu');
1296 gState
:= STATE_MENU
;
1300 // Обновляем список серверов
1301 slReturnPressed
:= True;
1302 if g_Net_Slist_Fetch(slCurrent
) then
1304 if slCurrent
= nil then
1305 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1308 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1309 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1312 g_Game_ExecuteEvent('ongameend');
1316 EXIT_RESTART
: // Начать уровень сначала
1318 if not g_Game_IsClient
then g_Game_Restart();
1321 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1323 // Статистика Своей игры:
1324 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1326 CustomStat
.GameTime
:= gTime
;
1327 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1328 CustomStat
.MapName
:= gMapInfo
.Name
;
1329 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1330 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1331 CustomStat
.TeamStat
:= gTeamStat
;
1333 CustomStat
.PlayerStat
:= nil;
1335 // Статистика игроков:
1336 if gPlayers
<> nil then
1338 for a
:= 0 to High(gPlayers
) do
1339 if gPlayers
[a
] <> nil then
1341 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1342 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1345 Name
:= gPlayers
[a
].Name
;
1346 Frags
:= gPlayers
[a
].Frags
;
1347 Deaths
:= gPlayers
[a
].Death
;
1348 Kills
:= gPlayers
[a
].Kills
;
1349 Team
:= gPlayers
[a
].Team
;
1350 Color
:= gPlayers
[a
].Model
.Color
;
1351 Spectator
:= gPlayers
[a
].FSpectator
;
1355 SortGameStat(CustomStat
.PlayerStat
);
1357 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1360 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1361 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1362 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1363 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1365 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1368 StatShotDone
:= False;
1371 g_Game_ExecuteEvent('onmapend');
1372 if not g_Game_IsClient
then g_Player_ResetReady
;
1373 gInterReadyCount
:= 0;
1375 // Затухающий экран:
1376 EndingGameCounter
:= 255;
1377 gState
:= STATE_FOLD
;
1379 if gDefInterTime
< 0 then
1380 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1382 gInterEndTime
:= gDefInterTime
* 1000;
1385 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1387 // Статистика Одиночной игры:
1388 SingleStat
.GameTime
:= gTime
;
1389 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1390 SingleStat
.TotalSecrets
:= gSecretsCount
;
1391 // Статистика первого игрока:
1392 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1393 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1394 // Статистика второго игрока (если есть):
1395 if SingleStat
.TwoPlayers
then
1397 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1398 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1401 g_Game_ExecuteEvent('onmapend');
1404 if gNextMap
<> '' then
1406 gMusic
.SetByName('MUSIC_INTERMUS');
1408 gState
:= STATE_INTERSINGLE
;
1411 g_Game_ExecuteEvent('oninter');
1413 else // Больше нет карт
1415 // Затухающий экран:
1416 EndingGameCounter
:= 255;
1417 gState
:= STATE_FOLD
;
1422 // Окончание обработано:
1423 if gExit
<> EXIT_QUIT
then
1427 procedure g_Game_Init();
1431 gTempDelete
:= False;
1433 sfsGCDisable(); // temporary disable removing of temporary volumes
1437 gPauseMain
:= false;
1438 gPauseHolmes
:= false;
1441 {e_MouseInfo.Accel := 1.0;}
1445 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1446 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1447 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1448 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1449 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1451 gMusic
:= TMusic
.Create();
1452 gMusic
.SetByName('MUSIC_MENU');
1455 gGameSettings
.WarmupTime
:= 30;
1457 gState
:= STATE_MENU
;
1459 SetLength(gEvents
, 6);
1460 gEvents
[0].Name
:= 'ongamestart';
1461 gEvents
[1].Name
:= 'ongameend';
1462 gEvents
[2].Name
:= 'onmapstart';
1463 gEvents
[3].Name
:= 'onmapend';
1464 gEvents
[4].Name
:= 'oninter';
1465 gEvents
[5].Name
:= 'onwadend';
1467 sfsGCEnable(); // enable releasing unused volumes
1471 procedure g_Game_Free(freeTextures
: Boolean=true);
1473 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1474 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1476 g_Map_Free(freeTextures
);
1479 {$IFDEF ENABLE_GIBS}
1482 {$IFDEF ENABLE_SHELLS}
1485 {$IFDEF ENABLE_CORPSES}
1486 g_Corpses_RemoveAll
;
1489 gGameSettings
.GameType
:= GT_NONE
;
1490 if gGameSettings
.GameMode
= GM_SINGLE
then
1491 gGameSettings
.GameMode
:= GM_DM
;
1492 gSwitchGameMode
:= gGameSettings
.GameMode
;
1495 gExitByTrigger
:= False;
1498 function IsActivePlayer(p
: TPlayer
): Boolean;
1503 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1506 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1512 if gPlayers
= nil then
1516 for a
:= Low(gPlayers
) to High(gPlayers
) do
1517 if IsActivePlayer(gPlayers
[a
]) then
1519 SetLength(ids
, Length(ids
) + 1);
1520 ids
[High(ids
)] := gPlayers
[a
].UID
;
1521 if gPlayers
[a
].UID
= Skip
then
1524 if Length(ids
) = 0 then
1529 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1532 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1538 if gPlayers
= nil then
1542 for a
:= Low(gPlayers
) to High(gPlayers
) do
1543 if IsActivePlayer(gPlayers
[a
]) then
1545 SetLength(ids
, Length(ids
) + 1);
1546 ids
[High(ids
)] := gPlayers
[a
].UID
;
1547 if gPlayers
[a
].UID
= Skip
then
1550 if Length(ids
) = 0 then
1553 Result
:= ids
[Length(ids
) - 1]
1555 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1558 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1564 if gPlayers
= nil then
1568 for a
:= Low(gPlayers
) to High(gPlayers
) do
1569 if IsActivePlayer(gPlayers
[a
]) then
1571 SetLength(ids
, Length(ids
) + 1);
1572 ids
[High(ids
)] := gPlayers
[a
].UID
;
1573 if gPlayers
[a
].UID
= Skip
then
1576 if Length(ids
) = 0 then
1578 if Length(ids
) = 1 then
1583 Result
:= ids
[Random(Length(ids
))];
1585 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1587 Result
:= ids
[Random(Length(ids
))];
1592 function GetRandomSpectMode(Current
: Byte): Byte;
1599 0: Result
:= SPECT_STATS
;
1600 1: Result
:= SPECT_MAPVIEW
;
1601 2: Result
:= SPECT_MAPVIEW
;
1602 3: Result
:= SPECT_PLAYERS
;
1603 4: Result
:= SPECT_PLAYERS
;
1604 5: Result
:= SPECT_PLAYERS
;
1605 6: Result
:= SPECT_PLAYERS
;
1607 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1611 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1617 if (plr
= nil) then exit
;
1618 if (p
= 2) then time
:= 1000 else time
:= 1;
1619 strafeDir
:= MoveButton
shr 4;
1620 MoveButton
:= MoveButton
and $0F;
1622 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1623 MoveButton
:= 1 // Нажата только "Влево"
1624 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1625 MoveButton
:= 2 // Нажата только "Вправо"
1626 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1627 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1629 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1630 if MoveButton
= 1 then
1631 plr
.PressKey(KEY_LEFT
, time
)
1632 else if MoveButton
= 2 then
1633 plr
.PressKey(KEY_RIGHT
, time
);
1635 // if we have "strafe" key, turn off old strafe mechanics
1636 if gPlayerAction
[p
, ACTION_STRAFE
] then
1638 // new strafe mechanics
1639 if (strafeDir
= 0) then
1640 strafeDir
:= MoveButton
; // start strafing
1641 // now set direction according to strafe (reversed)
1642 if (strafeDir
= 2) then
1643 plr
.SetDirection(TDirection
.D_LEFT
)
1644 else if (strafeDir
= 1) then
1645 plr
.SetDirection(TDirection
.D_RIGHT
)
1649 strafeDir
:= 0; // not strafing anymore
1650 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1651 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1652 plr
.SetDirection(TDirection
.D_LEFT
)
1653 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1654 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1655 plr
.SetDirection(TDirection
.D_RIGHT
)
1656 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1657 else if MoveButton
<> 0 then
1658 plr
.SetDirection(TDirection(MoveButton
-1))
1661 // fix movebutton state
1662 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1664 // Остальные клавиши:
1665 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1666 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1667 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1668 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1669 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1671 for i
:= WP_FACT
to WP_LACT
do
1673 if gWeaponAction
[p
, i
] then
1675 plr
.ProcessWeaponAction(i
);
1676 gWeaponAction
[p
, i
] := False
1680 for i
:= WP_FIRST
to WP_LAST
do
1682 if gSelectWeapon
[p
, i
] then
1684 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1685 gSelectWeapon
[p
, i
] := False
1689 {$IFDEF ENABLE_MENU}
1690 // HACK: add dynlight here
1691 if gwin_k8_enable_light_experiments
then
1693 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1695 g_playerLight
:= true;
1697 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1699 g_playerLight
:= false;
1703 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1707 // HACK: don't have a "key was pressed" function
1708 procedure InterReady();
1710 if InterReadyTime
> gTime
then Exit
;
1711 InterReadyTime
:= gTime
+ 3000;
1712 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1715 procedure g_Game_PreUpdate();
1717 // these are in separate PreUpdate functions because they can interact during Update()
1718 // and are synced over the net
1719 // we don't care that much about corpses and gibs
1720 g_Player_PreUpdate();
1721 g_Monsters_PreUpdate();
1722 g_Items_PreUpdate();
1723 g_Weapon_PreUpdate();
1726 procedure g_Game_SetupHearPoints
;
1727 var p1
, p2
: TPlayer
; a
, b
: Integer;
1731 gHearPoint1
.Active
:= false;
1732 gHearPoint2
.Active
:= false;
1733 if gSpectMode
= SPECT_MAPVIEW
then
1735 // TODO something better (render dependency)
1736 gHearPoint1
.Active
:= true;
1737 gHearPoint1
.Coords
.X
:= gSpectX
+ gScreenWidth
div 2;
1738 gHearPoint1
.Coords
.Y
:= gSpectY
+ gScreenHeight
div 2;
1740 else if gSpectMode
= SPECT_PLAYERS
then
1742 p1
:= g_Player_Get(gSpectPID1
);
1743 if gSpectViewTwo
then
1744 p2
:= g_Player_Get(gSpectPID2
);
1746 else if gSpectMode
= SPECT_NONE
then
1753 gHearPoint1
.Active
:= true;
1754 gHearPoint1
.Coords
.X
:= p1
.obj
.x
+ p1
.obj
.rect
.width
div 2;
1755 gHearPoint1
.Coords
.Y
:= p1
.obj
.y
+ p1
.obj
.rect
.height
div 2;
1757 if (p2
<> nil) and (p1
<> p2
) then
1759 gHearPoint2
.Active
:= true;
1760 gHearPoint2
.Coords
.X
:= p2
.obj
.x
+ p2
.obj
.rect
.width
div 2;
1761 gHearPoint2
.Coords
.Y
:= p2
.obj
.y
+ p2
.obj
.rect
.height
div 2;
1763 // TODO something better (render dependency)
1764 if (p1
<> nil) and (p2
<> nil) then
1766 gPlayerScreenSize
.X
:= gScreenWidth
- 196;
1767 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
1771 gPlayerScreenSize
.X
:= gScreenWidth
- 196;
1772 gPlayerScreenSize
.Y
:= gScreenHeight
;
1775 if gMapInfo
.Height
> gPlayerScreenSize
.Y
then a
:= gMapInfo
.Height
- gPlayerScreenSize
.Y
else a
:= gMapInfo
.Height
;
1776 if gMapInfo
.Width
> gPlayerScreenSize
.X
then b
:= gMapInfo
.Width
- gPlayerScreenSize
.X
else b
:= gMapInfo
.Width
;
1777 gMaxDist
:= Trunc(Hypot(a
, b
));
1780 procedure g_Game_Update();
1782 {$IFDEF ENABLE_MENU}
1783 Msg
: g_gui
.TMessage
;
1790 function sendMonsPos (mon
: TMonster
): Boolean;
1792 result
:= false; // don't stop
1793 // this will also reset "need-send" flag
1794 if mon
.gncNeedSend
then
1796 MH_SEND_MonsterPos(mon
.UID
);
1798 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1800 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1802 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1804 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1808 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1810 result
:= false; // don't stop
1811 // this will also reset "need-send" flag
1812 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1815 function sendItemPos (it
: PItem
): Boolean;
1817 result
:= false; // don't stop
1820 MH_SEND_ItemPos(it
.myId
);
1821 it
.needSend
:= False;
1826 reliableUpdate
: Boolean;
1831 // Пора выключать игру:
1832 if gExit
= EXIT_QUIT
then
1834 // Игра закончилась - обрабатываем:
1838 if gExit
= EXIT_QUIT
then
1842 // Читаем клавиатуру и джойстик, если окно активно
1843 // no need to, as we'll do it in event handler
1845 // Обновляем консоль (движение и сообщения):
1848 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1850 gExit
:= EXIT_SIMPLE
;
1855 // process master server communications
1856 g_Net_Slist_Pulse();
1859 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1860 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1861 STATE_INTERTEXT
, // Текст между уровнями
1862 STATE_INTERPIC
: // Картинка между уровнями
1864 if g_Game_IsNet
and g_Game_IsServer
then
1866 gInterTime
:= gInterTime
+ GAME_TICK
;
1867 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1868 if a
<> gServInterTime
then
1870 gServInterTime
:= a
;
1871 MH_SEND_TimeSync(gServInterTime
);
1875 if (not g_Game_IsClient
) and
1879 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1880 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1881 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1882 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1884 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1885 {$IFDEF ENABLE_MENU}
1886 and (g_ActiveWindow
= nil)
1889 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1892 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1893 g_Game_StopAllSounds(True);
1895 if gMapOnce
then // Это был тест
1896 gExit
:= EXIT_SIMPLE
1898 if gNextMap
<> '' then // Переходим на следующую карту
1899 g_Game_ChangeMap(gNextMap
)
1900 else // Следующей карты нет
1902 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1904 // Выход в главное меню:
1906 {$IFDEF ENABLE_MENU}
1907 g_GUI_ShowWindow('MainMenu');
1908 gMusic
.SetByName('MUSIC_MENU');
1911 gState
:= STATE_MENU
;
1914 // Финальная картинка:
1915 g_Game_ExecuteEvent('onwadend');
1917 if not gMusic
.SetByName('MUSIC_endmus') then
1918 gMusic
.SetByName('MUSIC_STDENDMUS');
1920 gState
:= STATE_ENDPIC
;
1922 g_Game_ExecuteEvent('ongameend');
1927 else if g_Game_IsClient
and
1930 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1931 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1932 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1933 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1935 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1936 {$IFDEF ENABLE_MENU}
1937 and (g_ActiveWindow
= nil)
1946 if gState
= STATE_INTERTEXT
then
1947 if InterText
.counter
> 0 then
1948 InterText
.counter
:= InterText
.counter
- 1;
1951 STATE_FOLD
: // Затухание экрана
1953 if EndingGameCounter
= 0 then
1955 // Закончился уровень в Своей игре:
1956 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1958 gState
:= STATE_INTERCUSTOM
;
1959 InterReadyTime
:= -1;
1960 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1962 g_Game_ExecuteEvent('onwadend');
1963 if not gMusic
.SetByName('MUSIC_endmus') then
1964 gMusic
.SetByName('MUSIC_STDENDMUS');
1967 gMusic
.SetByName('MUSIC_ROUNDMUS');
1971 else // Закончилась последняя карта в Одиночной игре
1973 gMusic
.SetByName('MUSIC_INTERMUS');
1975 gState
:= STATE_INTERSINGLE
;
1978 g_Game_ExecuteEvent('oninter');
1981 DecMin(EndingGameCounter
, 6, 0);
1984 STATE_ENDPIC
: // Картинка окончания мегаВада
1986 if gMapOnce
then // Это был тест
1988 gExit
:= EXIT_SIMPLE
;
1994 g_Serverlist_Control(slCurrent
, slTable
);
1997 // Статистика по Tab:
2000 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
2004 if g_Console_Action(ACTION_SCORES
) then
2006 if not gStatsPressed
then
2008 gStatsOff
:= not gStatsOff
;
2009 gStatsPressed
:= True;
2013 gStatsPressed
:= False;
2017 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
2019 // Время += 28 миллисекунд:
2020 gTime
:= gTime
+ GAME_TICK
;
2022 // Сообщение посередине экрана:
2023 if MessageTime
= 0 then
2025 if MessageTime
> 0 then
2026 MessageTime
:= MessageTime
- 1;
2028 if (g_Game_IsServer
) then
2030 // Был задан лимит времени:
2031 if (gGameSettings
.TimeLimit
> 0) then
2032 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
2033 begin // Он прошел => конец уровня
2038 // Надо респавнить игроков в LMS:
2039 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
2040 g_Game_RestartRound(gLMSSoftSpawn
);
2042 // Проверим результат голосования, если время прошло
2043 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2045 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2047 g_Console_Process(gVoteCommand
);
2049 gVotePassed
:= False;
2052 // Замеряем время захвата флагов
2053 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2054 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2055 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2056 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2058 // Был задан лимит побед:
2059 if (gGameSettings
.ScoreLimit
> 0) then
2063 if gGameSettings
.GameMode
= GM_DM
then
2064 begin // В DM ищем игрока с max фрагами
2065 for i
:= 0 to High(gPlayers
) do
2066 if gPlayers
[i
] <> nil then
2067 if gPlayers
[i
].Frags
> b
then
2068 b
:= gPlayers
[i
].Frags
;
2071 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2072 begin // В CTF/TDM выбираем команду с наибольшим счетом
2073 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2076 // Лимит побед набран => конец уровня:
2077 if b
>= gGameSettings
.ScoreLimit
then
2084 // Обрабатываем клавиши игроков:
2085 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2086 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2087 {$IFDEF DISABLE_MENU}
2088 if (not gConsoleShow
) and (not gChatShow
) then
2090 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2093 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2094 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2095 end // if not console
2098 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2100 // process weapon switch queue
2104 if (gPlayer1
= nil) and (gPlayer2
= nil)
2105 and (not gConsoleShow
) and (not gChatShow
)
2106 {$IFDEF ENABLE_MENU}
2107 and (g_ActiveWindow
= nil)
2111 if not gSpectKeyPress
then
2113 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2115 // switch spect mode
2117 SPECT_NONE
: ; // not spectator
2119 SPECT_MAPVIEW
: Inc(gSpectMode
);
2120 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2122 gSpectKeyPress
:= True;
2124 if (gSpectMode
= SPECT_MAPVIEW
)
2125 and (not gSpectAuto
) then
2127 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2128 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2129 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2130 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2131 if gPlayerAction
[0, ACTION_LOOKUP
] then
2132 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2133 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2134 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
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
, 0), gMapInfo
.Width
- gScreenWidth
);
2221 gSpectAutoNext
:= gTime
2224 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2226 gSpectAutoNext
:= gTime
2230 if gSpectAutoNext
<= gTime
then
2232 if gSpectAutoNext
> 0 then
2234 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2238 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2239 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2240 gSpectAutoStepX
:= Random(9) - 4;
2241 gSpectAutoStepY
:= Random(9) - 4;
2242 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2243 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2244 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2245 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2246 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) 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;
2264 (* spectator state check from render *)
2266 if (gPlayer1
= nil) and (gPlayer2
= nil) and (gSpectMode
= SPECT_NONE
) then
2267 gSpectMode
:= SPECT_STATS
;
2269 if IsActivePlayer(g_Player_Get(gSpectPID1
)) = false then
2270 gSpectPID1
:= GetActivePlayerID_Next();
2272 if IsActivePlayer(g_Player_Get(gSpectPID2
)) = false then
2273 gSpectPID2
:= GetActivePlayerID_Next();
2275 g_Game_SetupHearPoints
;
2277 // Обновляем все остальное:
2280 g_Triggers_Update();
2282 g_Monsters_Update();
2286 g_Player_UpdateAll();
2287 {$IFDEF ENABLE_GIBS}
2290 {$IFDEF ENABLE_CORPSES}
2293 {$IFDEF ENABLE_SHELLS}
2297 // server: send newly spawned monsters unconditionally
2298 if (gGameSettings
.GameType
= GT_SERVER
) then
2300 if (Length(gMonstersSpawned
) > 0) then
2302 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2303 SetLength(gMonstersSpawned
, 0);
2307 if (gSoundTriggerTime
> 8) then
2309 g_Game_UpdateTriggerSounds();
2310 gSoundTriggerTime
:= 0;
2314 Inc(gSoundTriggerTime
);
2317 if (NetMode
= NET_SERVER
) then
2319 Inc(NetTimeToUpdate
);
2320 Inc(NetTimeToReliable
);
2322 // send monster updates
2323 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2325 // send all monsters (periodic sync)
2326 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2328 for I
:= 0 to High(gPlayers
) do
2330 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2333 g_Mons_ForEach(sendMonsPos
);
2335 // update flags that aren't stationary
2336 if gGameSettings
.GameMode
= GM_CTF
then
2337 for I
:= FLAG_RED
to FLAG_BLUE
do
2338 if gFlags
[I
].NeedSend
then
2340 gFlags
[I
].NeedSend
:= False;
2344 // update items that aren't stationary
2345 g_Items_ForEachAlive(sendItemPos
);
2347 if reliableUpdate
then
2349 NetTimeToReliable
:= 0;
2350 NetTimeToUpdate
:= NetUpdateRate
;
2354 NetTimeToUpdate
:= 0;
2359 // send only mosters with some unexpected changes
2360 g_Mons_ForEach(sendMonsPosUnexpected
);
2363 // send unexpected platform changes
2364 g_Map_NetSendInterestingPanels();
2366 g_Net_Slist_ServerUpdate();
2368 if NetUseMaster then
2370 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2372 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2374 NetTimeToMaster := gTime + NetMasterRate;
2379 else if (NetMode
= NET_CLIENT
) then
2381 MC_SEND_PlayerPos();
2383 end; // if gameOn ...
2385 // Активно окно интерфейса - передаем клавиши ему:
2386 {$IFDEF ENABLE_MENU}
2387 if g_ActiveWindow
<> nil then
2389 w
:= e_GetFirstKeyPressed();
2391 if (w
<> IK_INVALID
) then
2393 Msg
.Msg
:= MESSAGE_DIKEY
;
2395 g_ActiveWindow
.OnMessage(Msg
);
2398 // Если оно от этого не закрылось, то обновляем:
2399 if g_ActiveWindow
<> nil then
2400 g_ActiveWindow
.Update();
2402 // Нужно сменить разрешение:
2403 if gResolutionChange
then
2405 {$IFDEF ENABLE_RENDER}
2406 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2409 gResolutionChange
:= False;
2410 g_ActiveWindow
:= nil;
2413 // Нужно сменить язык:
2414 if gLanguageChange
then
2416 //e_WriteLog('Read language file', MSG_NOTIFY);
2417 //g_Language_Load(DataDir + gLanguage + '.txt');
2418 g_Language_Set(gLanguage
);
2420 gLanguageChange
:= False;
2424 // Горячая клавиша для вызова меню выхода из игры (F10):
2425 if e_KeyPressed(IK_F10
) and
2427 (not gConsoleShow
) and
2428 (g_ActiveWindow
= nil) then
2434 Time
:= GetTickCount64() {div 1000};
2436 // Обработка отложенных событий:
2437 if gDelayedEvents
<> nil then
2438 for a
:= 0 to High(gDelayedEvents
) do
2439 if gDelayedEvents
[a
].Pending
and
2441 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2442 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2445 case gDelayedEvents
[a
].DEType
of
2447 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2450 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2454 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2455 if g_Game_IsNet
and g_Game_IsServer
then
2456 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2460 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2462 gDelayedEvents
[a
].Pending
:= False;
2465 // Каждую секунду обновляем счетчик обновлений:
2466 UPSCounter
:= UPSCounter
+ 1;
2467 if Time
- UPSTime
>= 1000 then
2476 g_Weapon_AddDynLights();
2477 g_Items_AddDynLights();
2481 procedure g_Game_LoadChatSounds(Resource
: string);
2484 FileName
, Snd
: string;
2486 len
, cnt
, tags
, i
, j
: Integer;
2489 FileName
:= g_ExtractWadName(Resource
);
2491 WAD
:= TWADFile
.Create();
2492 WAD
.ReadFile(FileName
);
2494 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2501 cfg
:= TConfig
.CreateMem(p
, len
);
2502 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2504 SetLength(gChatSounds
, cnt
);
2505 for i
:= 0 to Length(gChatSounds
) - 1 do
2507 gChatSounds
[i
].Sound
:= nil;
2508 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2509 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2510 if (Snd
= '') or (Tags
<= 0) then
2512 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2513 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2514 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2515 SetLength(gChatSounds
[i
].Tags
, tags
);
2516 for j
:= 0 to tags
- 1 do
2517 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2518 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2525 procedure g_Game_FreeChatSounds();
2529 for i
:= 0 to Length(gChatSounds
) - 1 do
2531 gChatSounds
[i
].Sound
.Free();
2532 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2534 SetLength(gChatSounds
, 0);
2538 procedure g_Game_LoadData();
2540 if DataLoaded
then Exit
;
2542 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2543 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
2545 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2546 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2547 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2548 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2549 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2550 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2551 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2552 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2553 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2554 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2555 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2556 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2557 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2558 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2559 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2560 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2561 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2562 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2563 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2564 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2565 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2566 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2567 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2568 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2569 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2570 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2571 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2572 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2573 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2574 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2575 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2576 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2578 goodsnd
[0] := TPlayableSound
.Create();
2579 goodsnd
[1] := TPlayableSound
.Create();
2580 goodsnd
[2] := TPlayableSound
.Create();
2581 goodsnd
[3] := TPlayableSound
.Create();
2583 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2584 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2585 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2586 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2588 killsnd
[0] := TPlayableSound
.Create();
2589 killsnd
[1] := TPlayableSound
.Create();
2590 killsnd
[2] := TPlayableSound
.Create();
2591 killsnd
[3] := TPlayableSound
.Create();
2593 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2594 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2595 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2596 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2598 hahasnd
[0] := TPlayableSound
.Create();
2599 hahasnd
[1] := TPlayableSound
.Create();
2600 hahasnd
[2] := TPlayableSound
.Create();
2602 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2603 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2604 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2606 sound_get_flag
[0] := TPlayableSound
.Create();
2607 sound_get_flag
[1] := TPlayableSound
.Create();
2608 sound_lost_flag
[0] := TPlayableSound
.Create();
2609 sound_lost_flag
[1] := TPlayableSound
.Create();
2610 sound_ret_flag
[0] := TPlayableSound
.Create();
2611 sound_ret_flag
[1] := TPlayableSound
.Create();
2612 sound_cap_flag
[0] := TPlayableSound
.Create();
2613 sound_cap_flag
[1] := TPlayableSound
.Create();
2615 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2616 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2617 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2618 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2619 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2620 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2621 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2622 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2624 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2628 g_Weapon_LoadData();
2630 g_Monsters_LoadData();
2635 procedure g_Game_Quit();
2637 g_Game_StopAllSounds(True);
2640 g_PlayerModel_FreeData();
2641 {$IFDEF ENABLE_MENU}
2642 // g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2645 if NetInitDone
then g_Net_Free
;
2647 // remove map after test
2648 if gMapToDelete
<> '' then
2649 g_Game_DeleteTestMap();
2653 {$IFDEF ENABLE_SYSTEM}
2658 procedure g_Game_FreeData();
2660 if not DataLoaded
then Exit
;
2663 g_Weapon_FreeData();
2664 g_Monsters_FreeData();
2666 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2668 g_Sound_Delete('SOUND_GAME_TELEPORT');
2669 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2670 g_Sound_Delete('SOUND_GAME_SECRET');
2671 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2672 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2673 g_Sound_Delete('SOUND_GAME_BULK1');
2674 g_Sound_Delete('SOUND_GAME_BULK2');
2675 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2676 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2677 g_Sound_Delete('SOUND_GAME_BURNING');
2678 g_Sound_Delete('SOUND_GAME_SWITCH1');
2679 g_Sound_Delete('SOUND_GAME_SWITCH0');
2686 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2687 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2688 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2689 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2696 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2697 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2698 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2699 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2705 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2706 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2707 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2709 sound_get_flag
[0].Free();
2710 sound_get_flag
[1].Free();
2711 sound_lost_flag
[0].Free();
2712 sound_lost_flag
[1].Free();
2713 sound_ret_flag
[0].Free();
2714 sound_ret_flag
[1].Free();
2715 sound_cap_flag
[0].Free();
2716 sound_cap_flag
[1].Free();
2718 g_Sound_Delete('SOUND_CTF_GET1');
2719 g_Sound_Delete('SOUND_CTF_GET2');
2720 g_Sound_Delete('SOUND_CTF_LOST1');
2721 g_Sound_Delete('SOUND_CTF_LOST2');
2722 g_Sound_Delete('SOUND_CTF_RETURN1');
2723 g_Sound_Delete('SOUND_CTF_RETURN2');
2724 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2725 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2727 g_Game_FreeChatSounds();
2729 DataLoaded
:= False;
2732 procedure g_FatalError(Text: String);
2734 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2735 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2737 gExit
:= EXIT_SIMPLE
;
2738 if gGameOn
then EndGame
;
2741 procedure g_SimpleError(Text: String);
2743 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2744 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2747 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2749 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2750 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2753 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2756 if gPlayer1
= nil then
2758 if g_Game_IsClient
then
2760 if NetPlrUID1
> -1 then
2761 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2765 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2766 Team
:= gPlayer1Settings
.Team
;
2768 // Создание первого игрока:
2769 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2770 gPlayer1Settings
.Color
,
2772 if gPlayer1
= nil then
2773 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2776 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2777 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2778 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2779 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2780 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2781 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2782 if g_Game_IsServer
and g_Game_IsNet
then
2783 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2784 gPlayer1
.Respawn(False, True);
2785 g_Net_Slist_ServerPlayerComes();
2790 if gPlayer2
= nil then
2792 if g_Game_IsClient
then
2794 if NetPlrUID2
> -1 then
2795 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2799 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2800 Team
:= gPlayer2Settings
.Team
;
2802 // Создание второго игрока:
2803 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2804 gPlayer2Settings
.Color
,
2806 if gPlayer2
= nil then
2807 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2810 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2811 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2812 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2813 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2814 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2815 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2816 if g_Game_IsServer
and g_Game_IsNet
then
2817 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2818 gPlayer2
.Respawn(False, True);
2819 g_Net_Slist_ServerPlayerComes();
2826 procedure g_Game_RemovePlayer();
2830 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2831 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2836 if g_Game_IsServer
then
2839 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2840 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2841 g_Player_Remove(Pl
.UID
);
2842 g_Net_Slist_ServerPlayerLeaves();
2846 gSpectLatchPID2
:= Pl
.UID
;
2854 if g_Game_IsServer
then
2857 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2858 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2859 g_Player_Remove(Pl
.UID
);
2860 g_Net_Slist_ServerPlayerLeaves();
2863 gSpectLatchPID1
:= Pl
.UID
;
2865 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2869 g_Net_Slist_ServerPlayerLeaves();
2872 procedure g_Game_Spectate();
2874 g_Game_RemovePlayer();
2875 if gPlayer1
<> nil then
2876 g_Game_RemovePlayer();
2879 procedure g_Game_SpectateCenterView();
2881 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2882 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2885 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2892 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2894 g_Game_ClearLoading();
2897 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2900 gGameSettings
.GameType
:= GT_SINGLE
;
2901 gGameSettings
.MaxLives
:= 0;
2902 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2903 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2904 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2905 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2906 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2907 gSwitchGameMode
:= GM_SINGLE
;
2909 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2910 gLMSRespawnTime
:= 0;
2911 gSpectLatchPID1
:= 0;
2912 gSpectLatchPID2
:= 0;
2914 g_Game_ExecuteEvent('ongamestart');
2916 // Создание первого игрока:
2917 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2918 gPlayer1Settings
.Color
,
2919 gPlayer1Settings
.Team
, False));
2920 if gPlayer1
= nil then
2922 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2926 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2927 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2928 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2929 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2930 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2933 // Создание второго игрока, если есть:
2936 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2937 gPlayer2Settings
.Color
,
2938 gPlayer2Settings
.Team
, False));
2939 if gPlayer2
= nil then
2941 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2945 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2946 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2947 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2948 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2949 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2953 // Загрузка и запуск карты:
2954 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2956 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2957 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2961 // Настройки игроков и ботов:
2965 for i
:= nPl
+1 to nPlayers
do
2966 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2969 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2970 TimeLimit
, ScoreLimit
: Word;
2972 Options
: LongWord; nPlayers
: Byte);
2978 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2980 g_Game_ClearLoading();
2983 gGameSettings
.GameType
:= GT_CUSTOM
;
2984 gGameSettings
.GameMode
:= GameMode
;
2985 gSwitchGameMode
:= GameMode
;
2986 gGameSettings
.TimeLimit
:= TimeLimit
;
2987 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2988 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2989 gGameSettings
.Options
:= Options
;
2991 gCoopTotalMonstersKilled
:= 0;
2992 gCoopTotalSecretsFound
:= 0;
2993 gCoopTotalMonsters
:= 0;
2994 gCoopTotalSecrets
:= 0;
2998 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2999 gLMSRespawnTime
:= 0;
3000 gSpectLatchPID1
:= 0;
3001 gSpectLatchPID2
:= 0;
3003 g_Game_ExecuteEvent('ongamestart');
3005 // Режим наблюдателя:
3006 if nPlayers
= 0 then
3013 if nPlayers
>= 1 then
3015 // Создание первого игрока:
3016 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3017 gPlayer1Settings
.Color
,
3018 gPlayer1Settings
.Team
, False));
3019 if gPlayer1
= nil then
3021 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3025 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3026 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3027 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3028 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3029 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3033 if nPlayers
>= 2 then
3035 // Создание второго игрока:
3036 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3037 gPlayer2Settings
.Color
,
3038 gPlayer2Settings
.Team
, False));
3039 if gPlayer2
= nil then
3041 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3045 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3046 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3047 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3048 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3049 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3053 // Загрузка и запуск карты:
3054 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3056 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3060 // Нет точек появления:
3061 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3062 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3063 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3064 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3065 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3067 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3071 // Настройки игроков и ботов:
3075 for i
:= nPl
+1 to nPlayers
do
3076 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3079 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3080 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3081 Options
: LongWord; nPlayers
: Byte;
3082 IPAddr
: LongWord; Port
: Word);
3085 g_Net_Slist_ServerClosed();
3087 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3089 g_Game_ClearLoading();
3094 gGameSettings
.GameType
:= GT_SERVER
;
3095 gGameSettings
.GameMode
:= GameMode
;
3096 gSwitchGameMode
:= GameMode
;
3097 gGameSettings
.TimeLimit
:= TimeLimit
;
3098 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3099 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3100 gGameSettings
.Options
:= Options
;
3102 gCoopTotalMonstersKilled
:= 0;
3103 gCoopTotalSecretsFound
:= 0;
3104 gCoopTotalMonsters
:= 0;
3105 gCoopTotalSecrets
:= 0;
3109 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3110 gLMSRespawnTime
:= 0;
3111 gSpectLatchPID1
:= 0;
3112 gSpectLatchPID2
:= 0;
3114 g_Game_ExecuteEvent('ongamestart');
3116 // Режим наблюдателя:
3117 if nPlayers
= 0 then
3123 if nPlayers
>= 1 then
3125 // Создание первого игрока:
3126 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3127 gPlayer1Settings
.Color
,
3128 gPlayer1Settings
.Team
, False));
3129 if gPlayer1
= nil then
3131 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3135 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3136 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3137 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3138 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3139 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3142 if nPlayers
>= 2 then
3144 // Создание второго игрока:
3145 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3146 gPlayer2Settings
.Color
,
3147 gPlayer2Settings
.Team
, False));
3148 if gPlayer2
= nil then
3150 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3154 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3155 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3156 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3157 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3158 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3161 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3162 if NetForwardPorts
then
3163 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3166 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3168 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3172 g_Net_Slist_Set(NetMasterList
);
3174 g_Net_Slist_ServerStarted();
3176 // Загрузка и запуск карты:
3177 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3179 g_Net_Slist_ServerClosed();
3180 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3184 // Нет точек появления:
3185 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3186 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3187 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3188 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3189 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3191 g_Net_Slist_ServerClosed();
3192 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3196 // Настройки игроков и ботов:
3199 g_Net_Slist_ServerMapStarted();
3200 NetState
:= NET_STATE_GAME
;
3203 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3218 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3219 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3221 g_Game_ClearLoading();
3226 gGameSettings
.GameType
:= GT_CLIENT
;
3228 gCoopTotalMonstersKilled
:= 0;
3229 gCoopTotalSecretsFound
:= 0;
3230 gCoopTotalMonsters
:= 0;
3231 gCoopTotalSecrets
:= 0;
3235 g_Game_ExecuteEvent('ongamestart');
3237 NetState
:= NET_STATE_AUTH
;
3239 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3241 // create (or update) map/resource databases
3242 g_Res_CreateDatabases(true);
3244 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3245 gLMSRespawnTime
:= 0;
3246 gSpectLatchPID1
:= 0;
3247 gSpectLatchPID2
:= 0;
3250 if not g_Net_Connect(Addr
, Port
) then
3252 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3253 NetState
:= NET_STATE_NONE
;
3257 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3259 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3264 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3265 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3266 // thank you, enet. let's ignore failures altogether then.
3267 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3269 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3271 Ptr
:= NetEvent
.packet
^.data
;
3272 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3274 enet_packet_destroy(NetEvent
.packet
);
3278 InMsg
.ReadLongWord(); // skip size
3279 MID
:= InMsg
.ReadByte();
3281 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3283 NetMyID
:= InMsg
.ReadByte();
3284 NetPlrUID1
:= InMsg
.ReadWord();
3286 WadName
:= InMsg
.ReadString();
3287 Map
:= InMsg
.ReadString();
3289 gWADHash
:= InMsg
.ReadMD5();
3291 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3292 gSwitchGameMode
:= gGameSettings
.GameMode
;
3293 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3294 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3295 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3296 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3297 T
:= InMsg
.ReadLongWord();
3299 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3300 //if newResPath = '' then
3302 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3303 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3304 if newResPath
= '' then
3306 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3307 enet_packet_destroy(NetEvent
.packet
);
3308 NetState
:= NET_STATE_NONE
;
3311 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3313 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3316 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3317 gPlayer1Settings
.Color
,
3318 gPlayer1Settings
.Team
, False));
3320 if gPlayer1
= nil then
3322 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3324 enet_packet_destroy(NetEvent
.packet
);
3325 NetState
:= NET_STATE_NONE
;
3329 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3330 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3331 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3332 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3333 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3334 gPlayer1
.UID
:= NetPlrUID1
;
3335 gPlayer1
.Reset(True);
3337 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3339 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3341 enet_packet_destroy(NetEvent
.packet
);
3342 NetState
:= NET_STATE_NONE
;
3350 enet_packet_destroy(NetEvent
.packet
);
3354 enet_packet_destroy(NetEvent
.packet
);
3358 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3361 if (NetEvent
.data
<= NET_DISC_MAX
) then
3362 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3363 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3370 ProcessLoading(True);
3371 if g_Net_UserRequestExit() then
3380 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3381 NetState
:= NET_STATE_NONE
;
3386 NetState
:= NET_STATE_GAME
;
3387 MC_SEND_FullStateRequest
;
3388 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3392 lastAsMegaWad
: Boolean = false;
3394 procedure g_Game_ChangeMap(const MapPath
: String);
3398 g_Game_ClearLoading();
3400 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3401 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3402 if gExitByTrigger
then
3405 gExitByTrigger
:= False;
3407 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3408 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3411 procedure g_Game_Restart();
3415 if g_Game_IsClient
then
3417 map
:= g_ExtractFileName(gMapInfo
.Map
);
3418 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3422 g_Game_ClearLoading();
3423 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3426 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3428 NewWAD
, ResName
: String;
3432 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3434 {$IFDEF ENABLE_GIBS}
3437 {$IFDEF ENABLE_SHELLS}
3440 {$IFDEF ENABLE_CORPSES}
3441 g_Corpses_RemoveAll
;
3444 if (not g_Game_IsClient
) and
3445 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3446 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3448 if gSwitchGameMode
= GM_CTF
then
3449 gGameSettings
.MaxLives
:= 0;
3450 gGameSettings
.GameMode
:= gSwitchGameMode
;
3453 gSwitchGameMode
:= gGameSettings
.GameMode
;
3455 g_Player_ResetTeams();
3457 lastAsMegaWad
:= asMegawad
;
3458 if isWadPath(Map
) then
3460 NewWAD
:= g_ExtractWadName(Map
);
3461 ResName
:= g_ExtractFileName(Map
);
3462 if g_Game_IsServer
then
3464 nws
:= findDiskWad(NewWAD
);
3465 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3468 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3469 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3473 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3474 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3476 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3477 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3479 if (length(nws
) = 0) then
3481 ResName
:= ''; // failed
3486 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3487 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3488 g_Game_LoadWAD(NewWAD
);
3493 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3494 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3499 NewWAD
:= gGameSettings
.WAD
;
3505 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3507 if (ResName
<> '') and (NewWAD
<> '') then
3509 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3510 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3514 {$IFDEF ENABLE_RENDER}
3515 r_Render_LoadTextures
;
3518 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3520 gState
:= STATE_NONE
;
3521 {$IFDEF ENABLE_MENU}
3522 g_ActiveWindow
:= nil;
3527 wNeedTimeReset
:= True;
3529 if gGameSettings
.GameMode
= GM_CTF
then
3531 g_Map_ResetFlag(FLAG_RED
);
3532 g_Map_ResetFlag(FLAG_BLUE
);
3533 // CTF, а флагов нет:
3534 if not g_Map_HaveFlagPoints() then
3535 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3540 gState
:= STATE_MENU
;
3545 gPauseMain
:= false;
3546 gPauseHolmes
:= false;
3547 NetTimeToUpdate
:= 1;
3548 NetTimeToReliable
:= 0;
3549 NetTimeToMaster
:= NetMasterRate
;
3550 gSpectLatchPID1
:= 0;
3551 gSpectLatchPID2
:= 0;
3552 gMissionFailed
:= False;
3555 gCoopMonstersKilled
:= 0;
3556 gCoopSecretsFound
:= 0;
3558 gVoteInProgress
:= False;
3559 gVotePassed
:= False;
3565 if not gGameOn
then Exit
;
3567 g_Game_SpectateCenterView();
3569 if g_Game_IsServer
then
3571 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3573 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3574 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3575 gLMSSoftSpawn
:= True;
3576 if g_Game_IsNet
then
3577 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3581 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3582 gLMSRespawnTime
:= 0;
3586 if NetMode
= NET_SERVER
then
3588 // reset full state flags
3589 if NetClients
<> nil then
3590 for I
:= 0 to High(NetClients
) do
3591 NetClients
[I
].FullUpdateSent
:= False;
3593 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3596 g_Net_Slist_ServerMapStarted();
3598 if NetClients
<> nil then
3599 for I
:= 0 to High(NetClients
) do
3600 if NetClients
[I
].Used
then
3602 NetClients
[I
].Voted
:= False;
3603 if NetClients
[I
].RequestedFullUpdate
then
3605 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3606 NetClients
[I
].RequestedFullUpdate
:= False;
3610 g_Net_UnbanNonPermHosts();
3615 gCoopTotalMonstersKilled
:= 0;
3616 gCoopTotalSecretsFound
:= 0;
3617 gCoopTotalMonsters
:= 0;
3618 gCoopTotalSecrets
:= 0;
3622 g_Game_ExecuteEvent('onmapstart');
3625 procedure SetFirstLevel
;
3629 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3630 if MapList
= nil then
3633 SortSArray(MapList
);
3634 gNextMap
:= MapList
[Low(MapList
)];
3639 procedure g_Game_ExitLevel(const Map
: AnsiString);
3643 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3644 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3645 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3646 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3648 // Вышли в выход в Одиночной игре:
3649 if gGameSettings
.GameType
= GT_SINGLE
then
3650 gExit
:= EXIT_ENDLEVELSINGLE
3651 else // Вышли в выход в Своей игре
3653 gExit
:= EXIT_ENDLEVELCUSTOM
;
3654 if gGameSettings
.GameMode
= GM_COOP
then
3655 g_Player_RememberAll
;
3657 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3660 if gGameSettings
.GameMode
= GM_COOP
then
3663 gStatsPressed
:= True;
3664 gNextMap
:= 'MAP01';
3666 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3669 if g_Game_IsNet
then
3671 MH_SEND_GameStats();
3672 MH_SEND_CoopStats();
3678 procedure g_Game_RestartLevel();
3682 if gGameSettings
.GameMode
= GM_SINGLE
then
3687 gExit
:= EXIT_ENDLEVELCUSTOM
;
3688 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3692 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3694 gWAD
{, xwad}: String;
3697 if not g_Game_IsClient
then Exit
;
3698 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3700 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3705 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3709 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3712 g_Game_LoadWAD(NewWAD
);
3716 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3717 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3720 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3721 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3725 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3729 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3730 g_Game_LoadWAD(NewWAD);
3734 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3736 i
, n
, nb
, nr
: Integer;
3738 if not g_Game_IsServer
then Exit
;
3739 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3740 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3741 gLMSRespawnTime
:= 0;
3744 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3746 gMissionFailed
:= True;
3747 g_Game_RestartLevel
;
3751 n
:= 0; nb
:= 0; nr
:= 0;
3752 for i
:= Low(gPlayers
) to High(gPlayers
) do
3753 if (gPlayers
[i
] <> nil) and
3754 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3755 (gPlayers
[i
] is TBot
)) then
3758 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3759 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3762 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3764 // wait a second until the fuckers finally decide to join
3765 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3766 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3767 gLMSSoftSpawn
:= NoMapRestart
;
3768 if g_Game_IsNet
then
3769 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3773 {$IFDEF ENABLE_GIBS}
3776 {$IFDEF ENABLE_SHELLS}
3779 {$IFDEF ENABLE_CORPSES}
3780 g_Corpses_RemoveAll
;
3783 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3784 if g_Game_IsNet
then
3785 MH_SEND_GameEvent(NET_EV_LMS_START
);
3787 for i
:= Low(gPlayers
) to High(gPlayers
) do
3789 if gPlayers
[i
] = nil then continue
;
3790 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3791 // don't touch normal spectators
3792 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3794 gPlayers
[i
].FNoRespawn
:= True;
3795 gPlayers
[i
].Lives
:= 0;
3796 if g_Game_IsNet
then
3797 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3800 gPlayers
[i
].FNoRespawn
:= False;
3801 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3802 gPlayers
[i
].Respawn(False, True);
3803 if gGameSettings
.GameMode
= GM_COOP
then
3805 gPlayers
[i
].Frags
:= 0;
3806 gPlayers
[i
].RecallState
;
3808 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3809 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3810 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3811 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3814 g_Items_RestartRound();
3816 gLMSSoftSpawn
:= False;
3819 function g_Game_GetFirstMap(WAD
: String): String;
3823 MapList
:= g_Map_GetMapsList(WAD
);
3824 if MapList
= nil then
3827 SortSArray(MapList
);
3828 Result
:= MapList
[Low(MapList
)];
3830 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3836 function g_Game_GetNextMap(): String;
3843 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3844 if MapList
= nil then
3847 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3849 SortSArray(MapList
);
3851 for I
:= Low(MapList
) to High(MapList
) do
3852 if Map
= MapList
[I
] then
3858 if MapIndex
<> -255 then
3860 if MapIndex
= High(MapList
) then
3861 Result
:= MapList
[Low(MapList
)]
3863 Result
:= MapList
[MapIndex
+ 1];
3865 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3871 procedure g_Game_NextLevel();
3873 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3874 gExit
:= EXIT_ENDLEVELCUSTOM
3877 gExit
:= EXIT_ENDLEVELSINGLE
;
3881 if gNextMap
<> '' then Exit
;
3882 gNextMap
:= g_Game_GetNextMap();
3885 function g_Game_IsTestMap(): Boolean;
3887 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3890 procedure g_Game_DeleteTestMap();
3893 //MapName: AnsiString;
3901 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3902 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3903 if (a
= 0) then exit
;
3905 // Выделяем имя wad-файла и имя карты
3906 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3907 Delete(gMapToDelete
, 1, a
+5);
3908 gMapToDelete
:= UpperCase(gMapToDelete
);
3910 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3913 // Имя карты не стандартное тестовое:
3914 if MapName <> TEST_MAP_NAME then
3917 if not gTempDelete then
3919 time := g_GetFileTime(WadName);
3920 WAD := TWADFile.Create();
3923 if not WAD.ReadFile(WadName) then
3924 begin // Нет такого WAD-файла
3929 // Составляем список карт и ищем нужную:
3931 MapList := WAD.GetResourcesList('');
3933 if MapList <> nil then
3934 for a := 0 to High(MapList) do
3935 if MapList[a] = MapName then
3937 // Удаляем и сохраняем:
3938 WAD.RemoveResource('', MapName);
3939 WAD.SaveTo(WadName);
3944 g_SetFileTime(WadName, time);
3947 if gTempDelete
then DeleteFile(WadName
);
3950 procedure GameCVars(P
: SSArray
);
3953 stat
: TPlayerStatArray
;
3956 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3960 if Length(P
) > 1 then
3965 gsGameFlags
:= gsGameFlags
or Flag
3967 gsGameFlags
:= gsGameFlags
and (not Flag
);
3969 if g_Game_IsServer
then
3972 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3974 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3975 if g_Game_IsNet
then MH_SEND_GameSettings
;
3979 if LongBool(gsGameFlags
and Flag
) then
3980 g_Console_Add(_lc
[OnMsg
])
3982 g_Console_Add(_lc
[OffMsg
]);
3984 if OnMapChange
and g_Game_IsServer
then
3985 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3990 cmd
:= LowerCase(P
[0]);
3992 if cmd
= 'g_gamemode' then
3994 if (Length(P
) > 1) then
3996 a
:= g_Game_TextToMode(P
[1]);
3997 if a
= GM_SINGLE
then a
:= GM_COOP
;
3998 gsGameMode
:= g_Game_ModeToText(a
);
3999 if g_Game_IsServer
then
4001 gSwitchGameMode
:= a
;
4002 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4003 (gState
= STATE_INTERSINGLE
) then
4004 gSwitchGameMode
:= GM_SINGLE
;
4006 gGameSettings
.GameMode
:= gSwitchGameMode
;
4010 if gSwitchGameMode
= gGameSettings
.GameMode
then
4011 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4012 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4014 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4015 [g_Game_ModeToText(gGameSettings
.GameMode
),
4016 g_Game_ModeToText(gSwitchGameMode
)]));
4018 else if cmd
= 'g_friendlyfire' then
4020 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4022 else if cmd
= 'g_friendly_absorb_damage' then
4024 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
4026 else if cmd
= 'g_friendly_hit_trace' then
4028 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
4030 else if cmd
= 'g_friendly_hit_projectile' then
4032 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
4034 else if cmd
= 'g_weaponstay' then
4036 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
4038 else if cmd
= 'g_allow_exit' then
4040 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
4042 else if cmd
= 'g_allow_monsters' then
4044 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
4046 else if cmd
= 'g_allow_dropflag' then
4048 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
4050 else if cmd
= 'g_throw_flag' then
4052 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
4054 else if cmd
= 'g_bot_vsplayers' then
4056 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4058 else if cmd
= 'g_bot_vsmonsters' then
4060 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4062 else if cmd
= 'g_dm_keys' then
4064 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4066 else if cmd
= 'g_gameflags' then
4068 if Length(P
) > 1 then
4070 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4071 if g_Game_IsServer
then
4073 gGameSettings
.Options
:= gsGameFlags
;
4074 if g_Game_IsNet
then MH_SEND_GameSettings
;
4078 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4080 else if cmd
= 'g_warmup_time' then
4082 if Length(P
) > 1 then
4084 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4085 if g_Game_IsServer
then
4087 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4088 // extend warmup if it's already going
4089 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4091 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4092 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4094 if g_Game_IsNet
then MH_SEND_GameSettings
;
4098 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4099 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4101 else if cmd
= 'g_spawn_invul' then
4103 if Length(P
) > 1 then
4105 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4106 if g_Game_IsServer
then
4108 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4109 if g_Game_IsNet
then MH_SEND_GameSettings
;
4113 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4115 else if cmd
= 'g_item_respawn_time' then
4117 if Length(P
) > 1 then
4119 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4120 if g_Game_IsServer
then
4122 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4123 if g_Game_IsNet
then MH_SEND_GameSettings
;
4127 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4128 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4130 else if cmd
= 'sv_intertime' then
4132 if (Length(P
) > 1) then
4133 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4135 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4137 else if cmd
= 'g_max_particles' then
4139 if Length(p
) = 2 then
4142 a
:= Max(0, StrToIntDef(p
[1], 0));
4146 else if Length(p
) = 1 then
4149 e_LogWritefln('%s', [g_GFX_GetMax()])
4151 e_LogWritefln('%s', [0])
4156 e_LogWritefln('usage: %s <n>', [cmd
])
4159 else if cmd
= 'g_max_shells' then
4161 if Length(p
) = 2 then
4163 {$IFDEF ENABLE_SHELLS}
4164 a
:= Max(0, StrToIntDef(p
[1], 0));
4168 else if Length(p
) = 1 then
4170 {$IFDEF ENABLE_SHELLS}
4171 e_LogWritefln('%s', [g_Shells_GetMax()])
4173 e_LogWritefln('%s', [0])
4178 e_LogWritefln('usage: %s <n>', [cmd
])
4181 else if cmd
= 'g_max_gibs' then
4183 if Length(p
) = 2 then
4185 {$IFDEF ENABLE_GIBS}
4186 a
:= Max(0, StrToIntDef(p
[1], 0));
4190 else if Length(p
) = 1 then
4192 {$IFDEF ENABLE_GIBS}
4193 e_LogWritefln('%s', [g_Gibs_GetMax()])
4195 e_LogWritefln('%s', [0])
4200 e_LogWritefln('usage: %s <n>', [cmd
])
4203 else if cmd
= 'g_max_corpses' then
4205 if Length(p
) = 2 then
4207 {$IFDEF ENABLE_CORPSES}
4208 a
:= Max(0, StrToIntDef(p
[1], 0));
4212 else if Length(p
) = 1 then
4214 {$IFDEF ENABLE_CORPSES}
4215 e_LogWritefln('%s', [g_Corpses_GetMax()])
4217 e_LogWritefln('%s', [0])
4222 e_LogWritefln('usage: %s <n>', [cmd
])
4225 else if cmd
= 'g_force_model' then
4227 if Length(p
) = 2 then
4229 a
:= StrToIntDef(p
[1], 0);
4230 g_Force_Model_Set(a
);
4231 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4233 for a
:= Low(gPlayers
) to High(gPlayers
) do
4235 if (gPlayers
[a
] <> nil) then
4237 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4239 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4241 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4245 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4247 for a
:= Low(gPlayers
) to High(gPlayers
) do
4249 if (gPlayers
[a
] <> nil) then
4251 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4253 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4255 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4261 else if cmd
= 'g_force_model_name' then
4263 if (Length(P
) > 1) then
4265 cmd
:= b_Text_Unformat(P
[1]);
4266 g_Forced_Model_SetName(cmd
);
4267 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4269 for a
:= Low(gPlayers
) to High(gPlayers
) do
4271 if (gPlayers
[a
] <> nil) then
4273 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4275 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4277 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4283 else if cmd
= 'g_scorelimit' then
4285 if Length(P
) > 1 then
4287 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4289 if g_Game_IsServer
then
4292 if gGameSettings
.GameMode
= GM_DM
then
4294 stat
:= g_Player_GetStats();
4296 for a
:= 0 to High(stat
) do
4297 if stat
[a
].Frags
> b
then
4301 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4303 // if someone has a higher score, set it to that instead
4304 gsScoreLimit
:= max(gsScoreLimit
, b
);
4305 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4307 if g_Game_IsNet
then MH_SEND_GameSettings
;
4311 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4313 else if cmd
= 'g_timelimit' then
4315 if Length(P
) > 1 then
4317 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4318 if g_Game_IsServer
then
4320 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4321 if g_Game_IsNet
then MH_SEND_GameSettings
;
4324 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4325 [gsTimeLimit
div 3600,
4326 (gsTimeLimit
div 60) mod 60,
4327 gsTimeLimit
mod 60]));
4329 else if cmd
= 'g_max_bots' then
4331 if Length(P
) > 1 then
4332 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4333 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4335 else if cmd
= 'g_maxlives' then
4337 if Length(P
) > 1 then
4339 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4340 if g_Game_IsServer
then
4342 gGameSettings
.MaxLives
:= gsMaxLives
;
4343 if g_Game_IsNet
then MH_SEND_GameSettings
;
4347 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4351 procedure PlayerSettingsCVars(P
: SSArray
);
4356 function ParseTeam(s
: string): Byte;
4360 'red', '1': result
:= TEAM_RED
;
4361 'blue', '2': result
:= TEAM_BLUE
;
4362 else result
:= TEAM_NONE
;
4366 cmd
:= LowerCase(P
[0]);
4370 if (Length(P
) > 1) then
4372 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4373 if g_Game_IsClient
then
4374 MC_SEND_PlayerSettings
4375 else if gGameOn
and (gPlayer1
<> nil) then
4377 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4378 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4384 if (Length(P
) > 1) then
4386 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4387 if g_Game_IsClient
then
4388 MC_SEND_PlayerSettings
4389 else if gGameOn
and (gPlayer2
<> nil) then
4391 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4392 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4398 if Length(P
) > 3 then
4400 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4401 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4402 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4403 if g_Game_IsClient
then
4404 MC_SEND_PlayerSettings
4405 else if gGameOn
and (gPlayer1
<> nil) then
4407 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4408 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4414 if Length(P
) > 3 then
4416 gPlayer2Settings
.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 (gPlayer2
<> nil) then
4423 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4424 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4430 if (Length(P
) > 1) then
4432 gPlayer1Settings
.Model
:= P
[1];
4433 if g_Game_IsClient
then
4434 MC_SEND_PlayerSettings
4435 else if gGameOn
and (gPlayer1
<> nil) then
4437 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4438 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4439 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4445 if (Length(P
) > 1) then
4447 gPlayer2Settings
.Model
:= P
[1];
4448 if g_Game_IsClient
then
4449 MC_SEND_PlayerSettings
4450 else if gGameOn
and (gPlayer2
<> nil) then
4452 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4453 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4454 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4460 // TODO: switch teams if in game or store this separately
4461 if (Length(P
) > 1) then
4463 team
:= ParseTeam(P
[1]);
4464 if team
= TEAM_NONE
then
4465 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4466 else if not gGameOn
and not g_Game_IsNet
then
4467 gPlayer1Settings
.Team
:= team
4469 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4474 // TODO: switch teams if in game or store this separately
4475 if (Length(P
) > 1) then
4477 team
:= ParseTeam(P
[1]);
4478 if team
= TEAM_NONE
then
4479 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4480 else if not gGameOn
and not g_Game_IsNet
then
4481 gPlayer2Settings
.Team
:= team
4483 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4488 if (Length(P
) = 2) then
4489 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4493 if (Length(P
) = 2) then
4494 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4498 if (Length(P
) = 2) then
4499 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4503 if (Length(P
) = 2) then
4504 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4508 if (Length(P
) = 2) then
4509 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4513 if (Length(P
) = 2) then
4514 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4516 'p1_priority_kastet':
4518 if (Length(P
) = 2) then
4519 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4521 'p2_priority_kastet':
4523 if (Length(P
) = 2) then
4524 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4528 if (Length(P
) = 2) then
4529 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4533 if (Length(P
) = 2) then
4534 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4536 'p1_priority_pistol':
4538 if (Length(P
) = 2) then
4539 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4541 'p2_priority_pistol':
4543 if (Length(P
) = 2) then
4544 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4546 'p1_priority_shotgun1':
4548 if (Length(P
) = 2) then
4549 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4551 'p2_priority_shotgun1':
4553 if (Length(P
) = 2) then
4554 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4556 'p1_priority_shotgun2':
4558 if (Length(P
) = 2) then
4559 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4561 'p2_priority_shotgun2':
4563 if (Length(P
) = 2) then
4564 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4566 'p1_priority_chaingun':
4568 if (Length(P
) = 2) then
4569 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4571 'p2_priority_chaingun':
4573 if (Length(P
) = 2) then
4574 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4576 'p1_priority_rocketlauncher':
4578 if (Length(P
) = 2) then
4579 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4581 'p2_priority_rocketlauncher':
4583 if (Length(P
) = 2) then
4584 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4586 'p1_priority_plasma':
4588 if (Length(P
) = 2) then
4589 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4591 'p2_priority_plasma':
4593 if (Length(P
) = 2) then
4594 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4598 if (Length(P
) = 2) then
4599 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4603 if (Length(P
) = 2) then
4604 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4606 'p1_priority_super':
4608 if (Length(P
) = 2) then
4609 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4611 'p2_priority_super':
4613 if (Length(P
) = 2) then
4614 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4616 'p1_priority_flamethrower':
4618 if (Length(P
) = 2) then
4619 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4621 'p2_priority_flamethrower':
4623 if (Length(P
) = 2) then
4624 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4626 'p1_priority_berserk':
4628 if (Length(P
) = 2) then
4629 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4631 'p2_priority_berserk':
4633 if (Length(P
) = 2) then
4634 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4639 procedure PrintHeapStats();
4643 hs
:= GetFPCHeapStatus();
4644 e_LogWriteLn ('v===== heap status =====v');
4645 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4646 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4647 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4648 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4649 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4650 e_LogWriteLn ('^=======================^');
4653 procedure DebugCommands(P
: SSArray
);
4660 // Команды отладочного режима:
4661 if {gDebugMode}conIsCheatsEnabled
then
4663 cmd
:= LowerCase(P
[0]);
4664 if cmd
= 'd_window' then
4666 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4667 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4669 else if cmd
= 'd_sounds' then
4671 if (Length(P
) > 1) and
4672 ((P
[1] = '1') or (P
[1] = '0')) then
4673 g_Debug_Sounds
:= (P
[1][1] = '1');
4675 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4677 else if cmd
= 'd_winmsg' then
4679 if (Length(P
) > 1) and
4680 ((P
[1] = '1') or (P
[1] = '0')) then
4681 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4683 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
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_health') then
4749 if (Length(P
) > 1) and
4750 ((P
[1] = '1') or (P
[1] = '0')) then
4751 g_debug_HealthBar
:= (P
[1][1] = '1');
4753 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4755 else if (cmd
= 'd_player') then
4757 if (Length(P
) > 1) and
4758 ((P
[1] = '1') or (P
[1] = '0')) then
4759 g_debug_Player
:= (P
[1][1] = '1');
4761 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4763 else if (cmd
= 'd_mem') then
4769 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4773 procedure GameCheats(P
: SSArray
);
4779 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4781 g_Console_Add('not available');
4787 g_Console_Add('where is the player?!');
4790 cmd
:= LowerCase(P
[0]);
4794 plr
.GodMode
:= not plr
.GodMode
;
4795 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4798 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4799 if cmd
= 'give' then
4801 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4802 for f
:= 1 to High(P
) do
4804 cmd
:= LowerCase(P
[f
]);
4805 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4806 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4807 if cmd
= 'exit' then
4809 if gTriggers
<> nil then
4811 for a
:= 0 to High(gTriggers
) do
4813 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4815 g_Console_Add('player left the map');
4816 gExitByTrigger
:= True;
4817 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4818 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4826 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4827 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4828 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4829 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4830 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4832 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4833 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4835 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4836 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;
4838 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4839 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4841 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4842 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4844 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4845 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4847 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4848 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4849 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4851 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4852 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4853 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4854 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;
4855 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4856 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4858 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;
4859 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;
4860 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;
4861 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;
4862 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;
4863 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;
4865 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4866 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;
4868 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;
4869 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;
4871 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4873 if cmd
= 'ammo' then
4875 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4876 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4877 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4878 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4879 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4880 g_Console_Add('player got some ammo');
4884 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4885 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4887 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4888 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4890 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4891 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4893 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4894 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4896 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4898 if cmd
= 'weapons' then
4900 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4901 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4902 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4903 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4904 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4905 plr
.GiveItem(ITEM_WEAPON_BFG
);
4906 g_Console_Add('player got weapons');
4910 if cmd
= 'keys' then
4912 plr
.GiveItem(ITEM_KEY_RED
);
4913 plr
.GiveItem(ITEM_KEY_GREEN
);
4914 plr
.GiveItem(ITEM_KEY_BLUE
);
4915 g_Console_Add('player got all keys');
4919 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4924 if cmd
= 'open' then
4926 g_Console_Add('player activated sesame');
4927 g_Triggers_OpenAll();
4934 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4938 if cmd
= 'noclip' then
4941 g_Console_Add('wall hardeness adjusted');
4945 if cmd
= 'notarget' then
4947 plr
.NoTarget
:= not plr
.NoTarget
;
4948 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4952 if cmd
= 'noreload' then
4954 plr
.NoReload
:= not plr
.NoReload
;
4955 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4959 if cmd
= 'speedy' then
4961 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4962 g_Console_Add('speed adjusted');
4966 if cmd
= 'jumpy' then
4968 VEL_JUMP
:= 30-VEL_JUMP
;
4969 g_Console_Add('jump height adjusted');
4973 if cmd
= 'automap' then
4975 gShowMap
:= not gShowMap
;
4976 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4980 if cmd
= 'aimline' then
4982 gAimLine
:= not gAimLine
;
4983 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4988 procedure GameCommands(P
: SSArray
);
4994 pl
: pTNetClient
= nil;
5002 cmd
:= LowerCase(P
[0]);
5004 if cmd
= 'pause' then
5006 {$IFDEF ENABLE_MENU}
5007 if (g_ActiveWindow
= nil) then
5008 g_Game_Pause(not gPauseMain
);
5010 g_Game_Pause(not gPauseMain
);
5013 else if cmd
= 'endgame' then
5014 gExit
:= EXIT_SIMPLE
5015 else if cmd
= 'restart' then
5017 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5019 if g_Game_IsClient
then
5021 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5026 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5028 else if cmd
= 'kick' then
5030 if g_Game_IsServer
then
5032 if Length(P
) < 2 then
5034 g_Console_Add('kick <name>');
5039 g_Console_Add('kick <name>');
5043 if g_Game_IsNet
then
5044 pl
:= g_Net_Client_ByName(P
[1]);
5047 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5048 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5049 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5050 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5051 g_Net_Slist_ServerPlayerLeaves();
5052 end else if gPlayers
<> nil then
5053 for a
:= Low(gPlayers
) to High(gPlayers
) do
5054 if gPlayers
[a
] <> nil then
5055 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5057 // Не отключать основных игроков в сингле
5058 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5060 gPlayers
[a
].Lives
:= 0;
5061 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5062 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5063 g_Player_Remove(gPlayers
[a
].UID
);
5064 g_Net_Slist_ServerPlayerLeaves();
5065 // Если не перемешать, при добавлении новых ботов появятся старые
5069 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5071 else if cmd
= 'kick_id' then
5073 if g_Game_IsServer
and g_Game_IsNet
then
5075 if Length(P
) < 2 then
5077 g_Console_Add('kick_id <client ID>');
5082 g_Console_Add('kick_id <client ID>');
5086 a
:= StrToIntDef(P
[1], 0);
5087 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5089 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5091 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5092 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
5093 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5094 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5095 g_Net_Slist_ServerPlayerLeaves();
5099 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5101 else if cmd
= 'kick_pid' then
5103 if g_Game_IsServer
and g_Game_IsNet
then
5105 if Length(P
) < 2 then
5107 g_Console_Add('kick_pid <player ID>');
5112 g_Console_Add('kick_pid <player ID>');
5116 a
:= StrToIntDef(P
[1], 0);
5117 pl
:= g_Net_Client_ByPlayer(a
);
5118 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5120 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5121 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5122 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5123 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5124 g_Net_Slist_ServerPlayerLeaves();
5127 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5129 else if cmd
= 'ban' then
5131 if g_Game_IsServer
and g_Game_IsNet
then
5133 if Length(P
) < 2 then
5135 g_Console_Add('ban <name>');
5140 g_Console_Add('ban <name>');
5144 pl
:= g_Net_Client_ByName(P
[1]);
5147 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5148 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5149 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5150 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5151 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5152 g_Net_Slist_ServerPlayerLeaves();
5154 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5156 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5158 else if cmd
= 'ban_id' then
5160 if g_Game_IsServer
and g_Game_IsNet
then
5162 if Length(P
) < 2 then
5164 g_Console_Add('ban_id <client ID>');
5169 g_Console_Add('ban_id <client ID>');
5173 a
:= StrToIntDef(P
[1], 0);
5174 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5175 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5177 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5178 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5179 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5180 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5181 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5182 g_Net_Slist_ServerPlayerLeaves();
5185 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5187 else if cmd
= 'ban_pid' then
5189 if g_Game_IsServer
and g_Game_IsNet
then
5191 if Length(P
) < 2 then
5193 g_Console_Add('ban_pid <player ID>');
5198 g_Console_Add('ban_pid <player ID>');
5202 a
:= StrToIntDef(P
[1], 0);
5203 pl
:= g_Net_Client_ByPlayer(a
);
5204 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5206 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5207 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5208 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5209 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5210 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5211 g_Net_Slist_ServerPlayerLeaves();
5214 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5216 else if cmd
= 'permban' then
5218 if g_Game_IsServer
and g_Game_IsNet
then
5220 if Length(P
) < 2 then
5222 g_Console_Add('permban <name>');
5227 g_Console_Add('permban <name>');
5231 pl
:= g_Net_Client_ByName(P
[1]);
5234 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5235 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5236 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5237 g_Net_SaveBanList();
5238 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5239 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5240 g_Net_Slist_ServerPlayerLeaves();
5242 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5244 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5246 else if cmd
= 'permban_id' then
5248 if g_Game_IsServer
and g_Game_IsNet
then
5250 if Length(P
) < 2 then
5252 g_Console_Add('permban_id <client ID>');
5257 g_Console_Add('permban_id <client ID>');
5261 a
:= StrToIntDef(P
[1], 0);
5262 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5263 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5265 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5266 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5267 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5268 g_Net_SaveBanList();
5269 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5270 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5271 g_Net_Slist_ServerPlayerLeaves();
5274 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5276 else if cmd
= 'permban_pid' then
5278 if g_Game_IsServer
and g_Game_IsNet
then
5280 if Length(P
) < 2 then
5282 g_Console_Add('permban_pid <player ID>');
5287 g_Console_Add('permban_pid <player ID>');
5291 a
:= StrToIntDef(P
[1], 0);
5292 pl
:= g_Net_Client_ByPlayer(a
);
5293 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5295 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5296 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5297 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5298 g_Net_SaveBanList();
5299 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5300 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5301 g_Net_Slist_ServerPlayerLeaves();
5304 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5306 else if cmd
= 'permban_ip' then
5308 if g_Game_IsServer
and g_Game_IsNet
then
5310 if Length(P
) < 2 then
5312 g_Console_Add('permban_ip <IP address>');
5317 g_Console_Add('permban_ip <IP address>');
5321 g_Net_BanHost(P
[1]);
5322 g_Net_SaveBanList();
5323 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5325 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5327 else if cmd
= 'unban' then
5329 if g_Game_IsServer
and g_Game_IsNet
then
5331 if Length(P
) < 2 then
5333 g_Console_Add('unban <IP Address>');
5338 g_Console_Add('unban <IP Address>');
5342 if g_Net_UnbanHost(P
[1]) then
5344 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5345 g_Net_SaveBanList();
5347 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5349 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5351 else if cmd
= 'clientlist' then
5353 if g_Game_IsServer
and g_Game_IsNet
then
5356 if NetClients
<> nil then
5357 for a
:= Low(NetClients
) to High(NetClients
) do
5358 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5360 plr
:= g_Player_Get(NetClients
[a
].Player
);
5361 if plr
= nil then continue
;
5363 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5364 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5367 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5369 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5371 else if cmd
= 'connect' then
5373 if (NetMode
= NET_NONE
) then
5375 if Length(P
) < 2 then
5377 g_Console_Add('connect <IP> [port] [password]');
5382 g_Console_Add('connect <IP> [port] [password]');
5386 if Length(P
) > 2 then
5387 prt
:= StrToIntDef(P
[2], 25666)
5391 if Length(P
) > 3 then
5396 g_Game_StartClient(P
[1], prt
, pw
);
5399 else if cmd
= 'disconnect' then
5401 if (NetMode
= NET_CLIENT
) then
5404 else if cmd
= 'reconnect' then
5406 if (NetMode
= NET_SERVER
) then
5409 if (NetMode
= NET_CLIENT
) then
5412 gExit
:= EXIT_SIMPLE
;
5416 //TODO: Use last successful password to reconnect, instead of ''
5417 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5419 else if (cmd
= 'addbot') or
5420 (cmd
= 'bot_add') then
5422 if Length(P
) > 2 then
5423 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5424 else if Length(P
) > 1 then
5425 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5427 g_Bot_Add(TEAM_NONE
, 2);
5429 else if cmd
= 'bot_addlist' then
5431 if Length(P
) > 1 then
5433 if Length(P
) = 2 then
5434 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5435 else if Length(P
) = 3 then
5436 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5438 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5441 else if cmd
= 'bot_removeall' then
5443 else if cmd
= 'chat' then
5445 if g_Game_IsNet
then
5447 if Length(P
) > 1 then
5449 for a
:= 1 to High(P
) do
5450 chstr
:= chstr
+ P
[a
] + ' ';
5452 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5454 if Length(chstr
) < 1 then
5456 g_Console_Add('chat <text>');
5460 chstr
:= b_Text_Format(chstr
);
5461 if g_Game_IsClient
then
5462 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5464 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5467 g_Console_Add('chat <text>');
5469 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5471 else if cmd
= 'teamchat' then
5473 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5475 if Length(P
) > 1 then
5477 for a
:= 1 to High(P
) do
5478 chstr
:= chstr
+ P
[a
] + ' ';
5480 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5482 if Length(chstr
) < 1 then
5484 g_Console_Add('teamchat <text>');
5488 chstr
:= b_Text_Format(chstr
);
5489 if g_Game_IsClient
then
5490 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5492 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5493 gPlayer1Settings
.Team
);
5496 g_Console_Add('teamchat <text>');
5498 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5500 else if (cmd
= 'an') or (cmd
= 'announce') then
5502 if g_Game_IsNet
then
5504 if Length(P
) > 1 then
5506 for a
:= 1 to High(P
) do
5507 chstr
:= chstr
+ P
[a
] + ' ';
5509 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5511 if Length(chstr
) < 1 then
5513 g_Console_Add('announce <text>');
5517 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5518 if g_Game_IsClient
then
5519 MC_SEND_RCONCommand(chstr
)
5521 g_Console_Process(chstr
, True);
5524 g_Console_Add('announce <text>');
5526 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5528 else if cmd
= 'game' then
5530 if gGameSettings
.GameType
<> GT_NONE
then
5532 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5535 if Length(P
) = 1 then
5537 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5540 // game not started yet, load fist map from some wad
5542 s
:= addWadExtension(P
[1]);
5543 found
:= e_FindResource(AllMapDirs
, s
);
5547 P
[1] := ExpandFileName(P
[1]);
5548 // if map not choosed then set first map
5549 if Length(P
) < 3 then
5552 P
[2] := g_Game_GetFirstMap(P
[1]);
5555 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5557 if g_Map_Exist(s
) then
5561 with gGameSettings
do
5563 Options
:= gsGameFlags
;
5564 GameMode
:= g_Game_TextToMode(gsGameMode
);
5565 if gSwitchGameMode
<> GM_NONE
then
5566 GameMode
:= gSwitchGameMode
;
5567 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5568 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5570 if Length(P
) >= 4 then
5571 b
:= StrToIntDef(P
[3], 1);
5572 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5573 ScoreLimit
, MaxLives
, Options
, b
);
5578 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5580 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5582 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5584 else if cmd
= 'host' then
5586 if gGameSettings
.GameType
<> GT_NONE
then
5588 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5591 if Length(P
) < 4 then
5593 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5596 if not StrToIp(P
[1], listen
) then
5598 prt
:= StrToIntDef(P
[2], 25666);
5600 s
:= addWadExtension(P
[3]);
5601 found
:= e_FindResource(AllMapDirs
, s
);
5605 // get first map in wad, if not specified
5606 if Length(P
) < 5 then
5609 P
[4] := g_Game_GetFirstMap(P
[1]);
5611 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5612 if g_Map_Exist(s
) then
5616 with gGameSettings
do
5618 Options
:= gsGameFlags
;
5619 GameMode
:= g_Game_TextToMode(gsGameMode
);
5620 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5621 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5622 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5624 if Length(P
) >= 6 then
5625 b
:= StrToIntDef(P
[5], 0);
5626 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5632 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5634 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5639 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5642 else if cmd
= 'map' then
5644 if Length(P
) = 1 then
5646 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5648 g_Console_Add(cmd
+ ' <MAP>');
5649 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5653 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5658 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5660 if Length(P
) < 3 then
5662 // first param is map or wad
5663 s
:= UpperCase(P
[1]);
5664 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5666 gExitByTrigger
:= False;
5669 // already in game, finish current map
5671 gExit
:= EXIT_ENDLEVELCUSTOM
;
5675 // intermission, so change map immediately
5682 found
:= e_FindResource(AllMapDirs
, s
);
5684 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5687 // no such map, found wad
5690 P
[1] := ExpandFileName(pw
);
5691 P
[2] := g_Game_GetFirstMap(P
[1]);
5692 s
:= P
[1] + ':\' + P
[2];
5693 if g_Map_Exist(s
) then
5695 gExitByTrigger
:= False;
5698 // already in game, finish current map
5700 gExit
:= EXIT_ENDLEVELCUSTOM
5704 // intermission, so change map immediately
5711 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5713 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5718 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5724 s
:= addWadExtension(P
[1]);
5725 found
:= e_FindResource(AllMapDirs
, s
);
5729 P
[2] := UpperCase(P
[2]);
5730 s
:= P
[1] + ':\' + P
[2];
5731 if g_Map_Exist(s
) then
5733 gExitByTrigger
:= False;
5737 gExit
:= EXIT_ENDLEVELCUSTOM
5746 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5751 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5757 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5761 else if cmd
= 'nextmap' then
5763 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5765 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5770 if Length(P
) = 1 then
5772 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5774 g_Console_Add(cmd
+ ' <MAP>');
5775 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5780 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5786 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5788 if Length(P
) < 3 then
5790 // first param is map or wad
5791 s
:= UpperCase(P
[1]);
5792 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5795 gExitByTrigger
:= False;
5801 // no such map, found wad
5802 pw
:= addWadExtension(P
[1]);
5803 found
:= e_FindResource(MapDirs
, pw
);
5805 found
:= e_FindResource(WadDirs
, pw
);
5807 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5810 // map not specified, select first map
5812 P
[2] := g_Game_GetFirstMap(P
[1]);
5813 s
:= P
[1] + ':\' + P
[2];
5814 if g_Map_Exist(s
) then
5816 gExitByTrigger
:= False;
5823 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5825 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5830 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5836 // specified two params wad + map
5837 pw
:= addWadExtension(P
[1]);
5838 found
:= e_FindResource(MapDirs
, pw
);
5840 found
:= e_FindResource(MapDirs
, pw
);
5844 P
[2] := UpperCase(P
[2]);
5845 s
:= P
[1] + ':\' + P
[2];
5846 if g_Map_Exist(s
) then
5848 gExitByTrigger
:= False;
5854 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5859 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5865 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5870 if gNextMap
= '' then
5871 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5873 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5877 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5881 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5885 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5887 gExitByTrigger
:= False;
5888 // next map not specified, try to find trigger EXIT
5889 if (gNextMap
= '') and (gTriggers
<> nil) then
5891 for a
:= 0 to High(gTriggers
) do
5893 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5895 gExitByTrigger
:= True;
5896 //gNextMap := gTriggers[a].Data.MapName;
5897 gNextMap
:= gTriggers
[a
].tgcMap
;
5902 if gNextMap
= '' then
5903 gNextMap
:= g_Game_GetNextMap();
5904 if not isWadPath(gNextMap
) then
5905 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5908 if g_Map_Exist(s
) then
5909 gExit
:= EXIT_ENDLEVELCUSTOM
5911 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5915 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5919 else if (cmd
= 'event') then
5921 if (Length(P
) <= 1) then
5923 for a
:= 0 to High(gEvents
) do
5924 if gEvents
[a
].Command
= '' then
5925 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5927 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5930 if (Length(P
) = 2) then
5932 for a
:= 0 to High(gEvents
) do
5933 if gEvents
[a
].Name
= P
[1] then
5934 if gEvents
[a
].Command
= '' then
5935 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5937 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5940 for a
:= 0 to High(gEvents
) do
5941 if gEvents
[a
].Name
= P
[1] then
5943 gEvents
[a
].Command
:= '';
5944 for b
:= 2 to High(P
) do
5945 if Pos(' ', P
[b
]) = 0 then
5946 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5948 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5949 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5953 else if cmd
= 'suicide' then
5957 if g_Game_IsClient
then
5958 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5961 if gPlayer1
<> nil then
5962 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5963 if gPlayer2
<> nil then
5964 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5968 else if cmd
= 'screenshot' then
5970 {$IFDEF ENABLE_RENDER}
5971 r_Render_RequestScreenShot
;
5974 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5976 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5978 gWeaponAction
[0, WP_PREV
] := True;
5980 gWeaponAction
[0, WP_NEXT
] := True;
5982 else if cmd
= 'weapon' then
5984 if Length(p
) = 2 then
5986 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5987 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5988 gSelectWeapon
[0, a
] := True
5991 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5992 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5994 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5995 b
:= ord(cmd
[2]) - ord('1');
5997 gWeaponAction
[b
, WP_PREV
] := True;
5999 gWeaponAction
[b
, WP_NEXT
] := True;
6001 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
6003 if Length(p
) = 2 then
6005 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
6006 b
:= ord(cmd
[2]) - ord('1');
6007 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6008 gSelectWeapon
[b
, a
] := True
6011 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
6013 b
:= ord(cmd
[2]) - ord('1');
6015 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
6017 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
6019 else if (cmd
= 'dropflag') then
6021 if g_Game_IsServer
then
6023 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
6024 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
6027 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6029 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
6031 b
:= ord(cmd
[2]) - ord('1');
6032 if g_Game_IsServer
then
6034 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
6035 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
6038 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6040 // Команды Своей игры:
6041 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6043 if cmd
= 'bot_addred' then
6045 if Length(P
) > 1 then
6046 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6048 g_Bot_Add(TEAM_RED
, 2);
6050 else if cmd
= 'bot_addblue' then
6052 if Length(P
) > 1 then
6053 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6055 g_Bot_Add(TEAM_BLUE
, 2);
6057 else if cmd
= 'spectate' then
6063 else if cmd
= 'say' then
6065 if g_Game_IsServer
and g_Game_IsNet
then
6067 if Length(P
) > 1 then
6070 for a
:= 1 to High(P
) do
6071 chstr
:= chstr
+ P
[a
] + ' ';
6073 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6075 if Length(chstr
) < 1 then
6077 g_Console_Add('say <text>');
6081 chstr
:= b_Text_Format(chstr
);
6082 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6084 else g_Console_Add('say <text>');
6086 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6088 else if cmd
= 'tell' then
6090 if g_Game_IsServer
and g_Game_IsNet
then
6092 if (Length(P
) > 2) and (P
[1] <> '') then
6095 for a
:= 2 to High(P
) do
6096 chstr
:= chstr
+ P
[a
] + ' ';
6098 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6100 if Length(chstr
) < 1 then
6102 g_Console_Add('tell <playername> <text>');
6106 pl
:= g_Net_Client_ByName(P
[1]);
6108 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6110 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6112 else g_Console_Add('tell <playername> <text>');
6114 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6116 else if cmd
= 'centerprint' then
6118 if (Length(P
) > 2) and (P
[1] <> '') then
6121 for a
:= 2 to High(P
) do
6122 chstr
:= chstr
+ P
[a
] + ' ';
6124 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6126 if Length(chstr
) < 1 then
6128 g_Console_Add('centerprint <timeout> <text>');
6132 a
:= StrToIntDef(P
[1], 100);
6133 chstr
:= b_Text_Format(chstr
);
6134 g_Game_Message(chstr
, a
);
6135 if g_Game_IsNet
and g_Game_IsServer
then
6136 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6138 else g_Console_Add('centerprint <timeout> <text>');
6140 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6142 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6144 // Дополнительное время:
6145 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6147 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6148 [gGameSettings
.TimeLimit
div 3600,
6149 (gGameSettings
.TimeLimit
div 60) mod 60,
6150 gGameSettings
.TimeLimit
mod 60]));
6151 if g_Game_IsNet
then MH_SEND_GameSettings
;
6153 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6155 if (Length(P
) <= 1) then
6156 g_Console_Add('rcon_password <password>')
6158 MC_SEND_RCONPassword(P
[1]);
6160 else if cmd
= 'rcon' then
6162 if g_Game_IsClient
then
6164 if Length(P
) > 1 then
6167 for a
:= 1 to High(P
) do
6168 chstr
:= chstr
+ P
[a
] + ' ';
6170 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6172 if Length(chstr
) < 1 then
6174 g_Console_Add('rcon <command>');
6178 MC_SEND_RCONCommand(chstr
);
6180 else g_Console_Add('rcon <command>');
6183 else if cmd
= 'ready' then
6185 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6186 gLMSRespawnTime
:= gTime
+ 100;
6188 else if (cmd
= 'callvote') and g_Game_IsNet
then
6190 if Length(P
) > 1 then
6193 for a
:= 1 to High(P
) do begin
6194 if a
> 1 then chstr
:= chstr
+ ' ';
6195 chstr
:= chstr
+ P
[a
];
6198 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6200 if Length(chstr
) < 1 then
6202 g_Console_Add('callvote <command>');
6206 if g_Game_IsClient
then
6207 MC_SEND_Vote(True, chstr
)
6209 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6210 g_Console_Process('vote', True);
6213 g_Console_Add('callvote <command>');
6215 else if (cmd
= 'vote') and g_Game_IsNet
then
6217 if g_Game_IsClient
then
6219 else if gVoteInProgress
then
6221 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6222 a
:= Floor((NetClientCount
+1)/2.0) + 1
6224 a
:= Floor(NetClientCount
/2.0) + 1;
6229 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6230 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6236 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6237 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6245 procedure SystemCommands(P
: SSArray
);
6249 cmd
:= LowerCase(P
[0]);
6256 {$IFDEF ENABLE_RENDER}
6262 if Length(p
) = 2 then
6264 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6266 gFrameTime
:= 1000 div gMaxFPS
6270 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6274 if Length(p
) = 2 then
6276 gAskLanguage
:= true;
6277 gLanguage
:= LANGUAGE_ENGLISH
;
6278 case LowerCase(p
[1]) of
6281 gAskLanguage
:= false;
6282 gLanguage
:= LANGUAGE_ENGLISH
;
6286 gAskLanguage
:= false;
6287 gLanguage
:= LANGUAGE_RUSSIAN
;
6291 gAskLanguage
:= true;
6292 gLanguage
:= LANGUAGE_ENGLISH
;
6295 g_Language_Set(gLanguage
);
6299 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6305 {$IFDEF ENABLE_MENU}
6306 procedure g_Game_InGameMenu(Show
: Boolean);
6308 if (g_ActiveWindow
= nil) and Show
then
6310 if gGameSettings
.GameType
= GT_SINGLE
then
6311 g_GUI_ShowWindow('GameSingleMenu')
6314 if g_Game_IsClient
then
6315 g_GUI_ShowWindow('GameClientMenu')
6317 if g_Game_IsNet
then
6318 g_GUI_ShowWindow('GameServerMenu')
6320 g_GUI_ShowWindow('GameCustomMenu');
6322 g_Sound_PlayEx('MENU_OPEN');
6324 // Пауза при меню только в одиночной игре:
6325 if (not g_Game_IsNet
) then
6329 if (g_ActiveWindow
<> nil) and (not Show
) then
6331 // Пауза при меню только в одиночной игре:
6332 if (not g_Game_IsNet
) then
6333 g_Game_Pause(False);
6338 procedure g_Game_Pause (Enable
: Boolean);
6342 if not gGameOn
then exit
;
6344 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6347 gPauseMain
:= Enable
;
6349 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6352 procedure g_Game_HolmesPause (Enable
: Boolean);
6356 if not gGameOn
then exit
;
6357 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6360 gPauseHolmes
:= Enable
;
6362 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6365 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6370 if gTriggers
<> nil then
6371 for i
:= 0 to High(gTriggers
) do
6372 with gTriggers
[i
] do
6373 if (TriggerType
= TRIGGER_SOUND
) and
6375 Sound
.IsPlaying() then
6377 Sound
.Pause(Enable
);
6381 if gPlayers
<> nil then
6382 for i
:= 0 to High(gPlayers
) do
6383 if gPlayers
[i
] <> nil then
6384 gPlayers
[i
].PauseSounds(Enable
);
6387 if gMusic
<> nil then
6388 gMusic
.Pause(Enable
);
6391 procedure g_Game_StopAllSounds(all
: Boolean);
6395 if gTriggers
<> nil then
6396 for i
:= 0 to High(gTriggers
) do
6397 with gTriggers
[i
] do
6398 if (TriggerType
= TRIGGER_SOUND
) and
6402 if gMusic
<> nil then
6409 procedure g_Game_UpdateTriggerSounds
;
6412 if gTriggers
<> nil then
6413 for i
:= 0 to High(gTriggers
) do
6414 with gTriggers
[i
] do
6415 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6416 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6419 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6422 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6427 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6432 if gSpectMode
<> SPECT_PLAYERS
then
6434 if gSpectPID1
= UID
then
6439 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6446 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6451 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6456 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6461 if gSpectMode
<> SPECT_PLAYERS
then
6463 Pl
:= g_Player_Get(gSpectPID1
);
6464 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6469 if gSpectViewTwo
then
6471 Pl
:= g_Player_Get(gSpectPID2
);
6472 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6480 procedure g_Game_Message (Msg
: string; Time
: Word);
6483 MessageTime
:= Time
;
6486 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6488 punct
: Array[0..13] of String =
6489 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6495 function IsPunctuation(S
: String): Boolean;
6500 if Length(S
) <> 1 then
6502 for i
:= Low(punct
) to High(punct
) do
6503 if S
= punct
[i
] then
6509 function FilterPunctuation(S
: String): String;
6513 for i
:= Low(punct
) to High(punct
) do
6514 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6520 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6522 // remove player name
6523 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6524 // for FullWord check
6525 Text := toLowerCase1251(' ' + Text + ' ');
6526 fpText
:= FilterPunctuation(Text);
6528 for i
:= 0 to Length(gChatSounds
) - 1 do
6531 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6533 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6534 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6536 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6542 gChatSounds
[i
].Sound
.Play();
6548 g_Sound_PlayEx('SOUND_GAME_RADIO');
6551 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6560 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6564 if goodsnd
[a
].IsPlaying() then
6567 goodsnd
[Random(4)].Play();
6570 procedure g_Game_Announce_KillCombo(Param
: Integer);
6577 UID
:= Param
and $FFFF;
6582 Pl
:= g_Player_Get(UID
);
6591 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6595 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6599 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6603 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6611 if not g_Game_IsWatchedPlayer(UID
) then
6614 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6618 if killsnd
[n
].IsPlaying() then
6623 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6631 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6635 if hahasnd
[a
].IsPlaying() then
6638 hahasnd
[Random(3)].Play();
6641 procedure g_Game_StartVote(Command
, Initiator
: string);
6645 if not gVotesEnabled
then Exit
;
6646 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6647 if gVoteInProgress
or gVotePassed
then
6649 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6650 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6653 gVoteInProgress
:= True;
6654 gVotePassed
:= False;
6655 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6658 gVoteCommand
:= Command
;
6660 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6661 Need
:= Floor((NetClientCount
+1)/2.0)+1
6663 Need
:= Floor(NetClientCount
/2.0)+1;
6664 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6665 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6668 procedure g_Game_CheckVote
;
6672 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6673 if not gVoteInProgress
then Exit
;
6675 if (gTime
>= gVoteTimer
) then
6677 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6678 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6680 Need
:= Floor(NetClientCount
/2.0) + 1;
6681 if gVoteCount
>= Need
then
6683 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6684 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6685 gVotePassed
:= True;
6686 gVoteCmdTimer
:= gTime
+ 5000;
6690 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6691 MH_SEND_VoteEvent(NET_VE_FAILED
);
6693 if NetClients
<> nil then
6694 for I
:= Low(NetClients
) to High(NetClients
) do
6695 if NetClients
[i
].Used
then
6696 NetClients
[i
].Voted
:= False;
6697 gVoteInProgress
:= False;
6703 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6704 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6706 Need
:= Floor(NetClientCount
/2.0) + 1;
6707 if gVoteCount
>= Need
then
6709 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6710 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6711 gVoteInProgress
:= False;
6712 gVotePassed
:= True;
6713 gVoteCmdTimer
:= gTime
+ 5000;
6716 if NetClients
<> nil then
6717 for I
:= Low(NetClients
) to High(NetClients
) do
6718 if NetClients
[i
].Used
then
6719 NetClients
[i
].Voted
:= False;
6724 procedure g_Game_LoadMapList(FileName
: string);
6732 if not FileExists(FileName
) then Exit
;
6734 AssignFile(ListFile
, FileName
);
6736 while not EOF(ListFile
) do
6738 ReadLn(ListFile
, s
);
6741 if s
= '' then Continue
;
6743 SetLength(MapList
, Length(MapList
)+1);
6744 MapList
[High(MapList
)] := s
;
6746 CloseFile(ListFile
);
6749 procedure g_Game_SetDebugMode();
6752 // Читы (даже в своей игре):
6756 procedure Parse_Params(var pars
: TParamStrValues
);
6763 while i
<= ParamCount
do
6766 if (Length(s
) > 1) and (s
[1] = '-') then
6768 if (Length(s
) > 2) and (s
[2] = '-') then
6769 begin // Одиночный параметр
6770 SetLength(pars
, Length(pars
) + 1);
6771 with pars
[High(pars
)] do
6773 Name
:= LowerCase(s
);
6778 if (i
< ParamCount
) then
6779 begin // Параметр со значением
6781 SetLength(pars
, Length(pars
) + 1);
6782 with pars
[High(pars
)] do
6784 Name
:= LowerCase(s
);
6785 Value
:= LowerCase(ParamStr(i
));
6794 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6799 for i
:= 0 to High(pars
) do
6800 if pars
[i
].Name
= aName
then
6802 Result
:= pars
[i
].Value
;
6807 procedure g_Game_Process_Params();
6809 pars
: TParamStrValues
;
6812 LimT
, LimS
: Integer;
6823 s
:= Find_Param_Value(pars
, '--debug');
6826 g_Game_SetDebugMode();
6827 s
:= Find_Param_Value(pars
, '--netdump');
6832 // Connect when game loads
6833 ip
:= Find_Param_Value(pars
, '-connect');
6837 s
:= Find_Param_Value(pars
, '-port');
6838 if (s
= '') or not TryStrToInt(s
, Port
) then
6841 s
:= Find_Param_Value(pars
, '-pw');
6843 g_Game_StartClient(ip
, Port
, s
);
6847 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6850 gDefaultMegawadStart
:= s
;
6853 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6854 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6856 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6859 // Start map when game loads:
6860 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6861 if isWadPath(map
) then
6864 s
:= Find_Param_Value(pars
, '-gm');
6865 GMode
:= g_Game_TextToMode(s
);
6866 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6867 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6870 s
:= Find_Param_Value(pars
, '-limt');
6871 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6877 s
:= Find_Param_Value(pars
, '-lims');
6878 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6884 s
:= Find_Param_Value(pars
, '-lives');
6885 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6891 s
:= Find_Param_Value(pars
, '-opt');
6895 Opt
:= StrToIntDef(s
, 0);
6898 s
:= Find_Param_Value(pars
, '--close');
6902 // Override map to test:
6903 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6906 if e_IsValidResourceName(s
) then
6907 e_FindResource(AllMapDirs
, s
);
6908 gTestMap
:= ExpandFileName(s
);
6911 // Delete test map after play:
6912 s
:= Find_Param_Value(pars
, '--testdelete');
6915 //gMapToDelete := MapsDir + map;
6916 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6920 // Delete temporary WAD after play:
6921 s
:= Find_Param_Value(pars
, '--tempdelete');
6922 if (s
<> '') and (gTestMap
<> '') then
6924 gMapToDelete
:= gTestMap
;
6925 gTempDelete
:= True;
6928 // Number of players:
6929 s
:= Find_Param_Value(pars
, '-pl');
6931 n
:= DEFAULT_PLAYERS
6933 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6936 s
:= Find_Param_Value(pars
, '-port');
6937 if (s
= '') or not TryStrToInt(s
, Port
) then
6938 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6940 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6943 // Execute script when game loads:
6944 s
:= Find_Param_Value(pars
, '-exec');
6947 // if not isWadPath(s) then
6948 // s := GameDir + '/' + s;
6953 if IOResult
<> 0 then
6955 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6956 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6960 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6961 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6966 if IOResult
<> 0 then
6968 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6969 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6973 if Pos('#', s
) <> 1 then // script comment
6974 g_Console_Process(s
, True);
6985 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6986 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6987 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6988 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6990 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6991 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6992 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6993 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6996 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6997 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7000 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7001 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7003 {$IFDEF ENABLE_HOLMES}
7004 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7007 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7009 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7010 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7012 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7013 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7015 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
7016 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
7017 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
7018 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
7019 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7020 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7021 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7022 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7023 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');