1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
24 SysUtils
, Classes
, MAPDEF
,
25 g_base
, g_basic
, g_player
, g_res_downloader
,
26 g_sound
, utils
, md5
, mempool
, xprofiler
,
31 TGameSettings
= record
38 ItemRespawnTime
: Word;
49 TDelayedEvent
= record
58 Sound
: TPlayableSound
;
59 Tags
: Array of String;
63 TPlayerSettings
= record
68 // ones below are sent only to the server
70 WeaponPreferences
: Array[WP_FIRST
..WP_LAST
+1] of Byte;
87 function g_Game_IsNet(): Boolean;
88 function g_Game_IsServer(): Boolean;
89 function g_Game_IsClient(): Boolean;
90 procedure g_Game_Init();
91 procedure g_Game_Free (freeTextures
: Boolean=true);
92 procedure g_Game_LoadData();
93 procedure g_Game_FreeData();
94 procedure g_Game_Update();
95 procedure g_Game_PreUpdate();
96 procedure g_Game_Quit();
97 function g_Game_ModeToText(Mode
: Byte): string;
98 function g_Game_TextToMode(Mode
: string): Byte;
99 procedure g_Game_ExecuteEvent(Name
: String);
100 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
101 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
102 procedure g_Game_RemovePlayer();
103 procedure g_Game_Spectate();
104 procedure g_Game_SpectateCenterView();
105 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
106 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
107 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
108 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
109 procedure g_Game_Restart();
110 procedure g_Game_RestartLevel();
111 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
112 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
113 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
114 procedure g_Game_ChangeMap(const MapPath
: String);
115 procedure g_Game_ExitLevel(const Map
: AnsiString);
116 function g_Game_GetFirstMap(WAD
: String): String;
117 function g_Game_GetNextMap(): String;
118 procedure g_Game_NextLevel();
119 procedure g_Game_Pause(Enable
: Boolean);
120 procedure g_Game_HolmesPause(Enable
: Boolean);
121 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
122 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
123 procedure g_Game_Message(Msg
: String; Time
: Word);
124 procedure g_Game_LoadMapList(FileName
: String);
125 procedure g_Game_PauseAllSounds(Enable
: Boolean);
126 procedure g_Game_StopAllSounds(all
: Boolean);
127 procedure g_Game_UpdateTriggerSounds();
128 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
129 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
130 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
131 procedure g_Game_Announce_KillCombo(Param
: Integer);
132 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
133 procedure g_Game_StartVote(Command
, Initiator
: string);
134 procedure g_Game_CheckVote
;
135 {$IFDEF ENABLE_RENDER}
136 procedure g_TakeScreenShot(Filename
: string = '');
138 procedure g_FatalError(Text: String);
139 procedure g_SimpleError(Text: String);
140 function g_Game_IsTestMap(): Boolean;
141 procedure g_Game_DeleteTestMap();
142 procedure GameCVars(P
: SSArray
);
143 procedure PlayerSettingsCVars(P
: SSArray
);
144 procedure SystemCommands(P
: SSArray
);
145 procedure GameCommands(P
: SSArray
);
146 procedure GameCheats(P
: SSArray
);
147 procedure DebugCommands(P
: SSArray
);
148 procedure g_Game_Process_Params
;
149 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
150 procedure g_Game_StepLoading(Value
: Integer = -1);
151 procedure g_Game_ClearLoading();
152 procedure g_Game_SetDebugMode();
154 function IsActivePlayer(p
: TPlayer
): Boolean;
155 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
156 procedure SortGameStat(var stat
: TPlayerStatArray
);
160 procedure g_Game_InGameMenu(Show
: Boolean);
162 {$IFDEF ENABLE_SYSTEM}
163 procedure CharPress (C
: AnsiChar);
166 procedure KeyPress (K
: Word);
168 { procedure SetWinPause(Enable: Boolean); }
173 LOADING_SHOW_STEP
= 100;
174 LOADING_INTERLINE
= 20;
192 EXIT_ENDLEVELSINGLE
= 4;
193 EXIT_ENDLEVELCUSTOM
= 5;
195 GAME_OPTION_RESERVED
= 1;
196 GAME_OPTION_TEAMDAMAGE
= 2;
197 GAME_OPTION_ALLOWEXIT
= 4;
198 GAME_OPTION_WEAPONSTAY
= 8;
199 GAME_OPTION_MONSTERS
= 16;
200 GAME_OPTION_BOTVSPLAYER
= 32;
201 GAME_OPTION_BOTVSMONSTER
= 64;
202 GAME_OPTION_DMKEYS
= 128;
203 GAME_OPTION_TEAMHITTRACE
= 256;
204 GAME_OPTION_TEAMHITPROJECTILE
= 512;
205 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
206 GAME_OPTION_ALLOWDROPFLAG
= 2048;
207 GAME_OPTION_THROWFLAG
= 4096;
212 STATE_INTERCUSTOM
= 3;
213 STATE_INTERSINGLE
= 4;
219 LMS_RESPAWN_NONE
= 0;
220 LMS_RESPAWN_WARMUP
= 1;
221 LMS_RESPAWN_FINAL
= 2;
238 CONFIG_FILENAME
= 'Doom2DF.cfg';
240 TEST_MAP_NAME
= '$$$_TEST_$$$';
242 STD_PLAYER_MODEL
= 'Doomer';
250 STATFILE_VERSION
= $03;
253 gGameSettings
: TGameSettings
;
254 gPlayer1Settings
: TPlayerSettings
;
255 gPlayer2Settings
: TPlayerSettings
;
257 gPlayerScreenSize
: TDFPoint
;
258 gPlayer1ScreenCoord
: TDFPoint
;
259 gPlayer2ScreenCoord
: TDFPoint
;
260 gPlayer1
: TPlayer
= nil;
261 gPlayer2
: TPlayer
= nil;
262 gPlayerDrawn
: TPlayer
= nil;
264 gLerpFactor
: Single = 1.0;
265 gSwitchGameMode
: Byte = GM_DM
;
266 gHearPoint1
, gHearPoint2
: THearPoint
;
267 gSoundEffectsDF
: Boolean = False;
268 gSoundTriggerTime
: Word = 0;
269 gAnnouncer
: Integer = ANNOUNCE_NONE
;
270 goodsnd
: array[0..3] of TPlayableSound
;
271 killsnd
: array[0..3] of TPlayableSound
;
272 hahasnd
: array[0..2] of TPlayableSound
;
273 sound_get_flag
: array[0..1] of TPlayableSound
;
274 sound_lost_flag
: array[0..1] of TPlayableSound
;
275 sound_ret_flag
: array[0..1] of TPlayableSound
;
276 sound_cap_flag
: array[0..1] of TPlayableSound
;
277 gBodyKillEvent
: Integer = -1;
278 gDefInterTime
: ShortInt = -1;
279 gInterEndTime
: LongWord = 0;
280 gInterTime
: LongWord = 0;
281 gServInterTime
: Byte = 0;
282 gGameStartTime
: LongWord = 0;
283 gTotalMonsters
: Integer = 0;
284 gPauseMain
: Boolean = false;
285 gPauseHolmes
: Boolean = false;
286 gShowTime
: Boolean = False;
287 gShowFPS
: Boolean = False;
288 gShowScore
: Boolean = True;
289 gShowStat
: Boolean = True;
290 gShowPIDs
: Boolean = False;
291 gShowKillMsg
: Boolean = True;
292 gShowLives
: Boolean = True;
293 gShowPing
: Boolean = False;
294 gShowMap
: Boolean = False;
296 gState
: Byte = STATE_NONE
;
298 sWidth
, sHeight
: Word;
299 gSpectMode
: Byte = SPECT_NONE
;
300 gSpectHUD
: Boolean = True;
301 gSpectKeyPress
: Boolean = False;
302 gSpectX
: Integer = 0;
303 gSpectY
: Integer = 0;
304 gSpectStep
: Byte = 8;
305 gSpectViewTwo
: Boolean = False;
306 gSpectPID1
: Integer = -1;
307 gSpectPID2
: Integer = -1;
308 gSpectAuto
: Boolean = False;
309 gSpectAutoNext
: LongWord;
310 gSpectAutoStepX
: Integer;
311 gSpectAutoStepY
: Integer;
312 gMusic
: TMusic
= nil;
313 gLoadGameMode
: Boolean;
314 gCheats
: Boolean = False;
315 gMapOnce
: Boolean = False;
316 gMapToDelete
: String;
317 gTempDelete
: Boolean = False;
318 gLastMap
: Boolean = False;
321 gResolutionChange
: Boolean = False;
322 gRC_Width
, gRC_Height
: Integer;
323 gRC_FullScreen
, gRC_Maximized
: Boolean;
324 gLanguageChange
: Boolean = False;
325 gDebugMode
: Boolean = False;
326 g_debug_Sounds
: Boolean = False;
327 g_debug_Frames
: Boolean = False;
328 g_debug_WinMsgs
: Boolean = False;
329 g_debug_MonsterOff
: Boolean = False;
330 g_debug_BotAIOff
: Byte = 0;
331 g_debug_HealthBar
: Boolean = False;
332 g_Debug_Player
: Boolean = False;
333 gCoopMonstersKilled
: Word = 0;
334 gCoopSecretsFound
: Word = 0;
335 gCoopTotalMonstersKilled
: Word = 0;
336 gCoopTotalSecretsFound
: Word = 0;
337 gCoopTotalMonsters
: Word = 0;
338 gCoopTotalSecrets
: Word = 0;
339 gStatsOff
: Boolean = False;
340 gStatsPressed
: Boolean = False;
341 gExitByTrigger
: Boolean = False;
342 gNextMap
: String = '';
343 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
344 gLMSRespawnTime
: Cardinal = 0;
345 gLMSSoftSpawn
: Boolean = False;
346 gMissionFailed
: Boolean = False;
347 gVoteInProgress
: Boolean = False;
348 gVotePassed
: Boolean = False;
349 gVoteCommand
: string = '';
350 gVoteTimer
: Cardinal = 0;
351 gVoteCmdTimer
: Cardinal = 0;
352 gVoteCount
: Integer = 0;
353 gVoteTimeout
: Cardinal = 30;
354 gVoted
: Boolean = False;
355 gVotesEnabled
: Boolean = True;
356 gEvents
: Array of TGameEvent
;
357 gDelayedEvents
: Array of TDelayedEvent
;
358 gUseChatSounds
: Boolean = True;
359 gChatSounds
: Array of TChatSound
;
360 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
361 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
362 gInterReadyCount
: Integer = 0;
363 gMaxBots
: Integer = 127;
365 g_dbg_ignore_bounds
: Boolean = false;
366 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
367 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
369 // move button values:
370 // bits 0-1: l/r state:
371 // 0: neither left, nor right pressed
374 // bits 4-5: l/r state when strafe was pressed
375 P1MoveButton
: Byte = 0;
376 P2MoveButton
: Byte = 0;
378 g_profile_frame_update
: Boolean = false;
379 g_profile_frame_draw
: Boolean = false;
380 g_profile_collision
: Boolean = false;
381 g_profile_los
: Boolean = false;
382 g_profile_history_size
: Integer = 1000;
384 g_rlayer_back
: Boolean = true;
385 g_rlayer_step
: Boolean = true;
386 g_rlayer_wall
: Boolean = true;
387 g_rlayer_door
: Boolean = true;
388 g_rlayer_acid1
: Boolean = true;
389 g_rlayer_acid2
: Boolean = true;
390 g_rlayer_water
: Boolean = true;
391 g_rlayer_fore
: Boolean = true;
393 wNeedTimeReset
: Boolean = false;
395 procedure g_ResetDynlights ();
396 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
397 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
399 function conIsCheatsEnabled (): Boolean; inline;
400 function gPause (): Boolean; inline;
402 type (* private state *)
403 TEndCustomGameStat
= record
404 PlayerStat
: TPlayerStatArray
;
408 Map
, MapName
: String;
411 TEndSingleGameStat
= record
412 PlayerStat
: Array [0..1] of record
418 TotalSecrets
: Integer;
421 TLoadingStat
= record
425 Msgs
: Array of String;
427 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
431 x
, y
, radius
: Integer;
434 exploRadius
: Integer;
437 var (* private state *)
438 CustomStat
: TEndCustomGameStat
;
439 StatShotDone
: Boolean;
440 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
441 SingleStat
: TEndSingleGameStat
;
442 LoadingStat
: TLoadingStat
;
445 EndingGameCounter
: Byte;
447 g_playerLight
: Boolean;
448 g_dynLights
: array of TDynLight
= nil;
449 g_dynLightCount
: Integer = 0;
450 EndPicPath
: AnsiString; // full path, used by render
455 {$IFDEF ENABLE_HOLMES}
467 {$IFDEF ENABLE_SHELLS}
470 {$IFDEF ENABLE_CORPSES}
473 {$IFDEF ENABLE_RENDER}
476 {$IFDEF ENABLE_SYSTEM}
480 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
481 g_playermodel
, g_options
, Math
,
482 g_triggers
, g_monsters
, e_sound
, CONFIG
,
483 g_language
, g_net
, g_phys
,
484 ENet
, e_msg
, g_netmsg
, g_netmaster
,
488 charbuff
: packed array [0..15] of AnsiChar = (
489 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
492 function Translit (const S
: AnsiString): AnsiString;
497 for i
:= 1 to Length(Result
) do
500 #
$C9: Result
[i
] := 'Q';
501 #
$D6: Result
[i
] := 'W';
502 #
$D3: Result
[i
] := 'E';
503 #
$CA: Result
[i
] := 'R';
504 #
$C5: Result
[i
] := 'T';
505 #
$CD: Result
[i
] := 'Y';
506 #
$C3: Result
[i
] := 'U';
507 #
$D8: Result
[i
] := 'I';
508 #
$D9: Result
[i
] := 'O';
509 #
$C7: Result
[i
] := 'P';
510 #
$D5: Result
[i
] := '['; //Chr(219);
511 #
$DA: Result
[i
] := ']'; //Chr(221);
512 #
$D4: Result
[i
] := 'A';
513 #
$DB: Result
[i
] := 'S';
514 #
$C2: Result
[i
] := 'D';
515 #
$C0: Result
[i
] := 'F';
516 #
$CF: Result
[i
] := 'G';
517 #
$D0: Result
[i
] := 'H';
518 #
$CE: Result
[i
] := 'J';
519 #
$CB: Result
[i
] := 'K';
520 #
$C4: Result
[i
] := 'L';
521 #
$C6: Result
[i
] := ';'; //Chr(186);
522 #
$DD: Result
[i
] := #39; //Chr(222);
523 #
$DF: Result
[i
] := 'Z';
524 #
$D7: Result
[i
] := 'X';
525 #
$D1: Result
[i
] := 'C';
526 #
$CC: Result
[i
] := 'V';
527 #
$C8: Result
[i
] := 'B';
528 #
$D2: Result
[i
] := 'N';
529 #
$DC: Result
[i
] := 'M';
530 #
$C1: Result
[i
] := ','; //Chr(188);
531 #
$DE: Result
[i
] := '.'; //Chr(190);
537 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
542 ls2
:= Translit(CheatRus
[ct
]);
543 if length(ls1
) = 0 then ls1
:= '~';
544 if length(ls2
) = 0 then ls2
:= '~';
546 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
547 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
548 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
549 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
551 if ct = I_GAME_CHEAT_JETPACK then
553 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
554 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
555 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
556 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
557 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
558 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
574 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
575 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
576 or g_Game_IsNet then Exit;
578 if not gGameOn
then exit
;
579 if not conIsCheatsEnabled
then exit
;
581 s
:= 'SOUND_GAME_RADIO';
584 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
586 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
587 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
591 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
593 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
594 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
598 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
600 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
601 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
605 if CheckCheat(I_GAME_CHEAT_DEATH
) then
607 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
608 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
609 s
:= 'SOUND_MONSTER_HAHA';
613 if CheckCheat(I_GAME_CHEAT_DOORS
) then
615 g_Triggers_OpenAll();
619 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
621 if gTriggers
<> nil then
622 for a
:= 0 to High(gTriggers
) do
623 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
625 gExitByTrigger
:= True;
626 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
627 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
633 s2
:= Copy(charbuff
, 15, 2);
634 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
636 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
644 if CheckCheat(I_GAME_CHEAT_FLY
) then
650 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
652 VEL_JUMP
:= 30-VEL_JUMP
;
656 if CheckCheat(I_GAME_CHEAT_SPEED
) then
658 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
662 if CheckCheat(I_GAME_CHEAT_SUIT
) then
664 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
665 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
669 if CheckCheat(I_GAME_CHEAT_AIR
) then
671 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
672 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
676 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
678 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
679 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
683 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
685 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
686 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
690 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
692 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
693 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
697 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
699 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
700 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
704 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
706 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
707 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
710 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
712 gAimLine
:= not gAimLine
;
715 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
717 gShowMap
:= not gShowMap
;
728 procedure KeyPress (K
: Word);
729 var Msg
: g_gui
.TMessage
;
734 if (g_ActiveWindow
<> nil) then
736 Msg
.Msg
:= WM_KEYDOWN
;
737 Msg
.WParam
:= VK_ESCAPE
;
738 g_ActiveWindow
.OnMessage(Msg
);
739 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
741 else if (gState
<> STATE_FOLD
) then
743 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
745 g_Game_InGameMenu(True);
747 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
749 if (gState
<> STATE_MENU
) then
751 if (NetMode
<> NET_NONE
) then
753 g_Game_StopAllSounds(True);
755 gState
:= STATE_MENU
;
759 g_GUI_ShowWindow('MainMenu');
760 g_Sound_PlayEx('MENU_OPEN');
765 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
766 begin // <F2> .. <F6> � <F12>
767 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
769 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
770 if (not g_Game_IsNet
) then g_Game_Pause(True);
772 IK_F2
: g_Menu_Show_SaveMenu();
773 IK_F3
: g_Menu_Show_LoadMenu();
774 IK_F4
: g_Menu_Show_GameSetGame();
775 IK_F5
: g_Menu_Show_OptionsVideo();
776 IK_F6
: g_Menu_Show_OptionsSound();
777 IK_F7
: g_Menu_Show_EndGameMenu();
778 IK_F10
: g_Menu_Show_QuitGameMenu();
785 gJustChatted
:= False;
786 if gConsoleShow
or gChatShow
then
788 g_Console_Control(K
);
790 else if (g_ActiveWindow
<> nil) then
792 Msg
.Msg
:= WM_KEYDOWN
;
794 g_ActiveWindow
.OnMessage(Msg
);
796 else if (gState
= STATE_MENU
) then
798 g_GUI_ShowWindow('MainMenu');
799 g_Sound_PlayEx('MENU_OPEN');
805 procedure KeyPress (K
: Word);
807 gJustChatted
:= False;
808 if gConsoleShow
or gChatShow
then
810 g_Console_Control(K
);
815 {$IFDEF ENABLE_SYSTEM}
816 procedure CharPress (C
: AnsiChar);
818 var Msg
: g_gui
.TMessage
;
822 if gConsoleShow
or gChatShow
then
827 else if g_ActiveWindow
<> nil then
830 Msg
.WParam
:= Ord(C
);
831 g_ActiveWindow
.OnMessage(Msg
);
838 charbuff
[a
] := charbuff
[a
+ 1];
840 charbuff
[15] := upcase1251(C
);
847 // ////////////////////////////////////////////////////////////////////////// //
848 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
850 procedure g_ResetDynlights ();
854 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
856 for idx
:= 0 to g_dynLightCount
-1 do
858 if g_dynLights
[idx
].exploCount
= -666 then
865 Inc(g_dynLights
[idx
].exploCount
);
866 if (g_dynLights
[idx
].exploCount
< 10) then
868 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
869 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
870 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
871 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
876 g_dynLightCount
:= lnum
;
879 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
881 if not gwin_has_stencil
then exit
;
882 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
883 g_dynLights
[g_dynLightCount
].x
:= x
;
884 g_dynLights
[g_dynLightCount
].y
:= y
;
885 g_dynLights
[g_dynLightCount
].radius
:= radius
;
886 g_dynLights
[g_dynLightCount
].r
:= r
;
887 g_dynLights
[g_dynLightCount
].g
:= g
;
888 g_dynLights
[g_dynLightCount
].b
:= b
;
889 g_dynLights
[g_dynLightCount
].a
:= a
;
890 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
891 Inc(g_dynLightCount
);
894 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
896 if not gwin_has_stencil
then exit
;
897 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
898 g_dynLights
[g_dynLightCount
].x
:= x
;
899 g_dynLights
[g_dynLightCount
].y
:= y
;
900 g_dynLights
[g_dynLightCount
].radius
:= 0;
901 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
902 g_dynLights
[g_dynLightCount
].r
:= r
;
903 g_dynLights
[g_dynLightCount
].g
:= g
;
904 g_dynLights
[g_dynLightCount
].b
:= b
;
905 g_dynLights
[g_dynLightCount
].a
:= 0;
906 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
907 Inc(g_dynLightCount
);
910 // ////////////////////////////////////////////////////////////////////////// //
911 function conIsCheatsEnabled (): Boolean; inline;
914 if g_Game_IsNet
then exit
;
915 if not gDebugMode
then
917 //if not gCheats then exit;
918 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
919 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
924 // ////////////////////////////////////////////////////////////////////////// //
926 TParamStrValue
= record
931 TParamStrValues
= Array of TParamStrValue
;
934 INTER_ACTION_TEXT
= 1;
935 INTER_ACTION_PIC
= 2;
936 INTER_ACTION_MUSIC
= 3;
941 DataLoaded
: Boolean = False;
943 MapList
: SSArray
= nil;
944 MapIndex
: Integer = -1;
945 InterReadyTime
: Integer = -1;
946 StatDate
: string = '';
961 function Compare(a
, b
: TPlayerStat
): Integer;
963 if a
.Spectator
then Result
:= 1
964 else if b
.Spectator
then Result
:= -1
965 else if a
.Frags
< b
.Frags
then Result
:= 1
966 else if a
.Frags
> b
.Frags
then Result
:= -1
967 else if a
.Deaths
< b
.Deaths
then Result
:= -1
968 else if a
.Deaths
> b
.Deaths
then Result
:= 1
969 else if a
.Kills
< b
.Kills
then Result
:= -1
973 procedure SortGameStat(var stat
: TPlayerStatArray
);
978 if stat
= nil then Exit
;
980 for I
:= High(stat
) downto Low(stat
) do
981 for J
:= Low(stat
) to High(stat
) - 1 do
982 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
985 stat
[J
] := stat
[J
+ 1];
990 // saves a shitty CSV containing the game stats passed to it
991 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
994 dir
, fname
, map
, mode
, etime
: String;
998 dir
:= e_GetWriteableDir(StatsDirs
);
999 // stats are placed in stats/yy/mm/dd/*.csv
1000 fname
:= e_CatPath(dir
, Path
);
1001 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
1002 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
1003 AssignFile(s
, fname
);
1005 SetTextCodePage(s
, CP_UTF8
);
1007 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
1008 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
1009 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
1010 mode
:= g_Game_ModeToText(Stat
.GameMode
);
1011 etime
:= Format('%d:%.2d:%.2d', [
1012 Stat
.GameTime
div 1000 div 3600,
1013 (Stat
.GameTime
div 1000 div 60) mod 60,
1014 Stat
.GameTime
div 1000 mod 60
1016 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
1017 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
1023 gGameSettings
.TimeLimit
,
1024 gGameSettings
.ScoreLimit
,
1025 gGameSettings
.Options
,
1027 Length(Stat
.PlayerStat
)
1029 // line 2: game specific shit
1030 // if it's a team game: red score, blue score
1031 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1032 // otherwise nothing
1033 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1035 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
1036 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1038 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1039 // lines 3-...: team, player name, frags, deaths
1040 WriteLn(s
, 'team,name,frags,deaths');
1041 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1042 with Stat
.PlayerStat
[I
] do
1043 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1045 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1048 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1053 procedure ClearDebugCvars();
1055 g_debug_Sounds
:= False;
1056 g_debug_Frames
:= False;
1057 g_debug_WinMsgs
:= False;
1058 g_debug_MonsterOff
:= False;
1059 g_debug_BotAIOff
:= 0;
1060 g_debug_HealthBar
:= False;
1061 g_Debug_Player
:= False;
1064 function g_Game_ModeToText(Mode
: Byte): string;
1068 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1069 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1070 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1071 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1072 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1076 function g_Game_TextToMode(Mode
: string): Byte;
1079 Mode
:= UpperCase(Mode
);
1080 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1085 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1090 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1095 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1100 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1102 Result
:= GM_SINGLE
;
1107 function g_Game_IsNet(): Boolean;
1109 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1112 function g_Game_IsServer(): Boolean;
1114 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1117 function g_Game_IsClient(): Boolean;
1119 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1122 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1129 Result
.name
:= ExtractFileName(WAD
);
1130 Result
.description
:= '';
1131 Result
.author
:= '';
1133 w
:= TWADFile
.Create();
1136 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1142 cfg
:= TConfig
.CreateMem(p
, len
);
1143 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1144 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1145 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1146 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1152 procedure g_Game_FreeWAD
;
1155 g_Sound_Delete('MUSIC_endmus');
1156 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1157 gGameSettings
.WAD
:= '';
1160 procedure g_Game_LoadWAD(WAD
: string);
1169 gGameSettings
.WAD
:= WAD
;
1170 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1173 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1175 w
:= TWADFile
.Create();
1178 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1184 cfg
:= TConfig
.CreateMem(p
, len
);
1187 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1188 if MegaWAD
.endpic
<> '' then
1189 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1191 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1192 if MegaWAD
.endmus
<> '' then
1194 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1195 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1203 {procedure start_trigger(t: string);
1207 function next_trigger(): Boolean;
1211 procedure DisableCheats();
1217 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1218 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1219 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1220 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1222 {$IF DEFINED(D2F_DEBUG)}
1223 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1224 gAimLine
:= g_dbg_aimline_on
;
1228 procedure g_Game_ExecuteEvent(Name
: String);
1234 if gEvents
= nil then
1236 for a
:= 0 to High(gEvents
) do
1237 if gEvents
[a
].Name
= Name
then
1239 if gEvents
[a
].Command
<> '' then
1240 g_Console_Process(gEvents
[a
].Command
, True);
1245 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1250 if gDelayedEvents
<> nil then
1251 for a
:= 0 to High(gDelayedEvents
) do
1252 if not gDelayedEvents
[a
].Pending
then
1259 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1260 n
:= High(gDelayedEvents
);
1262 gDelayedEvents
[n
].Pending
:= True;
1263 gDelayedEvents
[n
].DEType
:= DEType
;
1264 gDelayedEvents
[n
].DENum
:= Num
;
1265 gDelayedEvents
[n
].DEStr
:= Str
;
1266 if DEType
= DE_GLOBEVENT
then
1267 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1269 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1273 procedure EndGame();
1279 if g_Game_IsNet
and g_Game_IsServer
then
1280 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1283 gPauseMain
:= false;
1284 gPauseHolmes
:= false;
1287 g_Game_StopAllSounds(False);
1292 EndingGameCounter
:= 0;
1294 {$IFDEF ENABLE_MENU}
1295 g_ActiveWindow
:= nil;
1298 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1299 gLMSRespawnTime
:= 0;
1302 EXIT_SIMPLE
: // Выход через меню или конец теста
1306 begin // Это был тест
1310 begin // Выход в главное меню
1311 {$IFDEF DISABLE_MENU}
1312 gState
:= STATE_MENU
; // ???
1314 gMusic
.SetByName('MUSIC_MENU');
1316 if gState
<> STATE_SLIST
then
1318 g_GUI_ShowWindow('MainMenu');
1319 gState
:= STATE_MENU
;
1323 // Обновляем список серверов
1324 slReturnPressed
:= True;
1325 if g_Net_Slist_Fetch(slCurrent
) then
1327 if slCurrent
= nil then
1328 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1331 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1332 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1335 g_Game_ExecuteEvent('ongameend');
1339 EXIT_RESTART
: // Начать уровень сначала
1341 if not g_Game_IsClient
then g_Game_Restart();
1344 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1346 // Статистика Своей игры:
1347 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1349 CustomStat
.GameTime
:= gTime
;
1350 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1351 CustomStat
.MapName
:= gMapInfo
.Name
;
1352 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1353 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1354 CustomStat
.TeamStat
:= gTeamStat
;
1356 CustomStat
.PlayerStat
:= nil;
1358 // Статистика игроков:
1359 if gPlayers
<> nil then
1361 for a
:= 0 to High(gPlayers
) do
1362 if gPlayers
[a
] <> nil then
1364 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1365 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1368 Name
:= gPlayers
[a
].Name
;
1369 Frags
:= gPlayers
[a
].Frags
;
1370 Deaths
:= gPlayers
[a
].Death
;
1371 Kills
:= gPlayers
[a
].Kills
;
1372 Team
:= gPlayers
[a
].Team
;
1373 Color
:= gPlayers
[a
].Model
.Color
;
1374 Spectator
:= gPlayers
[a
].FSpectator
;
1378 SortGameStat(CustomStat
.PlayerStat
);
1380 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1383 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1384 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1385 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1386 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1388 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1391 StatShotDone
:= False;
1394 g_Game_ExecuteEvent('onmapend');
1395 if not g_Game_IsClient
then g_Player_ResetReady
;
1396 gInterReadyCount
:= 0;
1398 // Затухающий экран:
1399 EndingGameCounter
:= 255;
1400 gState
:= STATE_FOLD
;
1402 if gDefInterTime
< 0 then
1403 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1405 gInterEndTime
:= gDefInterTime
* 1000;
1408 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1410 // Статистика Одиночной игры:
1411 SingleStat
.GameTime
:= gTime
;
1412 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1413 SingleStat
.TotalSecrets
:= gSecretsCount
;
1414 // Статистика первого игрока:
1415 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1416 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1417 // Статистика второго игрока (если есть):
1418 if SingleStat
.TwoPlayers
then
1420 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1421 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1424 g_Game_ExecuteEvent('onmapend');
1427 if gNextMap
<> '' then
1429 gMusic
.SetByName('MUSIC_INTERMUS');
1431 gState
:= STATE_INTERSINGLE
;
1434 g_Game_ExecuteEvent('oninter');
1436 else // Больше нет карт
1438 // Затухающий экран:
1439 EndingGameCounter
:= 255;
1440 gState
:= STATE_FOLD
;
1445 // Окончание обработано:
1446 if gExit
<> EXIT_QUIT
then
1450 procedure g_Game_Init();
1454 gTempDelete
:= False;
1456 sfsGCDisable(); // temporary disable removing of temporary volumes
1459 g_Game_ClearLoading();
1460 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1461 g_Game_SetLoadingText('', 0, False);
1463 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1466 gPauseMain
:= false;
1467 gPauseHolmes
:= false;
1470 {e_MouseInfo.Accel := 1.0;}
1472 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1475 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1476 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1477 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1478 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1479 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1481 gMusic
:= TMusic
.Create();
1482 gMusic
.SetByName('MUSIC_MENU');
1485 gGameSettings
.WarmupTime
:= 30;
1487 gState
:= STATE_MENU
;
1489 SetLength(gEvents
, 6);
1490 gEvents
[0].Name
:= 'ongamestart';
1491 gEvents
[1].Name
:= 'ongameend';
1492 gEvents
[2].Name
:= 'onmapstart';
1493 gEvents
[3].Name
:= 'onmapend';
1494 gEvents
[4].Name
:= 'oninter';
1495 gEvents
[5].Name
:= 'onwadend';
1497 sfsGCEnable(); // enable releasing unused volumes
1501 procedure g_Game_Free(freeTextures
: Boolean=true);
1503 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1504 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1506 g_Map_Free(freeTextures
);
1509 {$IFDEF ENABLE_GIBS}
1512 {$IFDEF ENALBE_SHELLS}
1515 {$IFDEF ENABLE_CORPSES}
1516 g_Corpses_RemoveAll
;
1519 gGameSettings
.GameType
:= GT_NONE
;
1520 if gGameSettings
.GameMode
= GM_SINGLE
then
1521 gGameSettings
.GameMode
:= GM_DM
;
1522 gSwitchGameMode
:= gGameSettings
.GameMode
;
1525 gExitByTrigger
:= False;
1528 function IsActivePlayer(p
: TPlayer
): Boolean;
1533 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1536 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1542 if gPlayers
= nil then
1546 for a
:= Low(gPlayers
) to High(gPlayers
) do
1547 if IsActivePlayer(gPlayers
[a
]) then
1549 SetLength(ids
, Length(ids
) + 1);
1550 ids
[High(ids
)] := gPlayers
[a
].UID
;
1551 if gPlayers
[a
].UID
= Skip
then
1554 if Length(ids
) = 0 then
1559 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1562 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1568 if gPlayers
= nil then
1572 for a
:= Low(gPlayers
) to High(gPlayers
) do
1573 if IsActivePlayer(gPlayers
[a
]) then
1575 SetLength(ids
, Length(ids
) + 1);
1576 ids
[High(ids
)] := gPlayers
[a
].UID
;
1577 if gPlayers
[a
].UID
= Skip
then
1580 if Length(ids
) = 0 then
1583 Result
:= ids
[Length(ids
) - 1]
1585 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1588 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1594 if gPlayers
= nil then
1598 for a
:= Low(gPlayers
) to High(gPlayers
) do
1599 if IsActivePlayer(gPlayers
[a
]) then
1601 SetLength(ids
, Length(ids
) + 1);
1602 ids
[High(ids
)] := gPlayers
[a
].UID
;
1603 if gPlayers
[a
].UID
= Skip
then
1606 if Length(ids
) = 0 then
1608 if Length(ids
) = 1 then
1613 Result
:= ids
[Random(Length(ids
))];
1615 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1617 Result
:= ids
[Random(Length(ids
))];
1622 function GetRandomSpectMode(Current
: Byte): Byte;
1629 0: Result
:= SPECT_STATS
;
1630 1: Result
:= SPECT_MAPVIEW
;
1631 2: Result
:= SPECT_MAPVIEW
;
1632 3: Result
:= SPECT_PLAYERS
;
1633 4: Result
:= SPECT_PLAYERS
;
1634 5: Result
:= SPECT_PLAYERS
;
1635 6: Result
:= SPECT_PLAYERS
;
1637 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1641 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1647 if (plr
= nil) then exit
;
1648 if (p
= 2) then time
:= 1000 else time
:= 1;
1649 strafeDir
:= MoveButton
shr 4;
1650 MoveButton
:= MoveButton
and $0F;
1652 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1653 MoveButton
:= 1 // Нажата только "Влево"
1654 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1655 MoveButton
:= 2 // Нажата только "Вправо"
1656 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1657 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1659 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1660 if MoveButton
= 1 then
1661 plr
.PressKey(KEY_LEFT
, time
)
1662 else if MoveButton
= 2 then
1663 plr
.PressKey(KEY_RIGHT
, time
);
1665 // if we have "strafe" key, turn off old strafe mechanics
1666 if gPlayerAction
[p
, ACTION_STRAFE
] then
1668 // new strafe mechanics
1669 if (strafeDir
= 0) then
1670 strafeDir
:= MoveButton
; // start strafing
1671 // now set direction according to strafe (reversed)
1672 if (strafeDir
= 2) then
1673 plr
.SetDirection(TDirection
.D_LEFT
)
1674 else if (strafeDir
= 1) then
1675 plr
.SetDirection(TDirection
.D_RIGHT
)
1679 strafeDir
:= 0; // not strafing anymore
1680 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1681 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1682 plr
.SetDirection(TDirection
.D_LEFT
)
1683 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1684 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1685 plr
.SetDirection(TDirection
.D_RIGHT
)
1686 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1687 else if MoveButton
<> 0 then
1688 plr
.SetDirection(TDirection(MoveButton
-1))
1691 // fix movebutton state
1692 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1694 // Остальные клавиши:
1695 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1696 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1697 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1698 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1699 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1701 for i
:= WP_FACT
to WP_LACT
do
1703 if gWeaponAction
[p
, i
] then
1705 plr
.ProcessWeaponAction(i
);
1706 gWeaponAction
[p
, i
] := False
1710 for i
:= WP_FIRST
to WP_LAST
do
1712 if gSelectWeapon
[p
, i
] then
1714 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1715 gSelectWeapon
[p
, i
] := False
1719 {$IFDEF ENABLE_MENU}
1720 // HACK: add dynlight here
1721 if gwin_k8_enable_light_experiments
then
1723 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1725 g_playerLight
:= true;
1727 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1729 g_playerLight
:= false;
1733 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1737 // HACK: don't have a "key was pressed" function
1738 procedure InterReady();
1740 if InterReadyTime
> gTime
then Exit
;
1741 InterReadyTime
:= gTime
+ 3000;
1742 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1745 procedure g_Game_PreUpdate();
1747 // these are in separate PreUpdate functions because they can interact during Update()
1748 // and are synced over the net
1749 // we don't care that much about corpses and gibs
1750 g_Player_PreUpdate();
1751 g_Monsters_PreUpdate();
1752 g_Items_PreUpdate();
1753 g_Weapon_PreUpdate();
1756 procedure g_Game_Update();
1758 {$IFDEF ENABLE_MENU}
1759 Msg
: g_gui
.TMessage
;
1766 function sendMonsPos (mon
: TMonster
): Boolean;
1768 result
:= false; // don't stop
1769 // this will also reset "need-send" flag
1770 if mon
.gncNeedSend
then
1772 MH_SEND_MonsterPos(mon
.UID
);
1774 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1776 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1778 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1780 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1784 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1786 result
:= false; // don't stop
1787 // this will also reset "need-send" flag
1788 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1791 function sendItemPos (it
: PItem
): Boolean;
1793 result
:= false; // don't stop
1796 MH_SEND_ItemPos(it
.myId
);
1797 it
.needSend
:= False;
1802 reliableUpdate
: Boolean;
1807 // Пора выключать игру:
1808 if gExit
= EXIT_QUIT
then
1810 // Игра закончилась - обрабатываем:
1814 if gExit
= EXIT_QUIT
then
1818 // Читаем клавиатуру и джойстик, если окно активно
1819 // no need to, as we'll do it in event handler
1821 // Обновляем консоль (движение и сообщения):
1824 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1826 gExit
:= EXIT_SIMPLE
;
1831 // process master server communications
1832 g_Net_Slist_Pulse();
1835 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1836 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1837 STATE_INTERTEXT
, // Текст между уровнями
1838 STATE_INTERPIC
: // Картинка между уровнями
1840 if g_Game_IsNet
and g_Game_IsServer
then
1842 gInterTime
:= gInterTime
+ GAME_TICK
;
1843 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1844 if a
<> gServInterTime
then
1846 gServInterTime
:= a
;
1847 MH_SEND_TimeSync(gServInterTime
);
1851 if (not g_Game_IsClient
) and
1855 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1856 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1857 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1858 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1860 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1861 {$IFDEF ENABLE_MENU}
1862 and (g_ActiveWindow
= nil)
1865 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1868 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1869 g_Game_StopAllSounds(True);
1871 if gMapOnce
then // Это был тест
1872 gExit
:= EXIT_SIMPLE
1874 if gNextMap
<> '' then // Переходим на следующую карту
1875 g_Game_ChangeMap(gNextMap
)
1876 else // Следующей карты нет
1878 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1880 // Выход в главное меню:
1882 {$IFDEF ENABLE_MENU}
1883 g_GUI_ShowWindow('MainMenu');
1884 gMusic
.SetByName('MUSIC_MENU');
1887 gState
:= STATE_MENU
;
1890 // Финальная картинка:
1891 g_Game_ExecuteEvent('onwadend');
1893 if not gMusic
.SetByName('MUSIC_endmus') then
1894 gMusic
.SetByName('MUSIC_STDENDMUS');
1896 gState
:= STATE_ENDPIC
;
1898 g_Game_ExecuteEvent('ongameend');
1903 else if g_Game_IsClient
and
1906 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1907 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1908 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1909 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1911 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1912 {$IFDEF ENABLE_MENU}
1913 and (g_ActiveWindow
= nil)
1922 if gState
= STATE_INTERTEXT
then
1923 if InterText
.counter
> 0 then
1924 InterText
.counter
:= InterText
.counter
- 1;
1927 STATE_FOLD
: // Затухание экрана
1929 if EndingGameCounter
= 0 then
1931 // Закончился уровень в Своей игре:
1932 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1934 gState
:= STATE_INTERCUSTOM
;
1935 InterReadyTime
:= -1;
1936 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1938 g_Game_ExecuteEvent('onwadend');
1939 if not gMusic
.SetByName('MUSIC_endmus') then
1940 gMusic
.SetByName('MUSIC_STDENDMUS');
1943 gMusic
.SetByName('MUSIC_ROUNDMUS');
1947 else // Закончилась последняя карта в Одиночной игре
1949 gMusic
.SetByName('MUSIC_INTERMUS');
1951 gState
:= STATE_INTERSINGLE
;
1954 g_Game_ExecuteEvent('oninter');
1957 DecMin(EndingGameCounter
, 6, 0);
1960 STATE_ENDPIC
: // Картинка окончания мегаВада
1962 if gMapOnce
then // Это был тест
1964 gExit
:= EXIT_SIMPLE
;
1970 g_Serverlist_Control(slCurrent
, slTable
);
1973 // Статистика по Tab:
1975 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1978 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1980 // Время += 28 миллисекунд:
1981 gTime
:= gTime
+ GAME_TICK
;
1983 // Сообщение посередине экрана:
1984 if MessageTime
= 0 then
1986 if MessageTime
> 0 then
1987 MessageTime
:= MessageTime
- 1;
1989 if (g_Game_IsServer
) then
1991 // Был задан лимит времени:
1992 if (gGameSettings
.TimeLimit
> 0) then
1993 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1994 begin // Он прошел => конец уровня
1999 // Надо респавнить игроков в LMS:
2000 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
2001 g_Game_RestartRound(gLMSSoftSpawn
);
2003 // Проверим результат голосования, если время прошло
2004 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2006 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2008 g_Console_Process(gVoteCommand
);
2010 gVotePassed
:= False;
2013 // Замеряем время захвата флагов
2014 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2015 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2016 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2017 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2019 // Был задан лимит побед:
2020 if (gGameSettings
.ScoreLimit
> 0) then
2024 if gGameSettings
.GameMode
= GM_DM
then
2025 begin // В DM ищем игрока с max фрагами
2026 for i
:= 0 to High(gPlayers
) do
2027 if gPlayers
[i
] <> nil then
2028 if gPlayers
[i
].Frags
> b
then
2029 b
:= gPlayers
[i
].Frags
;
2032 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2033 begin // В CTF/TDM выбираем команду с наибольшим счетом
2034 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2037 // Лимит побед набран => конец уровня:
2038 if b
>= gGameSettings
.ScoreLimit
then
2045 // Обрабатываем клавиши игроков:
2046 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2047 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2048 {$IFDEF DISABLE_MENU}
2049 if (not gConsoleShow
) and (not gChatShow
) then
2051 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2054 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2055 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2056 end // if not console
2059 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2061 // process weapon switch queue
2065 if (gPlayer1
= nil) and (gPlayer2
= nil)
2066 and (not gConsoleShow
) and (not gChatShow
)
2067 {$IFDEF ENABLE_MENU}
2068 and (g_ActiveWindow
= nil)
2072 if not gSpectKeyPress
then
2074 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2076 // switch spect mode
2078 SPECT_NONE
: ; // not spectator
2080 SPECT_MAPVIEW
: Inc(gSpectMode
);
2081 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2083 gSpectKeyPress
:= True;
2085 if (gSpectMode
= SPECT_MAPVIEW
)
2086 and (not gSpectAuto
) then
2088 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2089 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2090 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2091 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2092 if gPlayerAction
[0, ACTION_LOOKUP
] then
2093 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2094 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2095 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2096 if gWeaponAction
[0, WP_PREV
] then
2099 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2100 gWeaponAction
[0, WP_PREV
] := False;
2102 if gWeaponAction
[0, WP_NEXT
] then
2105 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2106 gWeaponAction
[0, WP_NEXT
] := False;
2109 if (gSpectMode
= SPECT_PLAYERS
)
2110 and (not gSpectAuto
) then
2112 if gPlayerAction
[0, ACTION_LOOKUP
] then
2115 gSpectViewTwo
:= True;
2116 gSpectKeyPress
:= True;
2118 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2120 // remove second view
2121 gSpectViewTwo
:= False;
2122 gSpectKeyPress
:= True;
2124 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2126 // prev player (view 1)
2127 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2128 gSpectKeyPress
:= True;
2130 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2132 // next player (view 1)
2133 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2134 gSpectKeyPress
:= True;
2136 if gWeaponAction
[0, WP_PREV
] then
2138 // prev player (view 2)
2139 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2140 gWeaponAction
[0, WP_PREV
] := False;
2142 if gWeaponAction
[0, WP_NEXT
] then
2144 // next player (view 2)
2145 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2146 gWeaponAction
[0, WP_NEXT
] := False;
2149 if gPlayerAction
[0, ACTION_ATTACK
] then
2151 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2154 gSpectAutoNext
:= 0;
2155 gSpectViewTwo
:= False;
2156 gSpectKeyPress
:= True;
2161 gSpectMode
:= SPECT_STATS
;
2162 gSpectAuto
:= False;
2163 gSpectKeyPress
:= True;
2168 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2169 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2170 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2171 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2172 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2173 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2174 gSpectKeyPress
:= False;
2178 if gSpectMode
= SPECT_MAPVIEW
then
2180 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2182 gSpectAutoNext
:= gTime
2185 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2187 gSpectAutoNext
:= gTime
2191 if gSpectAutoNext
<= gTime
then
2193 if gSpectAutoNext
> 0 then
2195 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2199 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2200 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2201 gSpectAutoStepX
:= Random(9) - 4;
2202 gSpectAutoStepY
:= Random(9) - 4;
2203 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2204 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2205 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2206 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2207 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2208 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2212 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2217 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2218 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2219 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2225 // Обновляем все остальное:
2228 g_Triggers_Update();
2230 g_Monsters_Update();
2234 g_Player_UpdateAll();
2235 {$IFDEF ENABLE_GIBS}
2238 {$IFDEF ENABLE_CORPSES}
2241 {$IFDEF ENABLE_SHELLS}
2245 // server: send newly spawned monsters unconditionally
2246 if (gGameSettings
.GameType
= GT_SERVER
) then
2248 if (Length(gMonstersSpawned
) > 0) then
2250 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2251 SetLength(gMonstersSpawned
, 0);
2255 if (gSoundTriggerTime
> 8) then
2257 g_Game_UpdateTriggerSounds();
2258 gSoundTriggerTime
:= 0;
2262 Inc(gSoundTriggerTime
);
2265 if (NetMode
= NET_SERVER
) then
2267 Inc(NetTimeToUpdate
);
2268 Inc(NetTimeToReliable
);
2270 // send monster updates
2271 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2273 // send all monsters (periodic sync)
2274 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2276 for I
:= 0 to High(gPlayers
) do
2278 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2281 g_Mons_ForEach(sendMonsPos
);
2283 // update flags that aren't stationary
2284 if gGameSettings
.GameMode
= GM_CTF
then
2285 for I
:= FLAG_RED
to FLAG_BLUE
do
2286 if gFlags
[I
].NeedSend
then
2288 gFlags
[I
].NeedSend
:= False;
2292 // update items that aren't stationary
2293 g_Items_ForEachAlive(sendItemPos
);
2295 if reliableUpdate
then
2297 NetTimeToReliable
:= 0;
2298 NetTimeToUpdate
:= NetUpdateRate
;
2302 NetTimeToUpdate
:= 0;
2307 // send only mosters with some unexpected changes
2308 g_Mons_ForEach(sendMonsPosUnexpected
);
2311 // send unexpected platform changes
2312 g_Map_NetSendInterestingPanels();
2314 g_Net_Slist_ServerUpdate();
2316 if NetUseMaster then
2318 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2320 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2322 NetTimeToMaster := gTime + NetMasterRate;
2327 else if (NetMode
= NET_CLIENT
) then
2329 MC_SEND_PlayerPos();
2331 end; // if gameOn ...
2333 // Активно окно интерфейса - передаем клавиши ему:
2334 {$IFDEF ENABLE_MENU}
2335 if g_ActiveWindow
<> nil then
2337 w
:= e_GetFirstKeyPressed();
2339 if (w
<> IK_INVALID
) then
2341 Msg
.Msg
:= MESSAGE_DIKEY
;
2343 g_ActiveWindow
.OnMessage(Msg
);
2346 // Если оно от этого не закрылось, то обновляем:
2347 if g_ActiveWindow
<> nil then
2348 g_ActiveWindow
.Update();
2350 // Нужно сменить разрешение:
2351 if gResolutionChange
then
2353 {$IFDEF ENABLE_RENDER}
2354 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2357 gResolutionChange
:= False;
2358 g_ActiveWindow
:= nil;
2361 // Нужно сменить язык:
2362 if gLanguageChange
then
2364 //e_WriteLog('Read language file', MSG_NOTIFY);
2365 //g_Language_Load(DataDir + gLanguage + '.txt');
2366 g_Language_Set(gLanguage
);
2368 gLanguageChange
:= False;
2372 // Горячая клавиша для вызова меню выхода из игры (F10):
2373 if e_KeyPressed(IK_F10
) and
2375 (not gConsoleShow
) and
2376 (g_ActiveWindow
= nil) then
2382 Time
:= GetTickCount64() {div 1000};
2384 // Обработка отложенных событий:
2385 if gDelayedEvents
<> nil then
2386 for a
:= 0 to High(gDelayedEvents
) do
2387 if gDelayedEvents
[a
].Pending
and
2389 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2390 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2393 case gDelayedEvents
[a
].DEType
of
2395 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2398 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2402 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2403 if g_Game_IsNet
and g_Game_IsServer
then
2404 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2408 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2410 gDelayedEvents
[a
].Pending
:= False;
2413 // Каждую секунду обновляем счетчик обновлений:
2414 UPSCounter
:= UPSCounter
+ 1;
2415 if Time
- UPSTime
>= 1000 then
2424 g_Weapon_AddDynLights();
2425 g_Items_AddDynLights();
2429 procedure g_Game_LoadChatSounds(Resource
: string);
2432 FileName
, Snd
: string;
2434 len
, cnt
, tags
, i
, j
: Integer;
2437 FileName
:= g_ExtractWadName(Resource
);
2439 WAD
:= TWADFile
.Create();
2440 WAD
.ReadFile(FileName
);
2442 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2449 cfg
:= TConfig
.CreateMem(p
, len
);
2450 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2452 SetLength(gChatSounds
, cnt
);
2453 for i
:= 0 to Length(gChatSounds
) - 1 do
2455 gChatSounds
[i
].Sound
:= nil;
2456 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2457 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2458 if (Snd
= '') or (Tags
<= 0) then
2460 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2461 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2462 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2463 SetLength(gChatSounds
[i
].Tags
, tags
);
2464 for j
:= 0 to tags
- 1 do
2465 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2466 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2473 procedure g_Game_FreeChatSounds();
2477 for i
:= 0 to Length(gChatSounds
) - 1 do
2479 gChatSounds
[i
].Sound
.Free();
2480 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2482 SetLength(gChatSounds
, 0);
2486 procedure g_Game_LoadData();
2488 if DataLoaded
then Exit
;
2490 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2492 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2493 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2494 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2495 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2496 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2497 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2498 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2499 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2500 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2501 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2502 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2503 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2504 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2505 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2506 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2507 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2508 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2509 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2510 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2511 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2512 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2513 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2514 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2515 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2516 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2517 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2518 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2519 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2520 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2521 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2522 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2523 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2525 goodsnd
[0] := TPlayableSound
.Create();
2526 goodsnd
[1] := TPlayableSound
.Create();
2527 goodsnd
[2] := TPlayableSound
.Create();
2528 goodsnd
[3] := TPlayableSound
.Create();
2530 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2531 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2532 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2533 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2535 killsnd
[0] := TPlayableSound
.Create();
2536 killsnd
[1] := TPlayableSound
.Create();
2537 killsnd
[2] := TPlayableSound
.Create();
2538 killsnd
[3] := TPlayableSound
.Create();
2540 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2541 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2542 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2543 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2545 hahasnd
[0] := TPlayableSound
.Create();
2546 hahasnd
[1] := TPlayableSound
.Create();
2547 hahasnd
[2] := TPlayableSound
.Create();
2549 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2550 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2551 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2553 sound_get_flag
[0] := TPlayableSound
.Create();
2554 sound_get_flag
[1] := TPlayableSound
.Create();
2555 sound_lost_flag
[0] := TPlayableSound
.Create();
2556 sound_lost_flag
[1] := TPlayableSound
.Create();
2557 sound_ret_flag
[0] := TPlayableSound
.Create();
2558 sound_ret_flag
[1] := TPlayableSound
.Create();
2559 sound_cap_flag
[0] := TPlayableSound
.Create();
2560 sound_cap_flag
[1] := TPlayableSound
.Create();
2562 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2563 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2564 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2565 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2566 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2567 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2568 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2569 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2571 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2573 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2576 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2577 g_Weapon_LoadData();
2579 g_Monsters_LoadData();
2584 procedure g_Game_Quit();
2586 g_Game_StopAllSounds(True);
2589 g_PlayerModel_FreeData();
2590 {$IFDEF ENABLE_MENU}
2591 // g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2594 if NetInitDone
then g_Net_Free
;
2596 // remove map after test
2597 if gMapToDelete
<> '' then
2598 g_Game_DeleteTestMap();
2602 {$IFDEF ENABLE_SYSTEM}
2607 procedure g_Game_FreeData();
2609 if not DataLoaded
then Exit
;
2612 g_Weapon_FreeData();
2613 g_Monsters_FreeData();
2615 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2617 g_Sound_Delete('SOUND_GAME_TELEPORT');
2618 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2619 g_Sound_Delete('SOUND_GAME_SECRET');
2620 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2621 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2622 g_Sound_Delete('SOUND_GAME_BULK1');
2623 g_Sound_Delete('SOUND_GAME_BULK2');
2624 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2625 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2626 g_Sound_Delete('SOUND_GAME_BURNING');
2627 g_Sound_Delete('SOUND_GAME_SWITCH1');
2628 g_Sound_Delete('SOUND_GAME_SWITCH0');
2635 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2636 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2637 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2638 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2645 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2646 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2647 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2648 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2654 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2655 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2656 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2658 sound_get_flag
[0].Free();
2659 sound_get_flag
[1].Free();
2660 sound_lost_flag
[0].Free();
2661 sound_lost_flag
[1].Free();
2662 sound_ret_flag
[0].Free();
2663 sound_ret_flag
[1].Free();
2664 sound_cap_flag
[0].Free();
2665 sound_cap_flag
[1].Free();
2667 g_Sound_Delete('SOUND_CTF_GET1');
2668 g_Sound_Delete('SOUND_CTF_GET2');
2669 g_Sound_Delete('SOUND_CTF_LOST1');
2670 g_Sound_Delete('SOUND_CTF_LOST2');
2671 g_Sound_Delete('SOUND_CTF_RETURN1');
2672 g_Sound_Delete('SOUND_CTF_RETURN2');
2673 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2674 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2676 g_Game_FreeChatSounds();
2678 DataLoaded
:= False;
2681 procedure g_FatalError(Text: String);
2683 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2684 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2686 gExit
:= EXIT_SIMPLE
;
2687 if gGameOn
then EndGame
;
2690 procedure g_SimpleError(Text: String);
2692 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2693 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2696 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2698 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2699 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2702 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2705 if gPlayer1
= nil then
2707 if g_Game_IsClient
then
2709 if NetPlrUID1
> -1 then
2710 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2714 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2715 Team
:= gPlayer1Settings
.Team
;
2717 // Создание первого игрока:
2718 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2719 gPlayer1Settings
.Color
,
2721 if gPlayer1
= nil then
2722 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2725 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2726 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2727 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2728 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2729 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2730 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2731 if g_Game_IsServer
and g_Game_IsNet
then
2732 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2733 gPlayer1
.Respawn(False, True);
2734 g_Net_Slist_ServerPlayerComes();
2739 if gPlayer2
= nil then
2741 if g_Game_IsClient
then
2743 if NetPlrUID2
> -1 then
2744 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2748 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2749 Team
:= gPlayer2Settings
.Team
;
2751 // Создание второго игрока:
2752 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2753 gPlayer2Settings
.Color
,
2755 if gPlayer2
= nil then
2756 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2759 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2760 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2761 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2762 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2763 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2764 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2765 if g_Game_IsServer
and g_Game_IsNet
then
2766 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2767 gPlayer2
.Respawn(False, True);
2768 g_Net_Slist_ServerPlayerComes();
2775 procedure g_Game_RemovePlayer();
2779 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2780 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2785 if g_Game_IsServer
then
2788 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2789 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2790 g_Player_Remove(Pl
.UID
);
2791 g_Net_Slist_ServerPlayerLeaves();
2795 gSpectLatchPID2
:= Pl
.UID
;
2803 if g_Game_IsServer
then
2806 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2807 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2808 g_Player_Remove(Pl
.UID
);
2809 g_Net_Slist_ServerPlayerLeaves();
2812 gSpectLatchPID1
:= Pl
.UID
;
2814 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2818 g_Net_Slist_ServerPlayerLeaves();
2821 procedure g_Game_Spectate();
2823 g_Game_RemovePlayer();
2824 if gPlayer1
<> nil then
2825 g_Game_RemovePlayer();
2828 procedure g_Game_SpectateCenterView();
2830 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2831 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2834 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2841 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2843 g_Game_ClearLoading();
2846 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2849 gGameSettings
.GameType
:= GT_SINGLE
;
2850 gGameSettings
.MaxLives
:= 0;
2851 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2852 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2853 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2854 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2855 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2856 gSwitchGameMode
:= GM_SINGLE
;
2858 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2859 gLMSRespawnTime
:= 0;
2860 gSpectLatchPID1
:= 0;
2861 gSpectLatchPID2
:= 0;
2863 g_Game_ExecuteEvent('ongamestart');
2865 // Создание первого игрока:
2866 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2867 gPlayer1Settings
.Color
,
2868 gPlayer1Settings
.Team
, False));
2869 if gPlayer1
= nil then
2871 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2875 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2876 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2877 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2878 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2879 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2882 // Создание второго игрока, если есть:
2885 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2886 gPlayer2Settings
.Color
,
2887 gPlayer2Settings
.Team
, False));
2888 if gPlayer2
= nil then
2890 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2894 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2895 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2896 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2897 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2898 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2902 // Загрузка и запуск карты:
2903 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2905 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2906 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2910 // Настройки игроков и ботов:
2914 for i
:= nPl
+1 to nPlayers
do
2915 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2918 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2919 TimeLimit
, ScoreLimit
: Word;
2921 Options
: LongWord; nPlayers
: Byte);
2927 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2929 g_Game_ClearLoading();
2932 gGameSettings
.GameType
:= GT_CUSTOM
;
2933 gGameSettings
.GameMode
:= GameMode
;
2934 gSwitchGameMode
:= GameMode
;
2935 gGameSettings
.TimeLimit
:= TimeLimit
;
2936 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2937 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2938 gGameSettings
.Options
:= Options
;
2940 gCoopTotalMonstersKilled
:= 0;
2941 gCoopTotalSecretsFound
:= 0;
2942 gCoopTotalMonsters
:= 0;
2943 gCoopTotalSecrets
:= 0;
2947 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2948 gLMSRespawnTime
:= 0;
2949 gSpectLatchPID1
:= 0;
2950 gSpectLatchPID2
:= 0;
2952 g_Game_ExecuteEvent('ongamestart');
2954 // Режим наблюдателя:
2955 if nPlayers
= 0 then
2962 if nPlayers
>= 1 then
2964 // Создание первого игрока:
2965 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2966 gPlayer1Settings
.Color
,
2967 gPlayer1Settings
.Team
, False));
2968 if gPlayer1
= nil then
2970 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2974 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2975 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2976 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2977 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2978 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2982 if nPlayers
>= 2 then
2984 // Создание второго игрока:
2985 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2986 gPlayer2Settings
.Color
,
2987 gPlayer2Settings
.Team
, False));
2988 if gPlayer2
= nil then
2990 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2994 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2995 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2996 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2997 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2998 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3002 // Загрузка и запуск карты:
3003 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3005 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3009 // Нет точек появления:
3010 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3011 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3012 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3013 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3014 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3016 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3020 // Настройки игроков и ботов:
3024 for i
:= nPl
+1 to nPlayers
do
3025 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3028 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3029 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3030 Options
: LongWord; nPlayers
: Byte;
3031 IPAddr
: LongWord; Port
: Word);
3034 g_Net_Slist_ServerClosed();
3036 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3038 g_Game_ClearLoading();
3043 gGameSettings
.GameType
:= GT_SERVER
;
3044 gGameSettings
.GameMode
:= GameMode
;
3045 gSwitchGameMode
:= GameMode
;
3046 gGameSettings
.TimeLimit
:= TimeLimit
;
3047 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3048 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3049 gGameSettings
.Options
:= Options
;
3051 gCoopTotalMonstersKilled
:= 0;
3052 gCoopTotalSecretsFound
:= 0;
3053 gCoopTotalMonsters
:= 0;
3054 gCoopTotalSecrets
:= 0;
3058 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3059 gLMSRespawnTime
:= 0;
3060 gSpectLatchPID1
:= 0;
3061 gSpectLatchPID2
:= 0;
3063 g_Game_ExecuteEvent('ongamestart');
3065 // Режим наблюдателя:
3066 if nPlayers
= 0 then
3072 if nPlayers
>= 1 then
3074 // Создание первого игрока:
3075 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3076 gPlayer1Settings
.Color
,
3077 gPlayer1Settings
.Team
, False));
3078 if gPlayer1
= nil then
3080 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3084 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3085 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3086 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3087 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3088 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3091 if nPlayers
>= 2 then
3093 // Создание второго игрока:
3094 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3095 gPlayer2Settings
.Color
,
3096 gPlayer2Settings
.Team
, False));
3097 if gPlayer2
= nil then
3099 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3103 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3104 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3105 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3106 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3107 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3110 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3111 if NetForwardPorts
then
3112 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3115 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3117 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3121 g_Net_Slist_Set(NetMasterList
);
3123 g_Net_Slist_ServerStarted();
3125 // Загрузка и запуск карты:
3126 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3128 g_Net_Slist_ServerClosed();
3129 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3133 // Нет точек появления:
3134 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3135 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3136 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3137 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3138 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3140 g_Net_Slist_ServerClosed();
3141 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3145 // Настройки игроков и ботов:
3148 g_Net_Slist_ServerMapStarted();
3149 NetState
:= NET_STATE_GAME
;
3152 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3167 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3168 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3170 g_Game_ClearLoading();
3175 gGameSettings
.GameType
:= GT_CLIENT
;
3177 gCoopTotalMonstersKilled
:= 0;
3178 gCoopTotalSecretsFound
:= 0;
3179 gCoopTotalMonsters
:= 0;
3180 gCoopTotalSecrets
:= 0;
3184 g_Game_ExecuteEvent('ongamestart');
3186 NetState
:= NET_STATE_AUTH
;
3188 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3190 // create (or update) map/resource databases
3191 g_Res_CreateDatabases(true);
3193 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3194 gLMSRespawnTime
:= 0;
3195 gSpectLatchPID1
:= 0;
3196 gSpectLatchPID2
:= 0;
3199 if not g_Net_Connect(Addr
, Port
) then
3201 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3202 NetState
:= NET_STATE_NONE
;
3206 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3208 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3213 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3214 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3215 // thank you, enet. let's ignore failures altogether then.
3216 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3218 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3220 Ptr
:= NetEvent
.packet
^.data
;
3221 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3223 enet_packet_destroy(NetEvent
.packet
);
3227 InMsg
.ReadLongWord(); // skip size
3228 MID
:= InMsg
.ReadByte();
3230 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3232 NetMyID
:= InMsg
.ReadByte();
3233 NetPlrUID1
:= InMsg
.ReadWord();
3235 WadName
:= InMsg
.ReadString();
3236 Map
:= InMsg
.ReadString();
3238 gWADHash
:= InMsg
.ReadMD5();
3240 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3241 gSwitchGameMode
:= gGameSettings
.GameMode
;
3242 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3243 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3244 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3245 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3246 T
:= InMsg
.ReadLongWord();
3248 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3249 //if newResPath = '' then
3251 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3252 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3253 if newResPath
= '' then
3255 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3256 enet_packet_destroy(NetEvent
.packet
);
3257 NetState
:= NET_STATE_NONE
;
3260 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3262 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3265 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3266 gPlayer1Settings
.Color
,
3267 gPlayer1Settings
.Team
, False));
3269 if gPlayer1
= nil then
3271 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3273 enet_packet_destroy(NetEvent
.packet
);
3274 NetState
:= NET_STATE_NONE
;
3278 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3279 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3280 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3281 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3282 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3283 gPlayer1
.UID
:= NetPlrUID1
;
3284 gPlayer1
.Reset(True);
3286 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3288 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3290 enet_packet_destroy(NetEvent
.packet
);
3291 NetState
:= NET_STATE_NONE
;
3299 enet_packet_destroy(NetEvent
.packet
);
3303 enet_packet_destroy(NetEvent
.packet
);
3307 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3310 if (NetEvent
.data
<= NET_DISC_MAX
) then
3311 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3312 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3319 ProcessLoading(True);
3320 if g_Net_UserRequestExit() then
3329 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3330 NetState
:= NET_STATE_NONE
;
3335 NetState
:= NET_STATE_GAME
;
3336 MC_SEND_FullStateRequest
;
3337 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3341 lastAsMegaWad
: Boolean = false;
3343 procedure g_Game_ChangeMap(const MapPath
: String);
3347 g_Game_ClearLoading();
3349 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3350 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3351 if gExitByTrigger
then
3354 gExitByTrigger
:= False;
3356 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3357 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3360 procedure g_Game_Restart();
3364 if g_Game_IsClient
then
3366 map
:= g_ExtractFileName(gMapInfo
.Map
);
3367 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3371 g_Game_ClearLoading();
3372 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3375 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3377 NewWAD
, ResName
: String;
3381 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3383 {$IFDEF ENABLE_GIBS}
3386 {$IFDEF ENALBE_SHELLS}
3389 {$IFDEF ENABLE_CORPSES}
3390 g_Corpses_RemoveAll
;
3393 if (not g_Game_IsClient
) and
3394 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3395 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3397 if gSwitchGameMode
= GM_CTF
then
3398 gGameSettings
.MaxLives
:= 0;
3399 gGameSettings
.GameMode
:= gSwitchGameMode
;
3402 gSwitchGameMode
:= gGameSettings
.GameMode
;
3404 g_Player_ResetTeams();
3406 lastAsMegaWad
:= asMegawad
;
3407 if isWadPath(Map
) then
3409 NewWAD
:= g_ExtractWadName(Map
);
3410 ResName
:= g_ExtractFileName(Map
);
3411 if g_Game_IsServer
then
3413 nws
:= findDiskWad(NewWAD
);
3414 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3417 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3418 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3422 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3423 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3425 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3426 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3428 if (length(nws
) = 0) then
3430 ResName
:= ''; // failed
3435 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3436 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3437 g_Game_LoadWAD(NewWAD
);
3442 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3443 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3448 NewWAD
:= gGameSettings
.WAD
;
3454 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3456 if (ResName
<> '') and (NewWAD
<> '') then
3458 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3459 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3460 {$IFDEF ENABLE_RENDER}
3461 r_Render_LoadTextures
;
3466 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3468 gState
:= STATE_NONE
;
3469 {$IFDEF ENABLE_MENU}
3470 g_ActiveWindow
:= nil;
3475 wNeedTimeReset
:= True;
3477 if gGameSettings
.GameMode
= GM_CTF
then
3479 g_Map_ResetFlag(FLAG_RED
);
3480 g_Map_ResetFlag(FLAG_BLUE
);
3481 // CTF, а флагов нет:
3482 if not g_Map_HaveFlagPoints() then
3483 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3488 gState
:= STATE_MENU
;
3493 gPauseMain
:= false;
3494 gPauseHolmes
:= false;
3495 NetTimeToUpdate
:= 1;
3496 NetTimeToReliable
:= 0;
3497 NetTimeToMaster
:= NetMasterRate
;
3498 gSpectLatchPID1
:= 0;
3499 gSpectLatchPID2
:= 0;
3500 gMissionFailed
:= False;
3503 gCoopMonstersKilled
:= 0;
3504 gCoopSecretsFound
:= 0;
3506 gVoteInProgress
:= False;
3507 gVotePassed
:= False;
3513 if not gGameOn
then Exit
;
3515 g_Game_SpectateCenterView();
3517 if g_Game_IsServer
then
3519 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3521 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3522 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3523 gLMSSoftSpawn
:= True;
3524 if g_Game_IsNet
then
3525 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3529 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3530 gLMSRespawnTime
:= 0;
3534 if NetMode
= NET_SERVER
then
3536 // reset full state flags
3537 if NetClients
<> nil then
3538 for I
:= 0 to High(NetClients
) do
3539 NetClients
[I
].FullUpdateSent
:= False;
3541 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3544 g_Net_Slist_ServerMapStarted();
3546 if NetClients
<> nil then
3547 for I
:= 0 to High(NetClients
) do
3548 if NetClients
[I
].Used
then
3550 NetClients
[I
].Voted
:= False;
3551 if NetClients
[I
].RequestedFullUpdate
then
3553 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3554 NetClients
[I
].RequestedFullUpdate
:= False;
3558 g_Net_UnbanNonPermHosts();
3563 gCoopTotalMonstersKilled
:= 0;
3564 gCoopTotalSecretsFound
:= 0;
3565 gCoopTotalMonsters
:= 0;
3566 gCoopTotalSecrets
:= 0;
3570 g_Game_ExecuteEvent('onmapstart');
3573 procedure SetFirstLevel
;
3577 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3578 if MapList
= nil then
3581 SortSArray(MapList
);
3582 gNextMap
:= MapList
[Low(MapList
)];
3587 procedure g_Game_ExitLevel(const Map
: AnsiString);
3591 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3592 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3593 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3594 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3596 // Вышли в выход в Одиночной игре:
3597 if gGameSettings
.GameType
= GT_SINGLE
then
3598 gExit
:= EXIT_ENDLEVELSINGLE
3599 else // Вышли в выход в Своей игре
3601 gExit
:= EXIT_ENDLEVELCUSTOM
;
3602 if gGameSettings
.GameMode
= GM_COOP
then
3603 g_Player_RememberAll
;
3605 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3608 if gGameSettings
.GameMode
= GM_COOP
then
3611 gStatsPressed
:= True;
3612 gNextMap
:= 'MAP01';
3614 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3617 if g_Game_IsNet
then
3619 MH_SEND_GameStats();
3620 MH_SEND_CoopStats();
3626 procedure g_Game_RestartLevel();
3630 if gGameSettings
.GameMode
= GM_SINGLE
then
3635 gExit
:= EXIT_ENDLEVELCUSTOM
;
3636 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3640 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3642 gWAD
{, xwad}: String;
3645 if not g_Game_IsClient
then Exit
;
3646 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3648 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3653 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3657 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3660 g_Game_LoadWAD(NewWAD
);
3664 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3665 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3668 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3669 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3673 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3677 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3678 g_Game_LoadWAD(NewWAD);
3682 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3684 i
, n
, nb
, nr
: Integer;
3686 if not g_Game_IsServer
then Exit
;
3687 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3688 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3689 gLMSRespawnTime
:= 0;
3692 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3694 gMissionFailed
:= True;
3695 g_Game_RestartLevel
;
3699 n
:= 0; nb
:= 0; nr
:= 0;
3700 for i
:= Low(gPlayers
) to High(gPlayers
) do
3701 if (gPlayers
[i
] <> nil) and
3702 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3703 (gPlayers
[i
] is TBot
)) then
3706 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3707 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3710 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3712 // wait a second until the fuckers finally decide to join
3713 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3714 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3715 gLMSSoftSpawn
:= NoMapRestart
;
3716 if g_Game_IsNet
then
3717 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3721 {$IFDEF ENABLE_GIBS}
3724 {$IFDEF ENALBE_SHELLS}
3727 {$IFDEF ENABLE_CORPSES}
3728 g_Corpses_RemoveAll
;
3731 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3732 if g_Game_IsNet
then
3733 MH_SEND_GameEvent(NET_EV_LMS_START
);
3735 for i
:= Low(gPlayers
) to High(gPlayers
) do
3737 if gPlayers
[i
] = nil then continue
;
3738 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3739 // don't touch normal spectators
3740 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3742 gPlayers
[i
].FNoRespawn
:= True;
3743 gPlayers
[i
].Lives
:= 0;
3744 if g_Game_IsNet
then
3745 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3748 gPlayers
[i
].FNoRespawn
:= False;
3749 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3750 gPlayers
[i
].Respawn(False, True);
3751 if gGameSettings
.GameMode
= GM_COOP
then
3753 gPlayers
[i
].Frags
:= 0;
3754 gPlayers
[i
].RecallState
;
3756 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3757 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3758 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3759 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3762 g_Items_RestartRound();
3764 gLMSSoftSpawn
:= False;
3767 function g_Game_GetFirstMap(WAD
: String): String;
3771 MapList
:= g_Map_GetMapsList(WAD
);
3772 if MapList
= nil then
3775 SortSArray(MapList
);
3776 Result
:= MapList
[Low(MapList
)];
3778 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3784 function g_Game_GetNextMap(): String;
3791 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3792 if MapList
= nil then
3795 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3797 SortSArray(MapList
);
3799 for I
:= Low(MapList
) to High(MapList
) do
3800 if Map
= MapList
[I
] then
3806 if MapIndex
<> -255 then
3808 if MapIndex
= High(MapList
) then
3809 Result
:= MapList
[Low(MapList
)]
3811 Result
:= MapList
[MapIndex
+ 1];
3813 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3819 procedure g_Game_NextLevel();
3821 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3822 gExit
:= EXIT_ENDLEVELCUSTOM
3825 gExit
:= EXIT_ENDLEVELSINGLE
;
3829 if gNextMap
<> '' then Exit
;
3830 gNextMap
:= g_Game_GetNextMap();
3833 function g_Game_IsTestMap(): Boolean;
3835 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3838 procedure g_Game_DeleteTestMap();
3841 //MapName: AnsiString;
3849 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3850 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3851 if (a
= 0) then exit
;
3853 // Выделяем имя wad-файла и имя карты
3854 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3855 Delete(gMapToDelete
, 1, a
+5);
3856 gMapToDelete
:= UpperCase(gMapToDelete
);
3858 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3861 // Имя карты не стандартное тестовое:
3862 if MapName <> TEST_MAP_NAME then
3865 if not gTempDelete then
3867 time := g_GetFileTime(WadName);
3868 WAD := TWADFile.Create();
3871 if not WAD.ReadFile(WadName) then
3872 begin // Нет такого WAD-файла
3877 // Составляем список карт и ищем нужную:
3879 MapList := WAD.GetResourcesList('');
3881 if MapList <> nil then
3882 for a := 0 to High(MapList) do
3883 if MapList[a] = MapName then
3885 // Удаляем и сохраняем:
3886 WAD.RemoveResource('', MapName);
3887 WAD.SaveTo(WadName);
3892 g_SetFileTime(WadName, time);
3895 if gTempDelete
then DeleteFile(WadName
);
3898 procedure GameCVars(P
: SSArray
);
3901 stat
: TPlayerStatArray
;
3904 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3908 if Length(P
) > 1 then
3913 gsGameFlags
:= gsGameFlags
or Flag
3915 gsGameFlags
:= gsGameFlags
and (not Flag
);
3917 if g_Game_IsServer
then
3920 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3922 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3923 if g_Game_IsNet
then MH_SEND_GameSettings
;
3927 if LongBool(gsGameFlags
and Flag
) then
3928 g_Console_Add(_lc
[OnMsg
])
3930 g_Console_Add(_lc
[OffMsg
]);
3932 if OnMapChange
and g_Game_IsServer
then
3933 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3938 cmd
:= LowerCase(P
[0]);
3940 if cmd
= 'g_gamemode' then
3942 if (Length(P
) > 1) then
3944 a
:= g_Game_TextToMode(P
[1]);
3945 if a
= GM_SINGLE
then a
:= GM_COOP
;
3946 gsGameMode
:= g_Game_ModeToText(a
);
3947 if g_Game_IsServer
then
3949 gSwitchGameMode
:= a
;
3950 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3951 (gState
= STATE_INTERSINGLE
) then
3952 gSwitchGameMode
:= GM_SINGLE
;
3954 gGameSettings
.GameMode
:= gSwitchGameMode
;
3958 if gSwitchGameMode
= gGameSettings
.GameMode
then
3959 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3960 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3962 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3963 [g_Game_ModeToText(gGameSettings
.GameMode
),
3964 g_Game_ModeToText(gSwitchGameMode
)]));
3966 else if cmd
= 'g_friendlyfire' then
3968 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3970 else if cmd
= 'g_friendly_absorb_damage' then
3972 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
3974 else if cmd
= 'g_friendly_hit_trace' then
3976 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
3978 else if cmd
= 'g_friendly_hit_projectile' then
3980 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
3982 else if cmd
= 'g_weaponstay' then
3984 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3986 else if cmd
= 'g_allow_exit' then
3988 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3990 else if cmd
= 'g_allow_monsters' then
3992 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3994 else if cmd
= 'g_allow_dropflag' then
3996 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
3998 else if cmd
= 'g_throw_flag' then
4000 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
4002 else if cmd
= 'g_bot_vsplayers' then
4004 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4006 else if cmd
= 'g_bot_vsmonsters' then
4008 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4010 else if cmd
= 'g_dm_keys' then
4012 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4014 else if cmd
= 'g_gameflags' then
4016 if Length(P
) > 1 then
4018 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4019 if g_Game_IsServer
then
4021 gGameSettings
.Options
:= gsGameFlags
;
4022 if g_Game_IsNet
then MH_SEND_GameSettings
;
4026 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4028 else if cmd
= 'g_warmup_time' then
4030 if Length(P
) > 1 then
4032 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4033 if g_Game_IsServer
then
4035 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4036 // extend warmup if it's already going
4037 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4039 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4040 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4042 if g_Game_IsNet
then MH_SEND_GameSettings
;
4046 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4047 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4049 else if cmd
= 'g_spawn_invul' then
4051 if Length(P
) > 1 then
4053 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4054 if g_Game_IsServer
then
4056 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4057 if g_Game_IsNet
then MH_SEND_GameSettings
;
4061 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4063 else if cmd
= 'g_item_respawn_time' then
4065 if Length(P
) > 1 then
4067 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4068 if g_Game_IsServer
then
4070 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4071 if g_Game_IsNet
then MH_SEND_GameSettings
;
4075 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4076 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4078 else if cmd
= 'sv_intertime' then
4080 if (Length(P
) > 1) then
4081 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4083 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4085 else if cmd
= 'g_max_particles' then
4087 if Length(p
) = 2 then
4090 a
:= Max(0, StrToIntDef(p
[1], 0));
4094 else if Length(p
) = 1 then
4097 e_LogWritefln('%s', [g_GFX_GetMax()])
4099 e_LogWritefln('%s', [0])
4104 e_LogWritefln('usage: %s <n>', [cmd
])
4107 else if cmd
= 'g_max_shells' then
4109 if Length(p
) = 2 then
4111 {$IFDEF ENABLE_SHELLS}
4112 a
:= Max(0, StrToIntDef(p
[1], 0));
4116 else if Length(p
) = 1 then
4118 {$IFDEF ENABLE_SHELLS}
4119 e_LogWritefln('%s', [g_Shells_GetMax()])
4121 e_LogWritefln('%s', [0])
4126 e_LogWritefln('usage: %s <n>', [cmd
])
4129 else if cmd
= 'g_max_gibs' then
4131 if Length(p
) = 2 then
4133 {$IFDEF ENABLE_GIBS}
4134 a
:= Max(0, StrToIntDef(p
[1], 0));
4138 else if Length(p
) = 1 then
4140 {$IFDEF ENABLE_GIBS}
4141 e_LogWritefln('%s', [g_Gibs_GetMax()])
4143 e_LogWritefln('%s', [0])
4148 e_LogWritefln('usage: %s <n>', [cmd
])
4151 else if cmd
= 'g_max_corpses' then
4153 if Length(p
) = 2 then
4155 {$IFDEF ENABLE_CORPSES}
4156 a
:= Max(0, StrToIntDef(p
[1], 0));
4160 else if Length(p
) = 1 then
4162 {$IFDEF ENABLE_CORPSES}
4163 e_LogWritefln('%s', [g_Corpses_GetMax()])
4165 e_LogWritefln('%s', [0])
4170 e_LogWritefln('usage: %s <n>', [cmd
])
4173 else if cmd
= 'g_force_model' then
4175 if Length(p
) = 2 then
4177 a
:= StrToIntDef(p
[1], 0);
4178 g_Force_Model_Set(a
);
4179 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4181 for a
:= Low(gPlayers
) to High(gPlayers
) do
4183 if (gPlayers
[a
] <> nil) then
4185 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4187 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4189 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4193 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4195 for a
:= Low(gPlayers
) to High(gPlayers
) do
4197 if (gPlayers
[a
] <> nil) then
4199 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4201 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4203 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4209 else if cmd
= 'g_force_model_name' then
4211 if (Length(P
) > 1) then
4213 cmd
:= b_Text_Unformat(P
[1]);
4214 g_Forced_Model_SetName(cmd
);
4215 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4217 for a
:= Low(gPlayers
) to High(gPlayers
) do
4219 if (gPlayers
[a
] <> nil) then
4221 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4223 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4225 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4231 else if cmd
= 'g_scorelimit' then
4233 if Length(P
) > 1 then
4235 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4237 if g_Game_IsServer
then
4240 if gGameSettings
.GameMode
= GM_DM
then
4242 stat
:= g_Player_GetStats();
4244 for a
:= 0 to High(stat
) do
4245 if stat
[a
].Frags
> b
then
4249 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4251 // if someone has a higher score, set it to that instead
4252 gsScoreLimit
:= max(gsScoreLimit
, b
);
4253 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4255 if g_Game_IsNet
then MH_SEND_GameSettings
;
4259 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4261 else if cmd
= 'g_timelimit' then
4263 if Length(P
) > 1 then
4265 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4266 if g_Game_IsServer
then
4268 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4269 if g_Game_IsNet
then MH_SEND_GameSettings
;
4272 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4273 [gsTimeLimit
div 3600,
4274 (gsTimeLimit
div 60) mod 60,
4275 gsTimeLimit
mod 60]));
4277 else if cmd
= 'g_max_bots' then
4279 if Length(P
) > 1 then
4280 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4281 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4283 else if cmd
= 'g_maxlives' then
4285 if Length(P
) > 1 then
4287 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4288 if g_Game_IsServer
then
4290 gGameSettings
.MaxLives
:= gsMaxLives
;
4291 if g_Game_IsNet
then MH_SEND_GameSettings
;
4295 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4299 procedure PlayerSettingsCVars(P
: SSArray
);
4304 function ParseTeam(s
: string): Byte;
4308 'red', '1': result
:= TEAM_RED
;
4309 'blue', '2': result
:= TEAM_BLUE
;
4310 else result
:= TEAM_NONE
;
4314 cmd
:= LowerCase(P
[0]);
4318 if (Length(P
) > 1) then
4320 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4321 if g_Game_IsClient
then
4322 MC_SEND_PlayerSettings
4323 else if gGameOn
and (gPlayer1
<> nil) then
4325 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4326 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4332 if (Length(P
) > 1) then
4334 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4335 if g_Game_IsClient
then
4336 MC_SEND_PlayerSettings
4337 else if gGameOn
and (gPlayer2
<> nil) then
4339 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4340 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4346 if Length(P
) > 3 then
4348 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4349 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4350 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4351 if g_Game_IsClient
then
4352 MC_SEND_PlayerSettings
4353 else if gGameOn
and (gPlayer1
<> nil) then
4355 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4356 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4362 if Length(P
) > 3 then
4364 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4365 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4366 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4367 if g_Game_IsClient
then
4368 MC_SEND_PlayerSettings
4369 else if gGameOn
and (gPlayer2
<> nil) then
4371 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4372 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4378 if (Length(P
) > 1) then
4380 gPlayer1Settings
.Model
:= P
[1];
4381 if g_Game_IsClient
then
4382 MC_SEND_PlayerSettings
4383 else if gGameOn
and (gPlayer1
<> nil) then
4385 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4386 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4387 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4393 if (Length(P
) > 1) then
4395 gPlayer2Settings
.Model
:= P
[1];
4396 if g_Game_IsClient
then
4397 MC_SEND_PlayerSettings
4398 else if gGameOn
and (gPlayer2
<> nil) then
4400 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4401 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4402 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4408 // TODO: switch teams if in game or store this separately
4409 if (Length(P
) > 1) then
4411 team
:= ParseTeam(P
[1]);
4412 if team
= TEAM_NONE
then
4413 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4414 else if not gGameOn
and not g_Game_IsNet
then
4415 gPlayer1Settings
.Team
:= team
4417 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4422 // TODO: switch teams if in game or store this separately
4423 if (Length(P
) > 1) then
4425 team
:= ParseTeam(P
[1]);
4426 if team
= TEAM_NONE
then
4427 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4428 else if not gGameOn
and not g_Game_IsNet
then
4429 gPlayer2Settings
.Team
:= team
4431 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4436 if (Length(P
) = 2) then
4437 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4441 if (Length(P
) = 2) then
4442 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4446 if (Length(P
) = 2) then
4447 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4451 if (Length(P
) = 2) then
4452 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4456 if (Length(P
) = 2) then
4457 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4461 if (Length(P
) = 2) then
4462 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4464 'p1_priority_kastet':
4466 if (Length(P
) = 2) then
4467 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4469 'p2_priority_kastet':
4471 if (Length(P
) = 2) then
4472 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4476 if (Length(P
) = 2) then
4477 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4481 if (Length(P
) = 2) then
4482 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4484 'p1_priority_pistol':
4486 if (Length(P
) = 2) then
4487 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4489 'p2_priority_pistol':
4491 if (Length(P
) = 2) then
4492 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4494 'p1_priority_shotgun1':
4496 if (Length(P
) = 2) then
4497 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4499 'p2_priority_shotgun1':
4501 if (Length(P
) = 2) then
4502 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4504 'p1_priority_shotgun2':
4506 if (Length(P
) = 2) then
4507 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4509 'p2_priority_shotgun2':
4511 if (Length(P
) = 2) then
4512 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4514 'p1_priority_chaingun':
4516 if (Length(P
) = 2) then
4517 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4519 'p2_priority_chaingun':
4521 if (Length(P
) = 2) then
4522 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4524 'p1_priority_rocketlauncher':
4526 if (Length(P
) = 2) then
4527 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4529 'p2_priority_rocketlauncher':
4531 if (Length(P
) = 2) then
4532 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4534 'p1_priority_plasma':
4536 if (Length(P
) = 2) then
4537 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4539 'p2_priority_plasma':
4541 if (Length(P
) = 2) then
4542 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4546 if (Length(P
) = 2) then
4547 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4551 if (Length(P
) = 2) then
4552 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4554 'p1_priority_super':
4556 if (Length(P
) = 2) then
4557 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4559 'p2_priority_super':
4561 if (Length(P
) = 2) then
4562 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4564 'p1_priority_flamethrower':
4566 if (Length(P
) = 2) then
4567 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4569 'p2_priority_flamethrower':
4571 if (Length(P
) = 2) then
4572 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4574 'p1_priority_berserk':
4576 if (Length(P
) = 2) then
4577 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4579 'p2_priority_berserk':
4581 if (Length(P
) = 2) then
4582 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4587 procedure PrintHeapStats();
4591 hs
:= GetFPCHeapStatus();
4592 e_LogWriteLn ('v===== heap status =====v');
4593 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4594 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4595 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4596 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4597 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4598 e_LogWriteLn ('^=======================^');
4601 procedure DebugCommands(P
: SSArray
);
4608 // Команды отладочного режима:
4609 if {gDebugMode}conIsCheatsEnabled
then
4611 cmd
:= LowerCase(P
[0]);
4612 if cmd
= 'd_window' then
4614 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4615 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4617 else if cmd
= 'd_sounds' then
4619 if (Length(P
) > 1) and
4620 ((P
[1] = '1') or (P
[1] = '0')) then
4621 g_Debug_Sounds
:= (P
[1][1] = '1');
4623 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4625 else if cmd
= 'd_frames' then
4627 if (Length(P
) > 1) and
4628 ((P
[1] = '1') or (P
[1] = '0')) then
4629 g_Debug_Frames
:= (P
[1][1] = '1');
4631 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4633 else if cmd
= 'd_winmsg' then
4635 if (Length(P
) > 1) and
4636 ((P
[1] = '1') or (P
[1] = '0')) then
4637 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4639 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4641 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4643 if (Length(P
) > 1) and
4644 ((P
[1] = '1') or (P
[1] = '0')) then
4645 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4647 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4649 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4651 if Length(P
) > 1 then
4653 '0': g_debug_BotAIOff
:= 0;
4654 '1': g_debug_BotAIOff
:= 1;
4655 '2': g_debug_BotAIOff
:= 2;
4656 '3': g_debug_BotAIOff
:= 3;
4659 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4661 else if cmd
= 'd_monster' then
4663 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4664 if Length(P
) < 2 then
4666 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4667 g_Console_Add('ID | Name');
4668 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4669 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4670 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4673 a
:= StrToIntDef(P
[1], 0);
4674 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4675 a
:= g_Mons_TypeIdByName(P
[1]);
4677 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4678 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4681 with gPlayer1
.Obj
do
4683 mon
:= g_Monsters_Create(a
,
4684 X
+ Rect
.X
+ (Rect
.Width
div 2),
4685 Y
+ Rect
.Y
+ Rect
.Height
,
4686 gPlayer1
.Direction
, True);
4688 if (Length(P
) > 2) and (mon
<> nil) then
4690 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4691 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4692 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4693 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4694 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4695 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4696 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4697 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4698 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4703 else if (cmd
= 'd_health') then
4705 if (Length(P
) > 1) and
4706 ((P
[1] = '1') or (P
[1] = '0')) then
4707 g_debug_HealthBar
:= (P
[1][1] = '1');
4709 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4711 else if (cmd
= 'd_player') then
4713 if (Length(P
) > 1) and
4714 ((P
[1] = '1') or (P
[1] = '0')) then
4715 g_debug_Player
:= (P
[1][1] = '1');
4717 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4719 else if (cmd
= 'd_mem') then
4725 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4729 procedure GameCheats(P
: SSArray
);
4735 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4737 g_Console_Add('not available');
4743 g_Console_Add('where is the player?!');
4746 cmd
:= LowerCase(P
[0]);
4750 plr
.GodMode
:= not plr
.GodMode
;
4751 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4754 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4755 if cmd
= 'give' then
4757 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4758 for f
:= 1 to High(P
) do
4760 cmd
:= LowerCase(P
[f
]);
4761 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4762 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4763 if cmd
= 'exit' then
4765 if gTriggers
<> nil then
4767 for a
:= 0 to High(gTriggers
) do
4769 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4771 g_Console_Add('player left the map');
4772 gExitByTrigger
:= True;
4773 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4774 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4782 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4783 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4784 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4785 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4786 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4788 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4789 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4791 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4792 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;
4794 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4795 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4797 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4798 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4800 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4801 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4803 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4804 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4805 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4807 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4808 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4809 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4810 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;
4811 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4812 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4814 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;
4815 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;
4816 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;
4817 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;
4818 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;
4819 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;
4821 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4822 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;
4824 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;
4825 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;
4827 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4829 if cmd
= 'ammo' then
4831 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4832 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4833 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4834 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4835 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4836 g_Console_Add('player got some ammo');
4840 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4841 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4843 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4844 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4846 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4847 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4849 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4850 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4852 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4854 if cmd
= 'weapons' then
4856 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4857 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4858 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4859 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4860 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4861 plr
.GiveItem(ITEM_WEAPON_BFG
);
4862 g_Console_Add('player got weapons');
4866 if cmd
= 'keys' then
4868 plr
.GiveItem(ITEM_KEY_RED
);
4869 plr
.GiveItem(ITEM_KEY_GREEN
);
4870 plr
.GiveItem(ITEM_KEY_BLUE
);
4871 g_Console_Add('player got all keys');
4875 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4880 if cmd
= 'open' then
4882 g_Console_Add('player activated sesame');
4883 g_Triggers_OpenAll();
4890 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4894 if cmd
= 'noclip' then
4897 g_Console_Add('wall hardeness adjusted');
4901 if cmd
= 'notarget' then
4903 plr
.NoTarget
:= not plr
.NoTarget
;
4904 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4908 if cmd
= 'noreload' then
4910 plr
.NoReload
:= not plr
.NoReload
;
4911 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4915 if cmd
= 'speedy' then
4917 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4918 g_Console_Add('speed adjusted');
4922 if cmd
= 'jumpy' then
4924 VEL_JUMP
:= 30-VEL_JUMP
;
4925 g_Console_Add('jump height adjusted');
4929 if cmd
= 'automap' then
4931 gShowMap
:= not gShowMap
;
4932 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4936 if cmd
= 'aimline' then
4938 gAimLine
:= not gAimLine
;
4939 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4944 procedure GameCommands(P
: SSArray
);
4950 pl
: pTNetClient
= nil;
4958 cmd
:= LowerCase(P
[0]);
4960 if cmd
= 'pause' then
4962 {$IFDEF ENABLE_MENU}
4963 if (g_ActiveWindow
= nil) then
4964 g_Game_Pause(not gPauseMain
);
4966 g_Game_Pause(not gPauseMain
);
4969 else if cmd
= 'endgame' then
4970 gExit
:= EXIT_SIMPLE
4971 else if cmd
= 'restart' then
4973 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4975 if g_Game_IsClient
then
4977 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4982 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4984 else if cmd
= 'kick' then
4986 if g_Game_IsServer
then
4988 if Length(P
) < 2 then
4990 g_Console_Add('kick <name>');
4995 g_Console_Add('kick <name>');
4999 if g_Game_IsNet
then
5000 pl
:= g_Net_Client_ByName(P
[1]);
5003 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5004 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5005 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5006 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5007 g_Net_Slist_ServerPlayerLeaves();
5008 end else if gPlayers
<> nil then
5009 for a
:= Low(gPlayers
) to High(gPlayers
) do
5010 if gPlayers
[a
] <> nil then
5011 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5013 // Не отключать основных игроков в сингле
5014 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5016 gPlayers
[a
].Lives
:= 0;
5017 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5018 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5019 g_Player_Remove(gPlayers
[a
].UID
);
5020 g_Net_Slist_ServerPlayerLeaves();
5021 // Если не перемешать, при добавлении новых ботов появятся старые
5025 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5027 else if cmd
= 'kick_id' then
5029 if g_Game_IsServer
and g_Game_IsNet
then
5031 if Length(P
) < 2 then
5033 g_Console_Add('kick_id <client ID>');
5038 g_Console_Add('kick_id <client ID>');
5042 a
:= StrToIntDef(P
[1], 0);
5043 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5045 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5047 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5048 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
5049 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5050 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5051 g_Net_Slist_ServerPlayerLeaves();
5055 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5057 else if cmd
= 'kick_pid' then
5059 if g_Game_IsServer
and g_Game_IsNet
then
5061 if Length(P
) < 2 then
5063 g_Console_Add('kick_pid <player ID>');
5068 g_Console_Add('kick_pid <player ID>');
5072 a
:= StrToIntDef(P
[1], 0);
5073 pl
:= g_Net_Client_ByPlayer(a
);
5074 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5076 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5077 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5078 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5079 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5080 g_Net_Slist_ServerPlayerLeaves();
5083 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5085 else if cmd
= 'ban' then
5087 if g_Game_IsServer
and g_Game_IsNet
then
5089 if Length(P
) < 2 then
5091 g_Console_Add('ban <name>');
5096 g_Console_Add('ban <name>');
5100 pl
:= g_Net_Client_ByName(P
[1]);
5103 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5104 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5105 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5106 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5107 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5108 g_Net_Slist_ServerPlayerLeaves();
5110 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5112 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5114 else if cmd
= 'ban_id' then
5116 if g_Game_IsServer
and g_Game_IsNet
then
5118 if Length(P
) < 2 then
5120 g_Console_Add('ban_id <client ID>');
5125 g_Console_Add('ban_id <client ID>');
5129 a
:= StrToIntDef(P
[1], 0);
5130 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5131 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5133 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5134 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5135 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5136 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5137 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5138 g_Net_Slist_ServerPlayerLeaves();
5141 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5143 else if cmd
= 'ban_pid' then
5145 if g_Game_IsServer
and g_Game_IsNet
then
5147 if Length(P
) < 2 then
5149 g_Console_Add('ban_pid <player ID>');
5154 g_Console_Add('ban_pid <player ID>');
5158 a
:= StrToIntDef(P
[1], 0);
5159 pl
:= g_Net_Client_ByPlayer(a
);
5160 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5162 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5163 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5164 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5165 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5166 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5167 g_Net_Slist_ServerPlayerLeaves();
5170 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5172 else if cmd
= 'permban' then
5174 if g_Game_IsServer
and g_Game_IsNet
then
5176 if Length(P
) < 2 then
5178 g_Console_Add('permban <name>');
5183 g_Console_Add('permban <name>');
5187 pl
:= g_Net_Client_ByName(P
[1]);
5190 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5191 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5192 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5193 g_Net_SaveBanList();
5194 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5195 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5196 g_Net_Slist_ServerPlayerLeaves();
5198 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5200 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5202 else if cmd
= 'permban_id' then
5204 if g_Game_IsServer
and g_Game_IsNet
then
5206 if Length(P
) < 2 then
5208 g_Console_Add('permban_id <client ID>');
5213 g_Console_Add('permban_id <client ID>');
5217 a
:= StrToIntDef(P
[1], 0);
5218 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5219 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5221 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5222 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5223 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5224 g_Net_SaveBanList();
5225 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5226 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5227 g_Net_Slist_ServerPlayerLeaves();
5230 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5232 else if cmd
= 'permban_pid' then
5234 if g_Game_IsServer
and g_Game_IsNet
then
5236 if Length(P
) < 2 then
5238 g_Console_Add('permban_pid <player ID>');
5243 g_Console_Add('permban_pid <player ID>');
5247 a
:= StrToIntDef(P
[1], 0);
5248 pl
:= g_Net_Client_ByPlayer(a
);
5249 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5251 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5252 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5253 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5254 g_Net_SaveBanList();
5255 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5256 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5257 g_Net_Slist_ServerPlayerLeaves();
5260 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5262 else if cmd
= 'permban_ip' then
5264 if g_Game_IsServer
and g_Game_IsNet
then
5266 if Length(P
) < 2 then
5268 g_Console_Add('permban_ip <IP address>');
5273 g_Console_Add('permban_ip <IP address>');
5277 g_Net_BanHost(P
[1]);
5278 g_Net_SaveBanList();
5279 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5281 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5283 else if cmd
= 'unban' then
5285 if g_Game_IsServer
and g_Game_IsNet
then
5287 if Length(P
) < 2 then
5289 g_Console_Add('unban <IP Address>');
5294 g_Console_Add('unban <IP Address>');
5298 if g_Net_UnbanHost(P
[1]) then
5300 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5301 g_Net_SaveBanList();
5303 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5305 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5307 else if cmd
= 'clientlist' then
5309 if g_Game_IsServer
and g_Game_IsNet
then
5312 if NetClients
<> nil then
5313 for a
:= Low(NetClients
) to High(NetClients
) do
5314 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5316 plr
:= g_Player_Get(NetClients
[a
].Player
);
5317 if plr
= nil then continue
;
5319 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5320 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5323 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5325 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5327 else if cmd
= 'connect' then
5329 if (NetMode
= NET_NONE
) then
5331 if Length(P
) < 2 then
5333 g_Console_Add('connect <IP> [port] [password]');
5338 g_Console_Add('connect <IP> [port] [password]');
5342 if Length(P
) > 2 then
5343 prt
:= StrToIntDef(P
[2], 25666)
5347 if Length(P
) > 3 then
5352 g_Game_StartClient(P
[1], prt
, pw
);
5355 else if cmd
= 'disconnect' then
5357 if (NetMode
= NET_CLIENT
) then
5360 else if cmd
= 'reconnect' then
5362 if (NetMode
= NET_SERVER
) then
5365 if (NetMode
= NET_CLIENT
) then
5368 gExit
:= EXIT_SIMPLE
;
5372 //TODO: Use last successful password to reconnect, instead of ''
5373 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5375 else if (cmd
= 'addbot') or
5376 (cmd
= 'bot_add') then
5378 if Length(P
) > 2 then
5379 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5380 else if Length(P
) > 1 then
5381 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5383 g_Bot_Add(TEAM_NONE
, 2);
5385 else if cmd
= 'bot_addlist' then
5387 if Length(P
) > 1 then
5389 if Length(P
) = 2 then
5390 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5391 else if Length(P
) = 3 then
5392 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5394 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5397 else if cmd
= 'bot_removeall' then
5399 else if cmd
= 'chat' then
5401 if g_Game_IsNet
then
5403 if Length(P
) > 1 then
5405 for a
:= 1 to High(P
) do
5406 chstr
:= chstr
+ P
[a
] + ' ';
5408 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5410 if Length(chstr
) < 1 then
5412 g_Console_Add('chat <text>');
5416 chstr
:= b_Text_Format(chstr
);
5417 if g_Game_IsClient
then
5418 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5420 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5423 g_Console_Add('chat <text>');
5425 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5427 else if cmd
= 'teamchat' then
5429 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5431 if Length(P
) > 1 then
5433 for a
:= 1 to High(P
) do
5434 chstr
:= chstr
+ P
[a
] + ' ';
5436 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5438 if Length(chstr
) < 1 then
5440 g_Console_Add('teamchat <text>');
5444 chstr
:= b_Text_Format(chstr
);
5445 if g_Game_IsClient
then
5446 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5448 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5449 gPlayer1Settings
.Team
);
5452 g_Console_Add('teamchat <text>');
5454 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5456 else if (cmd
= 'an') or (cmd
= 'announce') then
5458 if g_Game_IsNet
then
5460 if Length(P
) > 1 then
5462 for a
:= 1 to High(P
) do
5463 chstr
:= chstr
+ P
[a
] + ' ';
5465 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5467 if Length(chstr
) < 1 then
5469 g_Console_Add('announce <text>');
5473 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5474 if g_Game_IsClient
then
5475 MC_SEND_RCONCommand(chstr
)
5477 g_Console_Process(chstr
, True);
5480 g_Console_Add('announce <text>');
5482 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5484 else if cmd
= 'game' then
5486 if gGameSettings
.GameType
<> GT_NONE
then
5488 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5491 if Length(P
) = 1 then
5493 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5496 // game not started yet, load fist map from some wad
5498 s
:= addWadExtension(P
[1]);
5499 found
:= e_FindResource(AllMapDirs
, s
);
5503 P
[1] := ExpandFileName(P
[1]);
5504 // if map not choosed then set first map
5505 if Length(P
) < 3 then
5508 P
[2] := g_Game_GetFirstMap(P
[1]);
5511 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5513 if g_Map_Exist(s
) then
5517 with gGameSettings
do
5519 Options
:= gsGameFlags
;
5520 GameMode
:= g_Game_TextToMode(gsGameMode
);
5521 if gSwitchGameMode
<> GM_NONE
then
5522 GameMode
:= gSwitchGameMode
;
5523 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5524 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5526 if Length(P
) >= 4 then
5527 b
:= StrToIntDef(P
[3], 1);
5528 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5529 ScoreLimit
, MaxLives
, Options
, b
);
5534 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5536 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5538 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5540 else if cmd
= 'host' then
5542 if gGameSettings
.GameType
<> GT_NONE
then
5544 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5547 if Length(P
) < 4 then
5549 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5552 if not StrToIp(P
[1], listen
) then
5554 prt
:= StrToIntDef(P
[2], 25666);
5556 s
:= addWadExtension(P
[3]);
5557 found
:= e_FindResource(AllMapDirs
, s
);
5561 // get first map in wad, if not specified
5562 if Length(P
) < 5 then
5565 P
[4] := g_Game_GetFirstMap(P
[1]);
5567 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5568 if g_Map_Exist(s
) then
5572 with gGameSettings
do
5574 Options
:= gsGameFlags
;
5575 GameMode
:= g_Game_TextToMode(gsGameMode
);
5576 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5577 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5578 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5580 if Length(P
) >= 6 then
5581 b
:= StrToIntDef(P
[5], 0);
5582 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5588 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5590 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5595 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5598 else if cmd
= 'map' then
5600 if Length(P
) = 1 then
5602 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5604 g_Console_Add(cmd
+ ' <MAP>');
5605 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5609 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5614 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5616 if Length(P
) < 3 then
5618 // first param is map or wad
5619 s
:= UpperCase(P
[1]);
5620 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5622 gExitByTrigger
:= False;
5625 // already in game, finish current map
5627 gExit
:= EXIT_ENDLEVELCUSTOM
;
5631 // intermission, so change map immediately
5638 found
:= e_FindResource(AllMapDirs
, s
);
5640 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5643 // no such map, found wad
5646 P
[1] := ExpandFileName(pw
);
5647 P
[2] := g_Game_GetFirstMap(P
[1]);
5648 s
:= P
[1] + ':\' + P
[2];
5649 if g_Map_Exist(s
) then
5651 gExitByTrigger
:= False;
5654 // already in game, finish current map
5656 gExit
:= EXIT_ENDLEVELCUSTOM
5660 // intermission, so change map immediately
5667 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5669 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5674 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5680 s
:= addWadExtension(P
[1]);
5681 found
:= e_FindResource(AllMapDirs
, s
);
5685 P
[2] := UpperCase(P
[2]);
5686 s
:= P
[1] + ':\' + P
[2];
5687 if g_Map_Exist(s
) then
5689 gExitByTrigger
:= False;
5693 gExit
:= EXIT_ENDLEVELCUSTOM
5702 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5707 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5713 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5717 else if cmd
= 'nextmap' then
5719 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5721 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5726 if Length(P
) = 1 then
5728 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5730 g_Console_Add(cmd
+ ' <MAP>');
5731 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5736 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5742 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5744 if Length(P
) < 3 then
5746 // first param is map or wad
5747 s
:= UpperCase(P
[1]);
5748 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5751 gExitByTrigger
:= False;
5757 // no such map, found wad
5758 pw
:= addWadExtension(P
[1]);
5759 found
:= e_FindResource(MapDirs
, pw
);
5761 found
:= e_FindResource(WadDirs
, pw
);
5763 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5766 // map not specified, select first map
5768 P
[2] := g_Game_GetFirstMap(P
[1]);
5769 s
:= P
[1] + ':\' + P
[2];
5770 if g_Map_Exist(s
) then
5772 gExitByTrigger
:= False;
5779 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5781 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5786 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5792 // specified two params wad + map
5793 pw
:= addWadExtension(P
[1]);
5794 found
:= e_FindResource(MapDirs
, pw
);
5796 found
:= e_FindResource(MapDirs
, pw
);
5800 P
[2] := UpperCase(P
[2]);
5801 s
:= P
[1] + ':\' + P
[2];
5802 if g_Map_Exist(s
) then
5804 gExitByTrigger
:= False;
5810 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5815 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5821 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5826 if gNextMap
= '' then
5827 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5829 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5833 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5837 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5841 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5843 gExitByTrigger
:= False;
5844 // next map not specified, try to find trigger EXIT
5845 if (gNextMap
= '') and (gTriggers
<> nil) then
5847 for a
:= 0 to High(gTriggers
) do
5849 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5851 gExitByTrigger
:= True;
5852 //gNextMap := gTriggers[a].Data.MapName;
5853 gNextMap
:= gTriggers
[a
].tgcMap
;
5858 if gNextMap
= '' then
5859 gNextMap
:= g_Game_GetNextMap();
5860 if not isWadPath(gNextMap
) then
5861 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5864 if g_Map_Exist(s
) then
5865 gExit
:= EXIT_ENDLEVELCUSTOM
5867 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5871 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5875 else if (cmd
= 'event') then
5877 if (Length(P
) <= 1) then
5879 for a
:= 0 to High(gEvents
) do
5880 if gEvents
[a
].Command
= '' then
5881 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5883 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5886 if (Length(P
) = 2) then
5888 for a
:= 0 to High(gEvents
) do
5889 if gEvents
[a
].Name
= P
[1] then
5890 if gEvents
[a
].Command
= '' then
5891 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5893 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5896 for a
:= 0 to High(gEvents
) do
5897 if gEvents
[a
].Name
= P
[1] then
5899 gEvents
[a
].Command
:= '';
5900 for b
:= 2 to High(P
) do
5901 if Pos(' ', P
[b
]) = 0 then
5902 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5904 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5905 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5909 else if cmd
= 'suicide' then
5913 if g_Game_IsClient
then
5914 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5917 if gPlayer1
<> nil then
5918 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5919 if gPlayer2
<> nil then
5920 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5924 else if cmd
= 'screenshot' then
5926 {$IFDEF ENABLE_RENDER}
5930 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5932 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5934 gWeaponAction
[0, WP_PREV
] := True;
5936 gWeaponAction
[0, WP_NEXT
] := True;
5938 else if cmd
= 'weapon' then
5940 if Length(p
) = 2 then
5942 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5943 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5944 gSelectWeapon
[0, a
] := True
5947 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5948 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5950 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5951 b
:= ord(cmd
[2]) - ord('1');
5953 gWeaponAction
[b
, WP_PREV
] := True;
5955 gWeaponAction
[b
, WP_NEXT
] := True;
5957 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5959 if Length(p
) = 2 then
5961 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5962 b
:= ord(cmd
[2]) - ord('1');
5963 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5964 gSelectWeapon
[b
, a
] := True
5967 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
5969 b
:= ord(cmd
[2]) - ord('1');
5971 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
5973 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
5975 else if (cmd
= 'dropflag') then
5977 if g_Game_IsServer
then
5979 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
5980 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
5983 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5985 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
5987 b
:= ord(cmd
[2]) - ord('1');
5988 if g_Game_IsServer
then
5990 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
5991 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
5994 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5996 // Команды Своей игры:
5997 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5999 if cmd
= 'bot_addred' then
6001 if Length(P
) > 1 then
6002 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6004 g_Bot_Add(TEAM_RED
, 2);
6006 else if cmd
= 'bot_addblue' then
6008 if Length(P
) > 1 then
6009 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6011 g_Bot_Add(TEAM_BLUE
, 2);
6013 else if cmd
= 'spectate' then
6019 else if cmd
= 'say' then
6021 if g_Game_IsServer
and g_Game_IsNet
then
6023 if Length(P
) > 1 then
6026 for a
:= 1 to High(P
) do
6027 chstr
:= chstr
+ P
[a
] + ' ';
6029 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6031 if Length(chstr
) < 1 then
6033 g_Console_Add('say <text>');
6037 chstr
:= b_Text_Format(chstr
);
6038 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6040 else g_Console_Add('say <text>');
6042 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6044 else if cmd
= 'tell' then
6046 if g_Game_IsServer
and g_Game_IsNet
then
6048 if (Length(P
) > 2) and (P
[1] <> '') then
6051 for a
:= 2 to High(P
) do
6052 chstr
:= chstr
+ P
[a
] + ' ';
6054 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6056 if Length(chstr
) < 1 then
6058 g_Console_Add('tell <playername> <text>');
6062 pl
:= g_Net_Client_ByName(P
[1]);
6064 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6066 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6068 else g_Console_Add('tell <playername> <text>');
6070 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6072 else if cmd
= 'centerprint' then
6074 if (Length(P
) > 2) and (P
[1] <> '') then
6077 for a
:= 2 to High(P
) do
6078 chstr
:= chstr
+ P
[a
] + ' ';
6080 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6082 if Length(chstr
) < 1 then
6084 g_Console_Add('centerprint <timeout> <text>');
6088 a
:= StrToIntDef(P
[1], 100);
6089 chstr
:= b_Text_Format(chstr
);
6090 g_Game_Message(chstr
, a
);
6091 if g_Game_IsNet
and g_Game_IsServer
then
6092 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6094 else g_Console_Add('centerprint <timeout> <text>');
6096 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6098 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6100 // Дополнительное время:
6101 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6103 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6104 [gGameSettings
.TimeLimit
div 3600,
6105 (gGameSettings
.TimeLimit
div 60) mod 60,
6106 gGameSettings
.TimeLimit
mod 60]));
6107 if g_Game_IsNet
then MH_SEND_GameSettings
;
6109 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6111 if (Length(P
) <= 1) then
6112 g_Console_Add('rcon_password <password>')
6114 MC_SEND_RCONPassword(P
[1]);
6116 else if cmd
= 'rcon' then
6118 if g_Game_IsClient
then
6120 if Length(P
) > 1 then
6123 for a
:= 1 to High(P
) do
6124 chstr
:= chstr
+ P
[a
] + ' ';
6126 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6128 if Length(chstr
) < 1 then
6130 g_Console_Add('rcon <command>');
6134 MC_SEND_RCONCommand(chstr
);
6136 else g_Console_Add('rcon <command>');
6139 else if cmd
= 'ready' then
6141 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6142 gLMSRespawnTime
:= gTime
+ 100;
6144 else if (cmd
= 'callvote') and g_Game_IsNet
then
6146 if Length(P
) > 1 then
6149 for a
:= 1 to High(P
) do begin
6150 if a
> 1 then chstr
:= chstr
+ ' ';
6151 chstr
:= chstr
+ P
[a
];
6154 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6156 if Length(chstr
) < 1 then
6158 g_Console_Add('callvote <command>');
6162 if g_Game_IsClient
then
6163 MC_SEND_Vote(True, chstr
)
6165 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6166 g_Console_Process('vote', True);
6169 g_Console_Add('callvote <command>');
6171 else if (cmd
= 'vote') and g_Game_IsNet
then
6173 if g_Game_IsClient
then
6175 else if gVoteInProgress
then
6177 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6178 a
:= Floor((NetClientCount
+1)/2.0) + 1
6180 a
:= Floor(NetClientCount
/2.0) + 1;
6185 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6186 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6192 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6193 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6201 procedure SystemCommands(P
: SSArray
);
6205 cmd
:= LowerCase(P
[0]);
6212 {$IFDEF ENABLE_RENDER}
6218 if Length(p
) = 2 then
6220 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6222 gFrameTime
:= 1000 div gMaxFPS
6226 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6230 if Length(p
) = 2 then
6232 gAskLanguage
:= true;
6233 gLanguage
:= LANGUAGE_ENGLISH
;
6234 case LowerCase(p
[1]) of
6237 gAskLanguage
:= false;
6238 gLanguage
:= LANGUAGE_ENGLISH
;
6242 gAskLanguage
:= false;
6243 gLanguage
:= LANGUAGE_RUSSIAN
;
6247 gAskLanguage
:= true;
6248 gLanguage
:= LANGUAGE_ENGLISH
;
6251 g_Language_Set(gLanguage
);
6255 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6261 {$IFDEF ENABLE_RENDER}
6262 procedure g_TakeScreenShot(Filename
: string = '');
6263 var t
: TDateTime
; dir
, date
, name
: String;
6265 if e_NoGraphics
then
6268 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6269 if Filename
= '' then
6272 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6273 Filename
:= 'screenshot-' + date
;
6276 name
:= e_CatPath(dir
, Filename
+ '.png');
6277 if r_Render_WriteScreenShot(name
) then
6278 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6280 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6284 {$IFDEF ENABLE_MENU}
6285 procedure g_Game_InGameMenu(Show
: Boolean);
6287 if (g_ActiveWindow
= nil) and Show
then
6289 if gGameSettings
.GameType
= GT_SINGLE
then
6290 g_GUI_ShowWindow('GameSingleMenu')
6293 if g_Game_IsClient
then
6294 g_GUI_ShowWindow('GameClientMenu')
6296 if g_Game_IsNet
then
6297 g_GUI_ShowWindow('GameServerMenu')
6299 g_GUI_ShowWindow('GameCustomMenu');
6301 g_Sound_PlayEx('MENU_OPEN');
6303 // Пауза при меню только в одиночной игре:
6304 if (not g_Game_IsNet
) then
6308 if (g_ActiveWindow
<> nil) and (not Show
) then
6310 // Пауза при меню только в одиночной игре:
6311 if (not g_Game_IsNet
) then
6312 g_Game_Pause(False);
6317 procedure g_Game_Pause (Enable
: Boolean);
6321 if not gGameOn
then exit
;
6323 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6326 gPauseMain
:= Enable
;
6328 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6331 procedure g_Game_HolmesPause (Enable
: Boolean);
6335 if not gGameOn
then exit
;
6336 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6339 gPauseHolmes
:= Enable
;
6341 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6344 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6349 if gTriggers
<> nil then
6350 for i
:= 0 to High(gTriggers
) do
6351 with gTriggers
[i
] do
6352 if (TriggerType
= TRIGGER_SOUND
) and
6354 Sound
.IsPlaying() then
6356 Sound
.Pause(Enable
);
6360 if gPlayers
<> nil then
6361 for i
:= 0 to High(gPlayers
) do
6362 if gPlayers
[i
] <> nil then
6363 gPlayers
[i
].PauseSounds(Enable
);
6366 if gMusic
<> nil then
6367 gMusic
.Pause(Enable
);
6370 procedure g_Game_StopAllSounds(all
: Boolean);
6374 if gTriggers
<> nil then
6375 for i
:= 0 to High(gTriggers
) do
6376 with gTriggers
[i
] do
6377 if (TriggerType
= TRIGGER_SOUND
) and
6381 if gMusic
<> nil then
6388 procedure g_Game_UpdateTriggerSounds
;
6391 if gTriggers
<> nil then
6392 for i
:= 0 to High(gTriggers
) do
6393 with gTriggers
[i
] do
6394 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6395 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6398 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6401 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6406 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6411 if gSpectMode
<> SPECT_PLAYERS
then
6413 if gSpectPID1
= UID
then
6418 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6425 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6430 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6435 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6440 if gSpectMode
<> SPECT_PLAYERS
then
6442 Pl
:= g_Player_Get(gSpectPID1
);
6443 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6448 if gSpectViewTwo
then
6450 Pl
:= g_Player_Get(gSpectPID2
);
6451 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6459 procedure g_Game_Message (Msg
: string; Time
: Word);
6462 MessageTime
:= Time
;
6465 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6467 punct
: Array[0..13] of String =
6468 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6474 function IsPunctuation(S
: String): Boolean;
6479 if Length(S
) <> 1 then
6481 for i
:= Low(punct
) to High(punct
) do
6482 if S
= punct
[i
] then
6488 function FilterPunctuation(S
: String): String;
6492 for i
:= Low(punct
) to High(punct
) do
6493 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6499 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6501 // remove player name
6502 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6503 // for FullWord check
6504 Text := toLowerCase1251(' ' + Text + ' ');
6505 fpText
:= FilterPunctuation(Text);
6507 for i
:= 0 to Length(gChatSounds
) - 1 do
6510 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6512 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6513 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6515 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6521 gChatSounds
[i
].Sound
.Play();
6527 g_Sound_PlayEx('SOUND_GAME_RADIO');
6530 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6539 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6543 if goodsnd
[a
].IsPlaying() then
6546 goodsnd
[Random(4)].Play();
6549 procedure g_Game_Announce_KillCombo(Param
: Integer);
6556 UID
:= Param
and $FFFF;
6561 Pl
:= g_Player_Get(UID
);
6570 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6574 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6578 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6582 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6590 if not g_Game_IsWatchedPlayer(UID
) then
6593 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6597 if killsnd
[n
].IsPlaying() then
6602 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6610 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6614 if hahasnd
[a
].IsPlaying() then
6617 hahasnd
[Random(3)].Play();
6620 procedure g_Game_StartVote(Command
, Initiator
: string);
6624 if not gVotesEnabled
then Exit
;
6625 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6626 if gVoteInProgress
or gVotePassed
then
6628 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6629 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6632 gVoteInProgress
:= True;
6633 gVotePassed
:= False;
6634 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6637 gVoteCommand
:= Command
;
6639 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6640 Need
:= Floor((NetClientCount
+1)/2.0)+1
6642 Need
:= Floor(NetClientCount
/2.0)+1;
6643 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6644 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6647 procedure g_Game_CheckVote
;
6651 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6652 if not gVoteInProgress
then Exit
;
6654 if (gTime
>= gVoteTimer
) then
6656 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6657 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6659 Need
:= Floor(NetClientCount
/2.0) + 1;
6660 if gVoteCount
>= Need
then
6662 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6663 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6664 gVotePassed
:= True;
6665 gVoteCmdTimer
:= gTime
+ 5000;
6669 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6670 MH_SEND_VoteEvent(NET_VE_FAILED
);
6672 if NetClients
<> nil then
6673 for I
:= Low(NetClients
) to High(NetClients
) do
6674 if NetClients
[i
].Used
then
6675 NetClients
[i
].Voted
:= False;
6676 gVoteInProgress
:= False;
6682 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6683 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6685 Need
:= Floor(NetClientCount
/2.0) + 1;
6686 if gVoteCount
>= Need
then
6688 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6689 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6690 gVoteInProgress
:= False;
6691 gVotePassed
:= True;
6692 gVoteCmdTimer
:= gTime
+ 5000;
6695 if NetClients
<> nil then
6696 for I
:= Low(NetClients
) to High(NetClients
) do
6697 if NetClients
[i
].Used
then
6698 NetClients
[i
].Voted
:= False;
6703 procedure g_Game_LoadMapList(FileName
: string);
6711 if not FileExists(FileName
) then Exit
;
6713 AssignFile(ListFile
, FileName
);
6715 while not EOF(ListFile
) do
6717 ReadLn(ListFile
, s
);
6720 if s
= '' then Continue
;
6722 SetLength(MapList
, Length(MapList
)+1);
6723 MapList
[High(MapList
)] := s
;
6725 CloseFile(ListFile
);
6728 procedure g_Game_SetDebugMode();
6731 // Читы (даже в своей игре):
6735 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6739 if Length(LoadingStat
.Msgs
) = 0 then
6745 begin // Переходим на следующую строку или скроллируем:
6746 if NextMsg
= Length(Msgs
) then
6748 for i
:= 0 to High(Msgs
)-1 do
6749 Msgs
[i
] := Msgs
[i
+1];
6757 Msgs
[NextMsg
-1] := Text;
6761 PBarWasHere
:= false;
6764 {$IFDEF ENABLE_MENU}
6765 g_ActiveWindow
:= nil;
6768 ProcessLoading(true);
6771 procedure g_Game_StepLoading(Value
: Integer = -1);
6783 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6786 ProcessLoading(False);
6791 procedure g_Game_ClearLoading();
6800 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6801 if len
< 1 then len
:= 1;
6802 SetLength(Msgs
, len
);
6803 for len
:= Low(Msgs
) to High(Msgs
) do
6806 PBarWasHere
:= false;
6810 procedure Parse_Params(var pars
: TParamStrValues
);
6817 while i
<= ParamCount
do
6820 if (Length(s
) > 1) and (s
[1] = '-') then
6822 if (Length(s
) > 2) and (s
[2] = '-') then
6823 begin // Одиночный параметр
6824 SetLength(pars
, Length(pars
) + 1);
6825 with pars
[High(pars
)] do
6827 Name
:= LowerCase(s
);
6832 if (i
< ParamCount
) then
6833 begin // Параметр со значением
6835 SetLength(pars
, Length(pars
) + 1);
6836 with pars
[High(pars
)] do
6838 Name
:= LowerCase(s
);
6839 Value
:= LowerCase(ParamStr(i
));
6848 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6853 for i
:= 0 to High(pars
) do
6854 if pars
[i
].Name
= aName
then
6856 Result
:= pars
[i
].Value
;
6861 procedure g_Game_Process_Params();
6863 pars
: TParamStrValues
;
6866 LimT
, LimS
: Integer;
6877 s
:= Find_Param_Value(pars
, '--debug');
6880 g_Game_SetDebugMode();
6881 s
:= Find_Param_Value(pars
, '--netdump');
6886 // Connect when game loads
6887 ip
:= Find_Param_Value(pars
, '-connect');
6891 s
:= Find_Param_Value(pars
, '-port');
6892 if (s
= '') or not TryStrToInt(s
, Port
) then
6895 s
:= Find_Param_Value(pars
, '-pw');
6897 g_Game_StartClient(ip
, Port
, s
);
6901 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6904 gDefaultMegawadStart
:= s
;
6907 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6908 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6910 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6913 // Start map when game loads:
6914 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6915 if isWadPath(map
) then
6918 s
:= Find_Param_Value(pars
, '-gm');
6919 GMode
:= g_Game_TextToMode(s
);
6920 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6921 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6924 s
:= Find_Param_Value(pars
, '-limt');
6925 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6931 s
:= Find_Param_Value(pars
, '-lims');
6932 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6938 s
:= Find_Param_Value(pars
, '-lives');
6939 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6945 s
:= Find_Param_Value(pars
, '-opt');
6949 Opt
:= StrToIntDef(s
, 0);
6952 s
:= Find_Param_Value(pars
, '--close');
6956 // Override map to test:
6957 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6960 if e_IsValidResourceName(s
) then
6961 e_FindResource(AllMapDirs
, s
);
6962 gTestMap
:= ExpandFileName(s
);
6965 // Delete test map after play:
6966 s
:= Find_Param_Value(pars
, '--testdelete');
6969 //gMapToDelete := MapsDir + map;
6970 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6974 // Delete temporary WAD after play:
6975 s
:= Find_Param_Value(pars
, '--tempdelete');
6976 if (s
<> '') and (gTestMap
<> '') then
6978 gMapToDelete
:= gTestMap
;
6979 gTempDelete
:= True;
6982 // Number of players:
6983 s
:= Find_Param_Value(pars
, '-pl');
6985 n
:= DEFAULT_PLAYERS
6987 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6990 s
:= Find_Param_Value(pars
, '-port');
6991 if (s
= '') or not TryStrToInt(s
, Port
) then
6992 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6994 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6997 // Execute script when game loads:
6998 s
:= Find_Param_Value(pars
, '-exec');
7001 // if not isWadPath(s) then
7002 // s := GameDir + '/' + s;
7007 if IOResult
<> 0 then
7009 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7010 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7014 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
7015 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7020 if IOResult
<> 0 then
7022 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7023 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7027 if Pos('#', s
) <> 1 then // script comment
7028 g_Console_Process(s
, True);
7039 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7040 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7041 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7042 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7044 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7045 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7046 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7047 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7050 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7051 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7054 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7055 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7057 {$IFDEF ENABLE_HOLMES}
7058 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7061 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7063 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7064 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7066 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7067 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7069 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
7070 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
7071 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
7072 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
7073 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7074 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7075 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7076 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7077 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');