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);
122 procedure g_Game_InGameMenu(Show
: Boolean);
124 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
125 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
126 procedure g_Game_Message(Msg
: String; Time
: Word);
127 procedure g_Game_LoadMapList(FileName
: String);
128 procedure g_Game_PauseAllSounds(Enable
: Boolean);
129 procedure g_Game_StopAllSounds(all
: Boolean);
130 procedure g_Game_UpdateTriggerSounds();
131 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
132 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
133 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
134 procedure g_Game_Announce_KillCombo(Param
: Integer);
135 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
136 procedure g_Game_StartVote(Command
, Initiator
: string);
137 procedure g_Game_CheckVote
;
139 procedure g_TakeScreenShot(Filename
: string = '');
141 procedure g_FatalError(Text: String);
142 procedure g_SimpleError(Text: String);
143 function g_Game_IsTestMap(): Boolean;
144 procedure g_Game_DeleteTestMap();
145 procedure GameCVars(P
: SSArray
);
146 procedure PlayerSettingsCVars(P
: SSArray
);
147 procedure SystemCommands(P
: SSArray
);
148 procedure GameCommands(P
: SSArray
);
149 procedure GameCheats(P
: SSArray
);
150 procedure DebugCommands(P
: SSArray
);
151 procedure g_Game_Process_Params
;
152 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
153 procedure g_Game_StepLoading(Value
: Integer = -1);
154 procedure g_Game_ClearLoading();
155 procedure g_Game_SetDebugMode();
157 function IsActivePlayer(p
: TPlayer
): Boolean;
158 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
159 procedure SortGameStat(var stat
: TPlayerStatArray
);
161 procedure KeyPress (K
: Word);
164 procedure CharPress (C
: AnsiChar);
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}
458 r_render
, g_menu
, r_playermodel
, g_system
,
461 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
462 g_playermodel
, g_gfx
, g_options
, Math
,
463 g_triggers
, g_monsters
, e_sound
, CONFIG
,
464 g_language
, g_net
, g_phys
,
465 ENet
, e_msg
, g_netmsg
, g_netmaster
,
469 charbuff
: packed array [0..15] of AnsiChar = (
470 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
473 function Translit (const S
: AnsiString): AnsiString;
478 for i
:= 1 to Length(Result
) do
481 #
$C9: Result
[i
] := 'Q';
482 #
$D6: Result
[i
] := 'W';
483 #
$D3: Result
[i
] := 'E';
484 #
$CA: Result
[i
] := 'R';
485 #
$C5: Result
[i
] := 'T';
486 #
$CD: Result
[i
] := 'Y';
487 #
$C3: Result
[i
] := 'U';
488 #
$D8: Result
[i
] := 'I';
489 #
$D9: Result
[i
] := 'O';
490 #
$C7: Result
[i
] := 'P';
491 #
$D5: Result
[i
] := '['; //Chr(219);
492 #
$DA: Result
[i
] := ']'; //Chr(221);
493 #
$D4: Result
[i
] := 'A';
494 #
$DB: Result
[i
] := 'S';
495 #
$C2: Result
[i
] := 'D';
496 #
$C0: Result
[i
] := 'F';
497 #
$CF: Result
[i
] := 'G';
498 #
$D0: Result
[i
] := 'H';
499 #
$CE: Result
[i
] := 'J';
500 #
$CB: Result
[i
] := 'K';
501 #
$C4: Result
[i
] := 'L';
502 #
$C6: Result
[i
] := ';'; //Chr(186);
503 #
$DD: Result
[i
] := #39; //Chr(222);
504 #
$DF: Result
[i
] := 'Z';
505 #
$D7: Result
[i
] := 'X';
506 #
$D1: Result
[i
] := 'C';
507 #
$CC: Result
[i
] := 'V';
508 #
$C8: Result
[i
] := 'B';
509 #
$D2: Result
[i
] := 'N';
510 #
$DC: Result
[i
] := 'M';
511 #
$C1: Result
[i
] := ','; //Chr(188);
512 #
$DE: Result
[i
] := '.'; //Chr(190);
518 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
523 ls2
:= Translit(CheatRus
[ct
]);
524 if length(ls1
) = 0 then ls1
:= '~';
525 if length(ls2
) = 0 then ls2
:= '~';
527 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
528 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
529 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
530 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
532 if ct = I_GAME_CHEAT_JETPACK then
534 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
535 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
536 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
537 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
538 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
539 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
555 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
556 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
557 or g_Game_IsNet then Exit;
559 if not gGameOn
then exit
;
560 if not conIsCheatsEnabled
then exit
;
562 s
:= 'SOUND_GAME_RADIO';
565 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
567 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
568 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
572 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
574 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
575 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
579 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
581 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
582 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
586 if CheckCheat(I_GAME_CHEAT_DEATH
) then
588 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
589 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
590 s
:= 'SOUND_MONSTER_HAHA';
594 if CheckCheat(I_GAME_CHEAT_DOORS
) then
596 g_Triggers_OpenAll();
600 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
602 if gTriggers
<> nil then
603 for a
:= 0 to High(gTriggers
) do
604 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
606 gExitByTrigger
:= True;
607 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
608 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
614 s2
:= Copy(charbuff
, 15, 2);
615 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
617 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
625 if CheckCheat(I_GAME_CHEAT_FLY
) then
631 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
633 VEL_JUMP
:= 30-VEL_JUMP
;
637 if CheckCheat(I_GAME_CHEAT_SPEED
) then
639 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
643 if CheckCheat(I_GAME_CHEAT_SUIT
) then
645 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
646 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
650 if CheckCheat(I_GAME_CHEAT_AIR
) then
652 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
653 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
657 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
659 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
660 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
664 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
666 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
667 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
671 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
673 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
674 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
678 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
680 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
681 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
685 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
687 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
688 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
691 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
693 gAimLine
:= not gAimLine
;
696 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
698 gShowMap
:= not gShowMap
;
708 procedure KeyPress (K
: Word);
718 if (g_ActiveWindow
<> nil) then
720 Msg
.Msg
:= WM_KEYDOWN
;
721 Msg
.WParam
:= VK_ESCAPE
;
722 g_ActiveWindow
.OnMessage(Msg
);
723 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
725 else if (gState
<> STATE_FOLD
) then
727 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
729 g_Game_InGameMenu(True);
731 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
733 if (gState
<> STATE_MENU
) then
735 if (NetMode
<> NET_NONE
) then
737 g_Game_StopAllSounds(True);
739 gState
:= STATE_MENU
;
743 g_GUI_ShowWindow('MainMenu');
744 g_Sound_PlayEx('MENU_OPEN');
749 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
750 begin // <F2> .. <F6> � <F12>
751 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
753 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
754 if (not g_Game_IsNet
) then g_Game_Pause(True);
756 IK_F2
: g_Menu_Show_SaveMenu();
757 IK_F3
: g_Menu_Show_LoadMenu();
758 IK_F4
: g_Menu_Show_GameSetGame();
759 IK_F5
: g_Menu_Show_OptionsVideo();
760 IK_F6
: g_Menu_Show_OptionsSound();
761 IK_F7
: g_Menu_Show_EndGameMenu();
762 IK_F10
: g_Menu_Show_QuitGameMenu();
769 gJustChatted
:= False;
770 if gConsoleShow
or gChatShow
then
772 g_Console_Control(K
);
774 else if (g_ActiveWindow
<> nil) then
776 Msg
.Msg
:= WM_KEYDOWN
;
778 g_ActiveWindow
.OnMessage(Msg
);
780 else if (gState
= STATE_MENU
) then
782 g_GUI_ShowWindow('MainMenu');
783 g_Sound_PlayEx('MENU_OPEN');
791 procedure CharPress (C
: AnsiChar);
796 if gConsoleShow
or gChatShow
then
800 else if (g_ActiveWindow
<> nil) then
803 Msg
.WParam
:= Ord(C
);
804 g_ActiveWindow
.OnMessage(Msg
);
808 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
809 charbuff
[15] := upcase1251(C
);
816 // ////////////////////////////////////////////////////////////////////////// //
817 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
819 procedure g_ResetDynlights ();
823 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
825 for idx
:= 0 to g_dynLightCount
-1 do
827 if g_dynLights
[idx
].exploCount
= -666 then
834 Inc(g_dynLights
[idx
].exploCount
);
835 if (g_dynLights
[idx
].exploCount
< 10) then
837 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
838 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
839 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
840 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
845 g_dynLightCount
:= lnum
;
848 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
850 if not gwin_has_stencil
then exit
;
851 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
852 g_dynLights
[g_dynLightCount
].x
:= x
;
853 g_dynLights
[g_dynLightCount
].y
:= y
;
854 g_dynLights
[g_dynLightCount
].radius
:= radius
;
855 g_dynLights
[g_dynLightCount
].r
:= r
;
856 g_dynLights
[g_dynLightCount
].g
:= g
;
857 g_dynLights
[g_dynLightCount
].b
:= b
;
858 g_dynLights
[g_dynLightCount
].a
:= a
;
859 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
860 Inc(g_dynLightCount
);
863 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
865 if not gwin_has_stencil
then exit
;
866 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
867 g_dynLights
[g_dynLightCount
].x
:= x
;
868 g_dynLights
[g_dynLightCount
].y
:= y
;
869 g_dynLights
[g_dynLightCount
].radius
:= 0;
870 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
871 g_dynLights
[g_dynLightCount
].r
:= r
;
872 g_dynLights
[g_dynLightCount
].g
:= g
;
873 g_dynLights
[g_dynLightCount
].b
:= b
;
874 g_dynLights
[g_dynLightCount
].a
:= 0;
875 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
876 Inc(g_dynLightCount
);
879 // ////////////////////////////////////////////////////////////////////////// //
880 function conIsCheatsEnabled (): Boolean; inline;
883 if g_Game_IsNet
then exit
;
884 if not gDebugMode
then
886 //if not gCheats then exit;
887 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
888 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
893 // ////////////////////////////////////////////////////////////////////////// //
895 TParamStrValue
= record
900 TParamStrValues
= Array of TParamStrValue
;
903 INTER_ACTION_TEXT
= 1;
904 INTER_ACTION_PIC
= 2;
905 INTER_ACTION_MUSIC
= 3;
910 DataLoaded
: Boolean = False;
912 MapList
: SSArray
= nil;
913 MapIndex
: Integer = -1;
914 InterReadyTime
: Integer = -1;
915 StatDate
: string = '';
930 function Compare(a
, b
: TPlayerStat
): Integer;
932 if a
.Spectator
then Result
:= 1
933 else if b
.Spectator
then Result
:= -1
934 else if a
.Frags
< b
.Frags
then Result
:= 1
935 else if a
.Frags
> b
.Frags
then Result
:= -1
936 else if a
.Deaths
< b
.Deaths
then Result
:= -1
937 else if a
.Deaths
> b
.Deaths
then Result
:= 1
938 else if a
.Kills
< b
.Kills
then Result
:= -1
942 procedure SortGameStat(var stat
: TPlayerStatArray
);
947 if stat
= nil then Exit
;
949 for I
:= High(stat
) downto Low(stat
) do
950 for J
:= Low(stat
) to High(stat
) - 1 do
951 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
954 stat
[J
] := stat
[J
+ 1];
959 // saves a shitty CSV containing the game stats passed to it
960 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
963 dir
, fname
, map
, mode
, etime
: String;
967 dir
:= e_GetWriteableDir(StatsDirs
);
968 // stats are placed in stats/yy/mm/dd/*.csv
969 fname
:= e_CatPath(dir
, Path
);
970 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
971 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
972 AssignFile(s
, fname
);
974 SetTextCodePage(s
, CP_UTF8
);
976 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
977 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
978 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
979 mode
:= g_Game_ModeToText(Stat
.GameMode
);
980 etime
:= Format('%d:%.2d:%.2d', [
981 Stat
.GameTime
div 1000 div 3600,
982 (Stat
.GameTime
div 1000 div 60) mod 60,
983 Stat
.GameTime
div 1000 mod 60
985 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
986 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
992 gGameSettings
.TimeLimit
,
993 gGameSettings
.ScoreLimit
,
994 gGameSettings
.Options
,
996 Length(Stat
.PlayerStat
)
998 // line 2: game specific shit
999 // if it's a team game: red score, blue score
1000 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1001 // otherwise nothing
1002 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1004 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
1005 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1007 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1008 // lines 3-...: team, player name, frags, deaths
1009 WriteLn(s
, 'team,name,frags,deaths');
1010 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1011 with Stat
.PlayerStat
[I
] do
1012 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1014 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1017 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1022 procedure ClearDebugCvars();
1024 g_debug_Sounds
:= False;
1025 g_debug_Frames
:= False;
1026 g_debug_WinMsgs
:= False;
1027 g_debug_MonsterOff
:= False;
1028 g_debug_BotAIOff
:= 0;
1029 g_debug_HealthBar
:= False;
1030 g_Debug_Player
:= False;
1033 function g_Game_ModeToText(Mode
: Byte): string;
1037 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1038 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1039 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1040 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1041 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1045 function g_Game_TextToMode(Mode
: string): Byte;
1048 Mode
:= UpperCase(Mode
);
1049 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1054 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1059 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1064 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1069 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1071 Result
:= GM_SINGLE
;
1076 function g_Game_IsNet(): Boolean;
1078 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1081 function g_Game_IsServer(): Boolean;
1083 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1086 function g_Game_IsClient(): Boolean;
1088 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1091 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1098 Result
.name
:= ExtractFileName(WAD
);
1099 Result
.description
:= '';
1100 Result
.author
:= '';
1102 w
:= TWADFile
.Create();
1105 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1111 cfg
:= TConfig
.CreateMem(p
, len
);
1112 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1113 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1114 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1115 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1121 procedure g_Game_FreeWAD
;
1124 g_Sound_Delete('MUSIC_endmus');
1125 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1126 gGameSettings
.WAD
:= '';
1129 procedure g_Game_LoadWAD(WAD
: string);
1138 gGameSettings
.WAD
:= WAD
;
1139 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1142 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1144 w
:= TWADFile
.Create();
1147 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1153 cfg
:= TConfig
.CreateMem(p
, len
);
1156 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1157 if MegaWAD
.endpic
<> '' then
1158 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1160 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1161 if MegaWAD
.endmus
<> '' then
1163 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1164 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1172 {procedure start_trigger(t: string);
1176 function next_trigger(): Boolean;
1180 procedure DisableCheats();
1186 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1187 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1188 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1189 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1191 {$IF DEFINED(D2F_DEBUG)}
1192 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1193 gAimLine
:= g_dbg_aimline_on
;
1197 procedure g_Game_ExecuteEvent(Name
: String);
1203 if gEvents
= nil then
1205 for a
:= 0 to High(gEvents
) do
1206 if gEvents
[a
].Name
= Name
then
1208 if gEvents
[a
].Command
<> '' then
1209 g_Console_Process(gEvents
[a
].Command
, True);
1214 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1219 if gDelayedEvents
<> nil then
1220 for a
:= 0 to High(gDelayedEvents
) do
1221 if not gDelayedEvents
[a
].Pending
then
1228 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1229 n
:= High(gDelayedEvents
);
1231 gDelayedEvents
[n
].Pending
:= True;
1232 gDelayedEvents
[n
].DEType
:= DEType
;
1233 gDelayedEvents
[n
].DENum
:= Num
;
1234 gDelayedEvents
[n
].DEStr
:= Str
;
1235 if DEType
= DE_GLOBEVENT
then
1236 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1238 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1242 procedure EndGame();
1248 if g_Game_IsNet
and g_Game_IsServer
then
1249 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1252 gPauseMain
:= false;
1253 gPauseHolmes
:= false;
1256 g_Game_StopAllSounds(False);
1261 EndingGameCounter
:= 0;
1264 g_ActiveWindow
:= nil;
1267 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1268 gLMSRespawnTime
:= 0;
1271 EXIT_SIMPLE
: // Выход через меню или конец теста
1275 begin // Это был тест
1279 begin // Выход в главное меню
1281 gState
:= STATE_MENU
; // ???
1283 gMusic
.SetByName('MUSIC_MENU');
1285 if gState
<> STATE_SLIST
then
1287 g_GUI_ShowWindow('MainMenu');
1288 gState
:= STATE_MENU
;
1291 // Обновляем список серверов
1292 slReturnPressed
:= True;
1293 if g_Net_Slist_Fetch(slCurrent
) then
1295 if slCurrent
= nil then
1296 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1299 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1300 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1303 g_Game_ExecuteEvent('ongameend');
1307 EXIT_RESTART
: // Начать уровень сначала
1309 if not g_Game_IsClient
then g_Game_Restart();
1312 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1314 // Статистика Своей игры:
1315 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1317 CustomStat
.GameTime
:= gTime
;
1318 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1319 CustomStat
.MapName
:= gMapInfo
.Name
;
1320 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1321 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1322 CustomStat
.TeamStat
:= gTeamStat
;
1324 CustomStat
.PlayerStat
:= nil;
1326 // Статистика игроков:
1327 if gPlayers
<> nil then
1329 for a
:= 0 to High(gPlayers
) do
1330 if gPlayers
[a
] <> nil then
1332 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1333 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1336 Name
:= gPlayers
[a
].Name
;
1337 Frags
:= gPlayers
[a
].Frags
;
1338 Deaths
:= gPlayers
[a
].Death
;
1339 Kills
:= gPlayers
[a
].Kills
;
1340 Team
:= gPlayers
[a
].Team
;
1341 Color
:= gPlayers
[a
].Model
.Color
;
1342 Spectator
:= gPlayers
[a
].FSpectator
;
1346 SortGameStat(CustomStat
.PlayerStat
);
1348 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1351 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1352 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1353 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1354 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1356 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1359 StatShotDone
:= False;
1362 g_Game_ExecuteEvent('onmapend');
1363 if not g_Game_IsClient
then g_Player_ResetReady
;
1364 gInterReadyCount
:= 0;
1366 // Затухающий экран:
1367 EndingGameCounter
:= 255;
1368 gState
:= STATE_FOLD
;
1370 if gDefInterTime
< 0 then
1371 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1373 gInterEndTime
:= gDefInterTime
* 1000;
1376 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1378 // Статистика Одиночной игры:
1379 SingleStat
.GameTime
:= gTime
;
1380 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1381 SingleStat
.TotalSecrets
:= gSecretsCount
;
1382 // Статистика первого игрока:
1383 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1384 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1385 // Статистика второго игрока (если есть):
1386 if SingleStat
.TwoPlayers
then
1388 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1389 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1392 g_Game_ExecuteEvent('onmapend');
1395 if gNextMap
<> '' then
1397 gMusic
.SetByName('MUSIC_INTERMUS');
1399 gState
:= STATE_INTERSINGLE
;
1402 g_Game_ExecuteEvent('oninter');
1404 else // Больше нет карт
1406 // Затухающий экран:
1407 EndingGameCounter
:= 255;
1408 gState
:= STATE_FOLD
;
1413 // Окончание обработано:
1414 if gExit
<> EXIT_QUIT
then
1418 procedure g_Game_Init();
1422 gTempDelete
:= False;
1424 sfsGCDisable(); // temporary disable removing of temporary volumes
1427 g_Game_ClearLoading();
1428 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1429 g_Game_SetLoadingText('', 0, False);
1431 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1434 gPauseMain
:= false;
1435 gPauseHolmes
:= false;
1438 {e_MouseInfo.Accel := 1.0;}
1440 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1443 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1444 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1445 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1446 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1447 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1449 gMusic
:= TMusic
.Create();
1450 gMusic
.SetByName('MUSIC_MENU');
1453 gGameSettings
.WarmupTime
:= 30;
1455 gState
:= STATE_MENU
;
1457 SetLength(gEvents
, 6);
1458 gEvents
[0].Name
:= 'ongamestart';
1459 gEvents
[1].Name
:= 'ongameend';
1460 gEvents
[2].Name
:= 'onmapstart';
1461 gEvents
[3].Name
:= 'onmapend';
1462 gEvents
[4].Name
:= 'oninter';
1463 gEvents
[5].Name
:= 'onwadend';
1465 sfsGCEnable(); // enable releasing unused volumes
1469 procedure g_Game_Free(freeTextures
: Boolean=true);
1471 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1472 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1474 g_Map_Free(freeTextures
);
1476 g_Player_RemoveAllCorpses();
1478 gGameSettings
.GameType
:= GT_NONE
;
1479 if gGameSettings
.GameMode
= GM_SINGLE
then
1480 gGameSettings
.GameMode
:= GM_DM
;
1481 gSwitchGameMode
:= gGameSettings
.GameMode
;
1484 gExitByTrigger
:= False;
1487 function IsActivePlayer(p
: TPlayer
): Boolean;
1492 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1495 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1501 if gPlayers
= nil then
1505 for a
:= Low(gPlayers
) to High(gPlayers
) do
1506 if IsActivePlayer(gPlayers
[a
]) then
1508 SetLength(ids
, Length(ids
) + 1);
1509 ids
[High(ids
)] := gPlayers
[a
].UID
;
1510 if gPlayers
[a
].UID
= Skip
then
1513 if Length(ids
) = 0 then
1518 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1521 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1527 if gPlayers
= nil then
1531 for a
:= Low(gPlayers
) to High(gPlayers
) do
1532 if IsActivePlayer(gPlayers
[a
]) then
1534 SetLength(ids
, Length(ids
) + 1);
1535 ids
[High(ids
)] := gPlayers
[a
].UID
;
1536 if gPlayers
[a
].UID
= Skip
then
1539 if Length(ids
) = 0 then
1542 Result
:= ids
[Length(ids
) - 1]
1544 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1547 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1553 if gPlayers
= nil then
1557 for a
:= Low(gPlayers
) to High(gPlayers
) do
1558 if IsActivePlayer(gPlayers
[a
]) then
1560 SetLength(ids
, Length(ids
) + 1);
1561 ids
[High(ids
)] := gPlayers
[a
].UID
;
1562 if gPlayers
[a
].UID
= Skip
then
1565 if Length(ids
) = 0 then
1567 if Length(ids
) = 1 then
1572 Result
:= ids
[Random(Length(ids
))];
1574 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1576 Result
:= ids
[Random(Length(ids
))];
1581 function GetRandomSpectMode(Current
: Byte): Byte;
1588 0: Result
:= SPECT_STATS
;
1589 1: Result
:= SPECT_MAPVIEW
;
1590 2: Result
:= SPECT_MAPVIEW
;
1591 3: Result
:= SPECT_PLAYERS
;
1592 4: Result
:= SPECT_PLAYERS
;
1593 5: Result
:= SPECT_PLAYERS
;
1594 6: Result
:= SPECT_PLAYERS
;
1596 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1600 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1606 if (plr
= nil) then exit
;
1607 if (p
= 2) then time
:= 1000 else time
:= 1;
1608 strafeDir
:= MoveButton
shr 4;
1609 MoveButton
:= MoveButton
and $0F;
1611 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1612 MoveButton
:= 1 // Нажата только "Влево"
1613 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1614 MoveButton
:= 2 // Нажата только "Вправо"
1615 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1616 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1618 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1619 if MoveButton
= 1 then
1620 plr
.PressKey(KEY_LEFT
, time
)
1621 else if MoveButton
= 2 then
1622 plr
.PressKey(KEY_RIGHT
, time
);
1624 // if we have "strafe" key, turn off old strafe mechanics
1625 if gPlayerAction
[p
, ACTION_STRAFE
] then
1627 // new strafe mechanics
1628 if (strafeDir
= 0) then
1629 strafeDir
:= MoveButton
; // start strafing
1630 // now set direction according to strafe (reversed)
1631 if (strafeDir
= 2) then
1632 plr
.SetDirection(TDirection
.D_LEFT
)
1633 else if (strafeDir
= 1) then
1634 plr
.SetDirection(TDirection
.D_RIGHT
)
1638 strafeDir
:= 0; // not strafing anymore
1639 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1640 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1641 plr
.SetDirection(TDirection
.D_LEFT
)
1642 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1643 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1644 plr
.SetDirection(TDirection
.D_RIGHT
)
1645 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1646 else if MoveButton
<> 0 then
1647 plr
.SetDirection(TDirection(MoveButton
-1))
1650 // fix movebutton state
1651 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1653 // Остальные клавиши:
1654 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1655 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1656 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1657 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1658 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1660 for i
:= WP_FACT
to WP_LACT
do
1662 if gWeaponAction
[p
, i
] then
1664 plr
.ProcessWeaponAction(i
);
1665 gWeaponAction
[p
, i
] := False
1669 for i
:= WP_FIRST
to WP_LAST
do
1671 if gSelectWeapon
[p
, i
] then
1673 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1674 gSelectWeapon
[p
, i
] := False
1679 // HACK: add dynlight here
1680 if gwin_k8_enable_light_experiments
then
1682 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1684 g_playerLight
:= true;
1686 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1688 g_playerLight
:= false;
1692 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1696 // HACK: don't have a "key was pressed" function
1697 procedure InterReady();
1699 if InterReadyTime
> gTime
then Exit
;
1700 InterReadyTime
:= gTime
+ 3000;
1701 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1704 procedure g_Game_PreUpdate();
1706 // these are in separate PreUpdate functions because they can interact during Update()
1707 // and are synced over the net
1708 // we don't care that much about corpses and gibs
1709 g_Player_PreUpdate();
1710 g_Monsters_PreUpdate();
1711 g_Items_PreUpdate();
1712 g_Weapon_PreUpdate();
1715 procedure g_Game_Update();
1718 Msg
: g_gui
.TMessage
;
1725 function sendMonsPos (mon
: TMonster
): Boolean;
1727 result
:= false; // don't stop
1728 // this will also reset "need-send" flag
1729 if mon
.gncNeedSend
then
1731 MH_SEND_MonsterPos(mon
.UID
);
1733 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1735 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1737 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1739 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1743 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1745 result
:= false; // don't stop
1746 // this will also reset "need-send" flag
1747 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1750 function sendItemPos (it
: PItem
): Boolean;
1752 result
:= false; // don't stop
1755 MH_SEND_ItemPos(it
.myId
);
1756 it
.needSend
:= False;
1761 reliableUpdate
: Boolean;
1766 // Пора выключать игру:
1767 if gExit
= EXIT_QUIT
then
1769 // Игра закончилась - обрабатываем:
1773 if gExit
= EXIT_QUIT
then
1777 // Читаем клавиатуру и джойстик, если окно активно
1778 // no need to, as we'll do it in event handler
1780 // Обновляем консоль (движение и сообщения):
1783 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1785 gExit
:= EXIT_SIMPLE
;
1790 // process master server communications
1791 g_Net_Slist_Pulse();
1794 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1795 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1796 STATE_INTERTEXT
, // Текст между уровнями
1797 STATE_INTERPIC
: // Картинка между уровнями
1799 if g_Game_IsNet
and g_Game_IsServer
then
1801 gInterTime
:= gInterTime
+ GAME_TICK
;
1802 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1803 if a
<> gServInterTime
then
1805 gServInterTime
:= a
;
1806 MH_SEND_TimeSync(gServInterTime
);
1810 if (not g_Game_IsClient
) and
1814 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1815 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1816 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1817 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1819 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1821 and (g_ActiveWindow
= nil)
1824 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1827 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1828 g_Game_StopAllSounds(True);
1830 if gMapOnce
then // Это был тест
1831 gExit
:= EXIT_SIMPLE
1833 if gNextMap
<> '' then // Переходим на следующую карту
1834 g_Game_ChangeMap(gNextMap
)
1835 else // Следующей карты нет
1837 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1839 // Выход в главное меню:
1842 g_GUI_ShowWindow('MainMenu');
1843 gMusic
.SetByName('MUSIC_MENU');
1846 gState
:= STATE_MENU
;
1849 // Финальная картинка:
1850 g_Game_ExecuteEvent('onwadend');
1852 if not gMusic
.SetByName('MUSIC_endmus') then
1853 gMusic
.SetByName('MUSIC_STDENDMUS');
1855 gState
:= STATE_ENDPIC
;
1857 g_Game_ExecuteEvent('ongameend');
1862 else if g_Game_IsClient
and
1865 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1866 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1867 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1868 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1870 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1872 and (g_ActiveWindow
= nil)
1881 if gState
= STATE_INTERTEXT
then
1882 if InterText
.counter
> 0 then
1883 InterText
.counter
:= InterText
.counter
- 1;
1886 STATE_FOLD
: // Затухание экрана
1888 if EndingGameCounter
= 0 then
1890 // Закончился уровень в Своей игре:
1891 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1893 gState
:= STATE_INTERCUSTOM
;
1894 InterReadyTime
:= -1;
1895 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1897 g_Game_ExecuteEvent('onwadend');
1898 if not gMusic
.SetByName('MUSIC_endmus') then
1899 gMusic
.SetByName('MUSIC_STDENDMUS');
1902 gMusic
.SetByName('MUSIC_ROUNDMUS');
1906 else // Закончилась последняя карта в Одиночной игре
1908 gMusic
.SetByName('MUSIC_INTERMUS');
1910 gState
:= STATE_INTERSINGLE
;
1913 g_Game_ExecuteEvent('oninter');
1916 DecMin(EndingGameCounter
, 6, 0);
1919 STATE_ENDPIC
: // Картинка окончания мегаВада
1921 if gMapOnce
then // Это был тест
1923 gExit
:= EXIT_SIMPLE
;
1929 g_Serverlist_Control(slCurrent
, slTable
);
1932 // Статистика по Tab:
1934 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1937 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1939 // Время += 28 миллисекунд:
1940 gTime
:= gTime
+ GAME_TICK
;
1942 // Сообщение посередине экрана:
1943 if MessageTime
= 0 then
1945 if MessageTime
> 0 then
1946 MessageTime
:= MessageTime
- 1;
1948 if (g_Game_IsServer
) then
1950 // Был задан лимит времени:
1951 if (gGameSettings
.TimeLimit
> 0) then
1952 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1953 begin // Он прошел => конец уровня
1958 // Надо респавнить игроков в LMS:
1959 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1960 g_Game_RestartRound(gLMSSoftSpawn
);
1962 // Проверим результат голосования, если время прошло
1963 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1965 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1967 g_Console_Process(gVoteCommand
);
1969 gVotePassed
:= False;
1972 // Замеряем время захвата флагов
1973 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1974 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1975 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1976 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1978 // Был задан лимит побед:
1979 if (gGameSettings
.ScoreLimit
> 0) then
1983 if gGameSettings
.GameMode
= GM_DM
then
1984 begin // В DM ищем игрока с max фрагами
1985 for i
:= 0 to High(gPlayers
) do
1986 if gPlayers
[i
] <> nil then
1987 if gPlayers
[i
].Frags
> b
then
1988 b
:= gPlayers
[i
].Frags
;
1991 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1992 begin // В CTF/TDM выбираем команду с наибольшим счетом
1993 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
1996 // Лимит побед набран => конец уровня:
1997 if b
>= gGameSettings
.ScoreLimit
then
2004 // Обрабатываем клавиши игроков:
2005 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2006 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2008 if (not gConsoleShow
) and (not gChatShow
) then
2010 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2013 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2014 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2015 end // if not console
2018 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2020 // process weapon switch queue
2024 if (gPlayer1
= nil) and (gPlayer2
= nil)
2025 and (not gConsoleShow
) and (not gChatShow
)
2027 and (g_ActiveWindow
= nil)
2031 if not gSpectKeyPress
then
2033 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2035 // switch spect mode
2037 SPECT_NONE
: ; // not spectator
2039 SPECT_MAPVIEW
: Inc(gSpectMode
);
2040 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2042 gSpectKeyPress
:= True;
2044 if (gSpectMode
= SPECT_MAPVIEW
)
2045 and (not gSpectAuto
) then
2047 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2048 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2049 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2050 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2051 if gPlayerAction
[0, ACTION_LOOKUP
] then
2052 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2053 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2054 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2055 if gWeaponAction
[0, WP_PREV
] then
2058 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2059 gWeaponAction
[0, WP_PREV
] := False;
2061 if gWeaponAction
[0, WP_NEXT
] then
2064 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2065 gWeaponAction
[0, WP_NEXT
] := False;
2068 if (gSpectMode
= SPECT_PLAYERS
)
2069 and (not gSpectAuto
) then
2071 if gPlayerAction
[0, ACTION_LOOKUP
] then
2074 gSpectViewTwo
:= True;
2075 gSpectKeyPress
:= True;
2077 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2079 // remove second view
2080 gSpectViewTwo
:= False;
2081 gSpectKeyPress
:= True;
2083 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2085 // prev player (view 1)
2086 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2087 gSpectKeyPress
:= True;
2089 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2091 // next player (view 1)
2092 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2093 gSpectKeyPress
:= True;
2095 if gWeaponAction
[0, WP_PREV
] then
2097 // prev player (view 2)
2098 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2099 gWeaponAction
[0, WP_PREV
] := False;
2101 if gWeaponAction
[0, WP_NEXT
] then
2103 // next player (view 2)
2104 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2105 gWeaponAction
[0, WP_NEXT
] := False;
2108 if gPlayerAction
[0, ACTION_ATTACK
] then
2110 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2113 gSpectAutoNext
:= 0;
2114 gSpectViewTwo
:= False;
2115 gSpectKeyPress
:= True;
2120 gSpectMode
:= SPECT_STATS
;
2121 gSpectAuto
:= False;
2122 gSpectKeyPress
:= True;
2127 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2128 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2129 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2130 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2131 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2132 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2133 gSpectKeyPress
:= False;
2137 if gSpectMode
= SPECT_MAPVIEW
then
2139 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2141 gSpectAutoNext
:= gTime
2144 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2146 gSpectAutoNext
:= gTime
2150 if gSpectAutoNext
<= gTime
then
2152 if gSpectAutoNext
> 0 then
2154 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2158 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2159 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2160 gSpectAutoStepX
:= Random(9) - 4;
2161 gSpectAutoStepY
:= Random(9) - 4;
2162 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2163 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2164 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2165 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2166 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2167 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2171 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2176 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2177 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2178 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2184 // Обновляем все остальное:
2187 g_Triggers_Update();
2189 g_Monsters_Update();
2191 g_Player_UpdateAll();
2192 g_Player_UpdatePhysicalObjects();
2194 // server: send newly spawned monsters unconditionally
2195 if (gGameSettings
.GameType
= GT_SERVER
) then
2197 if (Length(gMonstersSpawned
) > 0) then
2199 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2200 SetLength(gMonstersSpawned
, 0);
2204 if (gSoundTriggerTime
> 8) then
2206 g_Game_UpdateTriggerSounds();
2207 gSoundTriggerTime
:= 0;
2211 Inc(gSoundTriggerTime
);
2214 if (NetMode
= NET_SERVER
) then
2216 Inc(NetTimeToUpdate
);
2217 Inc(NetTimeToReliable
);
2219 // send monster updates
2220 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2222 // send all monsters (periodic sync)
2223 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2225 for I
:= 0 to High(gPlayers
) do
2227 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2230 g_Mons_ForEach(sendMonsPos
);
2232 // update flags that aren't stationary
2233 if gGameSettings
.GameMode
= GM_CTF
then
2234 for I
:= FLAG_RED
to FLAG_BLUE
do
2235 if gFlags
[I
].NeedSend
then
2237 gFlags
[I
].NeedSend
:= False;
2241 // update items that aren't stationary
2242 g_Items_ForEachAlive(sendItemPos
);
2244 if reliableUpdate
then
2246 NetTimeToReliable
:= 0;
2247 NetTimeToUpdate
:= NetUpdateRate
;
2251 NetTimeToUpdate
:= 0;
2256 // send only mosters with some unexpected changes
2257 g_Mons_ForEach(sendMonsPosUnexpected
);
2260 // send unexpected platform changes
2261 g_Map_NetSendInterestingPanels();
2263 g_Net_Slist_ServerUpdate();
2265 if NetUseMaster then
2267 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2269 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2271 NetTimeToMaster := gTime + NetMasterRate;
2276 else if (NetMode
= NET_CLIENT
) then
2278 MC_SEND_PlayerPos();
2280 end; // if gameOn ...
2282 // Активно окно интерфейса - передаем клавиши ему:
2284 if g_ActiveWindow
<> nil then
2286 w
:= e_GetFirstKeyPressed();
2288 if (w
<> IK_INVALID
) then
2290 Msg
.Msg
:= MESSAGE_DIKEY
;
2292 g_ActiveWindow
.OnMessage(Msg
);
2295 // Если оно от этого не закрылось, то обновляем:
2296 if g_ActiveWindow
<> nil then
2297 g_ActiveWindow
.Update();
2299 // Нужно сменить разрешение:
2300 if gResolutionChange
then
2303 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2306 gResolutionChange
:= False;
2307 g_ActiveWindow
:= nil;
2310 // Нужно сменить язык:
2311 if gLanguageChange
then
2313 //e_WriteLog('Read language file', MSG_NOTIFY);
2314 //g_Language_Load(DataDir + gLanguage + '.txt');
2315 g_Language_Set(gLanguage
);
2317 gLanguageChange
:= False;
2321 // Горячая клавиша для вызова меню выхода из игры (F10):
2322 if e_KeyPressed(IK_F10
) and
2324 (not gConsoleShow
) and
2325 (g_ActiveWindow
= nil) then
2329 {$ENDIF} // NOT HEADLESS
2331 Time
:= GetTickCount64() {div 1000};
2333 // Обработка отложенных событий:
2334 if gDelayedEvents
<> nil then
2335 for a
:= 0 to High(gDelayedEvents
) do
2336 if gDelayedEvents
[a
].Pending
and
2338 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2339 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2342 case gDelayedEvents
[a
].DEType
of
2344 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2347 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2351 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2352 if g_Game_IsNet
and g_Game_IsServer
then
2353 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2357 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2359 gDelayedEvents
[a
].Pending
:= False;
2362 // Каждую секунду обновляем счетчик обновлений:
2363 UPSCounter
:= UPSCounter
+ 1;
2364 if Time
- UPSTime
>= 1000 then
2373 g_Weapon_AddDynLights();
2374 g_Items_AddDynLights();
2378 procedure g_Game_LoadChatSounds(Resource
: string);
2381 FileName
, Snd
: string;
2383 len
, cnt
, tags
, i
, j
: Integer;
2386 FileName
:= g_ExtractWadName(Resource
);
2388 WAD
:= TWADFile
.Create();
2389 WAD
.ReadFile(FileName
);
2391 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2398 cfg
:= TConfig
.CreateMem(p
, len
);
2399 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2401 SetLength(gChatSounds
, cnt
);
2402 for i
:= 0 to Length(gChatSounds
) - 1 do
2404 gChatSounds
[i
].Sound
:= nil;
2405 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2406 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2407 if (Snd
= '') or (Tags
<= 0) then
2409 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2410 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2411 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2412 SetLength(gChatSounds
[i
].Tags
, tags
);
2413 for j
:= 0 to tags
- 1 do
2414 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2415 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2422 procedure g_Game_FreeChatSounds();
2426 for i
:= 0 to Length(gChatSounds
) - 1 do
2428 gChatSounds
[i
].Sound
.Free();
2429 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2431 SetLength(gChatSounds
, 0);
2435 procedure g_Game_LoadData();
2437 if DataLoaded
then Exit
;
2439 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2441 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2442 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2443 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2444 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2445 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2446 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2447 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2448 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2449 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2450 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2451 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2452 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2453 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2454 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2455 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2456 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2457 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2458 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2459 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2460 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2461 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2462 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2463 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2464 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2465 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2466 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2467 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2468 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2469 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2470 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2471 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2472 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2474 goodsnd
[0] := TPlayableSound
.Create();
2475 goodsnd
[1] := TPlayableSound
.Create();
2476 goodsnd
[2] := TPlayableSound
.Create();
2477 goodsnd
[3] := TPlayableSound
.Create();
2479 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2480 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2481 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2482 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2484 killsnd
[0] := TPlayableSound
.Create();
2485 killsnd
[1] := TPlayableSound
.Create();
2486 killsnd
[2] := TPlayableSound
.Create();
2487 killsnd
[3] := TPlayableSound
.Create();
2489 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2490 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2491 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2492 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2494 hahasnd
[0] := TPlayableSound
.Create();
2495 hahasnd
[1] := TPlayableSound
.Create();
2496 hahasnd
[2] := TPlayableSound
.Create();
2498 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2499 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2500 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2502 sound_get_flag
[0] := TPlayableSound
.Create();
2503 sound_get_flag
[1] := TPlayableSound
.Create();
2504 sound_lost_flag
[0] := TPlayableSound
.Create();
2505 sound_lost_flag
[1] := TPlayableSound
.Create();
2506 sound_ret_flag
[0] := TPlayableSound
.Create();
2507 sound_ret_flag
[1] := TPlayableSound
.Create();
2508 sound_cap_flag
[0] := TPlayableSound
.Create();
2509 sound_cap_flag
[1] := TPlayableSound
.Create();
2511 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2512 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2513 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2514 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2515 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2516 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2517 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2518 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2520 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2522 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2525 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2526 g_Weapon_LoadData();
2528 g_Monsters_LoadData();
2533 procedure g_Game_Quit();
2535 g_Game_StopAllSounds(True);
2538 g_PlayerModel_FreeData();
2540 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2543 if NetInitDone
then g_Net_Free
;
2545 // remove map after test
2546 if gMapToDelete
<> '' then
2547 g_Game_DeleteTestMap();
2556 procedure g_Game_FreeData();
2558 if not DataLoaded
then Exit
;
2561 g_Weapon_FreeData();
2562 g_Monsters_FreeData();
2564 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2566 g_Sound_Delete('SOUND_GAME_TELEPORT');
2567 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2568 g_Sound_Delete('SOUND_GAME_SECRET');
2569 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2570 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2571 g_Sound_Delete('SOUND_GAME_BULK1');
2572 g_Sound_Delete('SOUND_GAME_BULK2');
2573 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2574 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2575 g_Sound_Delete('SOUND_GAME_BURNING');
2576 g_Sound_Delete('SOUND_GAME_SWITCH1');
2577 g_Sound_Delete('SOUND_GAME_SWITCH0');
2584 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2585 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2586 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2587 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2594 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2595 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2596 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2597 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2603 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2604 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2605 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2607 sound_get_flag
[0].Free();
2608 sound_get_flag
[1].Free();
2609 sound_lost_flag
[0].Free();
2610 sound_lost_flag
[1].Free();
2611 sound_ret_flag
[0].Free();
2612 sound_ret_flag
[1].Free();
2613 sound_cap_flag
[0].Free();
2614 sound_cap_flag
[1].Free();
2616 g_Sound_Delete('SOUND_CTF_GET1');
2617 g_Sound_Delete('SOUND_CTF_GET2');
2618 g_Sound_Delete('SOUND_CTF_LOST1');
2619 g_Sound_Delete('SOUND_CTF_LOST2');
2620 g_Sound_Delete('SOUND_CTF_RETURN1');
2621 g_Sound_Delete('SOUND_CTF_RETURN2');
2622 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2623 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2625 g_Game_FreeChatSounds();
2627 DataLoaded
:= False;
2630 procedure g_FatalError(Text: String);
2632 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2633 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2635 gExit
:= EXIT_SIMPLE
;
2636 if gGameOn
then EndGame
;
2639 procedure g_SimpleError(Text: String);
2641 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2642 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2645 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2647 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2648 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2651 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2654 if gPlayer1
= nil then
2656 if g_Game_IsClient
then
2658 if NetPlrUID1
> -1 then
2659 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2663 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2664 Team
:= gPlayer1Settings
.Team
;
2666 // Создание первого игрока:
2667 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2668 gPlayer1Settings
.Color
,
2670 if gPlayer1
= nil then
2671 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2674 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2675 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2676 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2677 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2678 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2679 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2680 if g_Game_IsServer
and g_Game_IsNet
then
2681 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2682 gPlayer1
.Respawn(False, True);
2683 g_Net_Slist_ServerPlayerComes();
2688 if gPlayer2
= nil then
2690 if g_Game_IsClient
then
2692 if NetPlrUID2
> -1 then
2693 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2697 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2698 Team
:= gPlayer2Settings
.Team
;
2700 // Создание второго игрока:
2701 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2702 gPlayer2Settings
.Color
,
2704 if gPlayer2
= nil then
2705 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2708 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2709 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2710 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2711 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2712 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2713 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2714 if g_Game_IsServer
and g_Game_IsNet
then
2715 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2716 gPlayer2
.Respawn(False, True);
2717 g_Net_Slist_ServerPlayerComes();
2724 procedure g_Game_RemovePlayer();
2728 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2729 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2734 if g_Game_IsServer
then
2737 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2738 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2739 g_Player_Remove(Pl
.UID
);
2740 g_Net_Slist_ServerPlayerLeaves();
2744 gSpectLatchPID2
:= Pl
.UID
;
2752 if g_Game_IsServer
then
2755 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2756 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2757 g_Player_Remove(Pl
.UID
);
2758 g_Net_Slist_ServerPlayerLeaves();
2761 gSpectLatchPID1
:= Pl
.UID
;
2763 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2767 g_Net_Slist_ServerPlayerLeaves();
2770 procedure g_Game_Spectate();
2772 g_Game_RemovePlayer();
2773 if gPlayer1
<> nil then
2774 g_Game_RemovePlayer();
2777 procedure g_Game_SpectateCenterView();
2779 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2780 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2783 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2790 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2792 g_Game_ClearLoading();
2795 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2798 gGameSettings
.GameType
:= GT_SINGLE
;
2799 gGameSettings
.MaxLives
:= 0;
2800 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2801 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2802 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2803 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2804 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2805 gSwitchGameMode
:= GM_SINGLE
;
2807 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2808 gLMSRespawnTime
:= 0;
2809 gSpectLatchPID1
:= 0;
2810 gSpectLatchPID2
:= 0;
2812 g_Game_ExecuteEvent('ongamestart');
2814 // Создание первого игрока:
2815 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2816 gPlayer1Settings
.Color
,
2817 gPlayer1Settings
.Team
, False));
2818 if gPlayer1
= nil then
2820 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2824 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2825 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2826 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2827 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2828 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2831 // Создание второго игрока, если есть:
2834 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2835 gPlayer2Settings
.Color
,
2836 gPlayer2Settings
.Team
, False));
2837 if gPlayer2
= nil then
2839 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2843 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2844 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2845 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2846 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2847 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2851 // Загрузка и запуск карты:
2852 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2854 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2855 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2859 // Настройки игроков и ботов:
2863 for i
:= nPl
+1 to nPlayers
do
2864 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2867 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2868 TimeLimit
, ScoreLimit
: Word;
2870 Options
: LongWord; nPlayers
: Byte);
2876 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2878 g_Game_ClearLoading();
2881 gGameSettings
.GameType
:= GT_CUSTOM
;
2882 gGameSettings
.GameMode
:= GameMode
;
2883 gSwitchGameMode
:= GameMode
;
2884 gGameSettings
.TimeLimit
:= TimeLimit
;
2885 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2886 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2887 gGameSettings
.Options
:= Options
;
2889 gCoopTotalMonstersKilled
:= 0;
2890 gCoopTotalSecretsFound
:= 0;
2891 gCoopTotalMonsters
:= 0;
2892 gCoopTotalSecrets
:= 0;
2896 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2897 gLMSRespawnTime
:= 0;
2898 gSpectLatchPID1
:= 0;
2899 gSpectLatchPID2
:= 0;
2901 g_Game_ExecuteEvent('ongamestart');
2903 // Режим наблюдателя:
2904 if nPlayers
= 0 then
2911 if nPlayers
>= 1 then
2913 // Создание первого игрока:
2914 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2915 gPlayer1Settings
.Color
,
2916 gPlayer1Settings
.Team
, False));
2917 if gPlayer1
= nil then
2919 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2923 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2924 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2925 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2926 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2927 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2931 if nPlayers
>= 2 then
2933 // Создание второго игрока:
2934 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2935 gPlayer2Settings
.Color
,
2936 gPlayer2Settings
.Team
, False));
2937 if gPlayer2
= nil then
2939 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2943 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2944 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2945 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2946 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2947 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2951 // Загрузка и запуск карты:
2952 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
2954 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2958 // Нет точек появления:
2959 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2960 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2961 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2962 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2963 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2965 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2969 // Настройки игроков и ботов:
2973 for i
:= nPl
+1 to nPlayers
do
2974 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2977 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
2978 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
2979 Options
: LongWord; nPlayers
: Byte;
2980 IPAddr
: LongWord; Port
: Word);
2983 g_Net_Slist_ServerClosed();
2985 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
2987 g_Game_ClearLoading();
2992 gGameSettings
.GameType
:= GT_SERVER
;
2993 gGameSettings
.GameMode
:= GameMode
;
2994 gSwitchGameMode
:= GameMode
;
2995 gGameSettings
.TimeLimit
:= TimeLimit
;
2996 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2997 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2998 gGameSettings
.Options
:= Options
;
3000 gCoopTotalMonstersKilled
:= 0;
3001 gCoopTotalSecretsFound
:= 0;
3002 gCoopTotalMonsters
:= 0;
3003 gCoopTotalSecrets
:= 0;
3007 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3008 gLMSRespawnTime
:= 0;
3009 gSpectLatchPID1
:= 0;
3010 gSpectLatchPID2
:= 0;
3012 g_Game_ExecuteEvent('ongamestart');
3014 // Режим наблюдателя:
3015 if nPlayers
= 0 then
3021 if nPlayers
>= 1 then
3023 // Создание первого игрока:
3024 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3025 gPlayer1Settings
.Color
,
3026 gPlayer1Settings
.Team
, False));
3027 if gPlayer1
= nil then
3029 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3033 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3034 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3035 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3036 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3037 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3040 if nPlayers
>= 2 then
3042 // Создание второго игрока:
3043 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3044 gPlayer2Settings
.Color
,
3045 gPlayer2Settings
.Team
, False));
3046 if gPlayer2
= nil then
3048 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3052 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3053 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3054 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3055 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3056 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3059 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3060 if NetForwardPorts
then
3061 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3064 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3066 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3070 g_Net_Slist_Set(NetMasterList
);
3072 g_Net_Slist_ServerStarted();
3074 // Загрузка и запуск карты:
3075 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3077 g_Net_Slist_ServerClosed();
3078 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3082 // Нет точек появления:
3083 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3084 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3085 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3086 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3087 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3089 g_Net_Slist_ServerClosed();
3090 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3094 // Настройки игроков и ботов:
3097 g_Net_Slist_ServerMapStarted();
3098 NetState
:= NET_STATE_GAME
;
3101 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3116 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3117 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3119 g_Game_ClearLoading();
3124 gGameSettings
.GameType
:= GT_CLIENT
;
3126 gCoopTotalMonstersKilled
:= 0;
3127 gCoopTotalSecretsFound
:= 0;
3128 gCoopTotalMonsters
:= 0;
3129 gCoopTotalSecrets
:= 0;
3133 g_Game_ExecuteEvent('ongamestart');
3135 NetState
:= NET_STATE_AUTH
;
3137 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3139 // create (or update) map/resource databases
3140 g_Res_CreateDatabases(true);
3142 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3143 gLMSRespawnTime
:= 0;
3144 gSpectLatchPID1
:= 0;
3145 gSpectLatchPID2
:= 0;
3148 if not g_Net_Connect(Addr
, Port
) then
3150 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3151 NetState
:= NET_STATE_NONE
;
3155 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3157 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3162 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3163 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3164 // thank you, enet. let's ignore failures altogether then.
3165 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3167 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3169 Ptr
:= NetEvent
.packet
^.data
;
3170 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3172 enet_packet_destroy(NetEvent
.packet
);
3176 InMsg
.ReadLongWord(); // skip size
3177 MID
:= InMsg
.ReadByte();
3179 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3181 NetMyID
:= InMsg
.ReadByte();
3182 NetPlrUID1
:= InMsg
.ReadWord();
3184 WadName
:= InMsg
.ReadString();
3185 Map
:= InMsg
.ReadString();
3187 gWADHash
:= InMsg
.ReadMD5();
3189 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3190 gSwitchGameMode
:= gGameSettings
.GameMode
;
3191 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3192 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3193 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3194 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3195 T
:= InMsg
.ReadLongWord();
3197 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3198 //if newResPath = '' then
3200 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3201 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3202 if newResPath
= '' then
3204 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3205 enet_packet_destroy(NetEvent
.packet
);
3206 NetState
:= NET_STATE_NONE
;
3209 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3211 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3214 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3215 gPlayer1Settings
.Color
,
3216 gPlayer1Settings
.Team
, False));
3218 if gPlayer1
= nil then
3220 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3222 enet_packet_destroy(NetEvent
.packet
);
3223 NetState
:= NET_STATE_NONE
;
3227 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3228 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3229 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3230 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3231 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3232 gPlayer1
.UID
:= NetPlrUID1
;
3233 gPlayer1
.Reset(True);
3235 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3237 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3239 enet_packet_destroy(NetEvent
.packet
);
3240 NetState
:= NET_STATE_NONE
;
3248 enet_packet_destroy(NetEvent
.packet
);
3252 enet_packet_destroy(NetEvent
.packet
);
3256 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3259 if (NetEvent
.data
<= NET_DISC_MAX
) then
3260 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3261 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3268 ProcessLoading(True);
3269 if g_Net_UserRequestExit() then
3278 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3279 NetState
:= NET_STATE_NONE
;
3284 NetState
:= NET_STATE_GAME
;
3285 MC_SEND_FullStateRequest
;
3286 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3290 lastAsMegaWad
: Boolean = false;
3292 procedure g_Game_ChangeMap(const MapPath
: String);
3296 g_Game_ClearLoading();
3298 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3299 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3300 if gExitByTrigger
then
3303 gExitByTrigger
:= False;
3305 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3306 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3309 procedure g_Game_Restart();
3313 if g_Game_IsClient
then
3315 map
:= g_ExtractFileName(gMapInfo
.Map
);
3316 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3320 g_Game_ClearLoading();
3321 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3324 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3326 NewWAD
, ResName
: String;
3330 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3331 g_Player_RemoveAllCorpses();
3333 if (not g_Game_IsClient
) and
3334 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3335 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3337 if gSwitchGameMode
= GM_CTF
then
3338 gGameSettings
.MaxLives
:= 0;
3339 gGameSettings
.GameMode
:= gSwitchGameMode
;
3342 gSwitchGameMode
:= gGameSettings
.GameMode
;
3344 g_Player_ResetTeams();
3346 lastAsMegaWad
:= asMegawad
;
3347 if isWadPath(Map
) then
3349 NewWAD
:= g_ExtractWadName(Map
);
3350 ResName
:= g_ExtractFileName(Map
);
3351 if g_Game_IsServer
then
3353 nws
:= findDiskWad(NewWAD
);
3354 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3357 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3358 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3362 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3363 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3365 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3366 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3368 if (length(nws
) = 0) then
3370 ResName
:= ''; // failed
3375 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3376 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3377 g_Game_LoadWAD(NewWAD
);
3382 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3383 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3388 NewWAD
:= gGameSettings
.WAD
;
3394 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3396 if (ResName
<> '') and (NewWAD
<> '') then
3398 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3399 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3401 r_Render_LoadTextures
;
3406 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3408 gState
:= STATE_NONE
;
3410 g_ActiveWindow
:= nil;
3415 wNeedTimeReset
:= True;
3417 if gGameSettings
.GameMode
= GM_CTF
then
3419 g_Map_ResetFlag(FLAG_RED
);
3420 g_Map_ResetFlag(FLAG_BLUE
);
3421 // CTF, а флагов нет:
3422 if not g_Map_HaveFlagPoints() then
3423 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3428 gState
:= STATE_MENU
;
3433 gPauseMain
:= false;
3434 gPauseHolmes
:= false;
3435 NetTimeToUpdate
:= 1;
3436 NetTimeToReliable
:= 0;
3437 NetTimeToMaster
:= NetMasterRate
;
3438 gSpectLatchPID1
:= 0;
3439 gSpectLatchPID2
:= 0;
3440 gMissionFailed
:= False;
3443 gCoopMonstersKilled
:= 0;
3444 gCoopSecretsFound
:= 0;
3446 gVoteInProgress
:= False;
3447 gVotePassed
:= False;
3453 if not gGameOn
then Exit
;
3455 g_Game_SpectateCenterView();
3457 if g_Game_IsServer
then
3459 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3461 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3462 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3463 gLMSSoftSpawn
:= True;
3464 if g_Game_IsNet
then
3465 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3469 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3470 gLMSRespawnTime
:= 0;
3474 if NetMode
= NET_SERVER
then
3476 // reset full state flags
3477 if NetClients
<> nil then
3478 for I
:= 0 to High(NetClients
) do
3479 NetClients
[I
].FullUpdateSent
:= False;
3481 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3484 g_Net_Slist_ServerMapStarted();
3486 if NetClients
<> nil then
3487 for I
:= 0 to High(NetClients
) do
3488 if NetClients
[I
].Used
then
3490 NetClients
[I
].Voted
:= False;
3491 if NetClients
[I
].RequestedFullUpdate
then
3493 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3494 NetClients
[I
].RequestedFullUpdate
:= False;
3498 g_Net_UnbanNonPermHosts();
3503 gCoopTotalMonstersKilled
:= 0;
3504 gCoopTotalSecretsFound
:= 0;
3505 gCoopTotalMonsters
:= 0;
3506 gCoopTotalSecrets
:= 0;
3510 g_Game_ExecuteEvent('onmapstart');
3513 procedure SetFirstLevel
;
3517 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3518 if MapList
= nil then
3521 SortSArray(MapList
);
3522 gNextMap
:= MapList
[Low(MapList
)];
3527 procedure g_Game_ExitLevel(const Map
: AnsiString);
3531 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3532 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3533 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3534 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3536 // Вышли в выход в Одиночной игре:
3537 if gGameSettings
.GameType
= GT_SINGLE
then
3538 gExit
:= EXIT_ENDLEVELSINGLE
3539 else // Вышли в выход в Своей игре
3541 gExit
:= EXIT_ENDLEVELCUSTOM
;
3542 if gGameSettings
.GameMode
= GM_COOP
then
3543 g_Player_RememberAll
;
3545 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3548 if gGameSettings
.GameMode
= GM_COOP
then
3551 gStatsPressed
:= True;
3552 gNextMap
:= 'MAP01';
3554 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3557 if g_Game_IsNet
then
3559 MH_SEND_GameStats();
3560 MH_SEND_CoopStats();
3566 procedure g_Game_RestartLevel();
3570 if gGameSettings
.GameMode
= GM_SINGLE
then
3575 gExit
:= EXIT_ENDLEVELCUSTOM
;
3576 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3580 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3582 gWAD
{, xwad}: String;
3585 if not g_Game_IsClient
then Exit
;
3586 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3588 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3593 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3597 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3600 g_Game_LoadWAD(NewWAD
);
3604 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3605 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3608 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3609 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3613 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3617 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3618 g_Game_LoadWAD(NewWAD);
3622 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3624 i
, n
, nb
, nr
: Integer;
3626 if not g_Game_IsServer
then Exit
;
3627 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3628 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3629 gLMSRespawnTime
:= 0;
3632 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3634 gMissionFailed
:= True;
3635 g_Game_RestartLevel
;
3639 n
:= 0; nb
:= 0; nr
:= 0;
3640 for i
:= Low(gPlayers
) to High(gPlayers
) do
3641 if (gPlayers
[i
] <> nil) and
3642 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3643 (gPlayers
[i
] is TBot
)) then
3646 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3647 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3650 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3652 // wait a second until the fuckers finally decide to join
3653 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3654 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3655 gLMSSoftSpawn
:= NoMapRestart
;
3656 if g_Game_IsNet
then
3657 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3661 g_Player_RemoveAllCorpses
;
3662 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3663 if g_Game_IsNet
then
3664 MH_SEND_GameEvent(NET_EV_LMS_START
);
3666 for i
:= Low(gPlayers
) to High(gPlayers
) do
3668 if gPlayers
[i
] = nil then continue
;
3669 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3670 // don't touch normal spectators
3671 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3673 gPlayers
[i
].FNoRespawn
:= True;
3674 gPlayers
[i
].Lives
:= 0;
3675 if g_Game_IsNet
then
3676 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3679 gPlayers
[i
].FNoRespawn
:= False;
3680 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3681 gPlayers
[i
].Respawn(False, True);
3682 if gGameSettings
.GameMode
= GM_COOP
then
3684 gPlayers
[i
].Frags
:= 0;
3685 gPlayers
[i
].RecallState
;
3687 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3688 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3689 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3690 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3693 g_Items_RestartRound();
3695 gLMSSoftSpawn
:= False;
3698 function g_Game_GetFirstMap(WAD
: String): String;
3702 MapList
:= g_Map_GetMapsList(WAD
);
3703 if MapList
= nil then
3706 SortSArray(MapList
);
3707 Result
:= MapList
[Low(MapList
)];
3709 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3715 function g_Game_GetNextMap(): String;
3722 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3723 if MapList
= nil then
3726 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3728 SortSArray(MapList
);
3730 for I
:= Low(MapList
) to High(MapList
) do
3731 if Map
= MapList
[I
] then
3737 if MapIndex
<> -255 then
3739 if MapIndex
= High(MapList
) then
3740 Result
:= MapList
[Low(MapList
)]
3742 Result
:= MapList
[MapIndex
+ 1];
3744 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3750 procedure g_Game_NextLevel();
3752 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3753 gExit
:= EXIT_ENDLEVELCUSTOM
3756 gExit
:= EXIT_ENDLEVELSINGLE
;
3760 if gNextMap
<> '' then Exit
;
3761 gNextMap
:= g_Game_GetNextMap();
3764 function g_Game_IsTestMap(): Boolean;
3766 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3769 procedure g_Game_DeleteTestMap();
3772 //MapName: AnsiString;
3780 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3781 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3782 if (a
= 0) then exit
;
3784 // Выделяем имя wad-файла и имя карты
3785 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3786 Delete(gMapToDelete
, 1, a
+5);
3787 gMapToDelete
:= UpperCase(gMapToDelete
);
3789 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3792 // Имя карты не стандартное тестовое:
3793 if MapName <> TEST_MAP_NAME then
3796 if not gTempDelete then
3798 time := g_GetFileTime(WadName);
3799 WAD := TWADFile.Create();
3802 if not WAD.ReadFile(WadName) then
3803 begin // Нет такого WAD-файла
3808 // Составляем список карт и ищем нужную:
3810 MapList := WAD.GetResourcesList('');
3812 if MapList <> nil then
3813 for a := 0 to High(MapList) do
3814 if MapList[a] = MapName then
3816 // Удаляем и сохраняем:
3817 WAD.RemoveResource('', MapName);
3818 WAD.SaveTo(WadName);
3823 g_SetFileTime(WadName, time);
3826 if gTempDelete
then DeleteFile(WadName
);
3829 procedure GameCVars(P
: SSArray
);
3832 stat
: TPlayerStatArray
;
3835 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3839 if Length(P
) > 1 then
3844 gsGameFlags
:= gsGameFlags
or Flag
3846 gsGameFlags
:= gsGameFlags
and (not Flag
);
3848 if g_Game_IsServer
then
3851 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3853 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3854 if g_Game_IsNet
then MH_SEND_GameSettings
;
3858 if LongBool(gsGameFlags
and Flag
) then
3859 g_Console_Add(_lc
[OnMsg
])
3861 g_Console_Add(_lc
[OffMsg
]);
3863 if OnMapChange
and g_Game_IsServer
then
3864 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3869 cmd
:= LowerCase(P
[0]);
3871 if cmd
= 'g_gamemode' then
3873 if (Length(P
) > 1) then
3875 a
:= g_Game_TextToMode(P
[1]);
3876 if a
= GM_SINGLE
then a
:= GM_COOP
;
3877 gsGameMode
:= g_Game_ModeToText(a
);
3878 if g_Game_IsServer
then
3880 gSwitchGameMode
:= a
;
3881 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3882 (gState
= STATE_INTERSINGLE
) then
3883 gSwitchGameMode
:= GM_SINGLE
;
3885 gGameSettings
.GameMode
:= gSwitchGameMode
;
3889 if gSwitchGameMode
= gGameSettings
.GameMode
then
3890 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3891 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3893 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3894 [g_Game_ModeToText(gGameSettings
.GameMode
),
3895 g_Game_ModeToText(gSwitchGameMode
)]));
3897 else if cmd
= 'g_friendlyfire' then
3899 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3901 else if cmd
= 'g_friendly_absorb_damage' then
3903 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
3905 else if cmd
= 'g_friendly_hit_trace' then
3907 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
3909 else if cmd
= 'g_friendly_hit_projectile' then
3911 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
3913 else if cmd
= 'g_weaponstay' then
3915 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3917 else if cmd
= 'g_allow_exit' then
3919 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3921 else if cmd
= 'g_allow_monsters' then
3923 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3925 else if cmd
= 'g_allow_dropflag' then
3927 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
3929 else if cmd
= 'g_throw_flag' then
3931 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
3933 else if cmd
= 'g_bot_vsplayers' then
3935 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3937 else if cmd
= 'g_bot_vsmonsters' then
3939 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3941 else if cmd
= 'g_dm_keys' then
3943 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
3945 else if cmd
= 'g_gameflags' then
3947 if Length(P
) > 1 then
3949 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
3950 if g_Game_IsServer
then
3952 gGameSettings
.Options
:= gsGameFlags
;
3953 if g_Game_IsNet
then MH_SEND_GameSettings
;
3957 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
3959 else if cmd
= 'g_warmup_time' then
3961 if Length(P
) > 1 then
3963 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
3964 if g_Game_IsServer
then
3966 gGameSettings
.WarmupTime
:= gsWarmupTime
;
3967 // extend warmup if it's already going
3968 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
3970 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
3971 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3973 if g_Game_IsNet
then MH_SEND_GameSettings
;
3977 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
3978 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3980 else if cmd
= 'g_spawn_invul' then
3982 if Length(P
) > 1 then
3984 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
3985 if g_Game_IsServer
then
3987 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
3988 if g_Game_IsNet
then MH_SEND_GameSettings
;
3992 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
3994 else if cmd
= 'g_item_respawn_time' then
3996 if Length(P
) > 1 then
3998 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
3999 if g_Game_IsServer
then
4001 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4002 if g_Game_IsNet
then MH_SEND_GameSettings
;
4006 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4007 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4009 else if cmd
= 'sv_intertime' then
4011 if (Length(P
) > 1) then
4012 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4014 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4016 else if cmd
= 'g_max_particles' then
4018 if Length(p
) = 2 then
4020 a
:= Max(0, StrToIntDef(p
[1], 0));
4023 else if Length(p
) = 1 then
4025 e_LogWritefln('%s', [g_GFX_GetMax()])
4029 e_LogWritefln('usage: %s <n>', [cmd
])
4032 else if cmd
= 'g_max_shells' then
4034 if Length(p
) = 2 then
4036 a
:= Max(0, StrToIntDef(p
[1], 0));
4039 else if Length(p
) = 1 then
4041 e_LogWritefln('%s', [g_Shells_GetMax()])
4045 e_LogWritefln('usage: %s <n>', [cmd
])
4048 else if cmd
= 'g_max_gibs' then
4050 if Length(p
) = 2 then
4052 a
:= Max(0, StrToIntDef(p
[1], 0));
4055 else if Length(p
) = 1 then
4057 e_LogWritefln('%s', [g_Gibs_GetMax()])
4061 e_LogWritefln('usage: %s <n>', [cmd
])
4064 else if cmd
= 'g_max_corpses' then
4066 if Length(p
) = 2 then
4068 a
:= Max(0, StrToIntDef(p
[1], 0));
4071 else if Length(p
) = 1 then
4073 e_LogWritefln('%s', [g_Corpses_GetMax()])
4077 e_LogWritefln('usage: %s <n>', [cmd
])
4080 else if cmd
= 'g_force_model' then
4082 if Length(p
) = 2 then
4084 a
:= StrToIntDef(p
[1], 0);
4085 g_Force_Model_Set(a
);
4086 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4088 for a
:= Low(gPlayers
) to High(gPlayers
) do
4090 if (gPlayers
[a
] <> nil) then
4092 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4094 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4096 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4100 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4102 for a
:= Low(gPlayers
) to High(gPlayers
) do
4104 if (gPlayers
[a
] <> nil) then
4106 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4108 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4110 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4116 else if cmd
= 'g_force_model_name' then
4118 if (Length(P
) > 1) then
4120 cmd
:= b_Text_Unformat(P
[1]);
4121 g_Forced_Model_SetName(cmd
);
4122 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4124 for a
:= Low(gPlayers
) to High(gPlayers
) do
4126 if (gPlayers
[a
] <> nil) then
4128 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4130 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4132 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4138 else if cmd
= 'g_scorelimit' then
4140 if Length(P
) > 1 then
4142 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4144 if g_Game_IsServer
then
4147 if gGameSettings
.GameMode
= GM_DM
then
4149 stat
:= g_Player_GetStats();
4151 for a
:= 0 to High(stat
) do
4152 if stat
[a
].Frags
> b
then
4156 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4158 // if someone has a higher score, set it to that instead
4159 gsScoreLimit
:= max(gsScoreLimit
, b
);
4160 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4162 if g_Game_IsNet
then MH_SEND_GameSettings
;
4166 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4168 else if cmd
= 'g_timelimit' then
4170 if Length(P
) > 1 then
4172 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4173 if g_Game_IsServer
then
4175 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4176 if g_Game_IsNet
then MH_SEND_GameSettings
;
4179 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4180 [gsTimeLimit
div 3600,
4181 (gsTimeLimit
div 60) mod 60,
4182 gsTimeLimit
mod 60]));
4184 else if cmd
= 'g_max_bots' then
4186 if Length(P
) > 1 then
4187 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4188 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4190 else if cmd
= 'g_maxlives' then
4192 if Length(P
) > 1 then
4194 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4195 if g_Game_IsServer
then
4197 gGameSettings
.MaxLives
:= gsMaxLives
;
4198 if g_Game_IsNet
then MH_SEND_GameSettings
;
4202 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4206 procedure PlayerSettingsCVars(P
: SSArray
);
4211 function ParseTeam(s
: string): Byte;
4215 'red', '1': result
:= TEAM_RED
;
4216 'blue', '2': result
:= TEAM_BLUE
;
4217 else result
:= TEAM_NONE
;
4221 cmd
:= LowerCase(P
[0]);
4225 if (Length(P
) > 1) then
4227 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4228 if g_Game_IsClient
then
4229 MC_SEND_PlayerSettings
4230 else if gGameOn
and (gPlayer1
<> nil) then
4232 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4233 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4239 if (Length(P
) > 1) then
4241 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4242 if g_Game_IsClient
then
4243 MC_SEND_PlayerSettings
4244 else if gGameOn
and (gPlayer2
<> nil) then
4246 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4247 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4253 if Length(P
) > 3 then
4255 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4256 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4257 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4258 if g_Game_IsClient
then
4259 MC_SEND_PlayerSettings
4260 else if gGameOn
and (gPlayer1
<> nil) then
4262 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4263 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4269 if Length(P
) > 3 then
4271 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4272 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4273 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4274 if g_Game_IsClient
then
4275 MC_SEND_PlayerSettings
4276 else if gGameOn
and (gPlayer2
<> nil) then
4278 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4279 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4285 if (Length(P
) > 1) then
4287 gPlayer1Settings
.Model
:= P
[1];
4288 if g_Game_IsClient
then
4289 MC_SEND_PlayerSettings
4290 else if gGameOn
and (gPlayer1
<> nil) then
4292 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4293 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4294 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4300 if (Length(P
) > 1) then
4302 gPlayer2Settings
.Model
:= P
[1];
4303 if g_Game_IsClient
then
4304 MC_SEND_PlayerSettings
4305 else if gGameOn
and (gPlayer2
<> nil) then
4307 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4308 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4309 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4315 // TODO: switch teams if in game or store this separately
4316 if (Length(P
) > 1) then
4318 team
:= ParseTeam(P
[1]);
4319 if team
= TEAM_NONE
then
4320 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4321 else if not gGameOn
and not g_Game_IsNet
then
4322 gPlayer1Settings
.Team
:= team
4324 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4329 // TODO: switch teams if in game or store this separately
4330 if (Length(P
) > 1) then
4332 team
:= ParseTeam(P
[1]);
4333 if team
= TEAM_NONE
then
4334 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4335 else if not gGameOn
and not g_Game_IsNet
then
4336 gPlayer2Settings
.Team
:= team
4338 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4343 if (Length(P
) = 2) then
4344 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4348 if (Length(P
) = 2) then
4349 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4353 if (Length(P
) = 2) then
4354 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4358 if (Length(P
) = 2) then
4359 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4363 if (Length(P
) = 2) then
4364 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4368 if (Length(P
) = 2) then
4369 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4371 'p1_priority_kastet':
4373 if (Length(P
) = 2) then
4374 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4376 'p2_priority_kastet':
4378 if (Length(P
) = 2) then
4379 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4383 if (Length(P
) = 2) then
4384 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4388 if (Length(P
) = 2) then
4389 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4391 'p1_priority_pistol':
4393 if (Length(P
) = 2) then
4394 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4396 'p2_priority_pistol':
4398 if (Length(P
) = 2) then
4399 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4401 'p1_priority_shotgun1':
4403 if (Length(P
) = 2) then
4404 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4406 'p2_priority_shotgun1':
4408 if (Length(P
) = 2) then
4409 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4411 'p1_priority_shotgun2':
4413 if (Length(P
) = 2) then
4414 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4416 'p2_priority_shotgun2':
4418 if (Length(P
) = 2) then
4419 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4421 'p1_priority_chaingun':
4423 if (Length(P
) = 2) then
4424 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4426 'p2_priority_chaingun':
4428 if (Length(P
) = 2) then
4429 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4431 'p1_priority_rocketlauncher':
4433 if (Length(P
) = 2) then
4434 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4436 'p2_priority_rocketlauncher':
4438 if (Length(P
) = 2) then
4439 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4441 'p1_priority_plasma':
4443 if (Length(P
) = 2) then
4444 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4446 'p2_priority_plasma':
4448 if (Length(P
) = 2) then
4449 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4453 if (Length(P
) = 2) then
4454 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4458 if (Length(P
) = 2) then
4459 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4461 'p1_priority_super':
4463 if (Length(P
) = 2) then
4464 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4466 'p2_priority_super':
4468 if (Length(P
) = 2) then
4469 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4471 'p1_priority_flamethrower':
4473 if (Length(P
) = 2) then
4474 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4476 'p2_priority_flamethrower':
4478 if (Length(P
) = 2) then
4479 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4481 'p1_priority_berserk':
4483 if (Length(P
) = 2) then
4484 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4486 'p2_priority_berserk':
4488 if (Length(P
) = 2) then
4489 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4494 procedure PrintHeapStats();
4498 hs
:= GetFPCHeapStatus();
4499 e_LogWriteLn ('v===== heap status =====v');
4500 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4501 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4502 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4503 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4504 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4505 e_LogWriteLn ('^=======================^');
4508 procedure DebugCommands(P
: SSArray
);
4515 // Команды отладочного режима:
4516 if {gDebugMode}conIsCheatsEnabled
then
4518 cmd
:= LowerCase(P
[0]);
4519 if cmd
= 'd_window' then
4521 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4522 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4524 else if cmd
= 'd_sounds' then
4526 if (Length(P
) > 1) and
4527 ((P
[1] = '1') or (P
[1] = '0')) then
4528 g_Debug_Sounds
:= (P
[1][1] = '1');
4530 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4532 else if cmd
= 'd_frames' then
4534 if (Length(P
) > 1) and
4535 ((P
[1] = '1') or (P
[1] = '0')) then
4536 g_Debug_Frames
:= (P
[1][1] = '1');
4538 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4540 else if cmd
= 'd_winmsg' then
4542 if (Length(P
) > 1) and
4543 ((P
[1] = '1') or (P
[1] = '0')) then
4544 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4546 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4548 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4550 if (Length(P
) > 1) and
4551 ((P
[1] = '1') or (P
[1] = '0')) then
4552 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4554 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4556 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4558 if Length(P
) > 1 then
4560 '0': g_debug_BotAIOff
:= 0;
4561 '1': g_debug_BotAIOff
:= 1;
4562 '2': g_debug_BotAIOff
:= 2;
4563 '3': g_debug_BotAIOff
:= 3;
4566 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4568 else if cmd
= 'd_monster' then
4570 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4571 if Length(P
) < 2 then
4573 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4574 g_Console_Add('ID | Name');
4575 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4576 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4577 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4580 a
:= StrToIntDef(P
[1], 0);
4581 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4582 a
:= g_Mons_TypeIdByName(P
[1]);
4584 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4585 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4588 with gPlayer1
.Obj
do
4590 mon
:= g_Monsters_Create(a
,
4591 X
+ Rect
.X
+ (Rect
.Width
div 2),
4592 Y
+ Rect
.Y
+ Rect
.Height
,
4593 gPlayer1
.Direction
, True);
4595 if (Length(P
) > 2) and (mon
<> nil) then
4597 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4598 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4599 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4600 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4601 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4602 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4603 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4604 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4605 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4610 else if (cmd
= 'd_health') then
4612 if (Length(P
) > 1) and
4613 ((P
[1] = '1') or (P
[1] = '0')) then
4614 g_debug_HealthBar
:= (P
[1][1] = '1');
4616 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4618 else if (cmd
= 'd_player') then
4620 if (Length(P
) > 1) and
4621 ((P
[1] = '1') or (P
[1] = '0')) then
4622 g_debug_Player
:= (P
[1][1] = '1');
4624 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4626 else if (cmd
= 'd_mem') then
4632 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4636 procedure GameCheats(P
: SSArray
);
4642 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4644 g_Console_Add('not available');
4650 g_Console_Add('where is the player?!');
4653 cmd
:= LowerCase(P
[0]);
4657 plr
.GodMode
:= not plr
.GodMode
;
4658 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4661 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4662 if cmd
= 'give' then
4664 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4665 for f
:= 1 to High(P
) do
4667 cmd
:= LowerCase(P
[f
]);
4668 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4669 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4670 if cmd
= 'exit' then
4672 if gTriggers
<> nil then
4674 for a
:= 0 to High(gTriggers
) do
4676 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4678 g_Console_Add('player left the map');
4679 gExitByTrigger
:= True;
4680 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4681 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4689 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4690 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4691 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4692 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4693 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4695 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4696 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4698 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4699 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;
4701 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4702 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4704 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4705 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4707 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4708 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4710 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4711 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4712 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4714 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4715 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4716 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4717 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;
4718 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4719 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4721 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;
4722 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;
4723 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;
4724 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;
4725 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;
4726 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;
4728 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4729 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;
4731 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;
4732 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;
4734 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4736 if cmd
= 'ammo' then
4738 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4739 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4740 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4741 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4742 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4743 g_Console_Add('player got some ammo');
4747 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4748 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4750 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4751 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4753 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4754 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4756 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4757 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4759 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4761 if cmd
= 'weapons' then
4763 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4764 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4765 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4766 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4767 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4768 plr
.GiveItem(ITEM_WEAPON_BFG
);
4769 g_Console_Add('player got weapons');
4773 if cmd
= 'keys' then
4775 plr
.GiveItem(ITEM_KEY_RED
);
4776 plr
.GiveItem(ITEM_KEY_GREEN
);
4777 plr
.GiveItem(ITEM_KEY_BLUE
);
4778 g_Console_Add('player got all keys');
4782 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4787 if cmd
= 'open' then
4789 g_Console_Add('player activated sesame');
4790 g_Triggers_OpenAll();
4797 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4801 if cmd
= 'noclip' then
4804 g_Console_Add('wall hardeness adjusted');
4808 if cmd
= 'notarget' then
4810 plr
.NoTarget
:= not plr
.NoTarget
;
4811 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4815 if cmd
= 'noreload' then
4817 plr
.NoReload
:= not plr
.NoReload
;
4818 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4822 if cmd
= 'speedy' then
4824 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4825 g_Console_Add('speed adjusted');
4829 if cmd
= 'jumpy' then
4831 VEL_JUMP
:= 30-VEL_JUMP
;
4832 g_Console_Add('jump height adjusted');
4836 if cmd
= 'automap' then
4838 gShowMap
:= not gShowMap
;
4839 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4843 if cmd
= 'aimline' then
4845 gAimLine
:= not gAimLine
;
4846 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4851 procedure GameCommands(P
: SSArray
);
4857 pl
: pTNetClient
= nil;
4865 cmd
:= LowerCase(P
[0]);
4867 if cmd
= 'pause' then
4870 if (g_ActiveWindow
= nil) then
4871 g_Game_Pause(not gPauseMain
);
4873 g_Game_Pause(not gPauseMain
);
4876 else if cmd
= 'endgame' then
4877 gExit
:= EXIT_SIMPLE
4878 else if cmd
= 'restart' then
4880 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4882 if g_Game_IsClient
then
4884 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4889 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4891 else if cmd
= 'kick' then
4893 if g_Game_IsServer
then
4895 if Length(P
) < 2 then
4897 g_Console_Add('kick <name>');
4902 g_Console_Add('kick <name>');
4906 if g_Game_IsNet
then
4907 pl
:= g_Net_Client_ByName(P
[1]);
4910 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4911 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4912 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4913 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4914 g_Net_Slist_ServerPlayerLeaves();
4915 end else if gPlayers
<> nil then
4916 for a
:= Low(gPlayers
) to High(gPlayers
) do
4917 if gPlayers
[a
] <> nil then
4918 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4920 // Не отключать основных игроков в сингле
4921 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4923 gPlayers
[a
].Lives
:= 0;
4924 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4925 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4926 g_Player_Remove(gPlayers
[a
].UID
);
4927 g_Net_Slist_ServerPlayerLeaves();
4928 // Если не перемешать, при добавлении новых ботов появятся старые
4932 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4934 else if cmd
= 'kick_id' then
4936 if g_Game_IsServer
and g_Game_IsNet
then
4938 if Length(P
) < 2 then
4940 g_Console_Add('kick_id <client ID>');
4945 g_Console_Add('kick_id <client ID>');
4949 a
:= StrToIntDef(P
[1], 0);
4950 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4952 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4954 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4955 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
4956 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4957 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4958 g_Net_Slist_ServerPlayerLeaves();
4962 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4964 else if cmd
= 'kick_pid' then
4966 if g_Game_IsServer
and g_Game_IsNet
then
4968 if Length(P
) < 2 then
4970 g_Console_Add('kick_pid <player ID>');
4975 g_Console_Add('kick_pid <player ID>');
4979 a
:= StrToIntDef(P
[1], 0);
4980 pl
:= g_Net_Client_ByPlayer(a
);
4981 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4983 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4984 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4985 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4986 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4987 g_Net_Slist_ServerPlayerLeaves();
4990 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4992 else if cmd
= 'ban' then
4994 if g_Game_IsServer
and g_Game_IsNet
then
4996 if Length(P
) < 2 then
4998 g_Console_Add('ban <name>');
5003 g_Console_Add('ban <name>');
5007 pl
:= g_Net_Client_ByName(P
[1]);
5010 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5011 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5012 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5013 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5014 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5015 g_Net_Slist_ServerPlayerLeaves();
5017 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5019 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5021 else if cmd
= 'ban_id' then
5023 if g_Game_IsServer
and g_Game_IsNet
then
5025 if Length(P
) < 2 then
5027 g_Console_Add('ban_id <client ID>');
5032 g_Console_Add('ban_id <client ID>');
5036 a
:= StrToIntDef(P
[1], 0);
5037 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5038 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5040 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5041 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5042 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5043 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5044 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5045 g_Net_Slist_ServerPlayerLeaves();
5048 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5050 else if cmd
= 'ban_pid' then
5052 if g_Game_IsServer
and g_Game_IsNet
then
5054 if Length(P
) < 2 then
5056 g_Console_Add('ban_pid <player ID>');
5061 g_Console_Add('ban_pid <player ID>');
5065 a
:= StrToIntDef(P
[1], 0);
5066 pl
:= g_Net_Client_ByPlayer(a
);
5067 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5069 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5070 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5071 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5072 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5073 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5074 g_Net_Slist_ServerPlayerLeaves();
5077 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5079 else if cmd
= 'permban' then
5081 if g_Game_IsServer
and g_Game_IsNet
then
5083 if Length(P
) < 2 then
5085 g_Console_Add('permban <name>');
5090 g_Console_Add('permban <name>');
5094 pl
:= g_Net_Client_ByName(P
[1]);
5097 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5098 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5099 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5100 g_Net_SaveBanList();
5101 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5102 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5103 g_Net_Slist_ServerPlayerLeaves();
5105 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5107 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5109 else if cmd
= 'permban_id' then
5111 if g_Game_IsServer
and g_Game_IsNet
then
5113 if Length(P
) < 2 then
5115 g_Console_Add('permban_id <client ID>');
5120 g_Console_Add('permban_id <client ID>');
5124 a
:= StrToIntDef(P
[1], 0);
5125 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5126 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5128 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5129 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5130 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5131 g_Net_SaveBanList();
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
= 'permban_pid' then
5141 if g_Game_IsServer
and g_Game_IsNet
then
5143 if Length(P
) < 2 then
5145 g_Console_Add('permban_pid <player ID>');
5150 g_Console_Add('permban_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
);
5160 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5161 g_Net_SaveBanList();
5162 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5163 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5164 g_Net_Slist_ServerPlayerLeaves();
5167 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5169 else if cmd
= 'permban_ip' then
5171 if g_Game_IsServer
and g_Game_IsNet
then
5173 if Length(P
) < 2 then
5175 g_Console_Add('permban_ip <IP address>');
5180 g_Console_Add('permban_ip <IP address>');
5184 g_Net_BanHost(P
[1]);
5185 g_Net_SaveBanList();
5186 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5188 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5190 else if cmd
= 'unban' then
5192 if g_Game_IsServer
and g_Game_IsNet
then
5194 if Length(P
) < 2 then
5196 g_Console_Add('unban <IP Address>');
5201 g_Console_Add('unban <IP Address>');
5205 if g_Net_UnbanHost(P
[1]) then
5207 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5208 g_Net_SaveBanList();
5210 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5212 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5214 else if cmd
= 'clientlist' then
5216 if g_Game_IsServer
and g_Game_IsNet
then
5219 if NetClients
<> nil then
5220 for a
:= Low(NetClients
) to High(NetClients
) do
5221 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5223 plr
:= g_Player_Get(NetClients
[a
].Player
);
5224 if plr
= nil then continue
;
5226 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5227 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5230 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5232 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5234 else if cmd
= 'connect' then
5236 if (NetMode
= NET_NONE
) then
5238 if Length(P
) < 2 then
5240 g_Console_Add('connect <IP> [port] [password]');
5245 g_Console_Add('connect <IP> [port] [password]');
5249 if Length(P
) > 2 then
5250 prt
:= StrToIntDef(P
[2], 25666)
5254 if Length(P
) > 3 then
5259 g_Game_StartClient(P
[1], prt
, pw
);
5262 else if cmd
= 'disconnect' then
5264 if (NetMode
= NET_CLIENT
) then
5267 else if cmd
= 'reconnect' then
5269 if (NetMode
= NET_SERVER
) then
5272 if (NetMode
= NET_CLIENT
) then
5275 gExit
:= EXIT_SIMPLE
;
5279 //TODO: Use last successful password to reconnect, instead of ''
5280 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5282 else if (cmd
= 'addbot') or
5283 (cmd
= 'bot_add') then
5285 if Length(P
) > 2 then
5286 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5287 else if Length(P
) > 1 then
5288 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5290 g_Bot_Add(TEAM_NONE
, 2);
5292 else if cmd
= 'bot_addlist' then
5294 if Length(P
) > 1 then
5296 if Length(P
) = 2 then
5297 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5298 else if Length(P
) = 3 then
5299 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5301 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5304 else if cmd
= 'bot_removeall' then
5306 else if cmd
= 'chat' then
5308 if g_Game_IsNet
then
5310 if Length(P
) > 1 then
5312 for a
:= 1 to High(P
) do
5313 chstr
:= chstr
+ P
[a
] + ' ';
5315 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5317 if Length(chstr
) < 1 then
5319 g_Console_Add('chat <text>');
5323 chstr
:= b_Text_Format(chstr
);
5324 if g_Game_IsClient
then
5325 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5327 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5330 g_Console_Add('chat <text>');
5332 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5334 else if cmd
= 'teamchat' then
5336 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5338 if Length(P
) > 1 then
5340 for a
:= 1 to High(P
) do
5341 chstr
:= chstr
+ P
[a
] + ' ';
5343 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5345 if Length(chstr
) < 1 then
5347 g_Console_Add('teamchat <text>');
5351 chstr
:= b_Text_Format(chstr
);
5352 if g_Game_IsClient
then
5353 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5355 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5356 gPlayer1Settings
.Team
);
5359 g_Console_Add('teamchat <text>');
5361 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5363 else if (cmd
= 'an') or (cmd
= 'announce') then
5365 if g_Game_IsNet
then
5367 if Length(P
) > 1 then
5369 for a
:= 1 to High(P
) do
5370 chstr
:= chstr
+ P
[a
] + ' ';
5372 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5374 if Length(chstr
) < 1 then
5376 g_Console_Add('announce <text>');
5380 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5381 if g_Game_IsClient
then
5382 MC_SEND_RCONCommand(chstr
)
5384 g_Console_Process(chstr
, True);
5387 g_Console_Add('announce <text>');
5389 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5391 else if cmd
= 'game' then
5393 if gGameSettings
.GameType
<> GT_NONE
then
5395 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5398 if Length(P
) = 1 then
5400 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5403 // game not started yet, load fist map from some wad
5405 s
:= addWadExtension(P
[1]);
5406 found
:= e_FindResource(AllMapDirs
, s
);
5410 P
[1] := ExpandFileName(P
[1]);
5411 // if map not choosed then set first map
5412 if Length(P
) < 3 then
5415 P
[2] := g_Game_GetFirstMap(P
[1]);
5418 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5420 if g_Map_Exist(s
) then
5424 with gGameSettings
do
5426 Options
:= gsGameFlags
;
5427 GameMode
:= g_Game_TextToMode(gsGameMode
);
5428 if gSwitchGameMode
<> GM_NONE
then
5429 GameMode
:= gSwitchGameMode
;
5430 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5431 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5433 if Length(P
) >= 4 then
5434 b
:= StrToIntDef(P
[3], 1);
5435 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5436 ScoreLimit
, MaxLives
, Options
, b
);
5441 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5443 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5445 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5447 else if cmd
= 'host' then
5449 if gGameSettings
.GameType
<> GT_NONE
then
5451 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5454 if Length(P
) < 4 then
5456 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5459 if not StrToIp(P
[1], listen
) then
5461 prt
:= StrToIntDef(P
[2], 25666);
5463 s
:= addWadExtension(P
[3]);
5464 found
:= e_FindResource(AllMapDirs
, s
);
5468 // get first map in wad, if not specified
5469 if Length(P
) < 5 then
5472 P
[4] := g_Game_GetFirstMap(P
[1]);
5474 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5475 if g_Map_Exist(s
) then
5479 with gGameSettings
do
5481 Options
:= gsGameFlags
;
5482 GameMode
:= g_Game_TextToMode(gsGameMode
);
5483 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5484 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5485 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5487 if Length(P
) >= 6 then
5488 b
:= StrToIntDef(P
[5], 0);
5489 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5495 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5497 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5502 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5505 else if cmd
= 'map' then
5507 if Length(P
) = 1 then
5509 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5511 g_Console_Add(cmd
+ ' <MAP>');
5512 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5516 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5521 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5523 if Length(P
) < 3 then
5525 // first param is map or wad
5526 s
:= UpperCase(P
[1]);
5527 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5529 gExitByTrigger
:= False;
5532 // already in game, finish current map
5534 gExit
:= EXIT_ENDLEVELCUSTOM
;
5538 // intermission, so change map immediately
5545 found
:= e_FindResource(AllMapDirs
, s
);
5547 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5550 // no such map, found wad
5553 P
[1] := ExpandFileName(pw
);
5554 P
[2] := g_Game_GetFirstMap(P
[1]);
5555 s
:= P
[1] + ':\' + P
[2];
5556 if g_Map_Exist(s
) then
5558 gExitByTrigger
:= False;
5561 // already in game, finish current map
5563 gExit
:= EXIT_ENDLEVELCUSTOM
5567 // intermission, so change map immediately
5574 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5576 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5581 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5587 s
:= addWadExtension(P
[1]);
5588 found
:= e_FindResource(AllMapDirs
, s
);
5592 P
[2] := UpperCase(P
[2]);
5593 s
:= P
[1] + ':\' + P
[2];
5594 if g_Map_Exist(s
) then
5596 gExitByTrigger
:= False;
5600 gExit
:= EXIT_ENDLEVELCUSTOM
5609 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5614 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5620 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5624 else if cmd
= 'nextmap' then
5626 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5628 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5633 if Length(P
) = 1 then
5635 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5637 g_Console_Add(cmd
+ ' <MAP>');
5638 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5643 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5649 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5651 if Length(P
) < 3 then
5653 // first param is map or wad
5654 s
:= UpperCase(P
[1]);
5655 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5658 gExitByTrigger
:= False;
5664 // no such map, found wad
5665 pw
:= addWadExtension(P
[1]);
5666 found
:= e_FindResource(MapDirs
, pw
);
5668 found
:= e_FindResource(WadDirs
, pw
);
5670 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5673 // map not specified, select first map
5675 P
[2] := g_Game_GetFirstMap(P
[1]);
5676 s
:= P
[1] + ':\' + P
[2];
5677 if g_Map_Exist(s
) then
5679 gExitByTrigger
:= False;
5686 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5688 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5693 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5699 // specified two params wad + map
5700 pw
:= addWadExtension(P
[1]);
5701 found
:= e_FindResource(MapDirs
, pw
);
5703 found
:= e_FindResource(MapDirs
, pw
);
5707 P
[2] := UpperCase(P
[2]);
5708 s
:= P
[1] + ':\' + P
[2];
5709 if g_Map_Exist(s
) then
5711 gExitByTrigger
:= False;
5717 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5722 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5728 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5733 if gNextMap
= '' then
5734 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5736 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5740 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5744 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5748 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5750 gExitByTrigger
:= False;
5751 // next map not specified, try to find trigger EXIT
5752 if (gNextMap
= '') and (gTriggers
<> nil) then
5754 for a
:= 0 to High(gTriggers
) do
5756 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5758 gExitByTrigger
:= True;
5759 //gNextMap := gTriggers[a].Data.MapName;
5760 gNextMap
:= gTriggers
[a
].tgcMap
;
5765 if gNextMap
= '' then
5766 gNextMap
:= g_Game_GetNextMap();
5767 if not isWadPath(gNextMap
) then
5768 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5771 if g_Map_Exist(s
) then
5772 gExit
:= EXIT_ENDLEVELCUSTOM
5774 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5778 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5782 else if (cmd
= 'event') then
5784 if (Length(P
) <= 1) then
5786 for a
:= 0 to High(gEvents
) do
5787 if gEvents
[a
].Command
= '' then
5788 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5790 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5793 if (Length(P
) = 2) then
5795 for a
:= 0 to High(gEvents
) do
5796 if gEvents
[a
].Name
= P
[1] then
5797 if gEvents
[a
].Command
= '' then
5798 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5800 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5803 for a
:= 0 to High(gEvents
) do
5804 if gEvents
[a
].Name
= P
[1] then
5806 gEvents
[a
].Command
:= '';
5807 for b
:= 2 to High(P
) do
5808 if Pos(' ', P
[b
]) = 0 then
5809 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5811 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5812 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5816 else if cmd
= 'suicide' then
5820 if g_Game_IsClient
then
5821 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5824 if gPlayer1
<> nil then
5825 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5826 if gPlayer2
<> nil then
5827 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5831 else if cmd
= 'screenshot' then
5837 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5839 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5841 gWeaponAction
[0, WP_PREV
] := True;
5843 gWeaponAction
[0, WP_NEXT
] := True;
5845 else if cmd
= 'weapon' then
5847 if Length(p
) = 2 then
5849 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5850 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5851 gSelectWeapon
[0, a
] := True
5854 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5855 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5857 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5858 b
:= ord(cmd
[2]) - ord('1');
5860 gWeaponAction
[b
, WP_PREV
] := True;
5862 gWeaponAction
[b
, WP_NEXT
] := True;
5864 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5866 if Length(p
) = 2 then
5868 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5869 b
:= ord(cmd
[2]) - ord('1');
5870 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5871 gSelectWeapon
[b
, a
] := True
5874 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
5876 b
:= ord(cmd
[2]) - ord('1');
5878 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
5880 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
5882 else if (cmd
= 'dropflag') then
5884 if g_Game_IsServer
then
5886 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
5887 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
5890 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5892 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
5894 b
:= ord(cmd
[2]) - ord('1');
5895 if g_Game_IsServer
then
5897 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
5898 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
5901 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5903 // Команды Своей игры:
5904 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5906 if cmd
= 'bot_addred' then
5908 if Length(P
) > 1 then
5909 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5911 g_Bot_Add(TEAM_RED
, 2);
5913 else if cmd
= 'bot_addblue' then
5915 if Length(P
) > 1 then
5916 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5918 g_Bot_Add(TEAM_BLUE
, 2);
5920 else if cmd
= 'spectate' then
5926 else if cmd
= 'say' then
5928 if g_Game_IsServer
and g_Game_IsNet
then
5930 if Length(P
) > 1 then
5933 for a
:= 1 to High(P
) do
5934 chstr
:= chstr
+ P
[a
] + ' ';
5936 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5938 if Length(chstr
) < 1 then
5940 g_Console_Add('say <text>');
5944 chstr
:= b_Text_Format(chstr
);
5945 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5947 else g_Console_Add('say <text>');
5949 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5951 else if cmd
= 'tell' then
5953 if g_Game_IsServer
and g_Game_IsNet
then
5955 if (Length(P
) > 2) and (P
[1] <> '') then
5958 for a
:= 2 to High(P
) do
5959 chstr
:= chstr
+ P
[a
] + ' ';
5961 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5963 if Length(chstr
) < 1 then
5965 g_Console_Add('tell <playername> <text>');
5969 pl
:= g_Net_Client_ByName(P
[1]);
5971 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5973 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5975 else g_Console_Add('tell <playername> <text>');
5977 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5979 else if cmd
= 'centerprint' then
5981 if (Length(P
) > 2) and (P
[1] <> '') then
5984 for a
:= 2 to High(P
) do
5985 chstr
:= chstr
+ P
[a
] + ' ';
5987 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5989 if Length(chstr
) < 1 then
5991 g_Console_Add('centerprint <timeout> <text>');
5995 a
:= StrToIntDef(P
[1], 100);
5996 chstr
:= b_Text_Format(chstr
);
5997 g_Game_Message(chstr
, a
);
5998 if g_Game_IsNet
and g_Game_IsServer
then
5999 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6001 else g_Console_Add('centerprint <timeout> <text>');
6003 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6005 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6007 // Дополнительное время:
6008 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6010 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6011 [gGameSettings
.TimeLimit
div 3600,
6012 (gGameSettings
.TimeLimit
div 60) mod 60,
6013 gGameSettings
.TimeLimit
mod 60]));
6014 if g_Game_IsNet
then MH_SEND_GameSettings
;
6016 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6018 if (Length(P
) <= 1) then
6019 g_Console_Add('rcon_password <password>')
6021 MC_SEND_RCONPassword(P
[1]);
6023 else if cmd
= 'rcon' then
6025 if g_Game_IsClient
then
6027 if Length(P
) > 1 then
6030 for a
:= 1 to High(P
) do
6031 chstr
:= chstr
+ P
[a
] + ' ';
6033 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6035 if Length(chstr
) < 1 then
6037 g_Console_Add('rcon <command>');
6041 MC_SEND_RCONCommand(chstr
);
6043 else g_Console_Add('rcon <command>');
6046 else if cmd
= 'ready' then
6048 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6049 gLMSRespawnTime
:= gTime
+ 100;
6051 else if (cmd
= 'callvote') and g_Game_IsNet
then
6053 if Length(P
) > 1 then
6056 for a
:= 1 to High(P
) do begin
6057 if a
> 1 then chstr
:= chstr
+ ' ';
6058 chstr
:= chstr
+ P
[a
];
6061 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6063 if Length(chstr
) < 1 then
6065 g_Console_Add('callvote <command>');
6069 if g_Game_IsClient
then
6070 MC_SEND_Vote(True, chstr
)
6072 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6073 g_Console_Process('vote', True);
6076 g_Console_Add('callvote <command>');
6078 else if (cmd
= 'vote') and g_Game_IsNet
then
6080 if g_Game_IsClient
then
6082 else if gVoteInProgress
then
6084 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6085 a
:= Floor((NetClientCount
+1)/2.0) + 1
6087 a
:= Floor(NetClientCount
/2.0) + 1;
6092 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6093 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6099 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6100 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6108 procedure SystemCommands(P
: SSArray
);
6112 cmd
:= LowerCase(P
[0]);
6125 if Length(p
) = 2 then
6127 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6129 gFrameTime
:= 1000 div gMaxFPS
6133 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6137 if Length(p
) = 2 then
6139 gAskLanguage
:= true;
6140 gLanguage
:= LANGUAGE_ENGLISH
;
6141 case LowerCase(p
[1]) of
6144 gAskLanguage
:= false;
6145 gLanguage
:= LANGUAGE_ENGLISH
;
6149 gAskLanguage
:= false;
6150 gLanguage
:= LANGUAGE_RUSSIAN
;
6154 gAskLanguage
:= true;
6155 gLanguage
:= LANGUAGE_ENGLISH
;
6158 g_Language_Set(gLanguage
);
6162 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6169 procedure g_TakeScreenShot(Filename
: string = '');
6170 var t
: TDateTime
; dir
, date
, name
: String;
6172 if e_NoGraphics
then
6175 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6176 if Filename
= '' then
6179 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6180 Filename
:= 'screenshot-' + date
;
6183 name
:= e_CatPath(dir
, Filename
+ '.png');
6184 if r_Render_WriteScreenShot(name
) then
6185 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6187 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6192 procedure g_Game_InGameMenu(Show
: Boolean);
6194 if (g_ActiveWindow
= nil) and Show
then
6196 if gGameSettings
.GameType
= GT_SINGLE
then
6197 g_GUI_ShowWindow('GameSingleMenu')
6200 if g_Game_IsClient
then
6201 g_GUI_ShowWindow('GameClientMenu')
6203 if g_Game_IsNet
then
6204 g_GUI_ShowWindow('GameServerMenu')
6206 g_GUI_ShowWindow('GameCustomMenu');
6208 g_Sound_PlayEx('MENU_OPEN');
6210 // Пауза при меню только в одиночной игре:
6211 if (not g_Game_IsNet
) then
6215 if (g_ActiveWindow
<> nil) and (not Show
) then
6217 // Пауза при меню только в одиночной игре:
6218 if (not g_Game_IsNet
) then
6219 g_Game_Pause(False);
6224 procedure g_Game_Pause (Enable
: Boolean);
6228 if not gGameOn
then exit
;
6230 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6233 gPauseMain
:= Enable
;
6235 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6238 procedure g_Game_HolmesPause (Enable
: Boolean);
6242 if not gGameOn
then exit
;
6243 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6246 gPauseHolmes
:= Enable
;
6248 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6251 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6256 if gTriggers
<> nil then
6257 for i
:= 0 to High(gTriggers
) do
6258 with gTriggers
[i
] do
6259 if (TriggerType
= TRIGGER_SOUND
) and
6261 Sound
.IsPlaying() then
6263 Sound
.Pause(Enable
);
6267 if gPlayers
<> nil then
6268 for i
:= 0 to High(gPlayers
) do
6269 if gPlayers
[i
] <> nil then
6270 gPlayers
[i
].PauseSounds(Enable
);
6273 if gMusic
<> nil then
6274 gMusic
.Pause(Enable
);
6277 procedure g_Game_StopAllSounds(all
: Boolean);
6281 if gTriggers
<> nil then
6282 for i
:= 0 to High(gTriggers
) do
6283 with gTriggers
[i
] do
6284 if (TriggerType
= TRIGGER_SOUND
) and
6288 if gMusic
<> nil then
6295 procedure g_Game_UpdateTriggerSounds
;
6298 if gTriggers
<> nil then
6299 for i
:= 0 to High(gTriggers
) do
6300 with gTriggers
[i
] do
6301 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6302 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6305 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6308 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6313 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6318 if gSpectMode
<> SPECT_PLAYERS
then
6320 if gSpectPID1
= UID
then
6325 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6332 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6337 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6342 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6347 if gSpectMode
<> SPECT_PLAYERS
then
6349 Pl
:= g_Player_Get(gSpectPID1
);
6350 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6355 if gSpectViewTwo
then
6357 Pl
:= g_Player_Get(gSpectPID2
);
6358 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6366 procedure g_Game_Message (Msg
: string; Time
: Word);
6369 MessageTime
:= Time
;
6372 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6374 punct
: Array[0..13] of String =
6375 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6381 function IsPunctuation(S
: String): Boolean;
6386 if Length(S
) <> 1 then
6388 for i
:= Low(punct
) to High(punct
) do
6389 if S
= punct
[i
] then
6395 function FilterPunctuation(S
: String): String;
6399 for i
:= Low(punct
) to High(punct
) do
6400 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6406 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6408 // remove player name
6409 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6410 // for FullWord check
6411 Text := toLowerCase1251(' ' + Text + ' ');
6412 fpText
:= FilterPunctuation(Text);
6414 for i
:= 0 to Length(gChatSounds
) - 1 do
6417 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6419 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6420 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6422 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6428 gChatSounds
[i
].Sound
.Play();
6434 g_Sound_PlayEx('SOUND_GAME_RADIO');
6437 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6446 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6450 if goodsnd
[a
].IsPlaying() then
6453 goodsnd
[Random(4)].Play();
6456 procedure g_Game_Announce_KillCombo(Param
: Integer);
6463 UID
:= Param
and $FFFF;
6468 Pl
:= g_Player_Get(UID
);
6477 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6481 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6485 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6489 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6497 if not g_Game_IsWatchedPlayer(UID
) then
6500 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6504 if killsnd
[n
].IsPlaying() then
6509 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6517 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6521 if hahasnd
[a
].IsPlaying() then
6524 hahasnd
[Random(3)].Play();
6527 procedure g_Game_StartVote(Command
, Initiator
: string);
6531 if not gVotesEnabled
then Exit
;
6532 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6533 if gVoteInProgress
or gVotePassed
then
6535 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6536 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6539 gVoteInProgress
:= True;
6540 gVotePassed
:= False;
6541 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6544 gVoteCommand
:= Command
;
6546 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6547 Need
:= Floor((NetClientCount
+1)/2.0)+1
6549 Need
:= Floor(NetClientCount
/2.0)+1;
6550 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6551 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6554 procedure g_Game_CheckVote
;
6558 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6559 if not gVoteInProgress
then Exit
;
6561 if (gTime
>= gVoteTimer
) then
6563 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6564 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6566 Need
:= Floor(NetClientCount
/2.0) + 1;
6567 if gVoteCount
>= Need
then
6569 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6570 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6571 gVotePassed
:= True;
6572 gVoteCmdTimer
:= gTime
+ 5000;
6576 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6577 MH_SEND_VoteEvent(NET_VE_FAILED
);
6579 if NetClients
<> nil then
6580 for I
:= Low(NetClients
) to High(NetClients
) do
6581 if NetClients
[i
].Used
then
6582 NetClients
[i
].Voted
:= False;
6583 gVoteInProgress
:= False;
6589 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6590 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6592 Need
:= Floor(NetClientCount
/2.0) + 1;
6593 if gVoteCount
>= Need
then
6595 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6596 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6597 gVoteInProgress
:= False;
6598 gVotePassed
:= True;
6599 gVoteCmdTimer
:= gTime
+ 5000;
6602 if NetClients
<> nil then
6603 for I
:= Low(NetClients
) to High(NetClients
) do
6604 if NetClients
[i
].Used
then
6605 NetClients
[i
].Voted
:= False;
6610 procedure g_Game_LoadMapList(FileName
: string);
6618 if not FileExists(FileName
) then Exit
;
6620 AssignFile(ListFile
, FileName
);
6622 while not EOF(ListFile
) do
6624 ReadLn(ListFile
, s
);
6627 if s
= '' then Continue
;
6629 SetLength(MapList
, Length(MapList
)+1);
6630 MapList
[High(MapList
)] := s
;
6632 CloseFile(ListFile
);
6635 procedure g_Game_SetDebugMode();
6638 // Читы (даже в своей игре):
6642 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6646 if Length(LoadingStat
.Msgs
) = 0 then
6652 begin // Переходим на следующую строку или скроллируем:
6653 if NextMsg
= Length(Msgs
) then
6655 for i
:= 0 to High(Msgs
)-1 do
6656 Msgs
[i
] := Msgs
[i
+1];
6664 Msgs
[NextMsg
-1] := Text;
6668 PBarWasHere
:= false;
6672 g_ActiveWindow
:= nil;
6675 ProcessLoading(true);
6678 procedure g_Game_StepLoading(Value
: Integer = -1);
6690 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6693 ProcessLoading(False);
6698 procedure g_Game_ClearLoading();
6707 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6708 if len
< 1 then len
:= 1;
6709 SetLength(Msgs
, len
);
6710 for len
:= Low(Msgs
) to High(Msgs
) do
6713 PBarWasHere
:= false;
6717 procedure Parse_Params(var pars
: TParamStrValues
);
6724 while i
<= ParamCount
do
6727 if (Length(s
) > 1) and (s
[1] = '-') then
6729 if (Length(s
) > 2) and (s
[2] = '-') then
6730 begin // Одиночный параметр
6731 SetLength(pars
, Length(pars
) + 1);
6732 with pars
[High(pars
)] do
6734 Name
:= LowerCase(s
);
6739 if (i
< ParamCount
) then
6740 begin // Параметр со значением
6742 SetLength(pars
, Length(pars
) + 1);
6743 with pars
[High(pars
)] do
6745 Name
:= LowerCase(s
);
6746 Value
:= LowerCase(ParamStr(i
));
6755 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6760 for i
:= 0 to High(pars
) do
6761 if pars
[i
].Name
= aName
then
6763 Result
:= pars
[i
].Value
;
6768 procedure g_Game_Process_Params();
6770 pars
: TParamStrValues
;
6773 LimT
, LimS
: Integer;
6784 s
:= Find_Param_Value(pars
, '--debug');
6787 g_Game_SetDebugMode();
6788 s
:= Find_Param_Value(pars
, '--netdump');
6793 // Connect when game loads
6794 ip
:= Find_Param_Value(pars
, '-connect');
6798 s
:= Find_Param_Value(pars
, '-port');
6799 if (s
= '') or not TryStrToInt(s
, Port
) then
6802 s
:= Find_Param_Value(pars
, '-pw');
6804 g_Game_StartClient(ip
, Port
, s
);
6808 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6811 gDefaultMegawadStart
:= s
;
6814 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6815 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6817 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6820 // Start map when game loads:
6821 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6822 if isWadPath(map
) then
6825 s
:= Find_Param_Value(pars
, '-gm');
6826 GMode
:= g_Game_TextToMode(s
);
6827 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6828 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6831 s
:= Find_Param_Value(pars
, '-limt');
6832 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6838 s
:= Find_Param_Value(pars
, '-lims');
6839 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6845 s
:= Find_Param_Value(pars
, '-lives');
6846 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6852 s
:= Find_Param_Value(pars
, '-opt');
6856 Opt
:= StrToIntDef(s
, 0);
6859 s
:= Find_Param_Value(pars
, '--close');
6863 // Override map to test:
6864 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6867 if e_IsValidResourceName(s
) then
6868 e_FindResource(AllMapDirs
, s
);
6869 gTestMap
:= ExpandFileName(s
);
6872 // Delete test map after play:
6873 s
:= Find_Param_Value(pars
, '--testdelete');
6876 //gMapToDelete := MapsDir + map;
6877 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6881 // Delete temporary WAD after play:
6882 s
:= Find_Param_Value(pars
, '--tempdelete');
6883 if (s
<> '') and (gTestMap
<> '') then
6885 gMapToDelete
:= gTestMap
;
6886 gTempDelete
:= True;
6889 // Number of players:
6890 s
:= Find_Param_Value(pars
, '-pl');
6892 n
:= DEFAULT_PLAYERS
6894 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6897 s
:= Find_Param_Value(pars
, '-port');
6898 if (s
= '') or not TryStrToInt(s
, Port
) then
6899 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6901 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6904 // Execute script when game loads:
6905 s
:= Find_Param_Value(pars
, '-exec');
6908 // if not isWadPath(s) then
6909 // s := GameDir + '/' + s;
6914 if IOResult
<> 0 then
6916 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6917 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6921 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6922 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6927 if IOResult
<> 0 then
6929 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6930 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6934 if Pos('#', s
) <> 1 then // script comment
6935 g_Console_Process(s
, True);
6946 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6947 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6948 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6949 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6951 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6952 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6953 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6954 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6956 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6957 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6959 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6960 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6962 {$IFDEF ENABLE_HOLMES}
6963 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6966 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6968 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6969 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6971 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6972 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6974 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6975 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6976 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6977 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
6978 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6979 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6980 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6981 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6982 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');