1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
24 SysUtils
, Classes
, MAPDEF
,
25 g_base
, g_basic
, g_player
, g_res_downloader
,
26 g_sound
, utils
, md5
, mempool
, xprofiler
,
31 TGameSettings
= record
38 ItemRespawnTime
: Word;
49 TDelayedEvent
= record
58 Sound
: TPlayableSound
;
59 Tags
: Array of String;
63 TPlayerSettings
= record
68 // ones below are sent only to the server
70 WeaponPreferences
: Array[WP_FIRST
..WP_LAST
+1] of Byte;
87 function g_Game_IsNet(): Boolean;
88 function g_Game_IsServer(): Boolean;
89 function g_Game_IsClient(): Boolean;
90 procedure g_Game_Init();
91 procedure g_Game_Free (freeTextures
: Boolean=true);
92 procedure g_Game_LoadData();
93 procedure g_Game_FreeData();
94 procedure g_Game_Update();
95 procedure g_Game_PreUpdate();
96 procedure g_Game_Quit();
97 function g_Game_ModeToText(Mode
: Byte): string;
98 function g_Game_TextToMode(Mode
: string): Byte;
99 procedure g_Game_ExecuteEvent(Name
: String);
100 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
101 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
102 procedure g_Game_RemovePlayer();
103 procedure g_Game_Spectate();
104 procedure g_Game_SpectateCenterView();
105 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
106 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
107 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
108 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
109 procedure g_Game_Restart();
110 procedure g_Game_RestartLevel();
111 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
112 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
113 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
114 procedure g_Game_ChangeMap(const MapPath
: String);
115 procedure g_Game_ExitLevel(const Map
: AnsiString);
116 function g_Game_GetFirstMap(WAD
: String): String;
117 function g_Game_GetNextMap(): String;
118 procedure g_Game_NextLevel();
119 procedure g_Game_Pause(Enable
: Boolean);
120 procedure g_Game_HolmesPause(Enable
: Boolean);
121 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
122 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
123 procedure g_Game_Message(Msg
: String; Time
: Word);
124 procedure g_Game_LoadMapList(FileName
: String);
125 procedure g_Game_PauseAllSounds(Enable
: Boolean);
126 procedure g_Game_StopAllSounds(all
: Boolean);
127 procedure g_Game_UpdateTriggerSounds();
128 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
129 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
130 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
131 procedure g_Game_Announce_KillCombo(Param
: Integer);
132 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
133 procedure g_Game_StartVote(Command
, Initiator
: string);
134 procedure g_Game_CheckVote
;
135 procedure g_FatalError(Text: String);
136 procedure g_SimpleError(Text: String);
137 function g_Game_IsTestMap(): Boolean;
138 procedure g_Game_DeleteTestMap();
139 procedure GameCVars(P
: SSArray
);
140 procedure PlayerSettingsCVars(P
: SSArray
);
141 procedure SystemCommands(P
: SSArray
);
142 procedure GameCommands(P
: SSArray
);
143 procedure GameCheats(P
: SSArray
);
144 procedure DebugCommands(P
: SSArray
);
145 procedure g_Game_Process_Params
;
146 procedure g_Game_SetDebugMode();
148 function IsActivePlayer(p
: TPlayer
): Boolean;
149 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
150 procedure SortGameStat(var stat
: TPlayerStatArray
);
154 procedure g_Game_InGameMenu(Show
: Boolean);
156 {$IFDEF ENABLE_SYSTEM}
157 procedure CharPress (C
: AnsiChar);
160 procedure KeyPress (K
: Word);
162 { procedure SetWinPause(Enable: Boolean); }
183 EXIT_ENDLEVELSINGLE
= 4;
184 EXIT_ENDLEVELCUSTOM
= 5;
186 GAME_OPTION_RESERVED
= 1;
187 GAME_OPTION_TEAMDAMAGE
= 2;
188 GAME_OPTION_ALLOWEXIT
= 4;
189 GAME_OPTION_WEAPONSTAY
= 8;
190 GAME_OPTION_MONSTERS
= 16;
191 GAME_OPTION_BOTVSPLAYER
= 32;
192 GAME_OPTION_BOTVSMONSTER
= 64;
193 GAME_OPTION_DMKEYS
= 128;
194 GAME_OPTION_TEAMHITTRACE
= 256;
195 GAME_OPTION_TEAMHITPROJECTILE
= 512;
196 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
197 GAME_OPTION_ALLOWDROPFLAG
= 2048;
198 GAME_OPTION_THROWFLAG
= 4096;
203 STATE_INTERCUSTOM
= 3;
204 STATE_INTERSINGLE
= 4;
210 LMS_RESPAWN_NONE
= 0;
211 LMS_RESPAWN_WARMUP
= 1;
212 LMS_RESPAWN_FINAL
= 2;
229 CONFIG_FILENAME
= 'Doom2DF.cfg';
231 TEST_MAP_NAME
= '$$$_TEST_$$$';
233 STD_PLAYER_MODEL
= 'Doomer';
241 STATFILE_VERSION
= $03;
244 gGameSettings
: TGameSettings
;
245 gPlayer1Settings
: TPlayerSettings
;
246 gPlayer2Settings
: TPlayerSettings
;
248 gPlayerScreenSize
: TDFPoint
;
249 gPlayer1
: TPlayer
= nil;
250 gPlayer2
: TPlayer
= nil;
252 gLerpFactor
: Single = 1.0;
253 gSwitchGameMode
: Byte = GM_DM
;
254 gHearPoint1
, gHearPoint2
: THearPoint
;
255 gMaxDist
: Integer = 1; // for sound
256 gSoundEffectsDF
: Boolean = False;
257 gSoundTriggerTime
: Word = 0;
258 gAnnouncer
: Integer = ANNOUNCE_NONE
;
259 goodsnd
: array[0..3] of TPlayableSound
;
260 killsnd
: array[0..3] of TPlayableSound
;
261 hahasnd
: array[0..2] of TPlayableSound
;
262 sound_get_flag
: array[0..1] of TPlayableSound
;
263 sound_lost_flag
: array[0..1] of TPlayableSound
;
264 sound_ret_flag
: array[0..1] of TPlayableSound
;
265 sound_cap_flag
: array[0..1] of TPlayableSound
;
266 gBodyKillEvent
: Integer = -1;
267 gDefInterTime
: ShortInt = -1;
268 gInterEndTime
: LongWord = 0;
269 gInterTime
: LongWord = 0;
270 gServInterTime
: Byte = 0;
271 gGameStartTime
: LongWord = 0;
272 gTotalMonsters
: Integer = 0;
273 gPauseMain
: Boolean = false;
274 gPauseHolmes
: Boolean = false;
275 gShowTime
: Boolean = False;
276 gShowFPS
: Boolean = False;
277 gShowScore
: Boolean = True;
278 gShowStat
: Boolean = True;
279 gShowPIDs
: Boolean = False;
280 gShowKillMsg
: Boolean = True;
281 gShowLives
: Boolean = True;
282 gShowPing
: Boolean = False;
283 gShowMap
: Boolean = False;
285 gState
: Byte = STATE_NONE
;
287 sWidth
, sHeight
: Word;
288 gSpectMode
: Byte = SPECT_NONE
;
289 gSpectHUD
: Boolean = True;
290 gSpectKeyPress
: Boolean = False;
291 gSpectX
: Integer = 0;
292 gSpectY
: Integer = 0;
293 gSpectStep
: Byte = 8;
294 gSpectViewTwo
: Boolean = False;
295 gSpectPID1
: Integer = -1;
296 gSpectPID2
: Integer = -1;
297 gSpectAuto
: Boolean = False;
298 gSpectAutoNext
: LongWord;
299 gSpectAutoStepX
: Integer;
300 gSpectAutoStepY
: Integer;
301 gMusic
: TMusic
= nil;
302 gLoadGameMode
: Boolean;
303 gCheats
: Boolean = False;
304 gMapOnce
: Boolean = False;
305 gMapToDelete
: String;
306 gTempDelete
: Boolean = False;
307 gLastMap
: Boolean = False;
310 gResolutionChange
: Boolean = False;
311 gRC_Width
, gRC_Height
: Integer;
312 gRC_FullScreen
, gRC_Maximized
: Boolean;
313 gLanguageChange
: Boolean = False;
314 gDebugMode
: Boolean = False;
315 g_debug_WinMsgs
: Boolean = False;
316 g_debug_MonsterOff
: Boolean = False;
317 g_debug_BotAIOff
: Byte = 0;
318 g_debug_HealthBar
: Boolean = False;
319 g_Debug_Player
: Boolean = False;
320 gCoopMonstersKilled
: Word = 0;
321 gCoopSecretsFound
: Word = 0;
322 gCoopTotalMonstersKilled
: Word = 0;
323 gCoopTotalSecretsFound
: Word = 0;
324 gCoopTotalMonsters
: Word = 0;
325 gCoopTotalSecrets
: Word = 0;
326 gStatsOff
: Boolean = False;
327 gStatsPressed
: Boolean = False;
328 gExitByTrigger
: Boolean = False;
329 gNextMap
: String = '';
330 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
331 gLMSRespawnTime
: Cardinal = 0;
332 gLMSSoftSpawn
: Boolean = False;
333 gMissionFailed
: Boolean = False;
334 gVoteInProgress
: Boolean = False;
335 gVotePassed
: Boolean = False;
336 gVoteCommand
: string = '';
337 gVoteTimer
: Cardinal = 0;
338 gVoteCmdTimer
: Cardinal = 0;
339 gVoteCount
: Integer = 0;
340 gVoteTimeout
: Cardinal = 30;
341 gVoted
: Boolean = False;
342 gVotesEnabled
: Boolean = True;
343 gEvents
: Array of TGameEvent
;
344 gDelayedEvents
: Array of TDelayedEvent
;
345 gUseChatSounds
: Boolean = True;
346 gChatSounds
: Array of TChatSound
;
347 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
348 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
349 gInterReadyCount
: Integer = 0;
350 gMaxBots
: Integer = 127;
352 g_dbg_ignore_bounds
: Boolean = false;
353 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
354 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
356 // move button values:
357 // bits 0-1: l/r state:
358 // 0: neither left, nor right pressed
361 // bits 4-5: l/r state when strafe was pressed
362 P1MoveButton
: Byte = 0;
363 P2MoveButton
: Byte = 0;
365 g_profile_frame_update
: Boolean = false;
366 g_profile_frame_draw
: Boolean = false;
367 g_profile_collision
: Boolean = false;
368 g_profile_los
: Boolean = false;
369 g_profile_history_size
: Integer = 1000;
371 g_rlayer_back
: Boolean = true;
372 g_rlayer_step
: Boolean = true;
373 g_rlayer_wall
: Boolean = true;
374 g_rlayer_door
: Boolean = true;
375 g_rlayer_acid1
: Boolean = true;
376 g_rlayer_acid2
: Boolean = true;
377 g_rlayer_water
: Boolean = true;
378 g_rlayer_fore
: Boolean = true;
380 wNeedTimeReset
: Boolean = false;
382 procedure g_ResetDynlights ();
383 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
384 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
386 function conIsCheatsEnabled (): Boolean; inline;
387 function gPause (): Boolean; inline;
389 type (* private state *)
390 TEndCustomGameStat
= record
391 PlayerStat
: TPlayerStatArray
;
395 Map
, MapName
: String;
398 TEndSingleGameStat
= record
399 PlayerStat
: Array [0..1] of record
405 TotalSecrets
: Integer;
409 x
, y
, radius
: Integer;
412 exploRadius
: Integer;
415 var (* private state *)
416 CustomStat
: TEndCustomGameStat
;
417 StatShotDone
: Boolean;
418 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
419 SingleStat
: TEndSingleGameStat
;
422 EndingGameCounter
: Byte;
424 g_playerLight
: Boolean;
425 g_dynLights
: array of TDynLight
= nil;
426 g_dynLightCount
: Integer = 0;
427 EndPicPath
: AnsiString; // full path, used by render
432 {$IFDEF ENABLE_HOLMES}
444 {$IFDEF ENABLE_SHELLS}
447 {$IFDEF ENABLE_CORPSES}
450 {$IFDEF ENABLE_RENDER}
453 {$IFDEF ENABLE_SYSTEM}
457 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
458 g_playermodel
, g_options
, Math
,
459 g_triggers
, g_monsters
, e_sound
, CONFIG
,
460 g_language
, g_net
, g_phys
,
461 ENet
, e_msg
, g_netmsg
, g_netmaster
,
465 charbuff
: packed array [0..15] of AnsiChar = (
466 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
469 function Translit (const S
: AnsiString): AnsiString;
474 for i
:= 1 to Length(Result
) do
477 #
$C9: Result
[i
] := 'Q';
478 #
$D6: Result
[i
] := 'W';
479 #
$D3: Result
[i
] := 'E';
480 #
$CA: Result
[i
] := 'R';
481 #
$C5: Result
[i
] := 'T';
482 #
$CD: Result
[i
] := 'Y';
483 #
$C3: Result
[i
] := 'U';
484 #
$D8: Result
[i
] := 'I';
485 #
$D9: Result
[i
] := 'O';
486 #
$C7: Result
[i
] := 'P';
487 #
$D5: Result
[i
] := '['; //Chr(219);
488 #
$DA: Result
[i
] := ']'; //Chr(221);
489 #
$D4: Result
[i
] := 'A';
490 #
$DB: Result
[i
] := 'S';
491 #
$C2: Result
[i
] := 'D';
492 #
$C0: Result
[i
] := 'F';
493 #
$CF: Result
[i
] := 'G';
494 #
$D0: Result
[i
] := 'H';
495 #
$CE: Result
[i
] := 'J';
496 #
$CB: Result
[i
] := 'K';
497 #
$C4: Result
[i
] := 'L';
498 #
$C6: Result
[i
] := ';'; //Chr(186);
499 #
$DD: Result
[i
] := #39; //Chr(222);
500 #
$DF: Result
[i
] := 'Z';
501 #
$D7: Result
[i
] := 'X';
502 #
$D1: Result
[i
] := 'C';
503 #
$CC: Result
[i
] := 'V';
504 #
$C8: Result
[i
] := 'B';
505 #
$D2: Result
[i
] := 'N';
506 #
$DC: Result
[i
] := 'M';
507 #
$C1: Result
[i
] := ','; //Chr(188);
508 #
$DE: Result
[i
] := '.'; //Chr(190);
514 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
519 ls2
:= Translit(CheatRus
[ct
]);
520 if length(ls1
) = 0 then ls1
:= '~';
521 if length(ls2
) = 0 then ls2
:= '~';
523 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
524 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
525 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
526 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
528 if ct = I_GAME_CHEAT_JETPACK then
530 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
531 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
532 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
533 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
534 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
535 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
551 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
552 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
553 or g_Game_IsNet then Exit;
555 if not gGameOn
then exit
;
556 if not conIsCheatsEnabled
then exit
;
558 s
:= 'SOUND_GAME_RADIO';
561 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
563 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
564 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
568 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
570 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
571 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
575 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
577 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
578 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
582 if CheckCheat(I_GAME_CHEAT_DEATH
) then
584 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
585 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
586 s
:= 'SOUND_MONSTER_HAHA';
590 if CheckCheat(I_GAME_CHEAT_DOORS
) then
592 g_Triggers_OpenAll();
596 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
598 if gTriggers
<> nil then
599 for a
:= 0 to High(gTriggers
) do
600 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
602 gExitByTrigger
:= True;
603 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
604 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
610 s2
:= Copy(charbuff
, 15, 2);
611 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
613 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
621 if CheckCheat(I_GAME_CHEAT_FLY
) then
627 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
629 VEL_JUMP
:= 30-VEL_JUMP
;
633 if CheckCheat(I_GAME_CHEAT_SPEED
) then
635 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
639 if CheckCheat(I_GAME_CHEAT_SUIT
) then
641 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
642 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
646 if CheckCheat(I_GAME_CHEAT_AIR
) then
648 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
649 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
653 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
655 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
656 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
660 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
662 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
663 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
667 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
669 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
670 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
674 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
676 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
677 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
681 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
683 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
684 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
687 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
689 gAimLine
:= not gAimLine
;
692 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
694 gShowMap
:= not gShowMap
;
705 procedure KeyPress (K
: Word);
706 var Msg
: g_gui
.TMessage
;
711 if (g_ActiveWindow
<> nil) then
713 Msg
.Msg
:= WM_KEYDOWN
;
714 Msg
.WParam
:= VK_ESCAPE
;
715 g_ActiveWindow
.OnMessage(Msg
);
716 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
718 else if (gState
<> STATE_FOLD
) then
720 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
722 g_Game_InGameMenu(True);
724 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
726 if (gState
<> STATE_MENU
) then
728 if (NetMode
<> NET_NONE
) then
730 g_Game_StopAllSounds(True);
732 gState
:= STATE_MENU
;
736 g_GUI_ShowWindow('MainMenu');
737 g_Sound_PlayEx('MENU_OPEN');
742 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
743 begin // <F2> .. <F6> � <F12>
744 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
746 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
747 if (not g_Game_IsNet
) then g_Game_Pause(True);
749 IK_F2
: g_Menu_Show_SaveMenu();
750 IK_F3
: g_Menu_Show_LoadMenu();
751 IK_F4
: g_Menu_Show_GameSetGame();
752 IK_F5
: g_Menu_Show_OptionsVideo();
753 IK_F6
: g_Menu_Show_OptionsSound();
754 IK_F7
: g_Menu_Show_EndGameMenu();
755 IK_F10
: g_Menu_Show_QuitGameMenu();
762 gJustChatted
:= False;
763 if gConsoleShow
or gChatShow
then
765 g_Console_Control(K
);
767 else if (g_ActiveWindow
<> nil) then
769 Msg
.Msg
:= WM_KEYDOWN
;
771 g_ActiveWindow
.OnMessage(Msg
);
773 else if (gState
= STATE_MENU
) then
775 g_GUI_ShowWindow('MainMenu');
776 g_Sound_PlayEx('MENU_OPEN');
782 procedure KeyPress (K
: Word);
784 gJustChatted
:= False;
785 if gConsoleShow
or gChatShow
then
787 g_Console_Control(K
);
792 {$IFDEF ENABLE_SYSTEM}
793 procedure CharPress (C
: AnsiChar);
795 var Msg
: g_gui
.TMessage
;
799 if gConsoleShow
or gChatShow
then
804 else if g_ActiveWindow
<> nil then
807 Msg
.WParam
:= Ord(C
);
808 g_ActiveWindow
.OnMessage(Msg
);
815 charbuff
[a
] := charbuff
[a
+ 1];
817 charbuff
[15] := upcase1251(C
);
824 // ////////////////////////////////////////////////////////////////////////// //
825 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
827 procedure g_ResetDynlights ();
831 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
833 for idx
:= 0 to g_dynLightCount
-1 do
835 if g_dynLights
[idx
].exploCount
= -666 then
842 Inc(g_dynLights
[idx
].exploCount
);
843 if (g_dynLights
[idx
].exploCount
< 10) then
845 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
846 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
847 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
848 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
853 g_dynLightCount
:= lnum
;
856 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
858 if not gwin_has_stencil
then exit
;
859 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
860 g_dynLights
[g_dynLightCount
].x
:= x
;
861 g_dynLights
[g_dynLightCount
].y
:= y
;
862 g_dynLights
[g_dynLightCount
].radius
:= radius
;
863 g_dynLights
[g_dynLightCount
].r
:= r
;
864 g_dynLights
[g_dynLightCount
].g
:= g
;
865 g_dynLights
[g_dynLightCount
].b
:= b
;
866 g_dynLights
[g_dynLightCount
].a
:= a
;
867 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
868 Inc(g_dynLightCount
);
871 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
873 if not gwin_has_stencil
then exit
;
874 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
875 g_dynLights
[g_dynLightCount
].x
:= x
;
876 g_dynLights
[g_dynLightCount
].y
:= y
;
877 g_dynLights
[g_dynLightCount
].radius
:= 0;
878 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
879 g_dynLights
[g_dynLightCount
].r
:= r
;
880 g_dynLights
[g_dynLightCount
].g
:= g
;
881 g_dynLights
[g_dynLightCount
].b
:= b
;
882 g_dynLights
[g_dynLightCount
].a
:= 0;
883 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
884 Inc(g_dynLightCount
);
887 // ////////////////////////////////////////////////////////////////////////// //
888 function conIsCheatsEnabled (): Boolean; inline;
891 if g_Game_IsNet
then exit
;
892 if not gDebugMode
then
894 //if not gCheats then exit;
895 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
896 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
901 // ////////////////////////////////////////////////////////////////////////// //
903 TParamStrValue
= record
908 TParamStrValues
= Array of TParamStrValue
;
911 INTER_ACTION_TEXT
= 1;
912 INTER_ACTION_PIC
= 2;
913 INTER_ACTION_MUSIC
= 3;
918 DataLoaded
: Boolean = False;
920 MapList
: SSArray
= nil;
921 MapIndex
: Integer = -1;
922 InterReadyTime
: Integer = -1;
923 StatDate
: string = '';
938 function Compare(a
, b
: TPlayerStat
): Integer;
940 if a
.Spectator
then Result
:= 1
941 else if b
.Spectator
then Result
:= -1
942 else if a
.Frags
< b
.Frags
then Result
:= 1
943 else if a
.Frags
> b
.Frags
then Result
:= -1
944 else if a
.Deaths
< b
.Deaths
then Result
:= -1
945 else if a
.Deaths
> b
.Deaths
then Result
:= 1
946 else if a
.Kills
< b
.Kills
then Result
:= -1
950 procedure SortGameStat(var stat
: TPlayerStatArray
);
955 if stat
= nil then Exit
;
957 for I
:= High(stat
) downto Low(stat
) do
958 for J
:= Low(stat
) to High(stat
) - 1 do
959 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
962 stat
[J
] := stat
[J
+ 1];
967 // saves a shitty CSV containing the game stats passed to it
968 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
971 dir
, fname
, map
, mode
, etime
: String;
975 dir
:= e_GetWriteableDir(StatsDirs
);
976 // stats are placed in stats/yy/mm/dd/*.csv
977 fname
:= e_CatPath(dir
, Path
);
978 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
979 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
980 AssignFile(s
, fname
);
982 SetTextCodePage(s
, CP_UTF8
);
984 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
985 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
986 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
987 mode
:= g_Game_ModeToText(Stat
.GameMode
);
988 etime
:= Format('%d:%.2d:%.2d', [
989 Stat
.GameTime
div 1000 div 3600,
990 (Stat
.GameTime
div 1000 div 60) mod 60,
991 Stat
.GameTime
div 1000 mod 60
993 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
994 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
1000 gGameSettings
.TimeLimit
,
1001 gGameSettings
.ScoreLimit
,
1002 gGameSettings
.Options
,
1004 Length(Stat
.PlayerStat
)
1006 // line 2: game specific shit
1007 // if it's a team game: red score, blue score
1008 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1009 // otherwise nothing
1010 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1012 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
1013 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1015 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1016 // lines 3-...: team, player name, frags, deaths
1017 WriteLn(s
, 'team,name,frags,deaths');
1018 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1019 with Stat
.PlayerStat
[I
] do
1020 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1022 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1025 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1030 procedure ClearDebugCvars();
1032 g_debug_WinMsgs
:= False;
1033 g_debug_MonsterOff
:= False;
1034 g_debug_BotAIOff
:= 0;
1035 g_debug_HealthBar
:= False;
1036 g_Debug_Player
:= False;
1039 function g_Game_ModeToText(Mode
: Byte): string;
1043 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1044 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1045 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1046 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1047 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1051 function g_Game_TextToMode(Mode
: string): Byte;
1054 Mode
:= UpperCase(Mode
);
1055 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1060 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1065 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1070 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1075 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1077 Result
:= GM_SINGLE
;
1082 function g_Game_IsNet(): Boolean;
1084 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1087 function g_Game_IsServer(): Boolean;
1089 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1092 function g_Game_IsClient(): Boolean;
1094 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1097 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1104 Result
.name
:= ExtractFileName(WAD
);
1105 Result
.description
:= '';
1106 Result
.author
:= '';
1108 w
:= TWADFile
.Create();
1111 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1117 cfg
:= TConfig
.CreateMem(p
, len
);
1118 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1119 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1120 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1121 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1127 procedure g_Game_FreeWAD
;
1130 g_Sound_Delete('MUSIC_endmus');
1131 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1132 gGameSettings
.WAD
:= '';
1135 procedure g_Game_LoadWAD(WAD
: string);
1144 gGameSettings
.WAD
:= WAD
;
1145 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1148 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1150 w
:= TWADFile
.Create();
1153 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1159 cfg
:= TConfig
.CreateMem(p
, len
);
1162 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1163 if MegaWAD
.endpic
<> '' then
1164 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1166 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1167 if MegaWAD
.endmus
<> '' then
1169 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1170 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1178 {procedure start_trigger(t: string);
1182 function next_trigger(): Boolean;
1186 procedure DisableCheats();
1192 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1193 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1194 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1195 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1197 {$IF DEFINED(D2F_DEBUG)}
1198 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1199 gAimLine
:= g_dbg_aimline_on
;
1203 procedure g_Game_ExecuteEvent(Name
: String);
1209 if gEvents
= nil then
1211 for a
:= 0 to High(gEvents
) do
1212 if gEvents
[a
].Name
= Name
then
1214 if gEvents
[a
].Command
<> '' then
1215 g_Console_Process(gEvents
[a
].Command
, True);
1220 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1225 if gDelayedEvents
<> nil then
1226 for a
:= 0 to High(gDelayedEvents
) do
1227 if not gDelayedEvents
[a
].Pending
then
1234 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1235 n
:= High(gDelayedEvents
);
1237 gDelayedEvents
[n
].Pending
:= True;
1238 gDelayedEvents
[n
].DEType
:= DEType
;
1239 gDelayedEvents
[n
].DENum
:= Num
;
1240 gDelayedEvents
[n
].DEStr
:= Str
;
1241 if DEType
= DE_GLOBEVENT
then
1242 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1244 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1248 procedure EndGame();
1254 if g_Game_IsNet
and g_Game_IsServer
then
1255 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1258 gPauseMain
:= false;
1259 gPauseHolmes
:= false;
1262 g_Game_StopAllSounds(False);
1267 EndingGameCounter
:= 0;
1269 {$IFDEF ENABLE_MENU}
1270 g_ActiveWindow
:= nil;
1273 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1274 gLMSRespawnTime
:= 0;
1277 EXIT_SIMPLE
: // Выход через меню или конец теста
1281 begin // Это был тест
1285 begin // Выход в главное меню
1286 {$IFDEF DISABLE_MENU}
1287 gState
:= STATE_MENU
; // ???
1289 gMusic
.SetByName('MUSIC_MENU');
1291 if gState
<> STATE_SLIST
then
1293 g_GUI_ShowWindow('MainMenu');
1294 gState
:= STATE_MENU
;
1298 // Обновляем список серверов
1299 slReturnPressed
:= True;
1300 if g_Net_Slist_Fetch(slCurrent
) then
1302 if slCurrent
= nil then
1303 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1306 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1307 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1310 g_Game_ExecuteEvent('ongameend');
1314 EXIT_RESTART
: // Начать уровень сначала
1316 if not g_Game_IsClient
then g_Game_Restart();
1319 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1321 // Статистика Своей игры:
1322 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1324 CustomStat
.GameTime
:= gTime
;
1325 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1326 CustomStat
.MapName
:= gMapInfo
.Name
;
1327 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1328 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1329 CustomStat
.TeamStat
:= gTeamStat
;
1331 CustomStat
.PlayerStat
:= nil;
1333 // Статистика игроков:
1334 if gPlayers
<> nil then
1336 for a
:= 0 to High(gPlayers
) do
1337 if gPlayers
[a
] <> nil then
1339 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1340 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1343 Name
:= gPlayers
[a
].Name
;
1344 Frags
:= gPlayers
[a
].Frags
;
1345 Deaths
:= gPlayers
[a
].Death
;
1346 Kills
:= gPlayers
[a
].Kills
;
1347 Team
:= gPlayers
[a
].Team
;
1348 Color
:= gPlayers
[a
].Model
.Color
;
1349 Spectator
:= gPlayers
[a
].FSpectator
;
1353 SortGameStat(CustomStat
.PlayerStat
);
1355 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1358 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1359 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1360 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1361 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1363 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1366 StatShotDone
:= False;
1369 g_Game_ExecuteEvent('onmapend');
1370 if not g_Game_IsClient
then g_Player_ResetReady
;
1371 gInterReadyCount
:= 0;
1373 // Затухающий экран:
1374 EndingGameCounter
:= 255;
1375 gState
:= STATE_FOLD
;
1377 if gDefInterTime
< 0 then
1378 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1380 gInterEndTime
:= gDefInterTime
* 1000;
1383 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1385 // Статистика Одиночной игры:
1386 SingleStat
.GameTime
:= gTime
;
1387 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1388 SingleStat
.TotalSecrets
:= gSecretsCount
;
1389 // Статистика первого игрока:
1390 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1391 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1392 // Статистика второго игрока (если есть):
1393 if SingleStat
.TwoPlayers
then
1395 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1396 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1399 g_Game_ExecuteEvent('onmapend');
1402 if gNextMap
<> '' then
1404 gMusic
.SetByName('MUSIC_INTERMUS');
1406 gState
:= STATE_INTERSINGLE
;
1409 g_Game_ExecuteEvent('oninter');
1411 else // Больше нет карт
1413 // Затухающий экран:
1414 EndingGameCounter
:= 255;
1415 gState
:= STATE_FOLD
;
1420 // Окончание обработано:
1421 if gExit
<> EXIT_QUIT
then
1425 procedure g_Game_Init();
1429 gTempDelete
:= False;
1431 sfsGCDisable(); // temporary disable removing of temporary volumes
1435 gPauseMain
:= false;
1436 gPauseHolmes
:= false;
1439 {e_MouseInfo.Accel := 1.0;}
1443 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1444 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1445 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1446 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1447 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1449 gMusic
:= TMusic
.Create();
1450 gMusic
.SetByName('MUSIC_MENU');
1453 gGameSettings
.WarmupTime
:= 30;
1455 gState
:= STATE_MENU
;
1457 SetLength(gEvents
, 6);
1458 gEvents
[0].Name
:= 'ongamestart';
1459 gEvents
[1].Name
:= 'ongameend';
1460 gEvents
[2].Name
:= 'onmapstart';
1461 gEvents
[3].Name
:= 'onmapend';
1462 gEvents
[4].Name
:= 'oninter';
1463 gEvents
[5].Name
:= 'onwadend';
1465 sfsGCEnable(); // enable releasing unused volumes
1469 procedure g_Game_Free(freeTextures
: Boolean=true);
1471 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1472 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1474 g_Map_Free(freeTextures
);
1477 {$IFDEF ENABLE_GIBS}
1480 {$IFDEF ENABLE_SHELLS}
1483 {$IFDEF ENABLE_CORPSES}
1484 g_Corpses_RemoveAll
;
1487 gGameSettings
.GameType
:= GT_NONE
;
1488 if gGameSettings
.GameMode
= GM_SINGLE
then
1489 gGameSettings
.GameMode
:= GM_DM
;
1490 gSwitchGameMode
:= gGameSettings
.GameMode
;
1493 gExitByTrigger
:= False;
1496 function IsActivePlayer(p
: TPlayer
): Boolean;
1501 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1504 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1510 if gPlayers
= nil then
1514 for a
:= Low(gPlayers
) to High(gPlayers
) do
1515 if IsActivePlayer(gPlayers
[a
]) then
1517 SetLength(ids
, Length(ids
) + 1);
1518 ids
[High(ids
)] := gPlayers
[a
].UID
;
1519 if gPlayers
[a
].UID
= Skip
then
1522 if Length(ids
) = 0 then
1527 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1530 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1536 if gPlayers
= nil then
1540 for a
:= Low(gPlayers
) to High(gPlayers
) do
1541 if IsActivePlayer(gPlayers
[a
]) then
1543 SetLength(ids
, Length(ids
) + 1);
1544 ids
[High(ids
)] := gPlayers
[a
].UID
;
1545 if gPlayers
[a
].UID
= Skip
then
1548 if Length(ids
) = 0 then
1551 Result
:= ids
[Length(ids
) - 1]
1553 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1556 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1562 if gPlayers
= nil then
1566 for a
:= Low(gPlayers
) to High(gPlayers
) do
1567 if IsActivePlayer(gPlayers
[a
]) then
1569 SetLength(ids
, Length(ids
) + 1);
1570 ids
[High(ids
)] := gPlayers
[a
].UID
;
1571 if gPlayers
[a
].UID
= Skip
then
1574 if Length(ids
) = 0 then
1576 if Length(ids
) = 1 then
1581 Result
:= ids
[Random(Length(ids
))];
1583 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1585 Result
:= ids
[Random(Length(ids
))];
1590 function GetRandomSpectMode(Current
: Byte): Byte;
1597 0: Result
:= SPECT_STATS
;
1598 1: Result
:= SPECT_MAPVIEW
;
1599 2: Result
:= SPECT_MAPVIEW
;
1600 3: Result
:= SPECT_PLAYERS
;
1601 4: Result
:= SPECT_PLAYERS
;
1602 5: Result
:= SPECT_PLAYERS
;
1603 6: Result
:= SPECT_PLAYERS
;
1605 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1609 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1615 if (plr
= nil) then exit
;
1616 if (p
= 2) then time
:= 1000 else time
:= 1;
1617 strafeDir
:= MoveButton
shr 4;
1618 MoveButton
:= MoveButton
and $0F;
1620 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1621 MoveButton
:= 1 // Нажата только "Влево"
1622 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1623 MoveButton
:= 2 // Нажата только "Вправо"
1624 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1625 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1627 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1628 if MoveButton
= 1 then
1629 plr
.PressKey(KEY_LEFT
, time
)
1630 else if MoveButton
= 2 then
1631 plr
.PressKey(KEY_RIGHT
, time
);
1633 // if we have "strafe" key, turn off old strafe mechanics
1634 if gPlayerAction
[p
, ACTION_STRAFE
] then
1636 // new strafe mechanics
1637 if (strafeDir
= 0) then
1638 strafeDir
:= MoveButton
; // start strafing
1639 // now set direction according to strafe (reversed)
1640 if (strafeDir
= 2) then
1641 plr
.SetDirection(TDirection
.D_LEFT
)
1642 else if (strafeDir
= 1) then
1643 plr
.SetDirection(TDirection
.D_RIGHT
)
1647 strafeDir
:= 0; // not strafing anymore
1648 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1649 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1650 plr
.SetDirection(TDirection
.D_LEFT
)
1651 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1652 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1653 plr
.SetDirection(TDirection
.D_RIGHT
)
1654 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1655 else if MoveButton
<> 0 then
1656 plr
.SetDirection(TDirection(MoveButton
-1))
1659 // fix movebutton state
1660 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1662 // Остальные клавиши:
1663 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1664 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1665 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1666 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1667 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1669 for i
:= WP_FACT
to WP_LACT
do
1671 if gWeaponAction
[p
, i
] then
1673 plr
.ProcessWeaponAction(i
);
1674 gWeaponAction
[p
, i
] := False
1678 for i
:= WP_FIRST
to WP_LAST
do
1680 if gSelectWeapon
[p
, i
] then
1682 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1683 gSelectWeapon
[p
, i
] := False
1687 {$IFDEF ENABLE_MENU}
1688 // HACK: add dynlight here
1689 if gwin_k8_enable_light_experiments
then
1691 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1693 g_playerLight
:= true;
1695 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1697 g_playerLight
:= false;
1701 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1705 // HACK: don't have a "key was pressed" function
1706 procedure InterReady();
1708 if InterReadyTime
> gTime
then Exit
;
1709 InterReadyTime
:= gTime
+ 3000;
1710 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1713 procedure g_Game_PreUpdate();
1715 // these are in separate PreUpdate functions because they can interact during Update()
1716 // and are synced over the net
1717 // we don't care that much about corpses and gibs
1718 g_Player_PreUpdate();
1719 g_Monsters_PreUpdate();
1720 g_Items_PreUpdate();
1721 g_Weapon_PreUpdate();
1724 procedure g_Game_SetupHearPoints
;
1725 var p1
, p2
: TPlayer
; a
, b
: Integer;
1729 gHearPoint1
.Active
:= false;
1730 gHearPoint2
.Active
:= false;
1731 if gSpectMode
= SPECT_MAPVIEW
then
1733 // TODO something better (render dependency)
1734 gHearPoint1
.Active
:= true;
1735 gHearPoint1
.Coords
.X
:= gSpectX
+ gScreenWidth
div 2;
1736 gHearPoint1
.Coords
.Y
:= gSpectY
+ gScreenHeight
div 2;
1738 else if gSpectMode
= SPECT_PLAYERS
then
1740 p1
:= g_Player_Get(gSpectPID1
);
1741 if gSpectViewTwo
then
1742 p2
:= g_Player_Get(gSpectPID2
);
1744 else if gSpectMode
= SPECT_NONE
then
1751 gHearPoint1
.Active
:= true;
1752 gHearPoint1
.Coords
.X
:= p1
.obj
.x
+ p1
.obj
.rect
.width
div 2;
1753 gHearPoint1
.Coords
.Y
:= p1
.obj
.y
+ p1
.obj
.rect
.height
div 2;
1755 if (p2
<> nil) and (p1
<> p2
) then
1757 gHearPoint2
.Active
:= true;
1758 gHearPoint2
.Coords
.X
:= p2
.obj
.x
+ p2
.obj
.rect
.width
div 2;
1759 gHearPoint2
.Coords
.Y
:= p2
.obj
.y
+ p2
.obj
.rect
.height
div 2;
1761 // TODO something better (render dependency)
1762 if (p1
<> nil) and (p2
<> nil) then
1764 gPlayerScreenSize
.X
:= gScreenWidth
- 196;
1765 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
1769 gPlayerScreenSize
.X
:= gScreenWidth
- 196;
1770 gPlayerScreenSize
.Y
:= gScreenHeight
;
1773 if gMapInfo
.Height
> gPlayerScreenSize
.Y
then a
:= gMapInfo
.Height
- gPlayerScreenSize
.Y
else a
:= gMapInfo
.Height
;
1774 if gMapInfo
.Width
> gPlayerScreenSize
.X
then b
:= gMapInfo
.Width
- gPlayerScreenSize
.X
else b
:= gMapInfo
.Width
;
1775 gMaxDist
:= Trunc(Hypot(a
, b
));
1778 procedure g_Game_Update();
1780 {$IFDEF ENABLE_MENU}
1781 Msg
: g_gui
.TMessage
;
1788 function sendMonsPos (mon
: TMonster
): Boolean;
1790 result
:= false; // don't stop
1791 // this will also reset "need-send" flag
1792 if mon
.gncNeedSend
then
1794 MH_SEND_MonsterPos(mon
.UID
);
1796 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1798 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1800 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1802 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1806 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1808 result
:= false; // don't stop
1809 // this will also reset "need-send" flag
1810 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1813 function sendItemPos (it
: PItem
): Boolean;
1815 result
:= false; // don't stop
1818 MH_SEND_ItemPos(it
.myId
);
1819 it
.needSend
:= False;
1824 reliableUpdate
: Boolean;
1829 // Пора выключать игру:
1830 if gExit
= EXIT_QUIT
then
1832 // Игра закончилась - обрабатываем:
1836 if gExit
= EXIT_QUIT
then
1840 // Читаем клавиатуру и джойстик, если окно активно
1841 // no need to, as we'll do it in event handler
1843 // Обновляем консоль (движение и сообщения):
1846 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1848 gExit
:= EXIT_SIMPLE
;
1853 // process master server communications
1854 g_Net_Slist_Pulse();
1857 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1858 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1859 STATE_INTERTEXT
, // Текст между уровнями
1860 STATE_INTERPIC
: // Картинка между уровнями
1862 if g_Game_IsNet
and g_Game_IsServer
then
1864 gInterTime
:= gInterTime
+ GAME_TICK
;
1865 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1866 if a
<> gServInterTime
then
1868 gServInterTime
:= a
;
1869 MH_SEND_TimeSync(gServInterTime
);
1873 if (not g_Game_IsClient
) and
1877 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1878 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1879 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1880 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1882 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1883 {$IFDEF ENABLE_MENU}
1884 and (g_ActiveWindow
= nil)
1887 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1890 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1891 g_Game_StopAllSounds(True);
1893 if gMapOnce
then // Это был тест
1894 gExit
:= EXIT_SIMPLE
1896 if gNextMap
<> '' then // Переходим на следующую карту
1897 g_Game_ChangeMap(gNextMap
)
1898 else // Следующей карты нет
1900 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1902 // Выход в главное меню:
1904 {$IFDEF ENABLE_MENU}
1905 g_GUI_ShowWindow('MainMenu');
1906 gMusic
.SetByName('MUSIC_MENU');
1909 gState
:= STATE_MENU
;
1912 // Финальная картинка:
1913 g_Game_ExecuteEvent('onwadend');
1915 if not gMusic
.SetByName('MUSIC_endmus') then
1916 gMusic
.SetByName('MUSIC_STDENDMUS');
1918 gState
:= STATE_ENDPIC
;
1920 g_Game_ExecuteEvent('ongameend');
1925 else if g_Game_IsClient
and
1928 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1929 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1930 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1931 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1933 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1934 {$IFDEF ENABLE_MENU}
1935 and (g_ActiveWindow
= nil)
1944 if gState
= STATE_INTERTEXT
then
1945 if InterText
.counter
> 0 then
1946 InterText
.counter
:= InterText
.counter
- 1;
1949 STATE_FOLD
: // Затухание экрана
1951 if EndingGameCounter
= 0 then
1953 // Закончился уровень в Своей игре:
1954 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1956 gState
:= STATE_INTERCUSTOM
;
1957 InterReadyTime
:= -1;
1958 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1960 g_Game_ExecuteEvent('onwadend');
1961 if not gMusic
.SetByName('MUSIC_endmus') then
1962 gMusic
.SetByName('MUSIC_STDENDMUS');
1965 gMusic
.SetByName('MUSIC_ROUNDMUS');
1969 else // Закончилась последняя карта в Одиночной игре
1971 gMusic
.SetByName('MUSIC_INTERMUS');
1973 gState
:= STATE_INTERSINGLE
;
1976 g_Game_ExecuteEvent('oninter');
1979 DecMin(EndingGameCounter
, 6, 0);
1982 STATE_ENDPIC
: // Картинка окончания мегаВада
1984 if gMapOnce
then // Это был тест
1986 gExit
:= EXIT_SIMPLE
;
1992 g_Serverlist_Control(slCurrent
, slTable
);
1995 // Статистика по Tab:
1998 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
2002 if g_Console_Action(ACTION_SCORES
) then
2004 if not gStatsPressed
then
2006 gStatsOff
:= not gStatsOff
;
2007 gStatsPressed
:= True;
2011 gStatsPressed
:= False;
2015 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
2017 // Время += 28 миллисекунд:
2018 gTime
:= gTime
+ GAME_TICK
;
2020 // Сообщение посередине экрана:
2021 if MessageTime
= 0 then
2023 if MessageTime
> 0 then
2024 MessageTime
:= MessageTime
- 1;
2026 if (g_Game_IsServer
) then
2028 // Был задан лимит времени:
2029 if (gGameSettings
.TimeLimit
> 0) then
2030 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
2031 begin // Он прошел => конец уровня
2036 // Надо респавнить игроков в LMS:
2037 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
2038 g_Game_RestartRound(gLMSSoftSpawn
);
2040 // Проверим результат голосования, если время прошло
2041 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2043 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2045 g_Console_Process(gVoteCommand
);
2047 gVotePassed
:= False;
2050 // Замеряем время захвата флагов
2051 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2052 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2053 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2054 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2056 // Был задан лимит побед:
2057 if (gGameSettings
.ScoreLimit
> 0) then
2061 if gGameSettings
.GameMode
= GM_DM
then
2062 begin // В DM ищем игрока с max фрагами
2063 for i
:= 0 to High(gPlayers
) do
2064 if gPlayers
[i
] <> nil then
2065 if gPlayers
[i
].Frags
> b
then
2066 b
:= gPlayers
[i
].Frags
;
2069 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2070 begin // В CTF/TDM выбираем команду с наибольшим счетом
2071 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2074 // Лимит побед набран => конец уровня:
2075 if b
>= gGameSettings
.ScoreLimit
then
2082 // Обрабатываем клавиши игроков:
2083 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2084 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2085 {$IFDEF DISABLE_MENU}
2086 if (not gConsoleShow
) and (not gChatShow
) then
2088 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2091 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2092 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2093 end // if not console
2096 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2098 // process weapon switch queue
2102 if (gPlayer1
= nil) and (gPlayer2
= nil)
2103 and (not gConsoleShow
) and (not gChatShow
)
2104 {$IFDEF ENABLE_MENU}
2105 and (g_ActiveWindow
= nil)
2109 if not gSpectKeyPress
then
2111 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2113 // switch spect mode
2115 SPECT_NONE
: ; // not spectator
2117 SPECT_MAPVIEW
: Inc(gSpectMode
);
2118 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2120 gSpectKeyPress
:= True;
2122 if (gSpectMode
= SPECT_MAPVIEW
)
2123 and (not gSpectAuto
) then
2125 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2126 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2127 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2128 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2129 if gPlayerAction
[0, ACTION_LOOKUP
] then
2130 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2131 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2132 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2133 if gWeaponAction
[0, WP_PREV
] then
2136 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2137 gWeaponAction
[0, WP_PREV
] := False;
2139 if gWeaponAction
[0, WP_NEXT
] then
2142 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2143 gWeaponAction
[0, WP_NEXT
] := False;
2146 if (gSpectMode
= SPECT_PLAYERS
)
2147 and (not gSpectAuto
) then
2149 if gPlayerAction
[0, ACTION_LOOKUP
] then
2152 gSpectViewTwo
:= True;
2153 gSpectKeyPress
:= True;
2155 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2157 // remove second view
2158 gSpectViewTwo
:= False;
2159 gSpectKeyPress
:= True;
2161 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2163 // prev player (view 1)
2164 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2165 gSpectKeyPress
:= True;
2167 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2169 // next player (view 1)
2170 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2171 gSpectKeyPress
:= True;
2173 if gWeaponAction
[0, WP_PREV
] then
2175 // prev player (view 2)
2176 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2177 gWeaponAction
[0, WP_PREV
] := False;
2179 if gWeaponAction
[0, WP_NEXT
] then
2181 // next player (view 2)
2182 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2183 gWeaponAction
[0, WP_NEXT
] := False;
2186 if gPlayerAction
[0, ACTION_ATTACK
] then
2188 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2191 gSpectAutoNext
:= 0;
2192 gSpectViewTwo
:= False;
2193 gSpectKeyPress
:= True;
2198 gSpectMode
:= SPECT_STATS
;
2199 gSpectAuto
:= False;
2200 gSpectKeyPress
:= True;
2205 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2206 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2207 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2208 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2209 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2210 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2211 gSpectKeyPress
:= False;
2215 if gSpectMode
= SPECT_MAPVIEW
then
2217 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2219 gSpectAutoNext
:= gTime
2222 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2224 gSpectAutoNext
:= gTime
2228 if gSpectAutoNext
<= gTime
then
2230 if gSpectAutoNext
> 0 then
2232 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2236 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2237 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2238 gSpectAutoStepX
:= Random(9) - 4;
2239 gSpectAutoStepY
:= Random(9) - 4;
2240 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2241 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2242 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2243 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2244 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2245 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2249 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2254 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2255 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2256 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2262 (* spectator state check from render *)
2264 if (gPlayer1
= nil) and (gPlayer2
= nil) and (gSpectMode
= SPECT_NONE
) then
2265 gSpectMode
:= SPECT_STATS
;
2267 if IsActivePlayer(g_Player_Get(gSpectPID1
)) = false then
2268 gSpectPID1
:= GetActivePlayerID_Next();
2270 if IsActivePlayer(g_Player_Get(gSpectPID2
)) = false then
2271 gSpectPID2
:= GetActivePlayerID_Next();
2273 g_Game_SetupHearPoints
;
2275 // Обновляем все остальное:
2278 g_Triggers_Update();
2280 g_Monsters_Update();
2284 g_Player_UpdateAll();
2285 {$IFDEF ENABLE_GIBS}
2288 {$IFDEF ENABLE_CORPSES}
2291 {$IFDEF ENABLE_SHELLS}
2295 // server: send newly spawned monsters unconditionally
2296 if (gGameSettings
.GameType
= GT_SERVER
) then
2298 if (Length(gMonstersSpawned
) > 0) then
2300 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2301 SetLength(gMonstersSpawned
, 0);
2305 if (gSoundTriggerTime
> 8) then
2307 g_Game_UpdateTriggerSounds();
2308 gSoundTriggerTime
:= 0;
2312 Inc(gSoundTriggerTime
);
2315 if (NetMode
= NET_SERVER
) then
2317 Inc(NetTimeToUpdate
);
2318 Inc(NetTimeToReliable
);
2320 // send monster updates
2321 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2323 // send all monsters (periodic sync)
2324 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2326 for I
:= 0 to High(gPlayers
) do
2328 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2331 g_Mons_ForEach(sendMonsPos
);
2333 // update flags that aren't stationary
2334 if gGameSettings
.GameMode
= GM_CTF
then
2335 for I
:= FLAG_RED
to FLAG_BLUE
do
2336 if gFlags
[I
].NeedSend
then
2338 gFlags
[I
].NeedSend
:= False;
2342 // update items that aren't stationary
2343 g_Items_ForEachAlive(sendItemPos
);
2345 if reliableUpdate
then
2347 NetTimeToReliable
:= 0;
2348 NetTimeToUpdate
:= NetUpdateRate
;
2352 NetTimeToUpdate
:= 0;
2357 // send only mosters with some unexpected changes
2358 g_Mons_ForEach(sendMonsPosUnexpected
);
2361 // send unexpected platform changes
2362 g_Map_NetSendInterestingPanels();
2364 g_Net_Slist_ServerUpdate();
2366 if NetUseMaster then
2368 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2370 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2372 NetTimeToMaster := gTime + NetMasterRate;
2377 else if (NetMode
= NET_CLIENT
) then
2379 MC_SEND_PlayerPos();
2381 end; // if gameOn ...
2383 // Активно окно интерфейса - передаем клавиши ему:
2384 {$IFDEF ENABLE_MENU}
2385 if g_ActiveWindow
<> nil then
2387 w
:= e_GetFirstKeyPressed();
2389 if (w
<> IK_INVALID
) then
2391 Msg
.Msg
:= MESSAGE_DIKEY
;
2393 g_ActiveWindow
.OnMessage(Msg
);
2396 // Если оно от этого не закрылось, то обновляем:
2397 if g_ActiveWindow
<> nil then
2398 g_ActiveWindow
.Update();
2400 // Нужно сменить разрешение:
2401 if gResolutionChange
then
2403 {$IFDEF ENABLE_RENDER}
2404 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2407 gResolutionChange
:= False;
2408 g_ActiveWindow
:= nil;
2411 // Нужно сменить язык:
2412 if gLanguageChange
then
2414 //e_WriteLog('Read language file', MSG_NOTIFY);
2415 //g_Language_Load(DataDir + gLanguage + '.txt');
2416 g_Language_Set(gLanguage
);
2418 gLanguageChange
:= False;
2422 // Горячая клавиша для вызова меню выхода из игры (F10):
2423 if e_KeyPressed(IK_F10
) and
2425 (not gConsoleShow
) and
2426 (g_ActiveWindow
= nil) then
2432 Time
:= GetTickCount64() {div 1000};
2434 // Обработка отложенных событий:
2435 if gDelayedEvents
<> nil then
2436 for a
:= 0 to High(gDelayedEvents
) do
2437 if gDelayedEvents
[a
].Pending
and
2439 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2440 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2443 case gDelayedEvents
[a
].DEType
of
2445 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2448 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2452 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2453 if g_Game_IsNet
and g_Game_IsServer
then
2454 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2458 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2460 gDelayedEvents
[a
].Pending
:= False;
2463 // Каждую секунду обновляем счетчик обновлений:
2464 UPSCounter
:= UPSCounter
+ 1;
2465 if Time
- UPSTime
>= 1000 then
2474 g_Weapon_AddDynLights();
2475 g_Items_AddDynLights();
2479 procedure g_Game_LoadChatSounds(Resource
: string);
2482 FileName
, Snd
: string;
2484 len
, cnt
, tags
, i
, j
: Integer;
2487 FileName
:= g_ExtractWadName(Resource
);
2489 WAD
:= TWADFile
.Create();
2490 WAD
.ReadFile(FileName
);
2492 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2499 cfg
:= TConfig
.CreateMem(p
, len
);
2500 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2502 SetLength(gChatSounds
, cnt
);
2503 for i
:= 0 to Length(gChatSounds
) - 1 do
2505 gChatSounds
[i
].Sound
:= nil;
2506 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2507 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2508 if (Snd
= '') or (Tags
<= 0) then
2510 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2511 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2512 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2513 SetLength(gChatSounds
[i
].Tags
, tags
);
2514 for j
:= 0 to tags
- 1 do
2515 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2516 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2523 procedure g_Game_FreeChatSounds();
2527 for i
:= 0 to Length(gChatSounds
) - 1 do
2529 gChatSounds
[i
].Sound
.Free();
2530 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2532 SetLength(gChatSounds
, 0);
2536 procedure g_Game_LoadData();
2538 if DataLoaded
then Exit
;
2540 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2541 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
2543 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2544 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2545 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2546 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2547 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2548 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2549 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2550 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2551 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2552 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2553 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2554 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2555 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2556 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2557 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2558 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2559 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2560 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2561 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2562 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2563 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2564 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2565 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2566 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2567 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2568 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2569 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2570 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2571 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2572 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2573 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2574 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2576 goodsnd
[0] := TPlayableSound
.Create();
2577 goodsnd
[1] := TPlayableSound
.Create();
2578 goodsnd
[2] := TPlayableSound
.Create();
2579 goodsnd
[3] := TPlayableSound
.Create();
2581 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2582 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2583 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2584 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2586 killsnd
[0] := TPlayableSound
.Create();
2587 killsnd
[1] := TPlayableSound
.Create();
2588 killsnd
[2] := TPlayableSound
.Create();
2589 killsnd
[3] := TPlayableSound
.Create();
2591 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2592 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2593 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2594 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2596 hahasnd
[0] := TPlayableSound
.Create();
2597 hahasnd
[1] := TPlayableSound
.Create();
2598 hahasnd
[2] := TPlayableSound
.Create();
2600 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2601 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2602 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2604 sound_get_flag
[0] := TPlayableSound
.Create();
2605 sound_get_flag
[1] := TPlayableSound
.Create();
2606 sound_lost_flag
[0] := TPlayableSound
.Create();
2607 sound_lost_flag
[1] := TPlayableSound
.Create();
2608 sound_ret_flag
[0] := TPlayableSound
.Create();
2609 sound_ret_flag
[1] := TPlayableSound
.Create();
2610 sound_cap_flag
[0] := TPlayableSound
.Create();
2611 sound_cap_flag
[1] := TPlayableSound
.Create();
2613 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2614 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2615 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2616 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2617 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2618 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2619 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2620 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2622 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2626 g_Weapon_LoadData();
2628 g_Monsters_LoadData();
2633 procedure g_Game_Quit();
2635 g_Game_StopAllSounds(True);
2638 g_PlayerModel_FreeData();
2639 {$IFDEF ENABLE_MENU}
2640 // g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2643 if NetInitDone
then g_Net_Free
;
2645 // remove map after test
2646 if gMapToDelete
<> '' then
2647 g_Game_DeleteTestMap();
2651 {$IFDEF ENABLE_SYSTEM}
2656 procedure g_Game_FreeData();
2658 if not DataLoaded
then Exit
;
2661 g_Weapon_FreeData();
2662 g_Monsters_FreeData();
2664 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2666 g_Sound_Delete('SOUND_GAME_TELEPORT');
2667 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2668 g_Sound_Delete('SOUND_GAME_SECRET');
2669 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2670 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2671 g_Sound_Delete('SOUND_GAME_BULK1');
2672 g_Sound_Delete('SOUND_GAME_BULK2');
2673 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2674 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2675 g_Sound_Delete('SOUND_GAME_BURNING');
2676 g_Sound_Delete('SOUND_GAME_SWITCH1');
2677 g_Sound_Delete('SOUND_GAME_SWITCH0');
2684 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2685 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2686 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2687 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2694 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2695 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2696 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2697 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2703 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2704 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2705 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2707 sound_get_flag
[0].Free();
2708 sound_get_flag
[1].Free();
2709 sound_lost_flag
[0].Free();
2710 sound_lost_flag
[1].Free();
2711 sound_ret_flag
[0].Free();
2712 sound_ret_flag
[1].Free();
2713 sound_cap_flag
[0].Free();
2714 sound_cap_flag
[1].Free();
2716 g_Sound_Delete('SOUND_CTF_GET1');
2717 g_Sound_Delete('SOUND_CTF_GET2');
2718 g_Sound_Delete('SOUND_CTF_LOST1');
2719 g_Sound_Delete('SOUND_CTF_LOST2');
2720 g_Sound_Delete('SOUND_CTF_RETURN1');
2721 g_Sound_Delete('SOUND_CTF_RETURN2');
2722 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2723 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2725 g_Game_FreeChatSounds();
2727 DataLoaded
:= False;
2730 procedure g_FatalError(Text: String);
2732 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2733 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2735 gExit
:= EXIT_SIMPLE
;
2736 if gGameOn
then EndGame
;
2739 procedure g_SimpleError(Text: String);
2741 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2742 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2745 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2747 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2748 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2751 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2754 if gPlayer1
= nil then
2756 if g_Game_IsClient
then
2758 if NetPlrUID1
> -1 then
2759 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2763 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2764 Team
:= gPlayer1Settings
.Team
;
2766 // Создание первого игрока:
2767 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2768 gPlayer1Settings
.Color
,
2770 if gPlayer1
= nil then
2771 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2774 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2775 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2776 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2777 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2778 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2779 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2780 if g_Game_IsServer
and g_Game_IsNet
then
2781 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2782 gPlayer1
.Respawn(False, True);
2783 g_Net_Slist_ServerPlayerComes();
2788 if gPlayer2
= nil then
2790 if g_Game_IsClient
then
2792 if NetPlrUID2
> -1 then
2793 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2797 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2798 Team
:= gPlayer2Settings
.Team
;
2800 // Создание второго игрока:
2801 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2802 gPlayer2Settings
.Color
,
2804 if gPlayer2
= nil then
2805 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2808 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2809 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2810 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2811 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2812 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2813 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2814 if g_Game_IsServer
and g_Game_IsNet
then
2815 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2816 gPlayer2
.Respawn(False, True);
2817 g_Net_Slist_ServerPlayerComes();
2824 procedure g_Game_RemovePlayer();
2828 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2829 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2834 if g_Game_IsServer
then
2837 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2838 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2839 g_Player_Remove(Pl
.UID
);
2840 g_Net_Slist_ServerPlayerLeaves();
2844 gSpectLatchPID2
:= Pl
.UID
;
2852 if g_Game_IsServer
then
2855 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2856 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2857 g_Player_Remove(Pl
.UID
);
2858 g_Net_Slist_ServerPlayerLeaves();
2861 gSpectLatchPID1
:= Pl
.UID
;
2863 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2867 g_Net_Slist_ServerPlayerLeaves();
2870 procedure g_Game_Spectate();
2872 g_Game_RemovePlayer();
2873 if gPlayer1
<> nil then
2874 g_Game_RemovePlayer();
2877 procedure g_Game_SpectateCenterView();
2879 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2880 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2883 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2890 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2892 g_Game_ClearLoading();
2895 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2898 gGameSettings
.GameType
:= GT_SINGLE
;
2899 gGameSettings
.MaxLives
:= 0;
2900 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2901 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2902 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2903 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2904 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2905 gSwitchGameMode
:= GM_SINGLE
;
2907 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2908 gLMSRespawnTime
:= 0;
2909 gSpectLatchPID1
:= 0;
2910 gSpectLatchPID2
:= 0;
2912 g_Game_ExecuteEvent('ongamestart');
2914 // Создание первого игрока:
2915 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2916 gPlayer1Settings
.Color
,
2917 gPlayer1Settings
.Team
, False));
2918 if gPlayer1
= nil then
2920 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2924 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2925 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2926 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2927 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2928 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2931 // Создание второго игрока, если есть:
2934 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2935 gPlayer2Settings
.Color
,
2936 gPlayer2Settings
.Team
, False));
2937 if gPlayer2
= nil then
2939 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2943 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2944 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2945 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2946 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2947 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2951 // Загрузка и запуск карты:
2952 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2954 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2955 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2959 // Настройки игроков и ботов:
2963 for i
:= nPl
+1 to nPlayers
do
2964 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2967 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2968 TimeLimit
, ScoreLimit
: Word;
2970 Options
: LongWord; nPlayers
: Byte);
2976 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2978 g_Game_ClearLoading();
2981 gGameSettings
.GameType
:= GT_CUSTOM
;
2982 gGameSettings
.GameMode
:= GameMode
;
2983 gSwitchGameMode
:= GameMode
;
2984 gGameSettings
.TimeLimit
:= TimeLimit
;
2985 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2986 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2987 gGameSettings
.Options
:= Options
;
2989 gCoopTotalMonstersKilled
:= 0;
2990 gCoopTotalSecretsFound
:= 0;
2991 gCoopTotalMonsters
:= 0;
2992 gCoopTotalSecrets
:= 0;
2996 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2997 gLMSRespawnTime
:= 0;
2998 gSpectLatchPID1
:= 0;
2999 gSpectLatchPID2
:= 0;
3001 g_Game_ExecuteEvent('ongamestart');
3003 // Режим наблюдателя:
3004 if nPlayers
= 0 then
3011 if nPlayers
>= 1 then
3013 // Создание первого игрока:
3014 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3015 gPlayer1Settings
.Color
,
3016 gPlayer1Settings
.Team
, False));
3017 if gPlayer1
= nil then
3019 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3023 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3024 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3025 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3026 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3027 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3031 if nPlayers
>= 2 then
3033 // Создание второго игрока:
3034 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3035 gPlayer2Settings
.Color
,
3036 gPlayer2Settings
.Team
, False));
3037 if gPlayer2
= nil then
3039 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3043 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3044 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3045 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3046 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3047 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3051 // Загрузка и запуск карты:
3052 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3054 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3058 // Нет точек появления:
3059 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3060 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3061 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3062 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3063 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3065 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3069 // Настройки игроков и ботов:
3073 for i
:= nPl
+1 to nPlayers
do
3074 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3077 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3078 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3079 Options
: LongWord; nPlayers
: Byte;
3080 IPAddr
: LongWord; Port
: Word);
3083 g_Net_Slist_ServerClosed();
3085 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3087 g_Game_ClearLoading();
3092 gGameSettings
.GameType
:= GT_SERVER
;
3093 gGameSettings
.GameMode
:= GameMode
;
3094 gSwitchGameMode
:= GameMode
;
3095 gGameSettings
.TimeLimit
:= TimeLimit
;
3096 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3097 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3098 gGameSettings
.Options
:= Options
;
3100 gCoopTotalMonstersKilled
:= 0;
3101 gCoopTotalSecretsFound
:= 0;
3102 gCoopTotalMonsters
:= 0;
3103 gCoopTotalSecrets
:= 0;
3107 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3108 gLMSRespawnTime
:= 0;
3109 gSpectLatchPID1
:= 0;
3110 gSpectLatchPID2
:= 0;
3112 g_Game_ExecuteEvent('ongamestart');
3114 // Режим наблюдателя:
3115 if nPlayers
= 0 then
3121 if nPlayers
>= 1 then
3123 // Создание первого игрока:
3124 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3125 gPlayer1Settings
.Color
,
3126 gPlayer1Settings
.Team
, False));
3127 if gPlayer1
= nil then
3129 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3133 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3134 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3135 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3136 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3137 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3140 if nPlayers
>= 2 then
3142 // Создание второго игрока:
3143 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3144 gPlayer2Settings
.Color
,
3145 gPlayer2Settings
.Team
, False));
3146 if gPlayer2
= nil then
3148 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3152 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3153 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3154 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3155 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3156 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3159 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3160 if NetForwardPorts
then
3161 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3164 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3166 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3170 g_Net_Slist_Set(NetMasterList
);
3172 g_Net_Slist_ServerStarted();
3174 // Загрузка и запуск карты:
3175 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3177 g_Net_Slist_ServerClosed();
3178 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3182 // Нет точек появления:
3183 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3184 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3185 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3186 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3187 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3189 g_Net_Slist_ServerClosed();
3190 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3194 // Настройки игроков и ботов:
3197 g_Net_Slist_ServerMapStarted();
3198 NetState
:= NET_STATE_GAME
;
3201 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3216 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3217 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3219 g_Game_ClearLoading();
3224 gGameSettings
.GameType
:= GT_CLIENT
;
3226 gCoopTotalMonstersKilled
:= 0;
3227 gCoopTotalSecretsFound
:= 0;
3228 gCoopTotalMonsters
:= 0;
3229 gCoopTotalSecrets
:= 0;
3233 g_Game_ExecuteEvent('ongamestart');
3235 NetState
:= NET_STATE_AUTH
;
3237 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3239 // create (or update) map/resource databases
3240 g_Res_CreateDatabases(true);
3242 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3243 gLMSRespawnTime
:= 0;
3244 gSpectLatchPID1
:= 0;
3245 gSpectLatchPID2
:= 0;
3248 if not g_Net_Connect(Addr
, Port
) then
3250 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3251 NetState
:= NET_STATE_NONE
;
3255 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3257 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3262 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3263 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3264 // thank you, enet. let's ignore failures altogether then.
3265 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3267 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3269 Ptr
:= NetEvent
.packet
^.data
;
3270 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3272 enet_packet_destroy(NetEvent
.packet
);
3276 InMsg
.ReadLongWord(); // skip size
3277 MID
:= InMsg
.ReadByte();
3279 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3281 NetMyID
:= InMsg
.ReadByte();
3282 NetPlrUID1
:= InMsg
.ReadWord();
3284 WadName
:= InMsg
.ReadString();
3285 Map
:= InMsg
.ReadString();
3287 gWADHash
:= InMsg
.ReadMD5();
3289 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3290 gSwitchGameMode
:= gGameSettings
.GameMode
;
3291 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3292 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3293 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3294 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3295 T
:= InMsg
.ReadLongWord();
3297 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3298 //if newResPath = '' then
3300 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3301 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3302 if newResPath
= '' then
3304 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3305 enet_packet_destroy(NetEvent
.packet
);
3306 NetState
:= NET_STATE_NONE
;
3309 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3311 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3314 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3315 gPlayer1Settings
.Color
,
3316 gPlayer1Settings
.Team
, False));
3318 if gPlayer1
= nil then
3320 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3322 enet_packet_destroy(NetEvent
.packet
);
3323 NetState
:= NET_STATE_NONE
;
3327 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3328 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3329 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3330 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3331 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3332 gPlayer1
.UID
:= NetPlrUID1
;
3333 gPlayer1
.Reset(True);
3335 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3337 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3339 enet_packet_destroy(NetEvent
.packet
);
3340 NetState
:= NET_STATE_NONE
;
3348 enet_packet_destroy(NetEvent
.packet
);
3352 enet_packet_destroy(NetEvent
.packet
);
3356 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3359 if (NetEvent
.data
<= NET_DISC_MAX
) then
3360 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3361 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3368 ProcessLoading(True);
3369 if g_Net_UserRequestExit() then
3378 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3379 NetState
:= NET_STATE_NONE
;
3384 NetState
:= NET_STATE_GAME
;
3385 MC_SEND_FullStateRequest
;
3386 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3390 lastAsMegaWad
: Boolean = false;
3392 procedure g_Game_ChangeMap(const MapPath
: String);
3396 g_Game_ClearLoading();
3398 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3399 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3400 if gExitByTrigger
then
3403 gExitByTrigger
:= False;
3405 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3406 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3409 procedure g_Game_Restart();
3413 if g_Game_IsClient
then
3415 map
:= g_ExtractFileName(gMapInfo
.Map
);
3416 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3420 g_Game_ClearLoading();
3421 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3424 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3426 NewWAD
, ResName
: String;
3430 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3432 {$IFDEF ENABLE_GIBS}
3435 {$IFDEF ENABLE_SHELLS}
3438 {$IFDEF ENABLE_CORPSES}
3439 g_Corpses_RemoveAll
;
3442 if (not g_Game_IsClient
) and
3443 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3444 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3446 if gSwitchGameMode
= GM_CTF
then
3447 gGameSettings
.MaxLives
:= 0;
3448 gGameSettings
.GameMode
:= gSwitchGameMode
;
3451 gSwitchGameMode
:= gGameSettings
.GameMode
;
3453 g_Player_ResetTeams();
3455 lastAsMegaWad
:= asMegawad
;
3456 if isWadPath(Map
) then
3458 NewWAD
:= g_ExtractWadName(Map
);
3459 ResName
:= g_ExtractFileName(Map
);
3460 if g_Game_IsServer
then
3462 nws
:= findDiskWad(NewWAD
);
3463 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3466 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3467 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3471 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3472 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3474 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3475 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3477 if (length(nws
) = 0) then
3479 ResName
:= ''; // failed
3484 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3485 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3486 g_Game_LoadWAD(NewWAD
);
3491 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3492 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3497 NewWAD
:= gGameSettings
.WAD
;
3503 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3505 if (ResName
<> '') and (NewWAD
<> '') then
3507 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3508 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3512 {$IFDEF ENABLE_RENDER}
3513 r_Render_LoadTextures
;
3516 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3518 gState
:= STATE_NONE
;
3519 {$IFDEF ENABLE_MENU}
3520 g_ActiveWindow
:= nil;
3525 wNeedTimeReset
:= True;
3527 if gGameSettings
.GameMode
= GM_CTF
then
3529 g_Map_ResetFlag(FLAG_RED
);
3530 g_Map_ResetFlag(FLAG_BLUE
);
3531 // CTF, а флагов нет:
3532 if not g_Map_HaveFlagPoints() then
3533 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3538 gState
:= STATE_MENU
;
3543 gPauseMain
:= false;
3544 gPauseHolmes
:= false;
3545 NetTimeToUpdate
:= 1;
3546 NetTimeToReliable
:= 0;
3547 NetTimeToMaster
:= NetMasterRate
;
3548 gSpectLatchPID1
:= 0;
3549 gSpectLatchPID2
:= 0;
3550 gMissionFailed
:= False;
3553 gCoopMonstersKilled
:= 0;
3554 gCoopSecretsFound
:= 0;
3556 gVoteInProgress
:= False;
3557 gVotePassed
:= False;
3563 if not gGameOn
then Exit
;
3565 g_Game_SpectateCenterView();
3567 if g_Game_IsServer
then
3569 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3571 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3572 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3573 gLMSSoftSpawn
:= True;
3574 if g_Game_IsNet
then
3575 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3579 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3580 gLMSRespawnTime
:= 0;
3584 if NetMode
= NET_SERVER
then
3586 // reset full state flags
3587 if NetClients
<> nil then
3588 for I
:= 0 to High(NetClients
) do
3589 NetClients
[I
].FullUpdateSent
:= False;
3591 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3594 g_Net_Slist_ServerMapStarted();
3596 if NetClients
<> nil then
3597 for I
:= 0 to High(NetClients
) do
3598 if NetClients
[I
].Used
then
3600 NetClients
[I
].Voted
:= False;
3601 if NetClients
[I
].RequestedFullUpdate
then
3603 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3604 NetClients
[I
].RequestedFullUpdate
:= False;
3608 g_Net_UnbanNonPermHosts();
3613 gCoopTotalMonstersKilled
:= 0;
3614 gCoopTotalSecretsFound
:= 0;
3615 gCoopTotalMonsters
:= 0;
3616 gCoopTotalSecrets
:= 0;
3620 g_Game_ExecuteEvent('onmapstart');
3623 procedure SetFirstLevel
;
3627 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3628 if MapList
= nil then
3631 SortSArray(MapList
);
3632 gNextMap
:= MapList
[Low(MapList
)];
3637 procedure g_Game_ExitLevel(const Map
: AnsiString);
3641 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3642 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3643 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3644 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3646 // Вышли в выход в Одиночной игре:
3647 if gGameSettings
.GameType
= GT_SINGLE
then
3648 gExit
:= EXIT_ENDLEVELSINGLE
3649 else // Вышли в выход в Своей игре
3651 gExit
:= EXIT_ENDLEVELCUSTOM
;
3652 if gGameSettings
.GameMode
= GM_COOP
then
3653 g_Player_RememberAll
;
3655 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3658 if gGameSettings
.GameMode
= GM_COOP
then
3661 gStatsPressed
:= True;
3662 gNextMap
:= 'MAP01';
3664 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3667 if g_Game_IsNet
then
3669 MH_SEND_GameStats();
3670 MH_SEND_CoopStats();
3676 procedure g_Game_RestartLevel();
3680 if gGameSettings
.GameMode
= GM_SINGLE
then
3685 gExit
:= EXIT_ENDLEVELCUSTOM
;
3686 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3690 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3692 gWAD
{, xwad}: String;
3695 if not g_Game_IsClient
then Exit
;
3696 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3698 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3703 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3707 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3710 g_Game_LoadWAD(NewWAD
);
3714 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3715 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3718 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3719 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3723 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3727 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3728 g_Game_LoadWAD(NewWAD);
3732 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3734 i
, n
, nb
, nr
: Integer;
3736 if not g_Game_IsServer
then Exit
;
3737 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3738 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3739 gLMSRespawnTime
:= 0;
3742 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3744 gMissionFailed
:= True;
3745 g_Game_RestartLevel
;
3749 n
:= 0; nb
:= 0; nr
:= 0;
3750 for i
:= Low(gPlayers
) to High(gPlayers
) do
3751 if (gPlayers
[i
] <> nil) and
3752 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3753 (gPlayers
[i
] is TBot
)) then
3756 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3757 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3760 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3762 // wait a second until the fuckers finally decide to join
3763 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3764 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3765 gLMSSoftSpawn
:= NoMapRestart
;
3766 if g_Game_IsNet
then
3767 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3771 {$IFDEF ENABLE_GIBS}
3774 {$IFDEF ENABLE_SHELLS}
3777 {$IFDEF ENABLE_CORPSES}
3778 g_Corpses_RemoveAll
;
3781 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3782 if g_Game_IsNet
then
3783 MH_SEND_GameEvent(NET_EV_LMS_START
);
3785 for i
:= Low(gPlayers
) to High(gPlayers
) do
3787 if gPlayers
[i
] = nil then continue
;
3788 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3789 // don't touch normal spectators
3790 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3792 gPlayers
[i
].FNoRespawn
:= True;
3793 gPlayers
[i
].Lives
:= 0;
3794 if g_Game_IsNet
then
3795 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3798 gPlayers
[i
].FNoRespawn
:= False;
3799 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3800 gPlayers
[i
].Respawn(False, True);
3801 if gGameSettings
.GameMode
= GM_COOP
then
3803 gPlayers
[i
].Frags
:= 0;
3804 gPlayers
[i
].RecallState
;
3806 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3807 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3808 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3809 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3812 g_Items_RestartRound();
3814 gLMSSoftSpawn
:= False;
3817 function g_Game_GetFirstMap(WAD
: String): String;
3821 MapList
:= g_Map_GetMapsList(WAD
);
3822 if MapList
= nil then
3825 SortSArray(MapList
);
3826 Result
:= MapList
[Low(MapList
)];
3828 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3834 function g_Game_GetNextMap(): String;
3841 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3842 if MapList
= nil then
3845 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3847 SortSArray(MapList
);
3849 for I
:= Low(MapList
) to High(MapList
) do
3850 if Map
= MapList
[I
] then
3856 if MapIndex
<> -255 then
3858 if MapIndex
= High(MapList
) then
3859 Result
:= MapList
[Low(MapList
)]
3861 Result
:= MapList
[MapIndex
+ 1];
3863 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3869 procedure g_Game_NextLevel();
3871 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3872 gExit
:= EXIT_ENDLEVELCUSTOM
3875 gExit
:= EXIT_ENDLEVELSINGLE
;
3879 if gNextMap
<> '' then Exit
;
3880 gNextMap
:= g_Game_GetNextMap();
3883 function g_Game_IsTestMap(): Boolean;
3885 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3888 procedure g_Game_DeleteTestMap();
3891 //MapName: AnsiString;
3899 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3900 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3901 if (a
= 0) then exit
;
3903 // Выделяем имя wad-файла и имя карты
3904 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3905 Delete(gMapToDelete
, 1, a
+5);
3906 gMapToDelete
:= UpperCase(gMapToDelete
);
3908 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3911 // Имя карты не стандартное тестовое:
3912 if MapName <> TEST_MAP_NAME then
3915 if not gTempDelete then
3917 time := g_GetFileTime(WadName);
3918 WAD := TWADFile.Create();
3921 if not WAD.ReadFile(WadName) then
3922 begin // Нет такого WAD-файла
3927 // Составляем список карт и ищем нужную:
3929 MapList := WAD.GetResourcesList('');
3931 if MapList <> nil then
3932 for a := 0 to High(MapList) do
3933 if MapList[a] = MapName then
3935 // Удаляем и сохраняем:
3936 WAD.RemoveResource('', MapName);
3937 WAD.SaveTo(WadName);
3942 g_SetFileTime(WadName, time);
3945 if gTempDelete
then DeleteFile(WadName
);
3948 procedure GameCVars(P
: SSArray
);
3951 stat
: TPlayerStatArray
;
3954 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3958 if Length(P
) > 1 then
3963 gsGameFlags
:= gsGameFlags
or Flag
3965 gsGameFlags
:= gsGameFlags
and (not Flag
);
3967 if g_Game_IsServer
then
3970 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3972 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3973 if g_Game_IsNet
then MH_SEND_GameSettings
;
3977 if LongBool(gsGameFlags
and Flag
) then
3978 g_Console_Add(_lc
[OnMsg
])
3980 g_Console_Add(_lc
[OffMsg
]);
3982 if OnMapChange
and g_Game_IsServer
then
3983 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3988 cmd
:= LowerCase(P
[0]);
3990 if cmd
= 'g_gamemode' then
3992 if (Length(P
) > 1) then
3994 a
:= g_Game_TextToMode(P
[1]);
3995 if a
= GM_SINGLE
then a
:= GM_COOP
;
3996 gsGameMode
:= g_Game_ModeToText(a
);
3997 if g_Game_IsServer
then
3999 gSwitchGameMode
:= a
;
4000 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4001 (gState
= STATE_INTERSINGLE
) then
4002 gSwitchGameMode
:= GM_SINGLE
;
4004 gGameSettings
.GameMode
:= gSwitchGameMode
;
4008 if gSwitchGameMode
= gGameSettings
.GameMode
then
4009 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4010 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4012 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4013 [g_Game_ModeToText(gGameSettings
.GameMode
),
4014 g_Game_ModeToText(gSwitchGameMode
)]));
4016 else if cmd
= 'g_friendlyfire' then
4018 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4020 else if cmd
= 'g_friendly_absorb_damage' then
4022 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
4024 else if cmd
= 'g_friendly_hit_trace' then
4026 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
4028 else if cmd
= 'g_friendly_hit_projectile' then
4030 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
4032 else if cmd
= 'g_weaponstay' then
4034 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
4036 else if cmd
= 'g_allow_exit' then
4038 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
4040 else if cmd
= 'g_allow_monsters' then
4042 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
4044 else if cmd
= 'g_allow_dropflag' then
4046 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
4048 else if cmd
= 'g_throw_flag' then
4050 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
4052 else if cmd
= 'g_bot_vsplayers' then
4054 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4056 else if cmd
= 'g_bot_vsmonsters' then
4058 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4060 else if cmd
= 'g_dm_keys' then
4062 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4064 else if cmd
= 'g_gameflags' then
4066 if Length(P
) > 1 then
4068 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4069 if g_Game_IsServer
then
4071 gGameSettings
.Options
:= gsGameFlags
;
4072 if g_Game_IsNet
then MH_SEND_GameSettings
;
4076 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4078 else if cmd
= 'g_warmup_time' then
4080 if Length(P
) > 1 then
4082 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4083 if g_Game_IsServer
then
4085 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4086 // extend warmup if it's already going
4087 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4089 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4090 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4092 if g_Game_IsNet
then MH_SEND_GameSettings
;
4096 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4097 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4099 else if cmd
= 'g_spawn_invul' then
4101 if Length(P
) > 1 then
4103 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4104 if g_Game_IsServer
then
4106 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4107 if g_Game_IsNet
then MH_SEND_GameSettings
;
4111 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4113 else if cmd
= 'g_item_respawn_time' then
4115 if Length(P
) > 1 then
4117 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4118 if g_Game_IsServer
then
4120 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4121 if g_Game_IsNet
then MH_SEND_GameSettings
;
4125 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4126 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4128 else if cmd
= 'sv_intertime' then
4130 if (Length(P
) > 1) then
4131 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4133 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4135 else if cmd
= 'g_max_particles' then
4137 if Length(p
) = 2 then
4140 a
:= Max(0, StrToIntDef(p
[1], 0));
4144 else if Length(p
) = 1 then
4147 e_LogWritefln('%s', [g_GFX_GetMax()])
4149 e_LogWritefln('%s', [0])
4154 e_LogWritefln('usage: %s <n>', [cmd
])
4157 else if cmd
= 'g_max_shells' then
4159 if Length(p
) = 2 then
4161 {$IFDEF ENABLE_SHELLS}
4162 a
:= Max(0, StrToIntDef(p
[1], 0));
4166 else if Length(p
) = 1 then
4168 {$IFDEF ENABLE_SHELLS}
4169 e_LogWritefln('%s', [g_Shells_GetMax()])
4171 e_LogWritefln('%s', [0])
4176 e_LogWritefln('usage: %s <n>', [cmd
])
4179 else if cmd
= 'g_max_gibs' then
4181 if Length(p
) = 2 then
4183 {$IFDEF ENABLE_GIBS}
4184 a
:= Max(0, StrToIntDef(p
[1], 0));
4188 else if Length(p
) = 1 then
4190 {$IFDEF ENABLE_GIBS}
4191 e_LogWritefln('%s', [g_Gibs_GetMax()])
4193 e_LogWritefln('%s', [0])
4198 e_LogWritefln('usage: %s <n>', [cmd
])
4201 else if cmd
= 'g_max_corpses' then
4203 if Length(p
) = 2 then
4205 {$IFDEF ENABLE_CORPSES}
4206 a
:= Max(0, StrToIntDef(p
[1], 0));
4210 else if Length(p
) = 1 then
4212 {$IFDEF ENABLE_CORPSES}
4213 e_LogWritefln('%s', [g_Corpses_GetMax()])
4215 e_LogWritefln('%s', [0])
4220 e_LogWritefln('usage: %s <n>', [cmd
])
4223 else if cmd
= 'g_force_model' then
4225 if Length(p
) = 2 then
4227 a
:= StrToIntDef(p
[1], 0);
4228 g_Force_Model_Set(a
);
4229 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4231 for a
:= Low(gPlayers
) to High(gPlayers
) do
4233 if (gPlayers
[a
] <> nil) then
4235 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4237 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4239 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4243 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4245 for a
:= Low(gPlayers
) to High(gPlayers
) do
4247 if (gPlayers
[a
] <> nil) then
4249 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4251 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4253 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4259 else if cmd
= 'g_force_model_name' then
4261 if (Length(P
) > 1) then
4263 cmd
:= b_Text_Unformat(P
[1]);
4264 g_Forced_Model_SetName(cmd
);
4265 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4267 for a
:= Low(gPlayers
) to High(gPlayers
) do
4269 if (gPlayers
[a
] <> nil) then
4271 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4273 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4275 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4281 else if cmd
= 'g_scorelimit' then
4283 if Length(P
) > 1 then
4285 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4287 if g_Game_IsServer
then
4290 if gGameSettings
.GameMode
= GM_DM
then
4292 stat
:= g_Player_GetStats();
4294 for a
:= 0 to High(stat
) do
4295 if stat
[a
].Frags
> b
then
4299 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4301 // if someone has a higher score, set it to that instead
4302 gsScoreLimit
:= max(gsScoreLimit
, b
);
4303 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4305 if g_Game_IsNet
then MH_SEND_GameSettings
;
4309 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4311 else if cmd
= 'g_timelimit' then
4313 if Length(P
) > 1 then
4315 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4316 if g_Game_IsServer
then
4318 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4319 if g_Game_IsNet
then MH_SEND_GameSettings
;
4322 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4323 [gsTimeLimit
div 3600,
4324 (gsTimeLimit
div 60) mod 60,
4325 gsTimeLimit
mod 60]));
4327 else if cmd
= 'g_max_bots' then
4329 if Length(P
) > 1 then
4330 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4331 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4333 else if cmd
= 'g_maxlives' then
4335 if Length(P
) > 1 then
4337 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4338 if g_Game_IsServer
then
4340 gGameSettings
.MaxLives
:= gsMaxLives
;
4341 if g_Game_IsNet
then MH_SEND_GameSettings
;
4345 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4349 procedure PlayerSettingsCVars(P
: SSArray
);
4354 function ParseTeam(s
: string): Byte;
4358 'red', '1': result
:= TEAM_RED
;
4359 'blue', '2': result
:= TEAM_BLUE
;
4360 else result
:= TEAM_NONE
;
4364 cmd
:= LowerCase(P
[0]);
4368 if (Length(P
) > 1) then
4370 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4371 if g_Game_IsClient
then
4372 MC_SEND_PlayerSettings
4373 else if gGameOn
and (gPlayer1
<> nil) then
4375 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4376 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4382 if (Length(P
) > 1) then
4384 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4385 if g_Game_IsClient
then
4386 MC_SEND_PlayerSettings
4387 else if gGameOn
and (gPlayer2
<> nil) then
4389 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4390 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4396 if Length(P
) > 3 then
4398 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4399 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4400 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4401 if g_Game_IsClient
then
4402 MC_SEND_PlayerSettings
4403 else if gGameOn
and (gPlayer1
<> nil) then
4405 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4406 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4412 if Length(P
) > 3 then
4414 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4415 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4416 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4417 if g_Game_IsClient
then
4418 MC_SEND_PlayerSettings
4419 else if gGameOn
and (gPlayer2
<> nil) then
4421 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4422 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4428 if (Length(P
) > 1) then
4430 gPlayer1Settings
.Model
:= P
[1];
4431 if g_Game_IsClient
then
4432 MC_SEND_PlayerSettings
4433 else if gGameOn
and (gPlayer1
<> nil) then
4435 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4436 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4437 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4443 if (Length(P
) > 1) then
4445 gPlayer2Settings
.Model
:= P
[1];
4446 if g_Game_IsClient
then
4447 MC_SEND_PlayerSettings
4448 else if gGameOn
and (gPlayer2
<> nil) then
4450 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4451 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4452 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4458 // TODO: switch teams if in game or store this separately
4459 if (Length(P
) > 1) then
4461 team
:= ParseTeam(P
[1]);
4462 if team
= TEAM_NONE
then
4463 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4464 else if not gGameOn
and not g_Game_IsNet
then
4465 gPlayer1Settings
.Team
:= team
4467 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4472 // TODO: switch teams if in game or store this separately
4473 if (Length(P
) > 1) then
4475 team
:= ParseTeam(P
[1]);
4476 if team
= TEAM_NONE
then
4477 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4478 else if not gGameOn
and not g_Game_IsNet
then
4479 gPlayer2Settings
.Team
:= team
4481 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4486 if (Length(P
) = 2) then
4487 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4491 if (Length(P
) = 2) then
4492 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4496 if (Length(P
) = 2) then
4497 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4501 if (Length(P
) = 2) then
4502 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4506 if (Length(P
) = 2) then
4507 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4511 if (Length(P
) = 2) then
4512 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4514 'p1_priority_kastet':
4516 if (Length(P
) = 2) then
4517 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4519 'p2_priority_kastet':
4521 if (Length(P
) = 2) then
4522 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4526 if (Length(P
) = 2) then
4527 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4531 if (Length(P
) = 2) then
4532 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4534 'p1_priority_pistol':
4536 if (Length(P
) = 2) then
4537 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4539 'p2_priority_pistol':
4541 if (Length(P
) = 2) then
4542 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4544 'p1_priority_shotgun1':
4546 if (Length(P
) = 2) then
4547 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4549 'p2_priority_shotgun1':
4551 if (Length(P
) = 2) then
4552 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4554 'p1_priority_shotgun2':
4556 if (Length(P
) = 2) then
4557 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4559 'p2_priority_shotgun2':
4561 if (Length(P
) = 2) then
4562 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4564 'p1_priority_chaingun':
4566 if (Length(P
) = 2) then
4567 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4569 'p2_priority_chaingun':
4571 if (Length(P
) = 2) then
4572 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4574 'p1_priority_rocketlauncher':
4576 if (Length(P
) = 2) then
4577 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4579 'p2_priority_rocketlauncher':
4581 if (Length(P
) = 2) then
4582 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4584 'p1_priority_plasma':
4586 if (Length(P
) = 2) then
4587 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4589 'p2_priority_plasma':
4591 if (Length(P
) = 2) then
4592 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4596 if (Length(P
) = 2) then
4597 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4601 if (Length(P
) = 2) then
4602 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4604 'p1_priority_super':
4606 if (Length(P
) = 2) then
4607 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4609 'p2_priority_super':
4611 if (Length(P
) = 2) then
4612 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4614 'p1_priority_flamethrower':
4616 if (Length(P
) = 2) then
4617 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4619 'p2_priority_flamethrower':
4621 if (Length(P
) = 2) then
4622 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4624 'p1_priority_berserk':
4626 if (Length(P
) = 2) then
4627 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4629 'p2_priority_berserk':
4631 if (Length(P
) = 2) then
4632 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4637 procedure PrintHeapStats();
4641 hs
:= GetFPCHeapStatus();
4642 e_LogWriteLn ('v===== heap status =====v');
4643 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4644 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4645 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4646 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4647 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4648 e_LogWriteLn ('^=======================^');
4651 procedure DebugCommands(P
: SSArray
);
4658 // Команды отладочного режима:
4659 if {gDebugMode}conIsCheatsEnabled
then
4661 cmd
:= LowerCase(P
[0]);
4662 if cmd
= 'd_window' then
4664 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4665 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4667 else if cmd
= 'd_winmsg' then
4669 if (Length(P
) > 1) and
4670 ((P
[1] = '1') or (P
[1] = '0')) then
4671 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4673 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4675 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4677 if (Length(P
) > 1) and
4678 ((P
[1] = '1') or (P
[1] = '0')) then
4679 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4681 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4683 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4685 if Length(P
) > 1 then
4687 '0': g_debug_BotAIOff
:= 0;
4688 '1': g_debug_BotAIOff
:= 1;
4689 '2': g_debug_BotAIOff
:= 2;
4690 '3': g_debug_BotAIOff
:= 3;
4693 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4695 else if cmd
= 'd_monster' then
4697 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4698 if Length(P
) < 2 then
4700 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4701 g_Console_Add('ID | Name');
4702 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4703 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4704 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4707 a
:= StrToIntDef(P
[1], 0);
4708 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4709 a
:= g_Mons_TypeIdByName(P
[1]);
4711 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4712 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4715 with gPlayer1
.Obj
do
4717 mon
:= g_Monsters_Create(a
,
4718 X
+ Rect
.X
+ (Rect
.Width
div 2),
4719 Y
+ Rect
.Y
+ Rect
.Height
,
4720 gPlayer1
.Direction
, True);
4722 if (Length(P
) > 2) and (mon
<> nil) then
4724 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4725 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4726 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4727 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4728 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4729 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4730 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4731 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4732 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4737 else if (cmd
= 'd_health') then
4739 if (Length(P
) > 1) and
4740 ((P
[1] = '1') or (P
[1] = '0')) then
4741 g_debug_HealthBar
:= (P
[1][1] = '1');
4743 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4745 else if (cmd
= 'd_player') then
4747 if (Length(P
) > 1) and
4748 ((P
[1] = '1') or (P
[1] = '0')) then
4749 g_debug_Player
:= (P
[1][1] = '1');
4751 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4753 else if (cmd
= 'd_mem') then
4759 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4763 procedure GameCheats(P
: SSArray
);
4769 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4771 g_Console_Add('not available');
4777 g_Console_Add('where is the player?!');
4780 cmd
:= LowerCase(P
[0]);
4784 plr
.GodMode
:= not plr
.GodMode
;
4785 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4788 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4789 if cmd
= 'give' then
4791 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4792 for f
:= 1 to High(P
) do
4794 cmd
:= LowerCase(P
[f
]);
4795 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4796 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4797 if cmd
= 'exit' then
4799 if gTriggers
<> nil then
4801 for a
:= 0 to High(gTriggers
) do
4803 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4805 g_Console_Add('player left the map');
4806 gExitByTrigger
:= True;
4807 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4808 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4816 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4817 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4818 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4819 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4820 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4822 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4823 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4825 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4826 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;
4828 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4829 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4831 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4832 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4834 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4835 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4837 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4838 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4839 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4841 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4842 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4843 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4844 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;
4845 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4846 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4848 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;
4849 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;
4850 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;
4851 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;
4852 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;
4853 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;
4855 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4856 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;
4858 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;
4859 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;
4861 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4863 if cmd
= 'ammo' then
4865 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4866 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4867 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4868 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4869 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4870 g_Console_Add('player got some ammo');
4874 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4875 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4877 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4878 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4880 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4881 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4883 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4884 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4886 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4888 if cmd
= 'weapons' then
4890 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4891 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4892 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4893 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4894 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4895 plr
.GiveItem(ITEM_WEAPON_BFG
);
4896 g_Console_Add('player got weapons');
4900 if cmd
= 'keys' then
4902 plr
.GiveItem(ITEM_KEY_RED
);
4903 plr
.GiveItem(ITEM_KEY_GREEN
);
4904 plr
.GiveItem(ITEM_KEY_BLUE
);
4905 g_Console_Add('player got all keys');
4909 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4914 if cmd
= 'open' then
4916 g_Console_Add('player activated sesame');
4917 g_Triggers_OpenAll();
4924 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4928 if cmd
= 'noclip' then
4931 g_Console_Add('wall hardeness adjusted');
4935 if cmd
= 'notarget' then
4937 plr
.NoTarget
:= not plr
.NoTarget
;
4938 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4942 if cmd
= 'noreload' then
4944 plr
.NoReload
:= not plr
.NoReload
;
4945 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4949 if cmd
= 'speedy' then
4951 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4952 g_Console_Add('speed adjusted');
4956 if cmd
= 'jumpy' then
4958 VEL_JUMP
:= 30-VEL_JUMP
;
4959 g_Console_Add('jump height adjusted');
4963 if cmd
= 'automap' then
4965 gShowMap
:= not gShowMap
;
4966 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4970 if cmd
= 'aimline' then
4972 gAimLine
:= not gAimLine
;
4973 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4978 procedure GameCommands(P
: SSArray
);
4984 pl
: pTNetClient
= nil;
4992 cmd
:= LowerCase(P
[0]);
4994 if cmd
= 'pause' then
4996 {$IFDEF ENABLE_MENU}
4997 if (g_ActiveWindow
= nil) then
4998 g_Game_Pause(not gPauseMain
);
5000 g_Game_Pause(not gPauseMain
);
5003 else if cmd
= 'endgame' then
5004 gExit
:= EXIT_SIMPLE
5005 else if cmd
= 'restart' then
5007 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5009 if g_Game_IsClient
then
5011 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5016 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5018 else if cmd
= 'kick' then
5020 if g_Game_IsServer
then
5022 if Length(P
) < 2 then
5024 g_Console_Add('kick <name>');
5029 g_Console_Add('kick <name>');
5033 if g_Game_IsNet
then
5034 pl
:= g_Net_Client_ByName(P
[1]);
5037 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5038 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5039 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5040 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5041 g_Net_Slist_ServerPlayerLeaves();
5042 end else if gPlayers
<> nil then
5043 for a
:= Low(gPlayers
) to High(gPlayers
) do
5044 if gPlayers
[a
] <> nil then
5045 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5047 // Не отключать основных игроков в сингле
5048 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5050 gPlayers
[a
].Lives
:= 0;
5051 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5052 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5053 g_Player_Remove(gPlayers
[a
].UID
);
5054 g_Net_Slist_ServerPlayerLeaves();
5055 // Если не перемешать, при добавлении новых ботов появятся старые
5059 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5061 else if cmd
= 'kick_id' then
5063 if g_Game_IsServer
and g_Game_IsNet
then
5065 if Length(P
) < 2 then
5067 g_Console_Add('kick_id <client ID>');
5072 g_Console_Add('kick_id <client ID>');
5076 a
:= StrToIntDef(P
[1], 0);
5077 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5079 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5081 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5082 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
5083 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5084 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5085 g_Net_Slist_ServerPlayerLeaves();
5089 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5091 else if cmd
= 'kick_pid' then
5093 if g_Game_IsServer
and g_Game_IsNet
then
5095 if Length(P
) < 2 then
5097 g_Console_Add('kick_pid <player ID>');
5102 g_Console_Add('kick_pid <player ID>');
5106 a
:= StrToIntDef(P
[1], 0);
5107 pl
:= g_Net_Client_ByPlayer(a
);
5108 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5110 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5111 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5112 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5113 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5114 g_Net_Slist_ServerPlayerLeaves();
5117 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5119 else if cmd
= 'ban' then
5121 if g_Game_IsServer
and g_Game_IsNet
then
5123 if Length(P
) < 2 then
5125 g_Console_Add('ban <name>');
5130 g_Console_Add('ban <name>');
5134 pl
:= g_Net_Client_ByName(P
[1]);
5137 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5138 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5139 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5140 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5141 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5142 g_Net_Slist_ServerPlayerLeaves();
5144 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5146 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5148 else if cmd
= 'ban_id' then
5150 if g_Game_IsServer
and g_Game_IsNet
then
5152 if Length(P
) < 2 then
5154 g_Console_Add('ban_id <client ID>');
5159 g_Console_Add('ban_id <client ID>');
5163 a
:= StrToIntDef(P
[1], 0);
5164 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5165 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5167 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5168 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5169 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5170 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5171 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5172 g_Net_Slist_ServerPlayerLeaves();
5175 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5177 else if cmd
= 'ban_pid' then
5179 if g_Game_IsServer
and g_Game_IsNet
then
5181 if Length(P
) < 2 then
5183 g_Console_Add('ban_pid <player ID>');
5188 g_Console_Add('ban_pid <player ID>');
5192 a
:= StrToIntDef(P
[1], 0);
5193 pl
:= g_Net_Client_ByPlayer(a
);
5194 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5196 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5197 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5198 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5199 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5200 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5201 g_Net_Slist_ServerPlayerLeaves();
5204 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5206 else if cmd
= 'permban' then
5208 if g_Game_IsServer
and g_Game_IsNet
then
5210 if Length(P
) < 2 then
5212 g_Console_Add('permban <name>');
5217 g_Console_Add('permban <name>');
5221 pl
:= g_Net_Client_ByName(P
[1]);
5224 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5225 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5226 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5227 g_Net_SaveBanList();
5228 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5229 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5230 g_Net_Slist_ServerPlayerLeaves();
5232 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5234 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5236 else if cmd
= 'permban_id' then
5238 if g_Game_IsServer
and g_Game_IsNet
then
5240 if Length(P
) < 2 then
5242 g_Console_Add('permban_id <client ID>');
5247 g_Console_Add('permban_id <client ID>');
5251 a
:= StrToIntDef(P
[1], 0);
5252 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5253 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5255 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5256 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5257 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5258 g_Net_SaveBanList();
5259 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5260 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5261 g_Net_Slist_ServerPlayerLeaves();
5264 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5266 else if cmd
= 'permban_pid' then
5268 if g_Game_IsServer
and g_Game_IsNet
then
5270 if Length(P
) < 2 then
5272 g_Console_Add('permban_pid <player ID>');
5277 g_Console_Add('permban_pid <player ID>');
5281 a
:= StrToIntDef(P
[1], 0);
5282 pl
:= g_Net_Client_ByPlayer(a
);
5283 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5285 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5286 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5287 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5288 g_Net_SaveBanList();
5289 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5290 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5291 g_Net_Slist_ServerPlayerLeaves();
5294 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5296 else if cmd
= 'permban_ip' then
5298 if g_Game_IsServer
and g_Game_IsNet
then
5300 if Length(P
) < 2 then
5302 g_Console_Add('permban_ip <IP address>');
5307 g_Console_Add('permban_ip <IP address>');
5311 g_Net_BanHost(P
[1]);
5312 g_Net_SaveBanList();
5313 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5315 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5317 else if cmd
= 'unban' then
5319 if g_Game_IsServer
and g_Game_IsNet
then
5321 if Length(P
) < 2 then
5323 g_Console_Add('unban <IP Address>');
5328 g_Console_Add('unban <IP Address>');
5332 if g_Net_UnbanHost(P
[1]) then
5334 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5335 g_Net_SaveBanList();
5337 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5339 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5341 else if cmd
= 'clientlist' then
5343 if g_Game_IsServer
and g_Game_IsNet
then
5346 if NetClients
<> nil then
5347 for a
:= Low(NetClients
) to High(NetClients
) do
5348 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5350 plr
:= g_Player_Get(NetClients
[a
].Player
);
5351 if plr
= nil then continue
;
5353 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5354 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5357 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5359 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5361 else if cmd
= 'connect' then
5363 if (NetMode
= NET_NONE
) then
5365 if Length(P
) < 2 then
5367 g_Console_Add('connect <IP> [port] [password]');
5372 g_Console_Add('connect <IP> [port] [password]');
5376 if Length(P
) > 2 then
5377 prt
:= StrToIntDef(P
[2], 25666)
5381 if Length(P
) > 3 then
5386 g_Game_StartClient(P
[1], prt
, pw
);
5389 else if cmd
= 'disconnect' then
5391 if (NetMode
= NET_CLIENT
) then
5394 else if cmd
= 'reconnect' then
5396 if (NetMode
= NET_SERVER
) then
5399 if (NetMode
= NET_CLIENT
) then
5402 gExit
:= EXIT_SIMPLE
;
5406 //TODO: Use last successful password to reconnect, instead of ''
5407 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5409 else if (cmd
= 'addbot') or
5410 (cmd
= 'bot_add') then
5412 if Length(P
) > 2 then
5413 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5414 else if Length(P
) > 1 then
5415 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5417 g_Bot_Add(TEAM_NONE
, 2);
5419 else if cmd
= 'bot_addlist' then
5421 if Length(P
) > 1 then
5423 if Length(P
) = 2 then
5424 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5425 else if Length(P
) = 3 then
5426 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5428 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5431 else if cmd
= 'bot_removeall' then
5433 else if cmd
= 'chat' then
5435 if g_Game_IsNet
then
5437 if Length(P
) > 1 then
5439 for a
:= 1 to High(P
) do
5440 chstr
:= chstr
+ P
[a
] + ' ';
5442 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5444 if Length(chstr
) < 1 then
5446 g_Console_Add('chat <text>');
5450 chstr
:= b_Text_Format(chstr
);
5451 if g_Game_IsClient
then
5452 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5454 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5457 g_Console_Add('chat <text>');
5459 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5461 else if cmd
= 'teamchat' then
5463 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5465 if Length(P
) > 1 then
5467 for a
:= 1 to High(P
) do
5468 chstr
:= chstr
+ P
[a
] + ' ';
5470 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5472 if Length(chstr
) < 1 then
5474 g_Console_Add('teamchat <text>');
5478 chstr
:= b_Text_Format(chstr
);
5479 if g_Game_IsClient
then
5480 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5482 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5483 gPlayer1Settings
.Team
);
5486 g_Console_Add('teamchat <text>');
5488 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5490 else if (cmd
= 'an') or (cmd
= 'announce') then
5492 if g_Game_IsNet
then
5494 if Length(P
) > 1 then
5496 for a
:= 1 to High(P
) do
5497 chstr
:= chstr
+ P
[a
] + ' ';
5499 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5501 if Length(chstr
) < 1 then
5503 g_Console_Add('announce <text>');
5507 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5508 if g_Game_IsClient
then
5509 MC_SEND_RCONCommand(chstr
)
5511 g_Console_Process(chstr
, True);
5514 g_Console_Add('announce <text>');
5516 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5518 else if cmd
= 'game' then
5520 if gGameSettings
.GameType
<> GT_NONE
then
5522 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5525 if Length(P
) = 1 then
5527 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5530 // game not started yet, load fist map from some wad
5532 s
:= addWadExtension(P
[1]);
5533 found
:= e_FindResource(AllMapDirs
, s
);
5537 P
[1] := ExpandFileName(P
[1]);
5538 // if map not choosed then set first map
5539 if Length(P
) < 3 then
5542 P
[2] := g_Game_GetFirstMap(P
[1]);
5545 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5547 if g_Map_Exist(s
) then
5551 with gGameSettings
do
5553 Options
:= gsGameFlags
;
5554 GameMode
:= g_Game_TextToMode(gsGameMode
);
5555 if gSwitchGameMode
<> GM_NONE
then
5556 GameMode
:= gSwitchGameMode
;
5557 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5558 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5560 if Length(P
) >= 4 then
5561 b
:= StrToIntDef(P
[3], 1);
5562 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5563 ScoreLimit
, MaxLives
, Options
, b
);
5568 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5570 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5572 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5574 else if cmd
= 'host' then
5576 if gGameSettings
.GameType
<> GT_NONE
then
5578 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5581 if Length(P
) < 4 then
5583 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5586 if not StrToIp(P
[1], listen
) then
5588 prt
:= StrToIntDef(P
[2], 25666);
5590 s
:= addWadExtension(P
[3]);
5591 found
:= e_FindResource(AllMapDirs
, s
);
5595 // get first map in wad, if not specified
5596 if Length(P
) < 5 then
5599 P
[4] := g_Game_GetFirstMap(P
[1]);
5601 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5602 if g_Map_Exist(s
) then
5606 with gGameSettings
do
5608 Options
:= gsGameFlags
;
5609 GameMode
:= g_Game_TextToMode(gsGameMode
);
5610 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5611 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5612 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5614 if Length(P
) >= 6 then
5615 b
:= StrToIntDef(P
[5], 0);
5616 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5622 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5624 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5629 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5632 else if cmd
= 'map' then
5634 if Length(P
) = 1 then
5636 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5638 g_Console_Add(cmd
+ ' <MAP>');
5639 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5643 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5648 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5650 if Length(P
) < 3 then
5652 // first param is map or wad
5653 s
:= UpperCase(P
[1]);
5654 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5656 gExitByTrigger
:= False;
5659 // already in game, finish current map
5661 gExit
:= EXIT_ENDLEVELCUSTOM
;
5665 // intermission, so change map immediately
5672 found
:= e_FindResource(AllMapDirs
, s
);
5674 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5677 // no such map, found wad
5680 P
[1] := ExpandFileName(pw
);
5681 P
[2] := g_Game_GetFirstMap(P
[1]);
5682 s
:= P
[1] + ':\' + P
[2];
5683 if g_Map_Exist(s
) then
5685 gExitByTrigger
:= False;
5688 // already in game, finish current map
5690 gExit
:= EXIT_ENDLEVELCUSTOM
5694 // intermission, so change map immediately
5701 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5703 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5708 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5714 s
:= addWadExtension(P
[1]);
5715 found
:= e_FindResource(AllMapDirs
, s
);
5719 P
[2] := UpperCase(P
[2]);
5720 s
:= P
[1] + ':\' + P
[2];
5721 if g_Map_Exist(s
) then
5723 gExitByTrigger
:= False;
5727 gExit
:= EXIT_ENDLEVELCUSTOM
5736 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5741 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5747 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5751 else if cmd
= 'nextmap' then
5753 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5755 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5760 if Length(P
) = 1 then
5762 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5764 g_Console_Add(cmd
+ ' <MAP>');
5765 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5770 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5776 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5778 if Length(P
) < 3 then
5780 // first param is map or wad
5781 s
:= UpperCase(P
[1]);
5782 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5785 gExitByTrigger
:= False;
5791 // no such map, found wad
5792 pw
:= addWadExtension(P
[1]);
5793 found
:= e_FindResource(MapDirs
, pw
);
5795 found
:= e_FindResource(WadDirs
, pw
);
5797 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5800 // map not specified, select first map
5802 P
[2] := g_Game_GetFirstMap(P
[1]);
5803 s
:= P
[1] + ':\' + P
[2];
5804 if g_Map_Exist(s
) then
5806 gExitByTrigger
:= False;
5813 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5815 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5820 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5826 // specified two params wad + map
5827 pw
:= addWadExtension(P
[1]);
5828 found
:= e_FindResource(MapDirs
, pw
);
5830 found
:= e_FindResource(MapDirs
, pw
);
5834 P
[2] := UpperCase(P
[2]);
5835 s
:= P
[1] + ':\' + P
[2];
5836 if g_Map_Exist(s
) then
5838 gExitByTrigger
:= False;
5844 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5849 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5855 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5860 if gNextMap
= '' then
5861 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5863 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5867 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5871 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5875 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5877 gExitByTrigger
:= False;
5878 // next map not specified, try to find trigger EXIT
5879 if (gNextMap
= '') and (gTriggers
<> nil) then
5881 for a
:= 0 to High(gTriggers
) do
5883 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5885 gExitByTrigger
:= True;
5886 //gNextMap := gTriggers[a].Data.MapName;
5887 gNextMap
:= gTriggers
[a
].tgcMap
;
5892 if gNextMap
= '' then
5893 gNextMap
:= g_Game_GetNextMap();
5894 if not isWadPath(gNextMap
) then
5895 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5898 if g_Map_Exist(s
) then
5899 gExit
:= EXIT_ENDLEVELCUSTOM
5901 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5905 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5909 else if (cmd
= 'event') then
5911 if (Length(P
) <= 1) then
5913 for a
:= 0 to High(gEvents
) do
5914 if gEvents
[a
].Command
= '' then
5915 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5917 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5920 if (Length(P
) = 2) then
5922 for a
:= 0 to High(gEvents
) do
5923 if gEvents
[a
].Name
= P
[1] then
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 for a
:= 0 to High(gEvents
) do
5931 if gEvents
[a
].Name
= P
[1] then
5933 gEvents
[a
].Command
:= '';
5934 for b
:= 2 to High(P
) do
5935 if Pos(' ', P
[b
]) = 0 then
5936 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5938 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5939 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5943 else if cmd
= 'suicide' then
5947 if g_Game_IsClient
then
5948 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5951 if gPlayer1
<> nil then
5952 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5953 if gPlayer2
<> nil then
5954 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5958 else if cmd
= 'screenshot' then
5960 {$IFDEF ENABLE_RENDER}
5961 r_Render_RequestScreenShot
;
5964 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5966 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5968 gWeaponAction
[0, WP_PREV
] := True;
5970 gWeaponAction
[0, WP_NEXT
] := True;
5972 else if cmd
= 'weapon' then
5974 if Length(p
) = 2 then
5976 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5977 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5978 gSelectWeapon
[0, a
] := True
5981 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5982 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5984 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5985 b
:= ord(cmd
[2]) - ord('1');
5987 gWeaponAction
[b
, WP_PREV
] := True;
5989 gWeaponAction
[b
, WP_NEXT
] := True;
5991 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5993 if Length(p
) = 2 then
5995 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5996 b
:= ord(cmd
[2]) - ord('1');
5997 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5998 gSelectWeapon
[b
, a
] := True
6001 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
6003 b
:= ord(cmd
[2]) - ord('1');
6005 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
6007 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
6009 else if (cmd
= 'dropflag') then
6011 if g_Game_IsServer
then
6013 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
6014 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
6017 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6019 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
6021 b
:= ord(cmd
[2]) - ord('1');
6022 if g_Game_IsServer
then
6024 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
6025 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
6028 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6030 // Команды Своей игры:
6031 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6033 if cmd
= 'bot_addred' then
6035 if Length(P
) > 1 then
6036 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6038 g_Bot_Add(TEAM_RED
, 2);
6040 else if cmd
= 'bot_addblue' then
6042 if Length(P
) > 1 then
6043 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6045 g_Bot_Add(TEAM_BLUE
, 2);
6047 else if cmd
= 'spectate' then
6053 else if cmd
= 'say' then
6055 if g_Game_IsServer
and g_Game_IsNet
then
6057 if Length(P
) > 1 then
6060 for a
:= 1 to High(P
) do
6061 chstr
:= chstr
+ P
[a
] + ' ';
6063 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6065 if Length(chstr
) < 1 then
6067 g_Console_Add('say <text>');
6071 chstr
:= b_Text_Format(chstr
);
6072 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6074 else g_Console_Add('say <text>');
6076 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6078 else if cmd
= 'tell' then
6080 if g_Game_IsServer
and g_Game_IsNet
then
6082 if (Length(P
) > 2) and (P
[1] <> '') then
6085 for a
:= 2 to High(P
) do
6086 chstr
:= chstr
+ P
[a
] + ' ';
6088 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6090 if Length(chstr
) < 1 then
6092 g_Console_Add('tell <playername> <text>');
6096 pl
:= g_Net_Client_ByName(P
[1]);
6098 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6100 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6102 else g_Console_Add('tell <playername> <text>');
6104 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6106 else if cmd
= 'centerprint' then
6108 if (Length(P
) > 2) and (P
[1] <> '') then
6111 for a
:= 2 to High(P
) do
6112 chstr
:= chstr
+ P
[a
] + ' ';
6114 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6116 if Length(chstr
) < 1 then
6118 g_Console_Add('centerprint <timeout> <text>');
6122 a
:= StrToIntDef(P
[1], 100);
6123 chstr
:= b_Text_Format(chstr
);
6124 g_Game_Message(chstr
, a
);
6125 if g_Game_IsNet
and g_Game_IsServer
then
6126 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6128 else g_Console_Add('centerprint <timeout> <text>');
6130 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6132 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6134 // Дополнительное время:
6135 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6137 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6138 [gGameSettings
.TimeLimit
div 3600,
6139 (gGameSettings
.TimeLimit
div 60) mod 60,
6140 gGameSettings
.TimeLimit
mod 60]));
6141 if g_Game_IsNet
then MH_SEND_GameSettings
;
6143 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6145 if (Length(P
) <= 1) then
6146 g_Console_Add('rcon_password <password>')
6148 MC_SEND_RCONPassword(P
[1]);
6150 else if cmd
= 'rcon' then
6152 if g_Game_IsClient
then
6154 if Length(P
) > 1 then
6157 for a
:= 1 to High(P
) do
6158 chstr
:= chstr
+ P
[a
] + ' ';
6160 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6162 if Length(chstr
) < 1 then
6164 g_Console_Add('rcon <command>');
6168 MC_SEND_RCONCommand(chstr
);
6170 else g_Console_Add('rcon <command>');
6173 else if cmd
= 'ready' then
6175 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6176 gLMSRespawnTime
:= gTime
+ 100;
6178 else if (cmd
= 'callvote') and g_Game_IsNet
then
6180 if Length(P
) > 1 then
6183 for a
:= 1 to High(P
) do begin
6184 if a
> 1 then chstr
:= chstr
+ ' ';
6185 chstr
:= chstr
+ P
[a
];
6188 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6190 if Length(chstr
) < 1 then
6192 g_Console_Add('callvote <command>');
6196 if g_Game_IsClient
then
6197 MC_SEND_Vote(True, chstr
)
6199 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6200 g_Console_Process('vote', True);
6203 g_Console_Add('callvote <command>');
6205 else if (cmd
= 'vote') and g_Game_IsNet
then
6207 if g_Game_IsClient
then
6209 else if gVoteInProgress
then
6211 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6212 a
:= Floor((NetClientCount
+1)/2.0) + 1
6214 a
:= Floor(NetClientCount
/2.0) + 1;
6219 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6220 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6226 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6227 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6235 procedure SystemCommands(P
: SSArray
);
6239 cmd
:= LowerCase(P
[0]);
6246 {$IFDEF ENABLE_RENDER}
6252 if Length(p
) = 2 then
6254 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6256 gFrameTime
:= 1000 div gMaxFPS
6260 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6264 if Length(p
) = 2 then
6266 gAskLanguage
:= true;
6267 gLanguage
:= LANGUAGE_ENGLISH
;
6268 case LowerCase(p
[1]) of
6271 gAskLanguage
:= false;
6272 gLanguage
:= LANGUAGE_ENGLISH
;
6276 gAskLanguage
:= false;
6277 gLanguage
:= LANGUAGE_RUSSIAN
;
6281 gAskLanguage
:= true;
6282 gLanguage
:= LANGUAGE_ENGLISH
;
6285 g_Language_Set(gLanguage
);
6289 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6295 {$IFDEF ENABLE_MENU}
6296 procedure g_Game_InGameMenu(Show
: Boolean);
6298 if (g_ActiveWindow
= nil) and Show
then
6300 if gGameSettings
.GameType
= GT_SINGLE
then
6301 g_GUI_ShowWindow('GameSingleMenu')
6304 if g_Game_IsClient
then
6305 g_GUI_ShowWindow('GameClientMenu')
6307 if g_Game_IsNet
then
6308 g_GUI_ShowWindow('GameServerMenu')
6310 g_GUI_ShowWindow('GameCustomMenu');
6312 g_Sound_PlayEx('MENU_OPEN');
6314 // Пауза при меню только в одиночной игре:
6315 if (not g_Game_IsNet
) then
6319 if (g_ActiveWindow
<> nil) and (not Show
) then
6321 // Пауза при меню только в одиночной игре:
6322 if (not g_Game_IsNet
) then
6323 g_Game_Pause(False);
6328 procedure g_Game_Pause (Enable
: Boolean);
6332 if not gGameOn
then exit
;
6334 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6337 gPauseMain
:= Enable
;
6339 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6342 procedure g_Game_HolmesPause (Enable
: Boolean);
6346 if not gGameOn
then exit
;
6347 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6350 gPauseHolmes
:= Enable
;
6352 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6355 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6360 if gTriggers
<> nil then
6361 for i
:= 0 to High(gTriggers
) do
6362 with gTriggers
[i
] do
6363 if (TriggerType
= TRIGGER_SOUND
) and
6365 Sound
.IsPlaying() then
6367 Sound
.Pause(Enable
);
6371 if gPlayers
<> nil then
6372 for i
:= 0 to High(gPlayers
) do
6373 if gPlayers
[i
] <> nil then
6374 gPlayers
[i
].PauseSounds(Enable
);
6377 if gMusic
<> nil then
6378 gMusic
.Pause(Enable
);
6381 procedure g_Game_StopAllSounds(all
: Boolean);
6385 if gTriggers
<> nil then
6386 for i
:= 0 to High(gTriggers
) do
6387 with gTriggers
[i
] do
6388 if (TriggerType
= TRIGGER_SOUND
) and
6392 if gMusic
<> nil then
6399 procedure g_Game_UpdateTriggerSounds
;
6402 if gTriggers
<> nil then
6403 for i
:= 0 to High(gTriggers
) do
6404 with gTriggers
[i
] do
6405 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6406 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6409 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6412 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6417 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6422 if gSpectMode
<> SPECT_PLAYERS
then
6424 if gSpectPID1
= UID
then
6429 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6436 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6441 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6446 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6451 if gSpectMode
<> SPECT_PLAYERS
then
6453 Pl
:= g_Player_Get(gSpectPID1
);
6454 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6459 if gSpectViewTwo
then
6461 Pl
:= g_Player_Get(gSpectPID2
);
6462 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6470 procedure g_Game_Message (Msg
: string; Time
: Word);
6473 MessageTime
:= Time
;
6476 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6478 punct
: Array[0..13] of String =
6479 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6485 function IsPunctuation(S
: String): Boolean;
6490 if Length(S
) <> 1 then
6492 for i
:= Low(punct
) to High(punct
) do
6493 if S
= punct
[i
] then
6499 function FilterPunctuation(S
: String): String;
6503 for i
:= Low(punct
) to High(punct
) do
6504 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6510 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6512 // remove player name
6513 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6514 // for FullWord check
6515 Text := toLowerCase1251(' ' + Text + ' ');
6516 fpText
:= FilterPunctuation(Text);
6518 for i
:= 0 to Length(gChatSounds
) - 1 do
6521 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6523 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6524 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6526 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6532 gChatSounds
[i
].Sound
.Play();
6538 g_Sound_PlayEx('SOUND_GAME_RADIO');
6541 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6550 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6554 if goodsnd
[a
].IsPlaying() then
6557 goodsnd
[Random(4)].Play();
6560 procedure g_Game_Announce_KillCombo(Param
: Integer);
6567 UID
:= Param
and $FFFF;
6572 Pl
:= g_Player_Get(UID
);
6581 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6585 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6589 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6593 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6601 if not g_Game_IsWatchedPlayer(UID
) then
6604 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6608 if killsnd
[n
].IsPlaying() then
6613 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6621 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6625 if hahasnd
[a
].IsPlaying() then
6628 hahasnd
[Random(3)].Play();
6631 procedure g_Game_StartVote(Command
, Initiator
: string);
6635 if not gVotesEnabled
then Exit
;
6636 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6637 if gVoteInProgress
or gVotePassed
then
6639 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6640 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6643 gVoteInProgress
:= True;
6644 gVotePassed
:= False;
6645 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6648 gVoteCommand
:= Command
;
6650 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6651 Need
:= Floor((NetClientCount
+1)/2.0)+1
6653 Need
:= Floor(NetClientCount
/2.0)+1;
6654 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6655 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6658 procedure g_Game_CheckVote
;
6662 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6663 if not gVoteInProgress
then Exit
;
6665 if (gTime
>= gVoteTimer
) then
6667 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6668 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6670 Need
:= Floor(NetClientCount
/2.0) + 1;
6671 if gVoteCount
>= Need
then
6673 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6674 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6675 gVotePassed
:= True;
6676 gVoteCmdTimer
:= gTime
+ 5000;
6680 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6681 MH_SEND_VoteEvent(NET_VE_FAILED
);
6683 if NetClients
<> nil then
6684 for I
:= Low(NetClients
) to High(NetClients
) do
6685 if NetClients
[i
].Used
then
6686 NetClients
[i
].Voted
:= False;
6687 gVoteInProgress
:= False;
6693 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6694 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6696 Need
:= Floor(NetClientCount
/2.0) + 1;
6697 if gVoteCount
>= Need
then
6699 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6700 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6701 gVoteInProgress
:= False;
6702 gVotePassed
:= True;
6703 gVoteCmdTimer
:= gTime
+ 5000;
6706 if NetClients
<> nil then
6707 for I
:= Low(NetClients
) to High(NetClients
) do
6708 if NetClients
[i
].Used
then
6709 NetClients
[i
].Voted
:= False;
6714 procedure g_Game_LoadMapList(FileName
: string);
6722 if not FileExists(FileName
) then Exit
;
6724 AssignFile(ListFile
, FileName
);
6726 while not EOF(ListFile
) do
6728 ReadLn(ListFile
, s
);
6731 if s
= '' then Continue
;
6733 SetLength(MapList
, Length(MapList
)+1);
6734 MapList
[High(MapList
)] := s
;
6736 CloseFile(ListFile
);
6739 procedure g_Game_SetDebugMode();
6742 // Читы (даже в своей игре):
6746 procedure Parse_Params(var pars
: TParamStrValues
);
6753 while i
<= ParamCount
do
6756 if (Length(s
) > 1) and (s
[1] = '-') then
6758 if (Length(s
) > 2) and (s
[2] = '-') then
6759 begin // Одиночный параметр
6760 SetLength(pars
, Length(pars
) + 1);
6761 with pars
[High(pars
)] do
6763 Name
:= LowerCase(s
);
6768 if (i
< ParamCount
) then
6769 begin // Параметр со значением
6771 SetLength(pars
, Length(pars
) + 1);
6772 with pars
[High(pars
)] do
6774 Name
:= LowerCase(s
);
6775 Value
:= LowerCase(ParamStr(i
));
6784 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6789 for i
:= 0 to High(pars
) do
6790 if pars
[i
].Name
= aName
then
6792 Result
:= pars
[i
].Value
;
6797 procedure g_Game_Process_Params();
6799 pars
: TParamStrValues
;
6802 LimT
, LimS
: Integer;
6813 s
:= Find_Param_Value(pars
, '--debug');
6816 g_Game_SetDebugMode();
6817 s
:= Find_Param_Value(pars
, '--netdump');
6822 // Connect when game loads
6823 ip
:= Find_Param_Value(pars
, '-connect');
6827 s
:= Find_Param_Value(pars
, '-port');
6828 if (s
= '') or not TryStrToInt(s
, Port
) then
6831 s
:= Find_Param_Value(pars
, '-pw');
6833 g_Game_StartClient(ip
, Port
, s
);
6837 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6840 gDefaultMegawadStart
:= s
;
6843 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6844 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6846 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6849 // Start map when game loads:
6850 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6851 if isWadPath(map
) then
6854 s
:= Find_Param_Value(pars
, '-gm');
6855 GMode
:= g_Game_TextToMode(s
);
6856 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6857 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6860 s
:= Find_Param_Value(pars
, '-limt');
6861 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6867 s
:= Find_Param_Value(pars
, '-lims');
6868 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6874 s
:= Find_Param_Value(pars
, '-lives');
6875 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6881 s
:= Find_Param_Value(pars
, '-opt');
6885 Opt
:= StrToIntDef(s
, 0);
6888 s
:= Find_Param_Value(pars
, '--close');
6892 // Override map to test:
6893 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6896 if e_IsValidResourceName(s
) then
6897 e_FindResource(AllMapDirs
, s
);
6898 gTestMap
:= ExpandFileName(s
);
6901 // Delete test map after play:
6902 s
:= Find_Param_Value(pars
, '--testdelete');
6905 //gMapToDelete := MapsDir + map;
6906 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6910 // Delete temporary WAD after play:
6911 s
:= Find_Param_Value(pars
, '--tempdelete');
6912 if (s
<> '') and (gTestMap
<> '') then
6914 gMapToDelete
:= gTestMap
;
6915 gTempDelete
:= True;
6918 // Number of players:
6919 s
:= Find_Param_Value(pars
, '-pl');
6921 n
:= DEFAULT_PLAYERS
6923 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6926 s
:= Find_Param_Value(pars
, '-port');
6927 if (s
= '') or not TryStrToInt(s
, Port
) then
6928 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6930 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6933 // Execute script when game loads:
6934 s
:= Find_Param_Value(pars
, '-exec');
6937 // if not isWadPath(s) then
6938 // s := GameDir + '/' + s;
6943 if IOResult
<> 0 then
6945 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6946 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6950 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6951 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6956 if IOResult
<> 0 then
6958 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6959 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6963 if Pos('#', s
) <> 1 then // script comment
6964 g_Console_Process(s
, True);
6975 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6976 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6977 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6978 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6980 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6981 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6982 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6983 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6986 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6987 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6990 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6991 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6993 {$IFDEF ENABLE_HOLMES}
6994 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6997 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6999 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7000 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7002 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7003 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7005 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
7006 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
7007 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
7008 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
7009 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7010 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7011 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7012 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7013 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');