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
;
136 procedure g_TakeScreenShot(Filename
: string = '');
138 procedure g_FatalError(Text: String);
139 procedure g_SimpleError(Text: String);
140 function g_Game_IsTestMap(): Boolean;
141 procedure g_Game_DeleteTestMap();
142 procedure GameCVars(P
: SSArray
);
143 procedure PlayerSettingsCVars(P
: SSArray
);
144 procedure SystemCommands(P
: SSArray
);
145 procedure GameCommands(P
: SSArray
);
146 procedure GameCheats(P
: SSArray
);
147 procedure DebugCommands(P
: SSArray
);
148 procedure g_Game_Process_Params
;
149 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
150 procedure g_Game_StepLoading(Value
: Integer = -1);
151 procedure g_Game_ClearLoading();
152 procedure g_Game_SetDebugMode();
154 function IsActivePlayer(p
: TPlayer
): Boolean;
155 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
156 procedure SortGameStat(var stat
: TPlayerStatArray
);
160 procedure g_Game_InGameMenu(Show
: Boolean);
163 procedure CharPress (C
: AnsiChar);
165 procedure KeyPress (K
: Word);
167 { procedure SetWinPause(Enable: Boolean); }
172 LOADING_SHOW_STEP
= 100;
173 LOADING_INTERLINE
= 20;
191 EXIT_ENDLEVELSINGLE
= 4;
192 EXIT_ENDLEVELCUSTOM
= 5;
194 GAME_OPTION_RESERVED
= 1;
195 GAME_OPTION_TEAMDAMAGE
= 2;
196 GAME_OPTION_ALLOWEXIT
= 4;
197 GAME_OPTION_WEAPONSTAY
= 8;
198 GAME_OPTION_MONSTERS
= 16;
199 GAME_OPTION_BOTVSPLAYER
= 32;
200 GAME_OPTION_BOTVSMONSTER
= 64;
201 GAME_OPTION_DMKEYS
= 128;
202 GAME_OPTION_TEAMHITTRACE
= 256;
203 GAME_OPTION_TEAMHITPROJECTILE
= 512;
204 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
205 GAME_OPTION_ALLOWDROPFLAG
= 2048;
206 GAME_OPTION_THROWFLAG
= 4096;
211 STATE_INTERCUSTOM
= 3;
212 STATE_INTERSINGLE
= 4;
218 LMS_RESPAWN_NONE
= 0;
219 LMS_RESPAWN_WARMUP
= 1;
220 LMS_RESPAWN_FINAL
= 2;
237 CONFIG_FILENAME
= 'Doom2DF.cfg';
239 TEST_MAP_NAME
= '$$$_TEST_$$$';
241 STD_PLAYER_MODEL
= 'Doomer';
249 STATFILE_VERSION
= $03;
252 gGameSettings
: TGameSettings
;
253 gPlayer1Settings
: TPlayerSettings
;
254 gPlayer2Settings
: TPlayerSettings
;
256 gPlayerScreenSize
: TDFPoint
;
257 gPlayer1ScreenCoord
: TDFPoint
;
258 gPlayer2ScreenCoord
: TDFPoint
;
259 gPlayer1
: TPlayer
= nil;
260 gPlayer2
: TPlayer
= nil;
261 gPlayerDrawn
: TPlayer
= nil;
263 gLerpFactor
: Single = 1.0;
264 gSwitchGameMode
: Byte = GM_DM
;
265 gHearPoint1
, gHearPoint2
: THearPoint
;
266 gSoundEffectsDF
: Boolean = False;
267 gSoundTriggerTime
: Word = 0;
268 gAnnouncer
: Integer = ANNOUNCE_NONE
;
269 goodsnd
: array[0..3] of TPlayableSound
;
270 killsnd
: array[0..3] of TPlayableSound
;
271 hahasnd
: array[0..2] of TPlayableSound
;
272 sound_get_flag
: array[0..1] of TPlayableSound
;
273 sound_lost_flag
: array[0..1] of TPlayableSound
;
274 sound_ret_flag
: array[0..1] of TPlayableSound
;
275 sound_cap_flag
: array[0..1] of TPlayableSound
;
276 gBodyKillEvent
: Integer = -1;
277 gDefInterTime
: ShortInt = -1;
278 gInterEndTime
: LongWord = 0;
279 gInterTime
: LongWord = 0;
280 gServInterTime
: Byte = 0;
281 gGameStartTime
: LongWord = 0;
282 gTotalMonsters
: Integer = 0;
283 gPauseMain
: Boolean = false;
284 gPauseHolmes
: Boolean = false;
285 gShowTime
: Boolean = False;
286 gShowFPS
: Boolean = False;
287 gShowScore
: Boolean = True;
288 gShowStat
: Boolean = True;
289 gShowPIDs
: Boolean = False;
290 gShowKillMsg
: Boolean = True;
291 gShowLives
: Boolean = True;
292 gShowPing
: Boolean = False;
293 gShowMap
: Boolean = False;
295 gState
: Byte = STATE_NONE
;
297 sWidth
, sHeight
: Word;
298 gSpectMode
: Byte = SPECT_NONE
;
299 gSpectHUD
: Boolean = True;
300 gSpectKeyPress
: Boolean = False;
301 gSpectX
: Integer = 0;
302 gSpectY
: Integer = 0;
303 gSpectStep
: Byte = 8;
304 gSpectViewTwo
: Boolean = False;
305 gSpectPID1
: Integer = -1;
306 gSpectPID2
: Integer = -1;
307 gSpectAuto
: Boolean = False;
308 gSpectAutoNext
: LongWord;
309 gSpectAutoStepX
: Integer;
310 gSpectAutoStepY
: Integer;
311 gMusic
: TMusic
= nil;
312 gLoadGameMode
: Boolean;
313 gCheats
: Boolean = False;
314 gMapOnce
: Boolean = False;
315 gMapToDelete
: String;
316 gTempDelete
: Boolean = False;
317 gLastMap
: Boolean = False;
320 gResolutionChange
: Boolean = False;
321 gRC_Width
, gRC_Height
: Integer;
322 gRC_FullScreen
, gRC_Maximized
: Boolean;
323 gLanguageChange
: Boolean = False;
324 gDebugMode
: Boolean = False;
325 g_debug_Sounds
: Boolean = False;
326 g_debug_Frames
: Boolean = False;
327 g_debug_WinMsgs
: Boolean = False;
328 g_debug_MonsterOff
: Boolean = False;
329 g_debug_BotAIOff
: Byte = 0;
330 g_debug_HealthBar
: Boolean = False;
331 g_Debug_Player
: Boolean = False;
332 gCoopMonstersKilled
: Word = 0;
333 gCoopSecretsFound
: Word = 0;
334 gCoopTotalMonstersKilled
: Word = 0;
335 gCoopTotalSecretsFound
: Word = 0;
336 gCoopTotalMonsters
: Word = 0;
337 gCoopTotalSecrets
: Word = 0;
338 gStatsOff
: Boolean = False;
339 gStatsPressed
: Boolean = False;
340 gExitByTrigger
: Boolean = False;
341 gNextMap
: String = '';
342 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
343 gLMSRespawnTime
: Cardinal = 0;
344 gLMSSoftSpawn
: Boolean = False;
345 gMissionFailed
: Boolean = False;
346 gVoteInProgress
: Boolean = False;
347 gVotePassed
: Boolean = False;
348 gVoteCommand
: string = '';
349 gVoteTimer
: Cardinal = 0;
350 gVoteCmdTimer
: Cardinal = 0;
351 gVoteCount
: Integer = 0;
352 gVoteTimeout
: Cardinal = 30;
353 gVoted
: Boolean = False;
354 gVotesEnabled
: Boolean = True;
355 gEvents
: Array of TGameEvent
;
356 gDelayedEvents
: Array of TDelayedEvent
;
357 gUseChatSounds
: Boolean = True;
358 gChatSounds
: Array of TChatSound
;
359 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
360 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
361 gInterReadyCount
: Integer = 0;
362 gMaxBots
: Integer = 127;
364 g_dbg_ignore_bounds
: Boolean = false;
365 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
366 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
368 // move button values:
369 // bits 0-1: l/r state:
370 // 0: neither left, nor right pressed
373 // bits 4-5: l/r state when strafe was pressed
374 P1MoveButton
: Byte = 0;
375 P2MoveButton
: Byte = 0;
377 g_profile_frame_update
: Boolean = false;
378 g_profile_frame_draw
: Boolean = false;
379 g_profile_collision
: Boolean = false;
380 g_profile_los
: Boolean = false;
381 g_profile_history_size
: Integer = 1000;
383 g_rlayer_back
: Boolean = true;
384 g_rlayer_step
: Boolean = true;
385 g_rlayer_wall
: Boolean = true;
386 g_rlayer_door
: Boolean = true;
387 g_rlayer_acid1
: Boolean = true;
388 g_rlayer_acid2
: Boolean = true;
389 g_rlayer_water
: Boolean = true;
390 g_rlayer_fore
: Boolean = true;
392 wNeedTimeReset
: Boolean = false;
394 procedure g_ResetDynlights ();
395 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
396 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
398 function conIsCheatsEnabled (): Boolean; inline;
399 function gPause (): Boolean; inline;
401 type (* private state *)
402 TEndCustomGameStat
= record
403 PlayerStat
: TPlayerStatArray
;
407 Map
, MapName
: String;
410 TEndSingleGameStat
= record
411 PlayerStat
: Array [0..1] of record
417 TotalSecrets
: Integer;
420 TLoadingStat
= record
424 Msgs
: Array of String;
426 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
430 x
, y
, radius
: Integer;
433 exploRadius
: Integer;
436 var (* private state *)
437 CustomStat
: TEndCustomGameStat
;
438 StatShotDone
: Boolean;
439 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
440 SingleStat
: TEndSingleGameStat
;
441 LoadingStat
: TLoadingStat
;
444 EndingGameCounter
: Byte;
446 g_playerLight
: Boolean;
447 g_dynLights
: array of TDynLight
= nil;
448 g_dynLightCount
: Integer = 0;
449 EndPicPath
: AnsiString; // full path, used by render
454 {$IFDEF ENABLE_HOLMES}
466 {$IFDEF ENABLE_SHELLS}
469 {$IFDEF ENABLE_CORPSES}
476 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
477 g_playermodel
, g_options
, Math
,
478 g_triggers
, g_monsters
, e_sound
, CONFIG
,
479 g_language
, g_net
, g_phys
,
480 ENet
, e_msg
, g_netmsg
, g_netmaster
,
484 charbuff
: packed array [0..15] of AnsiChar = (
485 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
488 function Translit (const S
: AnsiString): AnsiString;
493 for i
:= 1 to Length(Result
) do
496 #
$C9: Result
[i
] := 'Q';
497 #
$D6: Result
[i
] := 'W';
498 #
$D3: Result
[i
] := 'E';
499 #
$CA: Result
[i
] := 'R';
500 #
$C5: Result
[i
] := 'T';
501 #
$CD: Result
[i
] := 'Y';
502 #
$C3: Result
[i
] := 'U';
503 #
$D8: Result
[i
] := 'I';
504 #
$D9: Result
[i
] := 'O';
505 #
$C7: Result
[i
] := 'P';
506 #
$D5: Result
[i
] := '['; //Chr(219);
507 #
$DA: Result
[i
] := ']'; //Chr(221);
508 #
$D4: Result
[i
] := 'A';
509 #
$DB: Result
[i
] := 'S';
510 #
$C2: Result
[i
] := 'D';
511 #
$C0: Result
[i
] := 'F';
512 #
$CF: Result
[i
] := 'G';
513 #
$D0: Result
[i
] := 'H';
514 #
$CE: Result
[i
] := 'J';
515 #
$CB: Result
[i
] := 'K';
516 #
$C4: Result
[i
] := 'L';
517 #
$C6: Result
[i
] := ';'; //Chr(186);
518 #
$DD: Result
[i
] := #39; //Chr(222);
519 #
$DF: Result
[i
] := 'Z';
520 #
$D7: Result
[i
] := 'X';
521 #
$D1: Result
[i
] := 'C';
522 #
$CC: Result
[i
] := 'V';
523 #
$C8: Result
[i
] := 'B';
524 #
$D2: Result
[i
] := 'N';
525 #
$DC: Result
[i
] := 'M';
526 #
$C1: Result
[i
] := ','; //Chr(188);
527 #
$DE: Result
[i
] := '.'; //Chr(190);
533 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
538 ls2
:= Translit(CheatRus
[ct
]);
539 if length(ls1
) = 0 then ls1
:= '~';
540 if length(ls2
) = 0 then ls2
:= '~';
542 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
543 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
544 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
545 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
547 if ct = I_GAME_CHEAT_JETPACK then
549 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
550 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
551 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
552 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
553 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
554 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
570 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
571 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
572 or g_Game_IsNet then Exit;
574 if not gGameOn
then exit
;
575 if not conIsCheatsEnabled
then exit
;
577 s
:= 'SOUND_GAME_RADIO';
580 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
582 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
583 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
587 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
589 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
590 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
594 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
596 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
597 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
601 if CheckCheat(I_GAME_CHEAT_DEATH
) then
603 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
604 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
605 s
:= 'SOUND_MONSTER_HAHA';
609 if CheckCheat(I_GAME_CHEAT_DOORS
) then
611 g_Triggers_OpenAll();
615 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
617 if gTriggers
<> nil then
618 for a
:= 0 to High(gTriggers
) do
619 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
621 gExitByTrigger
:= True;
622 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
623 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
629 s2
:= Copy(charbuff
, 15, 2);
630 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
632 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
640 if CheckCheat(I_GAME_CHEAT_FLY
) then
646 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
648 VEL_JUMP
:= 30-VEL_JUMP
;
652 if CheckCheat(I_GAME_CHEAT_SPEED
) then
654 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
658 if CheckCheat(I_GAME_CHEAT_SUIT
) then
660 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
661 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
665 if CheckCheat(I_GAME_CHEAT_AIR
) then
667 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
668 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
672 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
674 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
675 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
679 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
681 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
682 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
686 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
688 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
689 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
693 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
695 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
696 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
700 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
702 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
703 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
706 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
708 gAimLine
:= not gAimLine
;
711 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
713 gShowMap
:= not gShowMap
;
724 procedure KeyPress (K
: Word);
725 var Msg
: g_gui
.TMessage
;
730 if (g_ActiveWindow
<> nil) then
732 Msg
.Msg
:= WM_KEYDOWN
;
733 Msg
.WParam
:= VK_ESCAPE
;
734 g_ActiveWindow
.OnMessage(Msg
);
735 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
737 else if (gState
<> STATE_FOLD
) then
739 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
741 g_Game_InGameMenu(True);
743 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
745 if (gState
<> STATE_MENU
) then
747 if (NetMode
<> NET_NONE
) then
749 g_Game_StopAllSounds(True);
751 gState
:= STATE_MENU
;
755 g_GUI_ShowWindow('MainMenu');
756 g_Sound_PlayEx('MENU_OPEN');
761 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
762 begin // <F2> .. <F6> � <F12>
763 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
765 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
766 if (not g_Game_IsNet
) then g_Game_Pause(True);
768 IK_F2
: g_Menu_Show_SaveMenu();
769 IK_F3
: g_Menu_Show_LoadMenu();
770 IK_F4
: g_Menu_Show_GameSetGame();
771 IK_F5
: g_Menu_Show_OptionsVideo();
772 IK_F6
: g_Menu_Show_OptionsSound();
773 IK_F7
: g_Menu_Show_EndGameMenu();
774 IK_F10
: g_Menu_Show_QuitGameMenu();
781 gJustChatted
:= False;
782 if gConsoleShow
or gChatShow
then
784 g_Console_Control(K
);
786 else if (g_ActiveWindow
<> nil) then
788 Msg
.Msg
:= WM_KEYDOWN
;
790 g_ActiveWindow
.OnMessage(Msg
);
792 else if (gState
= STATE_MENU
) then
794 g_GUI_ShowWindow('MainMenu');
795 g_Sound_PlayEx('MENU_OPEN');
801 procedure KeyPress (K
: Word);
803 gJustChatted
:= False;
804 if gConsoleShow
or gChatShow
then
806 g_Console_Control(K
);
812 procedure CharPress (C
: AnsiChar);
814 var Msg
: g_gui
.TMessage
;
818 if gConsoleShow
or gChatShow
then
823 else if g_ActiveWindow
<> nil then
826 Msg
.WParam
:= Ord(C
);
827 g_ActiveWindow
.OnMessage(Msg
);
834 charbuff
[a
] := charbuff
[a
+ 1];
836 charbuff
[15] := upcase1251(C
);
843 // ////////////////////////////////////////////////////////////////////////// //
844 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
846 procedure g_ResetDynlights ();
850 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
852 for idx
:= 0 to g_dynLightCount
-1 do
854 if g_dynLights
[idx
].exploCount
= -666 then
861 Inc(g_dynLights
[idx
].exploCount
);
862 if (g_dynLights
[idx
].exploCount
< 10) then
864 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
865 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
866 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
867 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
872 g_dynLightCount
:= lnum
;
875 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
877 if not gwin_has_stencil
then exit
;
878 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
879 g_dynLights
[g_dynLightCount
].x
:= x
;
880 g_dynLights
[g_dynLightCount
].y
:= y
;
881 g_dynLights
[g_dynLightCount
].radius
:= radius
;
882 g_dynLights
[g_dynLightCount
].r
:= r
;
883 g_dynLights
[g_dynLightCount
].g
:= g
;
884 g_dynLights
[g_dynLightCount
].b
:= b
;
885 g_dynLights
[g_dynLightCount
].a
:= a
;
886 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
887 Inc(g_dynLightCount
);
890 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
892 if not gwin_has_stencil
then exit
;
893 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
894 g_dynLights
[g_dynLightCount
].x
:= x
;
895 g_dynLights
[g_dynLightCount
].y
:= y
;
896 g_dynLights
[g_dynLightCount
].radius
:= 0;
897 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
898 g_dynLights
[g_dynLightCount
].r
:= r
;
899 g_dynLights
[g_dynLightCount
].g
:= g
;
900 g_dynLights
[g_dynLightCount
].b
:= b
;
901 g_dynLights
[g_dynLightCount
].a
:= 0;
902 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
903 Inc(g_dynLightCount
);
906 // ////////////////////////////////////////////////////////////////////////// //
907 function conIsCheatsEnabled (): Boolean; inline;
910 if g_Game_IsNet
then exit
;
911 if not gDebugMode
then
913 //if not gCheats then exit;
914 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
915 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
920 // ////////////////////////////////////////////////////////////////////////// //
922 TParamStrValue
= record
927 TParamStrValues
= Array of TParamStrValue
;
930 INTER_ACTION_TEXT
= 1;
931 INTER_ACTION_PIC
= 2;
932 INTER_ACTION_MUSIC
= 3;
937 DataLoaded
: Boolean = False;
939 MapList
: SSArray
= nil;
940 MapIndex
: Integer = -1;
941 InterReadyTime
: Integer = -1;
942 StatDate
: string = '';
957 function Compare(a
, b
: TPlayerStat
): Integer;
959 if a
.Spectator
then Result
:= 1
960 else if b
.Spectator
then Result
:= -1
961 else if a
.Frags
< b
.Frags
then Result
:= 1
962 else if a
.Frags
> b
.Frags
then Result
:= -1
963 else if a
.Deaths
< b
.Deaths
then Result
:= -1
964 else if a
.Deaths
> b
.Deaths
then Result
:= 1
965 else if a
.Kills
< b
.Kills
then Result
:= -1
969 procedure SortGameStat(var stat
: TPlayerStatArray
);
974 if stat
= nil then Exit
;
976 for I
:= High(stat
) downto Low(stat
) do
977 for J
:= Low(stat
) to High(stat
) - 1 do
978 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
981 stat
[J
] := stat
[J
+ 1];
986 // saves a shitty CSV containing the game stats passed to it
987 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
990 dir
, fname
, map
, mode
, etime
: String;
994 dir
:= e_GetWriteableDir(StatsDirs
);
995 // stats are placed in stats/yy/mm/dd/*.csv
996 fname
:= e_CatPath(dir
, Path
);
997 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
998 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
999 AssignFile(s
, fname
);
1001 SetTextCodePage(s
, CP_UTF8
);
1003 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
1004 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
1005 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
1006 mode
:= g_Game_ModeToText(Stat
.GameMode
);
1007 etime
:= Format('%d:%.2d:%.2d', [
1008 Stat
.GameTime
div 1000 div 3600,
1009 (Stat
.GameTime
div 1000 div 60) mod 60,
1010 Stat
.GameTime
div 1000 mod 60
1012 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
1013 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
1019 gGameSettings
.TimeLimit
,
1020 gGameSettings
.ScoreLimit
,
1021 gGameSettings
.Options
,
1023 Length(Stat
.PlayerStat
)
1025 // line 2: game specific shit
1026 // if it's a team game: red score, blue score
1027 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1028 // otherwise nothing
1029 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1031 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
1032 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1034 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1035 // lines 3-...: team, player name, frags, deaths
1036 WriteLn(s
, 'team,name,frags,deaths');
1037 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1038 with Stat
.PlayerStat
[I
] do
1039 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1041 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1044 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1049 procedure ClearDebugCvars();
1051 g_debug_Sounds
:= False;
1052 g_debug_Frames
:= False;
1053 g_debug_WinMsgs
:= False;
1054 g_debug_MonsterOff
:= False;
1055 g_debug_BotAIOff
:= 0;
1056 g_debug_HealthBar
:= False;
1057 g_Debug_Player
:= False;
1060 function g_Game_ModeToText(Mode
: Byte): string;
1064 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1065 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1066 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1067 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1068 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1072 function g_Game_TextToMode(Mode
: string): Byte;
1075 Mode
:= UpperCase(Mode
);
1076 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1081 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1086 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1091 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1096 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1098 Result
:= GM_SINGLE
;
1103 function g_Game_IsNet(): Boolean;
1105 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1108 function g_Game_IsServer(): Boolean;
1110 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1113 function g_Game_IsClient(): Boolean;
1115 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1118 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1125 Result
.name
:= ExtractFileName(WAD
);
1126 Result
.description
:= '';
1127 Result
.author
:= '';
1129 w
:= TWADFile
.Create();
1132 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1138 cfg
:= TConfig
.CreateMem(p
, len
);
1139 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1140 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1141 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1142 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1148 procedure g_Game_FreeWAD
;
1151 g_Sound_Delete('MUSIC_endmus');
1152 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1153 gGameSettings
.WAD
:= '';
1156 procedure g_Game_LoadWAD(WAD
: string);
1165 gGameSettings
.WAD
:= WAD
;
1166 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1169 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1171 w
:= TWADFile
.Create();
1174 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1180 cfg
:= TConfig
.CreateMem(p
, len
);
1183 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1184 if MegaWAD
.endpic
<> '' then
1185 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1187 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1188 if MegaWAD
.endmus
<> '' then
1190 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1191 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1199 {procedure start_trigger(t: string);
1203 function next_trigger(): Boolean;
1207 procedure DisableCheats();
1213 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1214 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1215 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1216 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1218 {$IF DEFINED(D2F_DEBUG)}
1219 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1220 gAimLine
:= g_dbg_aimline_on
;
1224 procedure g_Game_ExecuteEvent(Name
: String);
1230 if gEvents
= nil then
1232 for a
:= 0 to High(gEvents
) do
1233 if gEvents
[a
].Name
= Name
then
1235 if gEvents
[a
].Command
<> '' then
1236 g_Console_Process(gEvents
[a
].Command
, True);
1241 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1246 if gDelayedEvents
<> nil then
1247 for a
:= 0 to High(gDelayedEvents
) do
1248 if not gDelayedEvents
[a
].Pending
then
1255 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1256 n
:= High(gDelayedEvents
);
1258 gDelayedEvents
[n
].Pending
:= True;
1259 gDelayedEvents
[n
].DEType
:= DEType
;
1260 gDelayedEvents
[n
].DENum
:= Num
;
1261 gDelayedEvents
[n
].DEStr
:= Str
;
1262 if DEType
= DE_GLOBEVENT
then
1263 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1265 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1269 procedure EndGame();
1275 if g_Game_IsNet
and g_Game_IsServer
then
1276 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1279 gPauseMain
:= false;
1280 gPauseHolmes
:= false;
1283 g_Game_StopAllSounds(False);
1288 EndingGameCounter
:= 0;
1290 {$IFDEF ENABLE_MENU}
1291 g_ActiveWindow
:= nil;
1294 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1295 gLMSRespawnTime
:= 0;
1298 EXIT_SIMPLE
: // Выход через меню или конец теста
1302 begin // Это был тест
1306 begin // Выход в главное меню
1307 {$IFDEF DISABLE_MENU}
1308 gState
:= STATE_MENU
; // ???
1310 gMusic
.SetByName('MUSIC_MENU');
1312 if gState
<> STATE_SLIST
then
1314 g_GUI_ShowWindow('MainMenu');
1315 gState
:= STATE_MENU
;
1319 // Обновляем список серверов
1320 slReturnPressed
:= True;
1321 if g_Net_Slist_Fetch(slCurrent
) then
1323 if slCurrent
= nil then
1324 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1327 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1328 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1331 g_Game_ExecuteEvent('ongameend');
1335 EXIT_RESTART
: // Начать уровень сначала
1337 if not g_Game_IsClient
then g_Game_Restart();
1340 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1342 // Статистика Своей игры:
1343 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1345 CustomStat
.GameTime
:= gTime
;
1346 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1347 CustomStat
.MapName
:= gMapInfo
.Name
;
1348 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1349 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1350 CustomStat
.TeamStat
:= gTeamStat
;
1352 CustomStat
.PlayerStat
:= nil;
1354 // Статистика игроков:
1355 if gPlayers
<> nil then
1357 for a
:= 0 to High(gPlayers
) do
1358 if gPlayers
[a
] <> nil then
1360 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1361 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1364 Name
:= gPlayers
[a
].Name
;
1365 Frags
:= gPlayers
[a
].Frags
;
1366 Deaths
:= gPlayers
[a
].Death
;
1367 Kills
:= gPlayers
[a
].Kills
;
1368 Team
:= gPlayers
[a
].Team
;
1369 Color
:= gPlayers
[a
].Model
.Color
;
1370 Spectator
:= gPlayers
[a
].FSpectator
;
1374 SortGameStat(CustomStat
.PlayerStat
);
1376 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1379 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1380 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1381 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1382 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1384 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1387 StatShotDone
:= False;
1390 g_Game_ExecuteEvent('onmapend');
1391 if not g_Game_IsClient
then g_Player_ResetReady
;
1392 gInterReadyCount
:= 0;
1394 // Затухающий экран:
1395 EndingGameCounter
:= 255;
1396 gState
:= STATE_FOLD
;
1398 if gDefInterTime
< 0 then
1399 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1401 gInterEndTime
:= gDefInterTime
* 1000;
1404 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1406 // Статистика Одиночной игры:
1407 SingleStat
.GameTime
:= gTime
;
1408 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1409 SingleStat
.TotalSecrets
:= gSecretsCount
;
1410 // Статистика первого игрока:
1411 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1412 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1413 // Статистика второго игрока (если есть):
1414 if SingleStat
.TwoPlayers
then
1416 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1417 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1420 g_Game_ExecuteEvent('onmapend');
1423 if gNextMap
<> '' then
1425 gMusic
.SetByName('MUSIC_INTERMUS');
1427 gState
:= STATE_INTERSINGLE
;
1430 g_Game_ExecuteEvent('oninter');
1432 else // Больше нет карт
1434 // Затухающий экран:
1435 EndingGameCounter
:= 255;
1436 gState
:= STATE_FOLD
;
1441 // Окончание обработано:
1442 if gExit
<> EXIT_QUIT
then
1446 procedure g_Game_Init();
1450 gTempDelete
:= False;
1452 sfsGCDisable(); // temporary disable removing of temporary volumes
1455 g_Game_ClearLoading();
1456 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1457 g_Game_SetLoadingText('', 0, False);
1459 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1462 gPauseMain
:= false;
1463 gPauseHolmes
:= false;
1466 {e_MouseInfo.Accel := 1.0;}
1468 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1471 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1472 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1473 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1474 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1475 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1477 gMusic
:= TMusic
.Create();
1478 gMusic
.SetByName('MUSIC_MENU');
1481 gGameSettings
.WarmupTime
:= 30;
1483 gState
:= STATE_MENU
;
1485 SetLength(gEvents
, 6);
1486 gEvents
[0].Name
:= 'ongamestart';
1487 gEvents
[1].Name
:= 'ongameend';
1488 gEvents
[2].Name
:= 'onmapstart';
1489 gEvents
[3].Name
:= 'onmapend';
1490 gEvents
[4].Name
:= 'oninter';
1491 gEvents
[5].Name
:= 'onwadend';
1493 sfsGCEnable(); // enable releasing unused volumes
1497 procedure g_Game_Free(freeTextures
: Boolean=true);
1499 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1500 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1502 g_Map_Free(freeTextures
);
1505 {$IFDEF ENABLE_GIBS}
1508 {$IFDEF ENALBE_SHELLS}
1511 {$IFDEF ENABLE_CORPSES}
1512 g_Corpses_RemoveAll
;
1515 gGameSettings
.GameType
:= GT_NONE
;
1516 if gGameSettings
.GameMode
= GM_SINGLE
then
1517 gGameSettings
.GameMode
:= GM_DM
;
1518 gSwitchGameMode
:= gGameSettings
.GameMode
;
1521 gExitByTrigger
:= False;
1524 function IsActivePlayer(p
: TPlayer
): Boolean;
1529 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1532 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1538 if gPlayers
= nil then
1542 for a
:= Low(gPlayers
) to High(gPlayers
) do
1543 if IsActivePlayer(gPlayers
[a
]) then
1545 SetLength(ids
, Length(ids
) + 1);
1546 ids
[High(ids
)] := gPlayers
[a
].UID
;
1547 if gPlayers
[a
].UID
= Skip
then
1550 if Length(ids
) = 0 then
1555 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1558 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1564 if gPlayers
= nil then
1568 for a
:= Low(gPlayers
) to High(gPlayers
) do
1569 if IsActivePlayer(gPlayers
[a
]) then
1571 SetLength(ids
, Length(ids
) + 1);
1572 ids
[High(ids
)] := gPlayers
[a
].UID
;
1573 if gPlayers
[a
].UID
= Skip
then
1576 if Length(ids
) = 0 then
1579 Result
:= ids
[Length(ids
) - 1]
1581 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1584 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1590 if gPlayers
= nil then
1594 for a
:= Low(gPlayers
) to High(gPlayers
) do
1595 if IsActivePlayer(gPlayers
[a
]) then
1597 SetLength(ids
, Length(ids
) + 1);
1598 ids
[High(ids
)] := gPlayers
[a
].UID
;
1599 if gPlayers
[a
].UID
= Skip
then
1602 if Length(ids
) = 0 then
1604 if Length(ids
) = 1 then
1609 Result
:= ids
[Random(Length(ids
))];
1611 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1613 Result
:= ids
[Random(Length(ids
))];
1618 function GetRandomSpectMode(Current
: Byte): Byte;
1625 0: Result
:= SPECT_STATS
;
1626 1: Result
:= SPECT_MAPVIEW
;
1627 2: Result
:= SPECT_MAPVIEW
;
1628 3: Result
:= SPECT_PLAYERS
;
1629 4: Result
:= SPECT_PLAYERS
;
1630 5: Result
:= SPECT_PLAYERS
;
1631 6: Result
:= SPECT_PLAYERS
;
1633 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1637 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1643 if (plr
= nil) then exit
;
1644 if (p
= 2) then time
:= 1000 else time
:= 1;
1645 strafeDir
:= MoveButton
shr 4;
1646 MoveButton
:= MoveButton
and $0F;
1648 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1649 MoveButton
:= 1 // Нажата только "Влево"
1650 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1651 MoveButton
:= 2 // Нажата только "Вправо"
1652 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1653 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1655 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1656 if MoveButton
= 1 then
1657 plr
.PressKey(KEY_LEFT
, time
)
1658 else if MoveButton
= 2 then
1659 plr
.PressKey(KEY_RIGHT
, time
);
1661 // if we have "strafe" key, turn off old strafe mechanics
1662 if gPlayerAction
[p
, ACTION_STRAFE
] then
1664 // new strafe mechanics
1665 if (strafeDir
= 0) then
1666 strafeDir
:= MoveButton
; // start strafing
1667 // now set direction according to strafe (reversed)
1668 if (strafeDir
= 2) then
1669 plr
.SetDirection(TDirection
.D_LEFT
)
1670 else if (strafeDir
= 1) then
1671 plr
.SetDirection(TDirection
.D_RIGHT
)
1675 strafeDir
:= 0; // not strafing anymore
1676 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1677 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1678 plr
.SetDirection(TDirection
.D_LEFT
)
1679 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1680 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1681 plr
.SetDirection(TDirection
.D_RIGHT
)
1682 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1683 else if MoveButton
<> 0 then
1684 plr
.SetDirection(TDirection(MoveButton
-1))
1687 // fix movebutton state
1688 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1690 // Остальные клавиши:
1691 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1692 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1693 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1694 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1695 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1697 for i
:= WP_FACT
to WP_LACT
do
1699 if gWeaponAction
[p
, i
] then
1701 plr
.ProcessWeaponAction(i
);
1702 gWeaponAction
[p
, i
] := False
1706 for i
:= WP_FIRST
to WP_LAST
do
1708 if gSelectWeapon
[p
, i
] then
1710 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1711 gSelectWeapon
[p
, i
] := False
1715 {$IFDEF ENABLE_MENU}
1716 // HACK: add dynlight here
1717 if gwin_k8_enable_light_experiments
then
1719 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1721 g_playerLight
:= true;
1723 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1725 g_playerLight
:= false;
1729 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1733 // HACK: don't have a "key was pressed" function
1734 procedure InterReady();
1736 if InterReadyTime
> gTime
then Exit
;
1737 InterReadyTime
:= gTime
+ 3000;
1738 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1741 procedure g_Game_PreUpdate();
1743 // these are in separate PreUpdate functions because they can interact during Update()
1744 // and are synced over the net
1745 // we don't care that much about corpses and gibs
1746 g_Player_PreUpdate();
1747 g_Monsters_PreUpdate();
1748 g_Items_PreUpdate();
1749 g_Weapon_PreUpdate();
1752 procedure g_Game_Update();
1754 {$IFDEF ENABLE_MENU}
1755 Msg
: g_gui
.TMessage
;
1762 function sendMonsPos (mon
: TMonster
): Boolean;
1764 result
:= false; // don't stop
1765 // this will also reset "need-send" flag
1766 if mon
.gncNeedSend
then
1768 MH_SEND_MonsterPos(mon
.UID
);
1770 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1772 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1774 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1776 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1780 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1782 result
:= false; // don't stop
1783 // this will also reset "need-send" flag
1784 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1787 function sendItemPos (it
: PItem
): Boolean;
1789 result
:= false; // don't stop
1792 MH_SEND_ItemPos(it
.myId
);
1793 it
.needSend
:= False;
1798 reliableUpdate
: Boolean;
1803 // Пора выключать игру:
1804 if gExit
= EXIT_QUIT
then
1806 // Игра закончилась - обрабатываем:
1810 if gExit
= EXIT_QUIT
then
1814 // Читаем клавиатуру и джойстик, если окно активно
1815 // no need to, as we'll do it in event handler
1817 // Обновляем консоль (движение и сообщения):
1820 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1822 gExit
:= EXIT_SIMPLE
;
1827 // process master server communications
1828 g_Net_Slist_Pulse();
1831 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1832 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1833 STATE_INTERTEXT
, // Текст между уровнями
1834 STATE_INTERPIC
: // Картинка между уровнями
1836 if g_Game_IsNet
and g_Game_IsServer
then
1838 gInterTime
:= gInterTime
+ GAME_TICK
;
1839 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1840 if a
<> gServInterTime
then
1842 gServInterTime
:= a
;
1843 MH_SEND_TimeSync(gServInterTime
);
1847 if (not g_Game_IsClient
) and
1851 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1852 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1853 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1854 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1856 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1857 {$IFDEF ENABLE_MENU}
1858 and (g_ActiveWindow
= nil)
1861 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1864 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1865 g_Game_StopAllSounds(True);
1867 if gMapOnce
then // Это был тест
1868 gExit
:= EXIT_SIMPLE
1870 if gNextMap
<> '' then // Переходим на следующую карту
1871 g_Game_ChangeMap(gNextMap
)
1872 else // Следующей карты нет
1874 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1876 // Выход в главное меню:
1878 {$IFDEF ENABLE_MENU}
1879 g_GUI_ShowWindow('MainMenu');
1880 gMusic
.SetByName('MUSIC_MENU');
1883 gState
:= STATE_MENU
;
1886 // Финальная картинка:
1887 g_Game_ExecuteEvent('onwadend');
1889 if not gMusic
.SetByName('MUSIC_endmus') then
1890 gMusic
.SetByName('MUSIC_STDENDMUS');
1892 gState
:= STATE_ENDPIC
;
1894 g_Game_ExecuteEvent('ongameend');
1899 else if g_Game_IsClient
and
1902 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1903 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1904 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1905 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1907 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1908 {$IFDEF ENABLE_MENU}
1909 and (g_ActiveWindow
= nil)
1918 if gState
= STATE_INTERTEXT
then
1919 if InterText
.counter
> 0 then
1920 InterText
.counter
:= InterText
.counter
- 1;
1923 STATE_FOLD
: // Затухание экрана
1925 if EndingGameCounter
= 0 then
1927 // Закончился уровень в Своей игре:
1928 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1930 gState
:= STATE_INTERCUSTOM
;
1931 InterReadyTime
:= -1;
1932 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1934 g_Game_ExecuteEvent('onwadend');
1935 if not gMusic
.SetByName('MUSIC_endmus') then
1936 gMusic
.SetByName('MUSIC_STDENDMUS');
1939 gMusic
.SetByName('MUSIC_ROUNDMUS');
1943 else // Закончилась последняя карта в Одиночной игре
1945 gMusic
.SetByName('MUSIC_INTERMUS');
1947 gState
:= STATE_INTERSINGLE
;
1950 g_Game_ExecuteEvent('oninter');
1953 DecMin(EndingGameCounter
, 6, 0);
1956 STATE_ENDPIC
: // Картинка окончания мегаВада
1958 if gMapOnce
then // Это был тест
1960 gExit
:= EXIT_SIMPLE
;
1966 g_Serverlist_Control(slCurrent
, slTable
);
1969 // Статистика по Tab:
1971 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1974 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1976 // Время += 28 миллисекунд:
1977 gTime
:= gTime
+ GAME_TICK
;
1979 // Сообщение посередине экрана:
1980 if MessageTime
= 0 then
1982 if MessageTime
> 0 then
1983 MessageTime
:= MessageTime
- 1;
1985 if (g_Game_IsServer
) then
1987 // Был задан лимит времени:
1988 if (gGameSettings
.TimeLimit
> 0) then
1989 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1990 begin // Он прошел => конец уровня
1995 // Надо респавнить игроков в LMS:
1996 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1997 g_Game_RestartRound(gLMSSoftSpawn
);
1999 // Проверим результат голосования, если время прошло
2000 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2002 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2004 g_Console_Process(gVoteCommand
);
2006 gVotePassed
:= False;
2009 // Замеряем время захвата флагов
2010 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2011 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2012 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2013 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2015 // Был задан лимит побед:
2016 if (gGameSettings
.ScoreLimit
> 0) then
2020 if gGameSettings
.GameMode
= GM_DM
then
2021 begin // В DM ищем игрока с max фрагами
2022 for i
:= 0 to High(gPlayers
) do
2023 if gPlayers
[i
] <> nil then
2024 if gPlayers
[i
].Frags
> b
then
2025 b
:= gPlayers
[i
].Frags
;
2028 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2029 begin // В CTF/TDM выбираем команду с наибольшим счетом
2030 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2033 // Лимит побед набран => конец уровня:
2034 if b
>= gGameSettings
.ScoreLimit
then
2041 // Обрабатываем клавиши игроков:
2042 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2043 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2044 {$IFDEF DISABLE_MENU}
2045 if (not gConsoleShow
) and (not gChatShow
) then
2047 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2050 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2051 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2052 end // if not console
2055 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2057 // process weapon switch queue
2061 if (gPlayer1
= nil) and (gPlayer2
= nil)
2062 and (not gConsoleShow
) and (not gChatShow
)
2063 {$IFDEF ENABLE_MENU}
2064 and (g_ActiveWindow
= nil)
2068 if not gSpectKeyPress
then
2070 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2072 // switch spect mode
2074 SPECT_NONE
: ; // not spectator
2076 SPECT_MAPVIEW
: Inc(gSpectMode
);
2077 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2079 gSpectKeyPress
:= True;
2081 if (gSpectMode
= SPECT_MAPVIEW
)
2082 and (not gSpectAuto
) then
2084 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2085 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2086 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2087 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2088 if gPlayerAction
[0, ACTION_LOOKUP
] then
2089 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2090 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2091 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2092 if gWeaponAction
[0, WP_PREV
] then
2095 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2096 gWeaponAction
[0, WP_PREV
] := False;
2098 if gWeaponAction
[0, WP_NEXT
] then
2101 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2102 gWeaponAction
[0, WP_NEXT
] := False;
2105 if (gSpectMode
= SPECT_PLAYERS
)
2106 and (not gSpectAuto
) then
2108 if gPlayerAction
[0, ACTION_LOOKUP
] then
2111 gSpectViewTwo
:= True;
2112 gSpectKeyPress
:= True;
2114 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2116 // remove second view
2117 gSpectViewTwo
:= False;
2118 gSpectKeyPress
:= True;
2120 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2122 // prev player (view 1)
2123 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2124 gSpectKeyPress
:= True;
2126 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2128 // next player (view 1)
2129 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2130 gSpectKeyPress
:= True;
2132 if gWeaponAction
[0, WP_PREV
] then
2134 // prev player (view 2)
2135 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2136 gWeaponAction
[0, WP_PREV
] := False;
2138 if gWeaponAction
[0, WP_NEXT
] then
2140 // next player (view 2)
2141 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2142 gWeaponAction
[0, WP_NEXT
] := False;
2145 if gPlayerAction
[0, ACTION_ATTACK
] then
2147 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2150 gSpectAutoNext
:= 0;
2151 gSpectViewTwo
:= False;
2152 gSpectKeyPress
:= True;
2157 gSpectMode
:= SPECT_STATS
;
2158 gSpectAuto
:= False;
2159 gSpectKeyPress
:= True;
2164 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2165 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2166 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2167 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2168 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2169 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2170 gSpectKeyPress
:= False;
2174 if gSpectMode
= SPECT_MAPVIEW
then
2176 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2178 gSpectAutoNext
:= gTime
2181 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2183 gSpectAutoNext
:= gTime
2187 if gSpectAutoNext
<= gTime
then
2189 if gSpectAutoNext
> 0 then
2191 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2195 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2196 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2197 gSpectAutoStepX
:= Random(9) - 4;
2198 gSpectAutoStepY
:= Random(9) - 4;
2199 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2200 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2201 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2202 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2203 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2204 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2208 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2213 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2214 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2215 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2221 // Обновляем все остальное:
2224 g_Triggers_Update();
2226 g_Monsters_Update();
2230 g_Player_UpdateAll();
2231 {$IFDEF ENABLE_GIBS}
2234 {$IFDEF ENABLE_CORPSES}
2237 {$IFDEF ENABLE_SHELLS}
2241 // server: send newly spawned monsters unconditionally
2242 if (gGameSettings
.GameType
= GT_SERVER
) then
2244 if (Length(gMonstersSpawned
) > 0) then
2246 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2247 SetLength(gMonstersSpawned
, 0);
2251 if (gSoundTriggerTime
> 8) then
2253 g_Game_UpdateTriggerSounds();
2254 gSoundTriggerTime
:= 0;
2258 Inc(gSoundTriggerTime
);
2261 if (NetMode
= NET_SERVER
) then
2263 Inc(NetTimeToUpdate
);
2264 Inc(NetTimeToReliable
);
2266 // send monster updates
2267 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2269 // send all monsters (periodic sync)
2270 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2272 for I
:= 0 to High(gPlayers
) do
2274 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2277 g_Mons_ForEach(sendMonsPos
);
2279 // update flags that aren't stationary
2280 if gGameSettings
.GameMode
= GM_CTF
then
2281 for I
:= FLAG_RED
to FLAG_BLUE
do
2282 if gFlags
[I
].NeedSend
then
2284 gFlags
[I
].NeedSend
:= False;
2288 // update items that aren't stationary
2289 g_Items_ForEachAlive(sendItemPos
);
2291 if reliableUpdate
then
2293 NetTimeToReliable
:= 0;
2294 NetTimeToUpdate
:= NetUpdateRate
;
2298 NetTimeToUpdate
:= 0;
2303 // send only mosters with some unexpected changes
2304 g_Mons_ForEach(sendMonsPosUnexpected
);
2307 // send unexpected platform changes
2308 g_Map_NetSendInterestingPanels();
2310 g_Net_Slist_ServerUpdate();
2312 if NetUseMaster then
2314 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2316 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2318 NetTimeToMaster := gTime + NetMasterRate;
2323 else if (NetMode
= NET_CLIENT
) then
2325 MC_SEND_PlayerPos();
2327 end; // if gameOn ...
2329 // Активно окно интерфейса - передаем клавиши ему:
2330 {$IFDEF ENABLE_MENU}
2331 if g_ActiveWindow
<> nil then
2333 w
:= e_GetFirstKeyPressed();
2335 if (w
<> IK_INVALID
) then
2337 Msg
.Msg
:= MESSAGE_DIKEY
;
2339 g_ActiveWindow
.OnMessage(Msg
);
2342 // Если оно от этого не закрылось, то обновляем:
2343 if g_ActiveWindow
<> nil then
2344 g_ActiveWindow
.Update();
2346 // Нужно сменить разрешение:
2347 if gResolutionChange
then
2350 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2353 gResolutionChange
:= False;
2354 g_ActiveWindow
:= nil;
2357 // Нужно сменить язык:
2358 if gLanguageChange
then
2360 //e_WriteLog('Read language file', MSG_NOTIFY);
2361 //g_Language_Load(DataDir + gLanguage + '.txt');
2362 g_Language_Set(gLanguage
);
2364 gLanguageChange
:= False;
2368 // Горячая клавиша для вызова меню выхода из игры (F10):
2369 if e_KeyPressed(IK_F10
) and
2371 (not gConsoleShow
) and
2372 (g_ActiveWindow
= nil) then
2378 Time
:= GetTickCount64() {div 1000};
2380 // Обработка отложенных событий:
2381 if gDelayedEvents
<> nil then
2382 for a
:= 0 to High(gDelayedEvents
) do
2383 if gDelayedEvents
[a
].Pending
and
2385 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2386 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2389 case gDelayedEvents
[a
].DEType
of
2391 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2394 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2398 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2399 if g_Game_IsNet
and g_Game_IsServer
then
2400 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2404 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2406 gDelayedEvents
[a
].Pending
:= False;
2409 // Каждую секунду обновляем счетчик обновлений:
2410 UPSCounter
:= UPSCounter
+ 1;
2411 if Time
- UPSTime
>= 1000 then
2420 g_Weapon_AddDynLights();
2421 g_Items_AddDynLights();
2425 procedure g_Game_LoadChatSounds(Resource
: string);
2428 FileName
, Snd
: string;
2430 len
, cnt
, tags
, i
, j
: Integer;
2433 FileName
:= g_ExtractWadName(Resource
);
2435 WAD
:= TWADFile
.Create();
2436 WAD
.ReadFile(FileName
);
2438 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2445 cfg
:= TConfig
.CreateMem(p
, len
);
2446 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2448 SetLength(gChatSounds
, cnt
);
2449 for i
:= 0 to Length(gChatSounds
) - 1 do
2451 gChatSounds
[i
].Sound
:= nil;
2452 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2453 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2454 if (Snd
= '') or (Tags
<= 0) then
2456 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2457 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2458 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2459 SetLength(gChatSounds
[i
].Tags
, tags
);
2460 for j
:= 0 to tags
- 1 do
2461 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2462 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2469 procedure g_Game_FreeChatSounds();
2473 for i
:= 0 to Length(gChatSounds
) - 1 do
2475 gChatSounds
[i
].Sound
.Free();
2476 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2478 SetLength(gChatSounds
, 0);
2482 procedure g_Game_LoadData();
2484 if DataLoaded
then Exit
;
2486 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2488 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2489 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2490 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2491 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2492 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2493 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2494 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2495 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2496 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2497 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2498 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2499 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2500 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2501 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2502 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2503 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2504 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2505 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2506 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2507 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2508 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2509 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2510 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2511 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2512 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2513 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2514 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2515 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2516 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2517 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2518 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2519 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2521 goodsnd
[0] := TPlayableSound
.Create();
2522 goodsnd
[1] := TPlayableSound
.Create();
2523 goodsnd
[2] := TPlayableSound
.Create();
2524 goodsnd
[3] := TPlayableSound
.Create();
2526 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2527 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2528 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2529 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2531 killsnd
[0] := TPlayableSound
.Create();
2532 killsnd
[1] := TPlayableSound
.Create();
2533 killsnd
[2] := TPlayableSound
.Create();
2534 killsnd
[3] := TPlayableSound
.Create();
2536 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2537 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2538 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2539 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2541 hahasnd
[0] := TPlayableSound
.Create();
2542 hahasnd
[1] := TPlayableSound
.Create();
2543 hahasnd
[2] := TPlayableSound
.Create();
2545 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2546 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2547 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2549 sound_get_flag
[0] := TPlayableSound
.Create();
2550 sound_get_flag
[1] := TPlayableSound
.Create();
2551 sound_lost_flag
[0] := TPlayableSound
.Create();
2552 sound_lost_flag
[1] := TPlayableSound
.Create();
2553 sound_ret_flag
[0] := TPlayableSound
.Create();
2554 sound_ret_flag
[1] := TPlayableSound
.Create();
2555 sound_cap_flag
[0] := TPlayableSound
.Create();
2556 sound_cap_flag
[1] := TPlayableSound
.Create();
2558 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2559 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2560 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2561 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2562 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2563 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2564 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2565 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2567 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2569 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2572 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2573 g_Weapon_LoadData();
2575 g_Monsters_LoadData();
2580 procedure g_Game_Quit();
2582 g_Game_StopAllSounds(True);
2585 g_PlayerModel_FreeData();
2587 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2590 if NetInitDone
then g_Net_Free
;
2592 // remove map after test
2593 if gMapToDelete
<> '' then
2594 g_Game_DeleteTestMap();
2603 procedure g_Game_FreeData();
2605 if not DataLoaded
then Exit
;
2608 g_Weapon_FreeData();
2609 g_Monsters_FreeData();
2611 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2613 g_Sound_Delete('SOUND_GAME_TELEPORT');
2614 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2615 g_Sound_Delete('SOUND_GAME_SECRET');
2616 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2617 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2618 g_Sound_Delete('SOUND_GAME_BULK1');
2619 g_Sound_Delete('SOUND_GAME_BULK2');
2620 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2621 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2622 g_Sound_Delete('SOUND_GAME_BURNING');
2623 g_Sound_Delete('SOUND_GAME_SWITCH1');
2624 g_Sound_Delete('SOUND_GAME_SWITCH0');
2631 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2632 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2633 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2634 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2641 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2642 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2643 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2644 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2650 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2651 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2652 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2654 sound_get_flag
[0].Free();
2655 sound_get_flag
[1].Free();
2656 sound_lost_flag
[0].Free();
2657 sound_lost_flag
[1].Free();
2658 sound_ret_flag
[0].Free();
2659 sound_ret_flag
[1].Free();
2660 sound_cap_flag
[0].Free();
2661 sound_cap_flag
[1].Free();
2663 g_Sound_Delete('SOUND_CTF_GET1');
2664 g_Sound_Delete('SOUND_CTF_GET2');
2665 g_Sound_Delete('SOUND_CTF_LOST1');
2666 g_Sound_Delete('SOUND_CTF_LOST2');
2667 g_Sound_Delete('SOUND_CTF_RETURN1');
2668 g_Sound_Delete('SOUND_CTF_RETURN2');
2669 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2670 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2672 g_Game_FreeChatSounds();
2674 DataLoaded
:= False;
2677 procedure g_FatalError(Text: String);
2679 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2680 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2682 gExit
:= EXIT_SIMPLE
;
2683 if gGameOn
then EndGame
;
2686 procedure g_SimpleError(Text: String);
2688 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2689 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2692 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2694 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2695 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2698 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2701 if gPlayer1
= nil then
2703 if g_Game_IsClient
then
2705 if NetPlrUID1
> -1 then
2706 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2710 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2711 Team
:= gPlayer1Settings
.Team
;
2713 // Создание первого игрока:
2714 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2715 gPlayer1Settings
.Color
,
2717 if gPlayer1
= nil then
2718 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2721 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2722 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2723 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2724 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2725 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2726 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2727 if g_Game_IsServer
and g_Game_IsNet
then
2728 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2729 gPlayer1
.Respawn(False, True);
2730 g_Net_Slist_ServerPlayerComes();
2735 if gPlayer2
= nil then
2737 if g_Game_IsClient
then
2739 if NetPlrUID2
> -1 then
2740 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2744 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2745 Team
:= gPlayer2Settings
.Team
;
2747 // Создание второго игрока:
2748 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2749 gPlayer2Settings
.Color
,
2751 if gPlayer2
= nil then
2752 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2755 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2756 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2757 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2758 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2759 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2760 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2761 if g_Game_IsServer
and g_Game_IsNet
then
2762 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2763 gPlayer2
.Respawn(False, True);
2764 g_Net_Slist_ServerPlayerComes();
2771 procedure g_Game_RemovePlayer();
2775 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2776 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2781 if g_Game_IsServer
then
2784 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2785 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2786 g_Player_Remove(Pl
.UID
);
2787 g_Net_Slist_ServerPlayerLeaves();
2791 gSpectLatchPID2
:= Pl
.UID
;
2799 if g_Game_IsServer
then
2802 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2803 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2804 g_Player_Remove(Pl
.UID
);
2805 g_Net_Slist_ServerPlayerLeaves();
2808 gSpectLatchPID1
:= Pl
.UID
;
2810 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2814 g_Net_Slist_ServerPlayerLeaves();
2817 procedure g_Game_Spectate();
2819 g_Game_RemovePlayer();
2820 if gPlayer1
<> nil then
2821 g_Game_RemovePlayer();
2824 procedure g_Game_SpectateCenterView();
2826 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2827 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2830 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2837 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2839 g_Game_ClearLoading();
2842 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2845 gGameSettings
.GameType
:= GT_SINGLE
;
2846 gGameSettings
.MaxLives
:= 0;
2847 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2848 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2849 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2850 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2851 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2852 gSwitchGameMode
:= GM_SINGLE
;
2854 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2855 gLMSRespawnTime
:= 0;
2856 gSpectLatchPID1
:= 0;
2857 gSpectLatchPID2
:= 0;
2859 g_Game_ExecuteEvent('ongamestart');
2861 // Создание первого игрока:
2862 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2863 gPlayer1Settings
.Color
,
2864 gPlayer1Settings
.Team
, False));
2865 if gPlayer1
= nil then
2867 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2871 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2872 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2873 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2874 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2875 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2878 // Создание второго игрока, если есть:
2881 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2882 gPlayer2Settings
.Color
,
2883 gPlayer2Settings
.Team
, False));
2884 if gPlayer2
= nil then
2886 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2890 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2891 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2892 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2893 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2894 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2898 // Загрузка и запуск карты:
2899 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2901 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2902 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2906 // Настройки игроков и ботов:
2910 for i
:= nPl
+1 to nPlayers
do
2911 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2914 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2915 TimeLimit
, ScoreLimit
: Word;
2917 Options
: LongWord; nPlayers
: Byte);
2923 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2925 g_Game_ClearLoading();
2928 gGameSettings
.GameType
:= GT_CUSTOM
;
2929 gGameSettings
.GameMode
:= GameMode
;
2930 gSwitchGameMode
:= GameMode
;
2931 gGameSettings
.TimeLimit
:= TimeLimit
;
2932 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2933 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2934 gGameSettings
.Options
:= Options
;
2936 gCoopTotalMonstersKilled
:= 0;
2937 gCoopTotalSecretsFound
:= 0;
2938 gCoopTotalMonsters
:= 0;
2939 gCoopTotalSecrets
:= 0;
2943 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2944 gLMSRespawnTime
:= 0;
2945 gSpectLatchPID1
:= 0;
2946 gSpectLatchPID2
:= 0;
2948 g_Game_ExecuteEvent('ongamestart');
2950 // Режим наблюдателя:
2951 if nPlayers
= 0 then
2958 if nPlayers
>= 1 then
2960 // Создание первого игрока:
2961 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2962 gPlayer1Settings
.Color
,
2963 gPlayer1Settings
.Team
, False));
2964 if gPlayer1
= nil then
2966 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2970 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2971 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2972 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2973 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2974 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2978 if nPlayers
>= 2 then
2980 // Создание второго игрока:
2981 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2982 gPlayer2Settings
.Color
,
2983 gPlayer2Settings
.Team
, False));
2984 if gPlayer2
= nil then
2986 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2990 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2991 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2992 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2993 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2994 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2998 // Загрузка и запуск карты:
2999 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3001 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3005 // Нет точек появления:
3006 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3007 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3008 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3009 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3010 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3012 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3016 // Настройки игроков и ботов:
3020 for i
:= nPl
+1 to nPlayers
do
3021 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3024 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3025 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3026 Options
: LongWord; nPlayers
: Byte;
3027 IPAddr
: LongWord; Port
: Word);
3030 g_Net_Slist_ServerClosed();
3032 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3034 g_Game_ClearLoading();
3039 gGameSettings
.GameType
:= GT_SERVER
;
3040 gGameSettings
.GameMode
:= GameMode
;
3041 gSwitchGameMode
:= GameMode
;
3042 gGameSettings
.TimeLimit
:= TimeLimit
;
3043 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3044 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3045 gGameSettings
.Options
:= Options
;
3047 gCoopTotalMonstersKilled
:= 0;
3048 gCoopTotalSecretsFound
:= 0;
3049 gCoopTotalMonsters
:= 0;
3050 gCoopTotalSecrets
:= 0;
3054 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3055 gLMSRespawnTime
:= 0;
3056 gSpectLatchPID1
:= 0;
3057 gSpectLatchPID2
:= 0;
3059 g_Game_ExecuteEvent('ongamestart');
3061 // Режим наблюдателя:
3062 if nPlayers
= 0 then
3068 if nPlayers
>= 1 then
3070 // Создание первого игрока:
3071 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3072 gPlayer1Settings
.Color
,
3073 gPlayer1Settings
.Team
, False));
3074 if gPlayer1
= nil then
3076 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3080 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3081 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3082 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3083 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3084 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3087 if nPlayers
>= 2 then
3089 // Создание второго игрока:
3090 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3091 gPlayer2Settings
.Color
,
3092 gPlayer2Settings
.Team
, False));
3093 if gPlayer2
= nil then
3095 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3099 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3100 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3101 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3102 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3103 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3106 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3107 if NetForwardPorts
then
3108 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3111 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3113 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3117 g_Net_Slist_Set(NetMasterList
);
3119 g_Net_Slist_ServerStarted();
3121 // Загрузка и запуск карты:
3122 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3124 g_Net_Slist_ServerClosed();
3125 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3129 // Нет точек появления:
3130 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3131 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3132 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3133 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3134 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3136 g_Net_Slist_ServerClosed();
3137 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3141 // Настройки игроков и ботов:
3144 g_Net_Slist_ServerMapStarted();
3145 NetState
:= NET_STATE_GAME
;
3148 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3163 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3164 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3166 g_Game_ClearLoading();
3171 gGameSettings
.GameType
:= GT_CLIENT
;
3173 gCoopTotalMonstersKilled
:= 0;
3174 gCoopTotalSecretsFound
:= 0;
3175 gCoopTotalMonsters
:= 0;
3176 gCoopTotalSecrets
:= 0;
3180 g_Game_ExecuteEvent('ongamestart');
3182 NetState
:= NET_STATE_AUTH
;
3184 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3186 // create (or update) map/resource databases
3187 g_Res_CreateDatabases(true);
3189 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3190 gLMSRespawnTime
:= 0;
3191 gSpectLatchPID1
:= 0;
3192 gSpectLatchPID2
:= 0;
3195 if not g_Net_Connect(Addr
, Port
) then
3197 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3198 NetState
:= NET_STATE_NONE
;
3202 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3204 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3209 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3210 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3211 // thank you, enet. let's ignore failures altogether then.
3212 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3214 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3216 Ptr
:= NetEvent
.packet
^.data
;
3217 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3219 enet_packet_destroy(NetEvent
.packet
);
3223 InMsg
.ReadLongWord(); // skip size
3224 MID
:= InMsg
.ReadByte();
3226 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3228 NetMyID
:= InMsg
.ReadByte();
3229 NetPlrUID1
:= InMsg
.ReadWord();
3231 WadName
:= InMsg
.ReadString();
3232 Map
:= InMsg
.ReadString();
3234 gWADHash
:= InMsg
.ReadMD5();
3236 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3237 gSwitchGameMode
:= gGameSettings
.GameMode
;
3238 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3239 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3240 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3241 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3242 T
:= InMsg
.ReadLongWord();
3244 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3245 //if newResPath = '' then
3247 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3248 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3249 if newResPath
= '' then
3251 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3252 enet_packet_destroy(NetEvent
.packet
);
3253 NetState
:= NET_STATE_NONE
;
3256 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3258 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3261 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3262 gPlayer1Settings
.Color
,
3263 gPlayer1Settings
.Team
, False));
3265 if gPlayer1
= nil then
3267 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3269 enet_packet_destroy(NetEvent
.packet
);
3270 NetState
:= NET_STATE_NONE
;
3274 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3275 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3276 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3277 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3278 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3279 gPlayer1
.UID
:= NetPlrUID1
;
3280 gPlayer1
.Reset(True);
3282 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3284 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3286 enet_packet_destroy(NetEvent
.packet
);
3287 NetState
:= NET_STATE_NONE
;
3295 enet_packet_destroy(NetEvent
.packet
);
3299 enet_packet_destroy(NetEvent
.packet
);
3303 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3306 if (NetEvent
.data
<= NET_DISC_MAX
) then
3307 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3308 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3315 ProcessLoading(True);
3316 if g_Net_UserRequestExit() then
3325 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3326 NetState
:= NET_STATE_NONE
;
3331 NetState
:= NET_STATE_GAME
;
3332 MC_SEND_FullStateRequest
;
3333 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3337 lastAsMegaWad
: Boolean = false;
3339 procedure g_Game_ChangeMap(const MapPath
: String);
3343 g_Game_ClearLoading();
3345 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3346 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3347 if gExitByTrigger
then
3350 gExitByTrigger
:= False;
3352 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3353 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3356 procedure g_Game_Restart();
3360 if g_Game_IsClient
then
3362 map
:= g_ExtractFileName(gMapInfo
.Map
);
3363 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3367 g_Game_ClearLoading();
3368 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3371 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3373 NewWAD
, ResName
: String;
3377 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3379 {$IFDEF ENABLE_GIBS}
3382 {$IFDEF ENALBE_SHELLS}
3385 {$IFDEF ENABLE_CORPSES}
3386 g_Corpses_RemoveAll
;
3389 if (not g_Game_IsClient
) and
3390 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3391 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3393 if gSwitchGameMode
= GM_CTF
then
3394 gGameSettings
.MaxLives
:= 0;
3395 gGameSettings
.GameMode
:= gSwitchGameMode
;
3398 gSwitchGameMode
:= gGameSettings
.GameMode
;
3400 g_Player_ResetTeams();
3402 lastAsMegaWad
:= asMegawad
;
3403 if isWadPath(Map
) then
3405 NewWAD
:= g_ExtractWadName(Map
);
3406 ResName
:= g_ExtractFileName(Map
);
3407 if g_Game_IsServer
then
3409 nws
:= findDiskWad(NewWAD
);
3410 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3413 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3414 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3418 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3419 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3421 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3422 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3424 if (length(nws
) = 0) then
3426 ResName
:= ''; // failed
3431 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3432 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3433 g_Game_LoadWAD(NewWAD
);
3438 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3439 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3444 NewWAD
:= gGameSettings
.WAD
;
3450 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3452 if (ResName
<> '') and (NewWAD
<> '') then
3454 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3455 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3457 r_Render_LoadTextures
;
3462 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3464 gState
:= STATE_NONE
;
3465 {$IFDEF ENABLE_MENU}
3466 g_ActiveWindow
:= nil;
3471 wNeedTimeReset
:= True;
3473 if gGameSettings
.GameMode
= GM_CTF
then
3475 g_Map_ResetFlag(FLAG_RED
);
3476 g_Map_ResetFlag(FLAG_BLUE
);
3477 // CTF, а флагов нет:
3478 if not g_Map_HaveFlagPoints() then
3479 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3484 gState
:= STATE_MENU
;
3489 gPauseMain
:= false;
3490 gPauseHolmes
:= false;
3491 NetTimeToUpdate
:= 1;
3492 NetTimeToReliable
:= 0;
3493 NetTimeToMaster
:= NetMasterRate
;
3494 gSpectLatchPID1
:= 0;
3495 gSpectLatchPID2
:= 0;
3496 gMissionFailed
:= False;
3499 gCoopMonstersKilled
:= 0;
3500 gCoopSecretsFound
:= 0;
3502 gVoteInProgress
:= False;
3503 gVotePassed
:= False;
3509 if not gGameOn
then Exit
;
3511 g_Game_SpectateCenterView();
3513 if g_Game_IsServer
then
3515 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3517 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3518 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3519 gLMSSoftSpawn
:= True;
3520 if g_Game_IsNet
then
3521 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3525 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3526 gLMSRespawnTime
:= 0;
3530 if NetMode
= NET_SERVER
then
3532 // reset full state flags
3533 if NetClients
<> nil then
3534 for I
:= 0 to High(NetClients
) do
3535 NetClients
[I
].FullUpdateSent
:= False;
3537 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3540 g_Net_Slist_ServerMapStarted();
3542 if NetClients
<> nil then
3543 for I
:= 0 to High(NetClients
) do
3544 if NetClients
[I
].Used
then
3546 NetClients
[I
].Voted
:= False;
3547 if NetClients
[I
].RequestedFullUpdate
then
3549 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3550 NetClients
[I
].RequestedFullUpdate
:= False;
3554 g_Net_UnbanNonPermHosts();
3559 gCoopTotalMonstersKilled
:= 0;
3560 gCoopTotalSecretsFound
:= 0;
3561 gCoopTotalMonsters
:= 0;
3562 gCoopTotalSecrets
:= 0;
3566 g_Game_ExecuteEvent('onmapstart');
3569 procedure SetFirstLevel
;
3573 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3574 if MapList
= nil then
3577 SortSArray(MapList
);
3578 gNextMap
:= MapList
[Low(MapList
)];
3583 procedure g_Game_ExitLevel(const Map
: AnsiString);
3587 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3588 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3589 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3590 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3592 // Вышли в выход в Одиночной игре:
3593 if gGameSettings
.GameType
= GT_SINGLE
then
3594 gExit
:= EXIT_ENDLEVELSINGLE
3595 else // Вышли в выход в Своей игре
3597 gExit
:= EXIT_ENDLEVELCUSTOM
;
3598 if gGameSettings
.GameMode
= GM_COOP
then
3599 g_Player_RememberAll
;
3601 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3604 if gGameSettings
.GameMode
= GM_COOP
then
3607 gStatsPressed
:= True;
3608 gNextMap
:= 'MAP01';
3610 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3613 if g_Game_IsNet
then
3615 MH_SEND_GameStats();
3616 MH_SEND_CoopStats();
3622 procedure g_Game_RestartLevel();
3626 if gGameSettings
.GameMode
= GM_SINGLE
then
3631 gExit
:= EXIT_ENDLEVELCUSTOM
;
3632 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3636 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3638 gWAD
{, xwad}: String;
3641 if not g_Game_IsClient
then Exit
;
3642 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3644 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3649 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3653 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3656 g_Game_LoadWAD(NewWAD
);
3660 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3661 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3664 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3665 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3669 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3673 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3674 g_Game_LoadWAD(NewWAD);
3678 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3680 i
, n
, nb
, nr
: Integer;
3682 if not g_Game_IsServer
then Exit
;
3683 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3684 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3685 gLMSRespawnTime
:= 0;
3688 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3690 gMissionFailed
:= True;
3691 g_Game_RestartLevel
;
3695 n
:= 0; nb
:= 0; nr
:= 0;
3696 for i
:= Low(gPlayers
) to High(gPlayers
) do
3697 if (gPlayers
[i
] <> nil) and
3698 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3699 (gPlayers
[i
] is TBot
)) then
3702 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3703 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3706 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3708 // wait a second until the fuckers finally decide to join
3709 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3710 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3711 gLMSSoftSpawn
:= NoMapRestart
;
3712 if g_Game_IsNet
then
3713 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3717 {$IFDEF ENABLE_GIBS}
3720 {$IFDEF ENALBE_SHELLS}
3723 {$IFDEF ENABLE_CORPSES}
3724 g_Corpses_RemoveAll
;
3727 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3728 if g_Game_IsNet
then
3729 MH_SEND_GameEvent(NET_EV_LMS_START
);
3731 for i
:= Low(gPlayers
) to High(gPlayers
) do
3733 if gPlayers
[i
] = nil then continue
;
3734 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3735 // don't touch normal spectators
3736 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3738 gPlayers
[i
].FNoRespawn
:= True;
3739 gPlayers
[i
].Lives
:= 0;
3740 if g_Game_IsNet
then
3741 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3744 gPlayers
[i
].FNoRespawn
:= False;
3745 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3746 gPlayers
[i
].Respawn(False, True);
3747 if gGameSettings
.GameMode
= GM_COOP
then
3749 gPlayers
[i
].Frags
:= 0;
3750 gPlayers
[i
].RecallState
;
3752 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3753 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3754 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3755 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3758 g_Items_RestartRound();
3760 gLMSSoftSpawn
:= False;
3763 function g_Game_GetFirstMap(WAD
: String): String;
3767 MapList
:= g_Map_GetMapsList(WAD
);
3768 if MapList
= nil then
3771 SortSArray(MapList
);
3772 Result
:= MapList
[Low(MapList
)];
3774 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3780 function g_Game_GetNextMap(): String;
3787 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3788 if MapList
= nil then
3791 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3793 SortSArray(MapList
);
3795 for I
:= Low(MapList
) to High(MapList
) do
3796 if Map
= MapList
[I
] then
3802 if MapIndex
<> -255 then
3804 if MapIndex
= High(MapList
) then
3805 Result
:= MapList
[Low(MapList
)]
3807 Result
:= MapList
[MapIndex
+ 1];
3809 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3815 procedure g_Game_NextLevel();
3817 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3818 gExit
:= EXIT_ENDLEVELCUSTOM
3821 gExit
:= EXIT_ENDLEVELSINGLE
;
3825 if gNextMap
<> '' then Exit
;
3826 gNextMap
:= g_Game_GetNextMap();
3829 function g_Game_IsTestMap(): Boolean;
3831 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3834 procedure g_Game_DeleteTestMap();
3837 //MapName: AnsiString;
3845 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3846 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3847 if (a
= 0) then exit
;
3849 // Выделяем имя wad-файла и имя карты
3850 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3851 Delete(gMapToDelete
, 1, a
+5);
3852 gMapToDelete
:= UpperCase(gMapToDelete
);
3854 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3857 // Имя карты не стандартное тестовое:
3858 if MapName <> TEST_MAP_NAME then
3861 if not gTempDelete then
3863 time := g_GetFileTime(WadName);
3864 WAD := TWADFile.Create();
3867 if not WAD.ReadFile(WadName) then
3868 begin // Нет такого WAD-файла
3873 // Составляем список карт и ищем нужную:
3875 MapList := WAD.GetResourcesList('');
3877 if MapList <> nil then
3878 for a := 0 to High(MapList) do
3879 if MapList[a] = MapName then
3881 // Удаляем и сохраняем:
3882 WAD.RemoveResource('', MapName);
3883 WAD.SaveTo(WadName);
3888 g_SetFileTime(WadName, time);
3891 if gTempDelete
then DeleteFile(WadName
);
3894 procedure GameCVars(P
: SSArray
);
3897 stat
: TPlayerStatArray
;
3900 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3904 if Length(P
) > 1 then
3909 gsGameFlags
:= gsGameFlags
or Flag
3911 gsGameFlags
:= gsGameFlags
and (not Flag
);
3913 if g_Game_IsServer
then
3916 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3918 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3919 if g_Game_IsNet
then MH_SEND_GameSettings
;
3923 if LongBool(gsGameFlags
and Flag
) then
3924 g_Console_Add(_lc
[OnMsg
])
3926 g_Console_Add(_lc
[OffMsg
]);
3928 if OnMapChange
and g_Game_IsServer
then
3929 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3934 cmd
:= LowerCase(P
[0]);
3936 if cmd
= 'g_gamemode' then
3938 if (Length(P
) > 1) then
3940 a
:= g_Game_TextToMode(P
[1]);
3941 if a
= GM_SINGLE
then a
:= GM_COOP
;
3942 gsGameMode
:= g_Game_ModeToText(a
);
3943 if g_Game_IsServer
then
3945 gSwitchGameMode
:= a
;
3946 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3947 (gState
= STATE_INTERSINGLE
) then
3948 gSwitchGameMode
:= GM_SINGLE
;
3950 gGameSettings
.GameMode
:= gSwitchGameMode
;
3954 if gSwitchGameMode
= gGameSettings
.GameMode
then
3955 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3956 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3958 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3959 [g_Game_ModeToText(gGameSettings
.GameMode
),
3960 g_Game_ModeToText(gSwitchGameMode
)]));
3962 else if cmd
= 'g_friendlyfire' then
3964 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3966 else if cmd
= 'g_friendly_absorb_damage' then
3968 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
3970 else if cmd
= 'g_friendly_hit_trace' then
3972 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
3974 else if cmd
= 'g_friendly_hit_projectile' then
3976 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
3978 else if cmd
= 'g_weaponstay' then
3980 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3982 else if cmd
= 'g_allow_exit' then
3984 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3986 else if cmd
= 'g_allow_monsters' then
3988 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3990 else if cmd
= 'g_allow_dropflag' then
3992 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
3994 else if cmd
= 'g_throw_flag' then
3996 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
3998 else if cmd
= 'g_bot_vsplayers' then
4000 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4002 else if cmd
= 'g_bot_vsmonsters' then
4004 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4006 else if cmd
= 'g_dm_keys' then
4008 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4010 else if cmd
= 'g_gameflags' then
4012 if Length(P
) > 1 then
4014 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4015 if g_Game_IsServer
then
4017 gGameSettings
.Options
:= gsGameFlags
;
4018 if g_Game_IsNet
then MH_SEND_GameSettings
;
4022 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4024 else if cmd
= 'g_warmup_time' then
4026 if Length(P
) > 1 then
4028 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4029 if g_Game_IsServer
then
4031 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4032 // extend warmup if it's already going
4033 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4035 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4036 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4038 if g_Game_IsNet
then MH_SEND_GameSettings
;
4042 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4043 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4045 else if cmd
= 'g_spawn_invul' then
4047 if Length(P
) > 1 then
4049 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4050 if g_Game_IsServer
then
4052 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4053 if g_Game_IsNet
then MH_SEND_GameSettings
;
4057 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4059 else if cmd
= 'g_item_respawn_time' then
4061 if Length(P
) > 1 then
4063 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4064 if g_Game_IsServer
then
4066 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4067 if g_Game_IsNet
then MH_SEND_GameSettings
;
4071 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4072 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4074 else if cmd
= 'sv_intertime' then
4076 if (Length(P
) > 1) then
4077 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4079 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4081 else if cmd
= 'g_max_particles' then
4083 if Length(p
) = 2 then
4086 a
:= Max(0, StrToIntDef(p
[1], 0));
4090 else if Length(p
) = 1 then
4093 e_LogWritefln('%s', [g_GFX_GetMax()])
4095 e_LogWritefln('%s', [0])
4100 e_LogWritefln('usage: %s <n>', [cmd
])
4103 else if cmd
= 'g_max_shells' then
4105 if Length(p
) = 2 then
4107 {$IFDEF ENABLE_SHELLS}
4108 a
:= Max(0, StrToIntDef(p
[1], 0));
4112 else if Length(p
) = 1 then
4114 {$IFDEF ENABLE_SHELLS}
4115 e_LogWritefln('%s', [g_Shells_GetMax()])
4117 e_LogWritefln('%s', [0])
4122 e_LogWritefln('usage: %s <n>', [cmd
])
4125 else if cmd
= 'g_max_gibs' then
4127 if Length(p
) = 2 then
4129 {$IFDEF ENABLE_GIBS}
4130 a
:= Max(0, StrToIntDef(p
[1], 0));
4134 else if Length(p
) = 1 then
4136 {$IFDEF ENABLE_GIBS}
4137 e_LogWritefln('%s', [g_Gibs_GetMax()])
4139 e_LogWritefln('%s', [0])
4144 e_LogWritefln('usage: %s <n>', [cmd
])
4147 else if cmd
= 'g_max_corpses' then
4149 if Length(p
) = 2 then
4151 {$IFDEF ENABLE_CORPSES}
4152 a
:= Max(0, StrToIntDef(p
[1], 0));
4156 else if Length(p
) = 1 then
4158 {$IFDEF ENABLE_CORPSES}
4159 e_LogWritefln('%s', [g_Corpses_GetMax()])
4161 e_LogWritefln('%s', [0])
4166 e_LogWritefln('usage: %s <n>', [cmd
])
4169 else if cmd
= 'g_force_model' then
4171 if Length(p
) = 2 then
4173 a
:= StrToIntDef(p
[1], 0);
4174 g_Force_Model_Set(a
);
4175 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4177 for a
:= Low(gPlayers
) to High(gPlayers
) do
4179 if (gPlayers
[a
] <> nil) then
4181 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4183 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4185 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4189 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4191 for a
:= Low(gPlayers
) to High(gPlayers
) do
4193 if (gPlayers
[a
] <> nil) then
4195 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4197 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4199 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4205 else if cmd
= 'g_force_model_name' then
4207 if (Length(P
) > 1) then
4209 cmd
:= b_Text_Unformat(P
[1]);
4210 g_Forced_Model_SetName(cmd
);
4211 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4213 for a
:= Low(gPlayers
) to High(gPlayers
) do
4215 if (gPlayers
[a
] <> nil) then
4217 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4219 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4221 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4227 else if cmd
= 'g_scorelimit' then
4229 if Length(P
) > 1 then
4231 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4233 if g_Game_IsServer
then
4236 if gGameSettings
.GameMode
= GM_DM
then
4238 stat
:= g_Player_GetStats();
4240 for a
:= 0 to High(stat
) do
4241 if stat
[a
].Frags
> b
then
4245 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4247 // if someone has a higher score, set it to that instead
4248 gsScoreLimit
:= max(gsScoreLimit
, b
);
4249 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4251 if g_Game_IsNet
then MH_SEND_GameSettings
;
4255 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4257 else if cmd
= 'g_timelimit' then
4259 if Length(P
) > 1 then
4261 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4262 if g_Game_IsServer
then
4264 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4265 if g_Game_IsNet
then MH_SEND_GameSettings
;
4268 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4269 [gsTimeLimit
div 3600,
4270 (gsTimeLimit
div 60) mod 60,
4271 gsTimeLimit
mod 60]));
4273 else if cmd
= 'g_max_bots' then
4275 if Length(P
) > 1 then
4276 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4277 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4279 else if cmd
= 'g_maxlives' then
4281 if Length(P
) > 1 then
4283 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4284 if g_Game_IsServer
then
4286 gGameSettings
.MaxLives
:= gsMaxLives
;
4287 if g_Game_IsNet
then MH_SEND_GameSettings
;
4291 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4295 procedure PlayerSettingsCVars(P
: SSArray
);
4300 function ParseTeam(s
: string): Byte;
4304 'red', '1': result
:= TEAM_RED
;
4305 'blue', '2': result
:= TEAM_BLUE
;
4306 else result
:= TEAM_NONE
;
4310 cmd
:= LowerCase(P
[0]);
4314 if (Length(P
) > 1) then
4316 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4317 if g_Game_IsClient
then
4318 MC_SEND_PlayerSettings
4319 else if gGameOn
and (gPlayer1
<> nil) then
4321 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4322 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4328 if (Length(P
) > 1) then
4330 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4331 if g_Game_IsClient
then
4332 MC_SEND_PlayerSettings
4333 else if gGameOn
and (gPlayer2
<> nil) then
4335 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4336 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4342 if Length(P
) > 3 then
4344 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4345 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4346 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4347 if g_Game_IsClient
then
4348 MC_SEND_PlayerSettings
4349 else if gGameOn
and (gPlayer1
<> nil) then
4351 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4352 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4358 if Length(P
) > 3 then
4360 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4361 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4362 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4363 if g_Game_IsClient
then
4364 MC_SEND_PlayerSettings
4365 else if gGameOn
and (gPlayer2
<> nil) then
4367 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4368 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4374 if (Length(P
) > 1) then
4376 gPlayer1Settings
.Model
:= P
[1];
4377 if g_Game_IsClient
then
4378 MC_SEND_PlayerSettings
4379 else if gGameOn
and (gPlayer1
<> nil) then
4381 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4382 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4383 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4389 if (Length(P
) > 1) then
4391 gPlayer2Settings
.Model
:= P
[1];
4392 if g_Game_IsClient
then
4393 MC_SEND_PlayerSettings
4394 else if gGameOn
and (gPlayer2
<> nil) then
4396 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4397 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4398 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4404 // TODO: switch teams if in game or store this separately
4405 if (Length(P
) > 1) then
4407 team
:= ParseTeam(P
[1]);
4408 if team
= TEAM_NONE
then
4409 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4410 else if not gGameOn
and not g_Game_IsNet
then
4411 gPlayer1Settings
.Team
:= team
4413 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4418 // TODO: switch teams if in game or store this separately
4419 if (Length(P
) > 1) then
4421 team
:= ParseTeam(P
[1]);
4422 if team
= TEAM_NONE
then
4423 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4424 else if not gGameOn
and not g_Game_IsNet
then
4425 gPlayer2Settings
.Team
:= team
4427 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4432 if (Length(P
) = 2) then
4433 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4437 if (Length(P
) = 2) then
4438 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4442 if (Length(P
) = 2) then
4443 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4447 if (Length(P
) = 2) then
4448 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4452 if (Length(P
) = 2) then
4453 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4457 if (Length(P
) = 2) then
4458 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4460 'p1_priority_kastet':
4462 if (Length(P
) = 2) then
4463 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4465 'p2_priority_kastet':
4467 if (Length(P
) = 2) then
4468 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4472 if (Length(P
) = 2) then
4473 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4477 if (Length(P
) = 2) then
4478 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4480 'p1_priority_pistol':
4482 if (Length(P
) = 2) then
4483 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4485 'p2_priority_pistol':
4487 if (Length(P
) = 2) then
4488 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4490 'p1_priority_shotgun1':
4492 if (Length(P
) = 2) then
4493 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4495 'p2_priority_shotgun1':
4497 if (Length(P
) = 2) then
4498 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4500 'p1_priority_shotgun2':
4502 if (Length(P
) = 2) then
4503 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4505 'p2_priority_shotgun2':
4507 if (Length(P
) = 2) then
4508 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4510 'p1_priority_chaingun':
4512 if (Length(P
) = 2) then
4513 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4515 'p2_priority_chaingun':
4517 if (Length(P
) = 2) then
4518 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4520 'p1_priority_rocketlauncher':
4522 if (Length(P
) = 2) then
4523 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4525 'p2_priority_rocketlauncher':
4527 if (Length(P
) = 2) then
4528 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4530 'p1_priority_plasma':
4532 if (Length(P
) = 2) then
4533 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4535 'p2_priority_plasma':
4537 if (Length(P
) = 2) then
4538 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4542 if (Length(P
) = 2) then
4543 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4547 if (Length(P
) = 2) then
4548 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4550 'p1_priority_super':
4552 if (Length(P
) = 2) then
4553 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4555 'p2_priority_super':
4557 if (Length(P
) = 2) then
4558 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4560 'p1_priority_flamethrower':
4562 if (Length(P
) = 2) then
4563 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4565 'p2_priority_flamethrower':
4567 if (Length(P
) = 2) then
4568 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4570 'p1_priority_berserk':
4572 if (Length(P
) = 2) then
4573 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4575 'p2_priority_berserk':
4577 if (Length(P
) = 2) then
4578 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4583 procedure PrintHeapStats();
4587 hs
:= GetFPCHeapStatus();
4588 e_LogWriteLn ('v===== heap status =====v');
4589 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4590 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4591 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4592 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4593 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4594 e_LogWriteLn ('^=======================^');
4597 procedure DebugCommands(P
: SSArray
);
4604 // Команды отладочного режима:
4605 if {gDebugMode}conIsCheatsEnabled
then
4607 cmd
:= LowerCase(P
[0]);
4608 if cmd
= 'd_window' then
4610 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4611 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4613 else if cmd
= 'd_sounds' then
4615 if (Length(P
) > 1) and
4616 ((P
[1] = '1') or (P
[1] = '0')) then
4617 g_Debug_Sounds
:= (P
[1][1] = '1');
4619 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4621 else if cmd
= 'd_frames' then
4623 if (Length(P
) > 1) and
4624 ((P
[1] = '1') or (P
[1] = '0')) then
4625 g_Debug_Frames
:= (P
[1][1] = '1');
4627 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4629 else if cmd
= 'd_winmsg' then
4631 if (Length(P
) > 1) and
4632 ((P
[1] = '1') or (P
[1] = '0')) then
4633 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4635 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4637 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4639 if (Length(P
) > 1) and
4640 ((P
[1] = '1') or (P
[1] = '0')) then
4641 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4643 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4645 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4647 if Length(P
) > 1 then
4649 '0': g_debug_BotAIOff
:= 0;
4650 '1': g_debug_BotAIOff
:= 1;
4651 '2': g_debug_BotAIOff
:= 2;
4652 '3': g_debug_BotAIOff
:= 3;
4655 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4657 else if cmd
= 'd_monster' then
4659 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4660 if Length(P
) < 2 then
4662 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4663 g_Console_Add('ID | Name');
4664 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4665 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4666 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4669 a
:= StrToIntDef(P
[1], 0);
4670 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4671 a
:= g_Mons_TypeIdByName(P
[1]);
4673 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4674 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4677 with gPlayer1
.Obj
do
4679 mon
:= g_Monsters_Create(a
,
4680 X
+ Rect
.X
+ (Rect
.Width
div 2),
4681 Y
+ Rect
.Y
+ Rect
.Height
,
4682 gPlayer1
.Direction
, True);
4684 if (Length(P
) > 2) and (mon
<> nil) then
4686 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4687 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4688 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4689 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4690 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4691 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4692 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4693 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4694 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4699 else if (cmd
= 'd_health') then
4701 if (Length(P
) > 1) and
4702 ((P
[1] = '1') or (P
[1] = '0')) then
4703 g_debug_HealthBar
:= (P
[1][1] = '1');
4705 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4707 else if (cmd
= 'd_player') then
4709 if (Length(P
) > 1) and
4710 ((P
[1] = '1') or (P
[1] = '0')) then
4711 g_debug_Player
:= (P
[1][1] = '1');
4713 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4715 else if (cmd
= 'd_mem') then
4721 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4725 procedure GameCheats(P
: SSArray
);
4731 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4733 g_Console_Add('not available');
4739 g_Console_Add('where is the player?!');
4742 cmd
:= LowerCase(P
[0]);
4746 plr
.GodMode
:= not plr
.GodMode
;
4747 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4750 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4751 if cmd
= 'give' then
4753 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4754 for f
:= 1 to High(P
) do
4756 cmd
:= LowerCase(P
[f
]);
4757 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4758 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4759 if cmd
= 'exit' then
4761 if gTriggers
<> nil then
4763 for a
:= 0 to High(gTriggers
) do
4765 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4767 g_Console_Add('player left the map');
4768 gExitByTrigger
:= True;
4769 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4770 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4778 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4779 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4780 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4781 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4782 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4784 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4785 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4787 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4788 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;
4790 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4791 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4793 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4794 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4796 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4797 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4799 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4800 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4801 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4803 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4804 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4805 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4806 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;
4807 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4808 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4810 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;
4811 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;
4812 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;
4813 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;
4814 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;
4815 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;
4817 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4818 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;
4820 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;
4821 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;
4823 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4825 if cmd
= 'ammo' then
4827 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4828 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4829 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4830 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4831 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4832 g_Console_Add('player got some ammo');
4836 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4837 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4839 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4840 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4842 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4843 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4845 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4846 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4848 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4850 if cmd
= 'weapons' then
4852 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4853 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4854 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4855 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4856 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4857 plr
.GiveItem(ITEM_WEAPON_BFG
);
4858 g_Console_Add('player got weapons');
4862 if cmd
= 'keys' then
4864 plr
.GiveItem(ITEM_KEY_RED
);
4865 plr
.GiveItem(ITEM_KEY_GREEN
);
4866 plr
.GiveItem(ITEM_KEY_BLUE
);
4867 g_Console_Add('player got all keys');
4871 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4876 if cmd
= 'open' then
4878 g_Console_Add('player activated sesame');
4879 g_Triggers_OpenAll();
4886 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4890 if cmd
= 'noclip' then
4893 g_Console_Add('wall hardeness adjusted');
4897 if cmd
= 'notarget' then
4899 plr
.NoTarget
:= not plr
.NoTarget
;
4900 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4904 if cmd
= 'noreload' then
4906 plr
.NoReload
:= not plr
.NoReload
;
4907 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4911 if cmd
= 'speedy' then
4913 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4914 g_Console_Add('speed adjusted');
4918 if cmd
= 'jumpy' then
4920 VEL_JUMP
:= 30-VEL_JUMP
;
4921 g_Console_Add('jump height adjusted');
4925 if cmd
= 'automap' then
4927 gShowMap
:= not gShowMap
;
4928 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4932 if cmd
= 'aimline' then
4934 gAimLine
:= not gAimLine
;
4935 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4940 procedure GameCommands(P
: SSArray
);
4946 pl
: pTNetClient
= nil;
4954 cmd
:= LowerCase(P
[0]);
4956 if cmd
= 'pause' then
4958 {$IFDEF ENABLE_MENU}
4959 if (g_ActiveWindow
= nil) then
4960 g_Game_Pause(not gPauseMain
);
4962 g_Game_Pause(not gPauseMain
);
4965 else if cmd
= 'endgame' then
4966 gExit
:= EXIT_SIMPLE
4967 else if cmd
= 'restart' then
4969 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4971 if g_Game_IsClient
then
4973 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4978 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4980 else if cmd
= 'kick' then
4982 if g_Game_IsServer
then
4984 if Length(P
) < 2 then
4986 g_Console_Add('kick <name>');
4991 g_Console_Add('kick <name>');
4995 if g_Game_IsNet
then
4996 pl
:= g_Net_Client_ByName(P
[1]);
4999 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5000 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5001 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5002 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5003 g_Net_Slist_ServerPlayerLeaves();
5004 end else if gPlayers
<> nil then
5005 for a
:= Low(gPlayers
) to High(gPlayers
) do
5006 if gPlayers
[a
] <> nil then
5007 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5009 // Не отключать основных игроков в сингле
5010 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5012 gPlayers
[a
].Lives
:= 0;
5013 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5014 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5015 g_Player_Remove(gPlayers
[a
].UID
);
5016 g_Net_Slist_ServerPlayerLeaves();
5017 // Если не перемешать, при добавлении новых ботов появятся старые
5021 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5023 else if cmd
= 'kick_id' then
5025 if g_Game_IsServer
and g_Game_IsNet
then
5027 if Length(P
) < 2 then
5029 g_Console_Add('kick_id <client ID>');
5034 g_Console_Add('kick_id <client ID>');
5038 a
:= StrToIntDef(P
[1], 0);
5039 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5041 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5043 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5044 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
5045 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5046 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5047 g_Net_Slist_ServerPlayerLeaves();
5051 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5053 else if cmd
= 'kick_pid' then
5055 if g_Game_IsServer
and g_Game_IsNet
then
5057 if Length(P
) < 2 then
5059 g_Console_Add('kick_pid <player ID>');
5064 g_Console_Add('kick_pid <player ID>');
5068 a
:= StrToIntDef(P
[1], 0);
5069 pl
:= g_Net_Client_ByPlayer(a
);
5070 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5072 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5073 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5074 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5075 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5076 g_Net_Slist_ServerPlayerLeaves();
5079 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5081 else if cmd
= 'ban' then
5083 if g_Game_IsServer
and g_Game_IsNet
then
5085 if Length(P
) < 2 then
5087 g_Console_Add('ban <name>');
5092 g_Console_Add('ban <name>');
5096 pl
:= g_Net_Client_ByName(P
[1]);
5099 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5100 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5101 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5102 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5103 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5104 g_Net_Slist_ServerPlayerLeaves();
5106 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5108 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5110 else if cmd
= 'ban_id' then
5112 if g_Game_IsServer
and g_Game_IsNet
then
5114 if Length(P
) < 2 then
5116 g_Console_Add('ban_id <client ID>');
5121 g_Console_Add('ban_id <client ID>');
5125 a
:= StrToIntDef(P
[1], 0);
5126 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5127 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5129 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5130 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5131 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5132 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5133 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5134 g_Net_Slist_ServerPlayerLeaves();
5137 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5139 else if cmd
= 'ban_pid' then
5141 if g_Game_IsServer
and g_Game_IsNet
then
5143 if Length(P
) < 2 then
5145 g_Console_Add('ban_pid <player ID>');
5150 g_Console_Add('ban_pid <player ID>');
5154 a
:= StrToIntDef(P
[1], 0);
5155 pl
:= g_Net_Client_ByPlayer(a
);
5156 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5158 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5159 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5160 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5161 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5162 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5163 g_Net_Slist_ServerPlayerLeaves();
5166 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5168 else if cmd
= 'permban' then
5170 if g_Game_IsServer
and g_Game_IsNet
then
5172 if Length(P
) < 2 then
5174 g_Console_Add('permban <name>');
5179 g_Console_Add('permban <name>');
5183 pl
:= g_Net_Client_ByName(P
[1]);
5186 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5187 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5188 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5189 g_Net_SaveBanList();
5190 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5191 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5192 g_Net_Slist_ServerPlayerLeaves();
5194 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5196 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5198 else if cmd
= 'permban_id' then
5200 if g_Game_IsServer
and g_Game_IsNet
then
5202 if Length(P
) < 2 then
5204 g_Console_Add('permban_id <client ID>');
5209 g_Console_Add('permban_id <client ID>');
5213 a
:= StrToIntDef(P
[1], 0);
5214 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5215 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5217 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5218 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5219 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5220 g_Net_SaveBanList();
5221 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5222 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5223 g_Net_Slist_ServerPlayerLeaves();
5226 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5228 else if cmd
= 'permban_pid' then
5230 if g_Game_IsServer
and g_Game_IsNet
then
5232 if Length(P
) < 2 then
5234 g_Console_Add('permban_pid <player ID>');
5239 g_Console_Add('permban_pid <player ID>');
5243 a
:= StrToIntDef(P
[1], 0);
5244 pl
:= g_Net_Client_ByPlayer(a
);
5245 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5247 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5248 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5249 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5250 g_Net_SaveBanList();
5251 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5252 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5253 g_Net_Slist_ServerPlayerLeaves();
5256 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5258 else if cmd
= 'permban_ip' then
5260 if g_Game_IsServer
and g_Game_IsNet
then
5262 if Length(P
) < 2 then
5264 g_Console_Add('permban_ip <IP address>');
5269 g_Console_Add('permban_ip <IP address>');
5273 g_Net_BanHost(P
[1]);
5274 g_Net_SaveBanList();
5275 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5277 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5279 else if cmd
= 'unban' then
5281 if g_Game_IsServer
and g_Game_IsNet
then
5283 if Length(P
) < 2 then
5285 g_Console_Add('unban <IP Address>');
5290 g_Console_Add('unban <IP Address>');
5294 if g_Net_UnbanHost(P
[1]) then
5296 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5297 g_Net_SaveBanList();
5299 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5301 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5303 else if cmd
= 'clientlist' then
5305 if g_Game_IsServer
and g_Game_IsNet
then
5308 if NetClients
<> nil then
5309 for a
:= Low(NetClients
) to High(NetClients
) do
5310 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5312 plr
:= g_Player_Get(NetClients
[a
].Player
);
5313 if plr
= nil then continue
;
5315 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5316 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5319 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5321 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5323 else if cmd
= 'connect' then
5325 if (NetMode
= NET_NONE
) then
5327 if Length(P
) < 2 then
5329 g_Console_Add('connect <IP> [port] [password]');
5334 g_Console_Add('connect <IP> [port] [password]');
5338 if Length(P
) > 2 then
5339 prt
:= StrToIntDef(P
[2], 25666)
5343 if Length(P
) > 3 then
5348 g_Game_StartClient(P
[1], prt
, pw
);
5351 else if cmd
= 'disconnect' then
5353 if (NetMode
= NET_CLIENT
) then
5356 else if cmd
= 'reconnect' then
5358 if (NetMode
= NET_SERVER
) then
5361 if (NetMode
= NET_CLIENT
) then
5364 gExit
:= EXIT_SIMPLE
;
5368 //TODO: Use last successful password to reconnect, instead of ''
5369 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5371 else if (cmd
= 'addbot') or
5372 (cmd
= 'bot_add') then
5374 if Length(P
) > 2 then
5375 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5376 else if Length(P
) > 1 then
5377 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5379 g_Bot_Add(TEAM_NONE
, 2);
5381 else if cmd
= 'bot_addlist' then
5383 if Length(P
) > 1 then
5385 if Length(P
) = 2 then
5386 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5387 else if Length(P
) = 3 then
5388 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5390 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5393 else if cmd
= 'bot_removeall' then
5395 else if cmd
= 'chat' then
5397 if g_Game_IsNet
then
5399 if Length(P
) > 1 then
5401 for a
:= 1 to High(P
) do
5402 chstr
:= chstr
+ P
[a
] + ' ';
5404 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5406 if Length(chstr
) < 1 then
5408 g_Console_Add('chat <text>');
5412 chstr
:= b_Text_Format(chstr
);
5413 if g_Game_IsClient
then
5414 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5416 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5419 g_Console_Add('chat <text>');
5421 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5423 else if cmd
= 'teamchat' then
5425 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5427 if Length(P
) > 1 then
5429 for a
:= 1 to High(P
) do
5430 chstr
:= chstr
+ P
[a
] + ' ';
5432 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5434 if Length(chstr
) < 1 then
5436 g_Console_Add('teamchat <text>');
5440 chstr
:= b_Text_Format(chstr
);
5441 if g_Game_IsClient
then
5442 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5444 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5445 gPlayer1Settings
.Team
);
5448 g_Console_Add('teamchat <text>');
5450 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5452 else if (cmd
= 'an') or (cmd
= 'announce') then
5454 if g_Game_IsNet
then
5456 if Length(P
) > 1 then
5458 for a
:= 1 to High(P
) do
5459 chstr
:= chstr
+ P
[a
] + ' ';
5461 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5463 if Length(chstr
) < 1 then
5465 g_Console_Add('announce <text>');
5469 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5470 if g_Game_IsClient
then
5471 MC_SEND_RCONCommand(chstr
)
5473 g_Console_Process(chstr
, True);
5476 g_Console_Add('announce <text>');
5478 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5480 else if cmd
= 'game' then
5482 if gGameSettings
.GameType
<> GT_NONE
then
5484 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5487 if Length(P
) = 1 then
5489 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5492 // game not started yet, load fist map from some wad
5494 s
:= addWadExtension(P
[1]);
5495 found
:= e_FindResource(AllMapDirs
, s
);
5499 P
[1] := ExpandFileName(P
[1]);
5500 // if map not choosed then set first map
5501 if Length(P
) < 3 then
5504 P
[2] := g_Game_GetFirstMap(P
[1]);
5507 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5509 if g_Map_Exist(s
) then
5513 with gGameSettings
do
5515 Options
:= gsGameFlags
;
5516 GameMode
:= g_Game_TextToMode(gsGameMode
);
5517 if gSwitchGameMode
<> GM_NONE
then
5518 GameMode
:= gSwitchGameMode
;
5519 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5520 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5522 if Length(P
) >= 4 then
5523 b
:= StrToIntDef(P
[3], 1);
5524 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5525 ScoreLimit
, MaxLives
, Options
, b
);
5530 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5532 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5534 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5536 else if cmd
= 'host' then
5538 if gGameSettings
.GameType
<> GT_NONE
then
5540 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5543 if Length(P
) < 4 then
5545 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5548 if not StrToIp(P
[1], listen
) then
5550 prt
:= StrToIntDef(P
[2], 25666);
5552 s
:= addWadExtension(P
[3]);
5553 found
:= e_FindResource(AllMapDirs
, s
);
5557 // get first map in wad, if not specified
5558 if Length(P
) < 5 then
5561 P
[4] := g_Game_GetFirstMap(P
[1]);
5563 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5564 if g_Map_Exist(s
) then
5568 with gGameSettings
do
5570 Options
:= gsGameFlags
;
5571 GameMode
:= g_Game_TextToMode(gsGameMode
);
5572 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5573 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5574 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5576 if Length(P
) >= 6 then
5577 b
:= StrToIntDef(P
[5], 0);
5578 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5584 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5586 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5591 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5594 else if cmd
= 'map' then
5596 if Length(P
) = 1 then
5598 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5600 g_Console_Add(cmd
+ ' <MAP>');
5601 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5605 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5610 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5612 if Length(P
) < 3 then
5614 // first param is map or wad
5615 s
:= UpperCase(P
[1]);
5616 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5618 gExitByTrigger
:= False;
5621 // already in game, finish current map
5623 gExit
:= EXIT_ENDLEVELCUSTOM
;
5627 // intermission, so change map immediately
5634 found
:= e_FindResource(AllMapDirs
, s
);
5636 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5639 // no such map, found wad
5642 P
[1] := ExpandFileName(pw
);
5643 P
[2] := g_Game_GetFirstMap(P
[1]);
5644 s
:= P
[1] + ':\' + P
[2];
5645 if g_Map_Exist(s
) then
5647 gExitByTrigger
:= False;
5650 // already in game, finish current map
5652 gExit
:= EXIT_ENDLEVELCUSTOM
5656 // intermission, so change map immediately
5663 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5665 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5670 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5676 s
:= addWadExtension(P
[1]);
5677 found
:= e_FindResource(AllMapDirs
, s
);
5681 P
[2] := UpperCase(P
[2]);
5682 s
:= P
[1] + ':\' + P
[2];
5683 if g_Map_Exist(s
) then
5685 gExitByTrigger
:= False;
5689 gExit
:= EXIT_ENDLEVELCUSTOM
5698 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5703 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5709 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5713 else if cmd
= 'nextmap' then
5715 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5717 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5722 if Length(P
) = 1 then
5724 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5726 g_Console_Add(cmd
+ ' <MAP>');
5727 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5732 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5738 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5740 if Length(P
) < 3 then
5742 // first param is map or wad
5743 s
:= UpperCase(P
[1]);
5744 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5747 gExitByTrigger
:= False;
5753 // no such map, found wad
5754 pw
:= addWadExtension(P
[1]);
5755 found
:= e_FindResource(MapDirs
, pw
);
5757 found
:= e_FindResource(WadDirs
, pw
);
5759 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5762 // map not specified, select first map
5764 P
[2] := g_Game_GetFirstMap(P
[1]);
5765 s
:= P
[1] + ':\' + P
[2];
5766 if g_Map_Exist(s
) then
5768 gExitByTrigger
:= False;
5775 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5777 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5782 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5788 // specified two params wad + map
5789 pw
:= addWadExtension(P
[1]);
5790 found
:= e_FindResource(MapDirs
, pw
);
5792 found
:= e_FindResource(MapDirs
, pw
);
5796 P
[2] := UpperCase(P
[2]);
5797 s
:= P
[1] + ':\' + P
[2];
5798 if g_Map_Exist(s
) then
5800 gExitByTrigger
:= False;
5806 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5811 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5817 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5822 if gNextMap
= '' then
5823 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5825 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5829 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5833 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5837 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5839 gExitByTrigger
:= False;
5840 // next map not specified, try to find trigger EXIT
5841 if (gNextMap
= '') and (gTriggers
<> nil) then
5843 for a
:= 0 to High(gTriggers
) do
5845 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5847 gExitByTrigger
:= True;
5848 //gNextMap := gTriggers[a].Data.MapName;
5849 gNextMap
:= gTriggers
[a
].tgcMap
;
5854 if gNextMap
= '' then
5855 gNextMap
:= g_Game_GetNextMap();
5856 if not isWadPath(gNextMap
) then
5857 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5860 if g_Map_Exist(s
) then
5861 gExit
:= EXIT_ENDLEVELCUSTOM
5863 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5867 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5871 else if (cmd
= 'event') then
5873 if (Length(P
) <= 1) then
5875 for a
:= 0 to High(gEvents
) do
5876 if gEvents
[a
].Command
= '' then
5877 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5879 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5882 if (Length(P
) = 2) then
5884 for a
:= 0 to High(gEvents
) do
5885 if gEvents
[a
].Name
= P
[1] then
5886 if gEvents
[a
].Command
= '' then
5887 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5889 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5892 for a
:= 0 to High(gEvents
) do
5893 if gEvents
[a
].Name
= P
[1] then
5895 gEvents
[a
].Command
:= '';
5896 for b
:= 2 to High(P
) do
5897 if Pos(' ', P
[b
]) = 0 then
5898 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5900 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5901 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5905 else if cmd
= 'suicide' then
5909 if g_Game_IsClient
then
5910 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5913 if gPlayer1
<> nil then
5914 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5915 if gPlayer2
<> nil then
5916 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5920 else if cmd
= 'screenshot' then
5926 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5928 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5930 gWeaponAction
[0, WP_PREV
] := True;
5932 gWeaponAction
[0, WP_NEXT
] := True;
5934 else if cmd
= 'weapon' then
5936 if Length(p
) = 2 then
5938 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5939 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5940 gSelectWeapon
[0, a
] := True
5943 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5944 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5946 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5947 b
:= ord(cmd
[2]) - ord('1');
5949 gWeaponAction
[b
, WP_PREV
] := True;
5951 gWeaponAction
[b
, WP_NEXT
] := True;
5953 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5955 if Length(p
) = 2 then
5957 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5958 b
:= ord(cmd
[2]) - ord('1');
5959 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5960 gSelectWeapon
[b
, a
] := True
5963 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
5965 b
:= ord(cmd
[2]) - ord('1');
5967 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
5969 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
5971 else if (cmd
= 'dropflag') then
5973 if g_Game_IsServer
then
5975 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
5976 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
5979 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5981 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
5983 b
:= ord(cmd
[2]) - ord('1');
5984 if g_Game_IsServer
then
5986 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
5987 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
5990 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5992 // Команды Своей игры:
5993 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5995 if cmd
= 'bot_addred' then
5997 if Length(P
) > 1 then
5998 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6000 g_Bot_Add(TEAM_RED
, 2);
6002 else if cmd
= 'bot_addblue' then
6004 if Length(P
) > 1 then
6005 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6007 g_Bot_Add(TEAM_BLUE
, 2);
6009 else if cmd
= 'spectate' then
6015 else if cmd
= 'say' then
6017 if g_Game_IsServer
and g_Game_IsNet
then
6019 if Length(P
) > 1 then
6022 for a
:= 1 to High(P
) do
6023 chstr
:= chstr
+ P
[a
] + ' ';
6025 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6027 if Length(chstr
) < 1 then
6029 g_Console_Add('say <text>');
6033 chstr
:= b_Text_Format(chstr
);
6034 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6036 else g_Console_Add('say <text>');
6038 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6040 else if cmd
= 'tell' then
6042 if g_Game_IsServer
and g_Game_IsNet
then
6044 if (Length(P
) > 2) and (P
[1] <> '') then
6047 for a
:= 2 to High(P
) do
6048 chstr
:= chstr
+ P
[a
] + ' ';
6050 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6052 if Length(chstr
) < 1 then
6054 g_Console_Add('tell <playername> <text>');
6058 pl
:= g_Net_Client_ByName(P
[1]);
6060 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6062 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6064 else g_Console_Add('tell <playername> <text>');
6066 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6068 else if cmd
= 'centerprint' then
6070 if (Length(P
) > 2) and (P
[1] <> '') then
6073 for a
:= 2 to High(P
) do
6074 chstr
:= chstr
+ P
[a
] + ' ';
6076 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6078 if Length(chstr
) < 1 then
6080 g_Console_Add('centerprint <timeout> <text>');
6084 a
:= StrToIntDef(P
[1], 100);
6085 chstr
:= b_Text_Format(chstr
);
6086 g_Game_Message(chstr
, a
);
6087 if g_Game_IsNet
and g_Game_IsServer
then
6088 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6090 else g_Console_Add('centerprint <timeout> <text>');
6092 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6094 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6096 // Дополнительное время:
6097 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6099 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6100 [gGameSettings
.TimeLimit
div 3600,
6101 (gGameSettings
.TimeLimit
div 60) mod 60,
6102 gGameSettings
.TimeLimit
mod 60]));
6103 if g_Game_IsNet
then MH_SEND_GameSettings
;
6105 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6107 if (Length(P
) <= 1) then
6108 g_Console_Add('rcon_password <password>')
6110 MC_SEND_RCONPassword(P
[1]);
6112 else if cmd
= 'rcon' then
6114 if g_Game_IsClient
then
6116 if Length(P
) > 1 then
6119 for a
:= 1 to High(P
) do
6120 chstr
:= chstr
+ P
[a
] + ' ';
6122 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6124 if Length(chstr
) < 1 then
6126 g_Console_Add('rcon <command>');
6130 MC_SEND_RCONCommand(chstr
);
6132 else g_Console_Add('rcon <command>');
6135 else if cmd
= 'ready' then
6137 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6138 gLMSRespawnTime
:= gTime
+ 100;
6140 else if (cmd
= 'callvote') and g_Game_IsNet
then
6142 if Length(P
) > 1 then
6145 for a
:= 1 to High(P
) do begin
6146 if a
> 1 then chstr
:= chstr
+ ' ';
6147 chstr
:= chstr
+ P
[a
];
6150 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6152 if Length(chstr
) < 1 then
6154 g_Console_Add('callvote <command>');
6158 if g_Game_IsClient
then
6159 MC_SEND_Vote(True, chstr
)
6161 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6162 g_Console_Process('vote', True);
6165 g_Console_Add('callvote <command>');
6167 else if (cmd
= 'vote') and g_Game_IsNet
then
6169 if g_Game_IsClient
then
6171 else if gVoteInProgress
then
6173 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6174 a
:= Floor((NetClientCount
+1)/2.0) + 1
6176 a
:= Floor(NetClientCount
/2.0) + 1;
6181 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6182 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6188 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6189 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6197 procedure SystemCommands(P
: SSArray
);
6201 cmd
:= LowerCase(P
[0]);
6214 if Length(p
) = 2 then
6216 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6218 gFrameTime
:= 1000 div gMaxFPS
6222 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6226 if Length(p
) = 2 then
6228 gAskLanguage
:= true;
6229 gLanguage
:= LANGUAGE_ENGLISH
;
6230 case LowerCase(p
[1]) of
6233 gAskLanguage
:= false;
6234 gLanguage
:= LANGUAGE_ENGLISH
;
6238 gAskLanguage
:= false;
6239 gLanguage
:= LANGUAGE_RUSSIAN
;
6243 gAskLanguage
:= true;
6244 gLanguage
:= LANGUAGE_ENGLISH
;
6247 g_Language_Set(gLanguage
);
6251 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6258 procedure g_TakeScreenShot(Filename
: string = '');
6259 var t
: TDateTime
; dir
, date
, name
: String;
6261 if e_NoGraphics
then
6264 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6265 if Filename
= '' then
6268 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6269 Filename
:= 'screenshot-' + date
;
6272 name
:= e_CatPath(dir
, Filename
+ '.png');
6273 if r_Render_WriteScreenShot(name
) then
6274 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6276 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6280 {$IFDEF ENABLE_MENU}
6281 procedure g_Game_InGameMenu(Show
: Boolean);
6283 if (g_ActiveWindow
= nil) and Show
then
6285 if gGameSettings
.GameType
= GT_SINGLE
then
6286 g_GUI_ShowWindow('GameSingleMenu')
6289 if g_Game_IsClient
then
6290 g_GUI_ShowWindow('GameClientMenu')
6292 if g_Game_IsNet
then
6293 g_GUI_ShowWindow('GameServerMenu')
6295 g_GUI_ShowWindow('GameCustomMenu');
6297 g_Sound_PlayEx('MENU_OPEN');
6299 // Пауза при меню только в одиночной игре:
6300 if (not g_Game_IsNet
) then
6304 if (g_ActiveWindow
<> nil) and (not Show
) then
6306 // Пауза при меню только в одиночной игре:
6307 if (not g_Game_IsNet
) then
6308 g_Game_Pause(False);
6313 procedure g_Game_Pause (Enable
: Boolean);
6317 if not gGameOn
then exit
;
6319 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6322 gPauseMain
:= Enable
;
6324 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6327 procedure g_Game_HolmesPause (Enable
: Boolean);
6331 if not gGameOn
then exit
;
6332 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6335 gPauseHolmes
:= Enable
;
6337 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6340 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6345 if gTriggers
<> nil then
6346 for i
:= 0 to High(gTriggers
) do
6347 with gTriggers
[i
] do
6348 if (TriggerType
= TRIGGER_SOUND
) and
6350 Sound
.IsPlaying() then
6352 Sound
.Pause(Enable
);
6356 if gPlayers
<> nil then
6357 for i
:= 0 to High(gPlayers
) do
6358 if gPlayers
[i
] <> nil then
6359 gPlayers
[i
].PauseSounds(Enable
);
6362 if gMusic
<> nil then
6363 gMusic
.Pause(Enable
);
6366 procedure g_Game_StopAllSounds(all
: Boolean);
6370 if gTriggers
<> nil then
6371 for i
:= 0 to High(gTriggers
) do
6372 with gTriggers
[i
] do
6373 if (TriggerType
= TRIGGER_SOUND
) and
6377 if gMusic
<> nil then
6384 procedure g_Game_UpdateTriggerSounds
;
6387 if gTriggers
<> nil then
6388 for i
:= 0 to High(gTriggers
) do
6389 with gTriggers
[i
] do
6390 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6391 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6394 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6397 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6402 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6407 if gSpectMode
<> SPECT_PLAYERS
then
6409 if gSpectPID1
= UID
then
6414 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6421 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6426 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6431 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6436 if gSpectMode
<> SPECT_PLAYERS
then
6438 Pl
:= g_Player_Get(gSpectPID1
);
6439 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6444 if gSpectViewTwo
then
6446 Pl
:= g_Player_Get(gSpectPID2
);
6447 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6455 procedure g_Game_Message (Msg
: string; Time
: Word);
6458 MessageTime
:= Time
;
6461 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6463 punct
: Array[0..13] of String =
6464 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6470 function IsPunctuation(S
: String): Boolean;
6475 if Length(S
) <> 1 then
6477 for i
:= Low(punct
) to High(punct
) do
6478 if S
= punct
[i
] then
6484 function FilterPunctuation(S
: String): String;
6488 for i
:= Low(punct
) to High(punct
) do
6489 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6495 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6497 // remove player name
6498 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6499 // for FullWord check
6500 Text := toLowerCase1251(' ' + Text + ' ');
6501 fpText
:= FilterPunctuation(Text);
6503 for i
:= 0 to Length(gChatSounds
) - 1 do
6506 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6508 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6509 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6511 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6517 gChatSounds
[i
].Sound
.Play();
6523 g_Sound_PlayEx('SOUND_GAME_RADIO');
6526 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6535 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6539 if goodsnd
[a
].IsPlaying() then
6542 goodsnd
[Random(4)].Play();
6545 procedure g_Game_Announce_KillCombo(Param
: Integer);
6552 UID
:= Param
and $FFFF;
6557 Pl
:= g_Player_Get(UID
);
6566 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6570 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6574 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6578 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6586 if not g_Game_IsWatchedPlayer(UID
) then
6589 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6593 if killsnd
[n
].IsPlaying() then
6598 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6606 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6610 if hahasnd
[a
].IsPlaying() then
6613 hahasnd
[Random(3)].Play();
6616 procedure g_Game_StartVote(Command
, Initiator
: string);
6620 if not gVotesEnabled
then Exit
;
6621 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6622 if gVoteInProgress
or gVotePassed
then
6624 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6625 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6628 gVoteInProgress
:= True;
6629 gVotePassed
:= False;
6630 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6633 gVoteCommand
:= Command
;
6635 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6636 Need
:= Floor((NetClientCount
+1)/2.0)+1
6638 Need
:= Floor(NetClientCount
/2.0)+1;
6639 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6640 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6643 procedure g_Game_CheckVote
;
6647 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6648 if not gVoteInProgress
then Exit
;
6650 if (gTime
>= gVoteTimer
) then
6652 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6653 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6655 Need
:= Floor(NetClientCount
/2.0) + 1;
6656 if gVoteCount
>= Need
then
6658 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6659 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6660 gVotePassed
:= True;
6661 gVoteCmdTimer
:= gTime
+ 5000;
6665 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6666 MH_SEND_VoteEvent(NET_VE_FAILED
);
6668 if NetClients
<> nil then
6669 for I
:= Low(NetClients
) to High(NetClients
) do
6670 if NetClients
[i
].Used
then
6671 NetClients
[i
].Voted
:= False;
6672 gVoteInProgress
:= False;
6678 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6679 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6681 Need
:= Floor(NetClientCount
/2.0) + 1;
6682 if gVoteCount
>= Need
then
6684 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6685 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6686 gVoteInProgress
:= False;
6687 gVotePassed
:= True;
6688 gVoteCmdTimer
:= gTime
+ 5000;
6691 if NetClients
<> nil then
6692 for I
:= Low(NetClients
) to High(NetClients
) do
6693 if NetClients
[i
].Used
then
6694 NetClients
[i
].Voted
:= False;
6699 procedure g_Game_LoadMapList(FileName
: string);
6707 if not FileExists(FileName
) then Exit
;
6709 AssignFile(ListFile
, FileName
);
6711 while not EOF(ListFile
) do
6713 ReadLn(ListFile
, s
);
6716 if s
= '' then Continue
;
6718 SetLength(MapList
, Length(MapList
)+1);
6719 MapList
[High(MapList
)] := s
;
6721 CloseFile(ListFile
);
6724 procedure g_Game_SetDebugMode();
6727 // Читы (даже в своей игре):
6731 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6735 if Length(LoadingStat
.Msgs
) = 0 then
6741 begin // Переходим на следующую строку или скроллируем:
6742 if NextMsg
= Length(Msgs
) then
6744 for i
:= 0 to High(Msgs
)-1 do
6745 Msgs
[i
] := Msgs
[i
+1];
6753 Msgs
[NextMsg
-1] := Text;
6757 PBarWasHere
:= false;
6760 {$IFDEF ENABLE_MENU}
6761 g_ActiveWindow
:= nil;
6764 ProcessLoading(true);
6767 procedure g_Game_StepLoading(Value
: Integer = -1);
6779 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6782 ProcessLoading(False);
6787 procedure g_Game_ClearLoading();
6796 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6797 if len
< 1 then len
:= 1;
6798 SetLength(Msgs
, len
);
6799 for len
:= Low(Msgs
) to High(Msgs
) do
6802 PBarWasHere
:= false;
6806 procedure Parse_Params(var pars
: TParamStrValues
);
6813 while i
<= ParamCount
do
6816 if (Length(s
) > 1) and (s
[1] = '-') then
6818 if (Length(s
) > 2) and (s
[2] = '-') then
6819 begin // Одиночный параметр
6820 SetLength(pars
, Length(pars
) + 1);
6821 with pars
[High(pars
)] do
6823 Name
:= LowerCase(s
);
6828 if (i
< ParamCount
) then
6829 begin // Параметр со значением
6831 SetLength(pars
, Length(pars
) + 1);
6832 with pars
[High(pars
)] do
6834 Name
:= LowerCase(s
);
6835 Value
:= LowerCase(ParamStr(i
));
6844 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6849 for i
:= 0 to High(pars
) do
6850 if pars
[i
].Name
= aName
then
6852 Result
:= pars
[i
].Value
;
6857 procedure g_Game_Process_Params();
6859 pars
: TParamStrValues
;
6862 LimT
, LimS
: Integer;
6873 s
:= Find_Param_Value(pars
, '--debug');
6876 g_Game_SetDebugMode();
6877 s
:= Find_Param_Value(pars
, '--netdump');
6882 // Connect when game loads
6883 ip
:= Find_Param_Value(pars
, '-connect');
6887 s
:= Find_Param_Value(pars
, '-port');
6888 if (s
= '') or not TryStrToInt(s
, Port
) then
6891 s
:= Find_Param_Value(pars
, '-pw');
6893 g_Game_StartClient(ip
, Port
, s
);
6897 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6900 gDefaultMegawadStart
:= s
;
6903 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6904 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6906 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6909 // Start map when game loads:
6910 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6911 if isWadPath(map
) then
6914 s
:= Find_Param_Value(pars
, '-gm');
6915 GMode
:= g_Game_TextToMode(s
);
6916 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6917 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6920 s
:= Find_Param_Value(pars
, '-limt');
6921 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6927 s
:= Find_Param_Value(pars
, '-lims');
6928 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6934 s
:= Find_Param_Value(pars
, '-lives');
6935 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6941 s
:= Find_Param_Value(pars
, '-opt');
6945 Opt
:= StrToIntDef(s
, 0);
6948 s
:= Find_Param_Value(pars
, '--close');
6952 // Override map to test:
6953 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6956 if e_IsValidResourceName(s
) then
6957 e_FindResource(AllMapDirs
, s
);
6958 gTestMap
:= ExpandFileName(s
);
6961 // Delete test map after play:
6962 s
:= Find_Param_Value(pars
, '--testdelete');
6965 //gMapToDelete := MapsDir + map;
6966 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6970 // Delete temporary WAD after play:
6971 s
:= Find_Param_Value(pars
, '--tempdelete');
6972 if (s
<> '') and (gTestMap
<> '') then
6974 gMapToDelete
:= gTestMap
;
6975 gTempDelete
:= True;
6978 // Number of players:
6979 s
:= Find_Param_Value(pars
, '-pl');
6981 n
:= DEFAULT_PLAYERS
6983 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6986 s
:= Find_Param_Value(pars
, '-port');
6987 if (s
= '') or not TryStrToInt(s
, Port
) then
6988 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6990 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6993 // Execute script when game loads:
6994 s
:= Find_Param_Value(pars
, '-exec');
6997 // if not isWadPath(s) then
6998 // s := GameDir + '/' + s;
7003 if IOResult
<> 0 then
7005 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7006 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7010 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
7011 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7016 if IOResult
<> 0 then
7018 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7019 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7023 if Pos('#', s
) <> 1 then // script comment
7024 g_Console_Process(s
, True);
7035 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7036 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7037 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7038 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7040 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7041 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7042 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7043 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7046 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7047 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7050 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7051 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7053 {$IFDEF ENABLE_HOLMES}
7054 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7057 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7059 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7060 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7062 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7063 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7065 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
7066 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
7067 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
7068 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
7069 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7070 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7071 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7072 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7073 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');