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);
163 procedure CharPress (C
: AnsiChar);
165 procedure KeyPress (K
: Word);
167 { procedure SetWinPause(Enable: Boolean); }
172 LOADING_SHOW_STEP
= 100;
173 LOADING_INTERLINE
= 20;
191 EXIT_ENDLEVELSINGLE
= 4;
192 EXIT_ENDLEVELCUSTOM
= 5;
194 GAME_OPTION_RESERVED
= 1;
195 GAME_OPTION_TEAMDAMAGE
= 2;
196 GAME_OPTION_ALLOWEXIT
= 4;
197 GAME_OPTION_WEAPONSTAY
= 8;
198 GAME_OPTION_MONSTERS
= 16;
199 GAME_OPTION_BOTVSPLAYER
= 32;
200 GAME_OPTION_BOTVSMONSTER
= 64;
201 GAME_OPTION_DMKEYS
= 128;
202 GAME_OPTION_TEAMHITTRACE
= 256;
203 GAME_OPTION_TEAMHITPROJECTILE
= 512;
204 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
205 GAME_OPTION_ALLOWDROPFLAG
= 2048;
206 GAME_OPTION_THROWFLAG
= 4096;
211 STATE_INTERCUSTOM
= 3;
212 STATE_INTERSINGLE
= 4;
218 LMS_RESPAWN_NONE
= 0;
219 LMS_RESPAWN_WARMUP
= 1;
220 LMS_RESPAWN_FINAL
= 2;
237 CONFIG_FILENAME
= 'Doom2DF.cfg';
239 TEST_MAP_NAME
= '$$$_TEST_$$$';
241 STD_PLAYER_MODEL
= 'Doomer';
249 STATFILE_VERSION
= $03;
252 gGameSettings
: TGameSettings
;
253 gPlayer1Settings
: TPlayerSettings
;
254 gPlayer2Settings
: TPlayerSettings
;
256 gPlayerScreenSize
: TDFPoint
;
257 gPlayer1ScreenCoord
: TDFPoint
;
258 gPlayer2ScreenCoord
: TDFPoint
;
259 gPlayer1
: TPlayer
= nil;
260 gPlayer2
: TPlayer
= nil;
261 gPlayerDrawn
: TPlayer
= nil;
263 gLerpFactor
: Single = 1.0;
264 gSwitchGameMode
: Byte = GM_DM
;
265 gHearPoint1
, gHearPoint2
: THearPoint
;
266 gSoundEffectsDF
: Boolean = False;
267 gSoundTriggerTime
: Word = 0;
268 gAnnouncer
: Integer = ANNOUNCE_NONE
;
269 goodsnd
: array[0..3] of TPlayableSound
;
270 killsnd
: array[0..3] of TPlayableSound
;
271 hahasnd
: array[0..2] of TPlayableSound
;
272 sound_get_flag
: array[0..1] of TPlayableSound
;
273 sound_lost_flag
: array[0..1] of TPlayableSound
;
274 sound_ret_flag
: array[0..1] of TPlayableSound
;
275 sound_cap_flag
: array[0..1] of TPlayableSound
;
276 gBodyKillEvent
: Integer = -1;
277 gDefInterTime
: ShortInt = -1;
278 gInterEndTime
: LongWord = 0;
279 gInterTime
: LongWord = 0;
280 gServInterTime
: Byte = 0;
281 gGameStartTime
: LongWord = 0;
282 gTotalMonsters
: Integer = 0;
283 gPauseMain
: Boolean = false;
284 gPauseHolmes
: Boolean = false;
285 gShowTime
: Boolean = False;
286 gShowFPS
: Boolean = False;
287 gShowScore
: Boolean = True;
288 gShowStat
: Boolean = True;
289 gShowPIDs
: Boolean = False;
290 gShowKillMsg
: Boolean = True;
291 gShowLives
: Boolean = True;
292 gShowPing
: Boolean = False;
293 gShowMap
: Boolean = False;
295 gState
: Byte = STATE_NONE
;
297 sWidth
, sHeight
: Word;
298 gSpectMode
: Byte = SPECT_NONE
;
299 gSpectHUD
: Boolean = True;
300 gSpectKeyPress
: Boolean = False;
301 gSpectX
: Integer = 0;
302 gSpectY
: Integer = 0;
303 gSpectStep
: Byte = 8;
304 gSpectViewTwo
: Boolean = False;
305 gSpectPID1
: Integer = -1;
306 gSpectPID2
: Integer = -1;
307 gSpectAuto
: Boolean = False;
308 gSpectAutoNext
: LongWord;
309 gSpectAutoStepX
: Integer;
310 gSpectAutoStepY
: Integer;
311 gMusic
: TMusic
= nil;
312 gLoadGameMode
: Boolean;
313 gCheats
: Boolean = False;
314 gMapOnce
: Boolean = False;
315 gMapToDelete
: String;
316 gTempDelete
: Boolean = False;
317 gLastMap
: Boolean = False;
320 gResolutionChange
: Boolean = False;
321 gRC_Width
, gRC_Height
: Integer;
322 gRC_FullScreen
, gRC_Maximized
: Boolean;
323 gLanguageChange
: Boolean = False;
324 gDebugMode
: Boolean = False;
325 g_debug_Sounds
: Boolean = False;
326 g_debug_Frames
: Boolean = False;
327 g_debug_WinMsgs
: Boolean = False;
328 g_debug_MonsterOff
: Boolean = False;
329 g_debug_BotAIOff
: Byte = 0;
330 g_debug_HealthBar
: Boolean = False;
331 g_Debug_Player
: Boolean = False;
332 gCoopMonstersKilled
: Word = 0;
333 gCoopSecretsFound
: Word = 0;
334 gCoopTotalMonstersKilled
: Word = 0;
335 gCoopTotalSecretsFound
: Word = 0;
336 gCoopTotalMonsters
: Word = 0;
337 gCoopTotalSecrets
: Word = 0;
338 gStatsOff
: Boolean = False;
339 gStatsPressed
: Boolean = False;
340 gExitByTrigger
: Boolean = False;
341 gNextMap
: String = '';
342 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
343 gLMSRespawnTime
: Cardinal = 0;
344 gLMSSoftSpawn
: Boolean = False;
345 gMissionFailed
: Boolean = False;
346 gVoteInProgress
: Boolean = False;
347 gVotePassed
: Boolean = False;
348 gVoteCommand
: string = '';
349 gVoteTimer
: Cardinal = 0;
350 gVoteCmdTimer
: Cardinal = 0;
351 gVoteCount
: Integer = 0;
352 gVoteTimeout
: Cardinal = 30;
353 gVoted
: Boolean = False;
354 gVotesEnabled
: Boolean = True;
355 gEvents
: Array of TGameEvent
;
356 gDelayedEvents
: Array of TDelayedEvent
;
357 gUseChatSounds
: Boolean = True;
358 gChatSounds
: Array of TChatSound
;
359 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
360 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
361 gInterReadyCount
: Integer = 0;
362 gMaxBots
: Integer = 127;
364 g_dbg_ignore_bounds
: Boolean = false;
365 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
366 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
368 // move button values:
369 // bits 0-1: l/r state:
370 // 0: neither left, nor right pressed
373 // bits 4-5: l/r state when strafe was pressed
374 P1MoveButton
: Byte = 0;
375 P2MoveButton
: Byte = 0;
377 g_profile_frame_update
: Boolean = false;
378 g_profile_frame_draw
: Boolean = false;
379 g_profile_collision
: Boolean = false;
380 g_profile_los
: Boolean = false;
381 g_profile_history_size
: Integer = 1000;
383 g_rlayer_back
: Boolean = true;
384 g_rlayer_step
: Boolean = true;
385 g_rlayer_wall
: Boolean = true;
386 g_rlayer_door
: Boolean = true;
387 g_rlayer_acid1
: Boolean = true;
388 g_rlayer_acid2
: Boolean = true;
389 g_rlayer_water
: Boolean = true;
390 g_rlayer_fore
: Boolean = true;
392 wNeedTimeReset
: Boolean = false;
394 procedure g_ResetDynlights ();
395 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
396 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
398 function conIsCheatsEnabled (): Boolean; inline;
399 function gPause (): Boolean; inline;
401 type (* private state *)
402 TEndCustomGameStat
= record
403 PlayerStat
: TPlayerStatArray
;
407 Map
, MapName
: String;
410 TEndSingleGameStat
= record
411 PlayerStat
: Array [0..1] of record
417 TotalSecrets
: Integer;
420 TLoadingStat
= record
424 Msgs
: Array of String;
426 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
430 x
, y
, radius
: Integer;
433 exploRadius
: Integer;
436 var (* private state *)
437 CustomStat
: TEndCustomGameStat
;
438 StatShotDone
: Boolean;
439 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
440 SingleStat
: TEndSingleGameStat
;
441 LoadingStat
: TLoadingStat
;
444 EndingGameCounter
: Byte;
446 g_playerLight
: Boolean;
447 g_dynLights
: array of TDynLight
= nil;
448 g_dynLightCount
: Integer = 0;
449 EndPicPath
: AnsiString; // full path, used by render
454 {$IFDEF ENABLE_HOLMES}
466 {$IFDEF ENABLE_SHELLS}
469 {$IFDEF ENABLE_CORPSES}
472 {$IFDEF ENABLE_RENDER}
475 {$IFDEF ENABLE_SYSTEM}
479 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
480 g_playermodel
, g_options
, Math
,
481 g_triggers
, g_monsters
, e_sound
, CONFIG
,
482 g_language
, g_net
, g_phys
,
483 ENet
, e_msg
, g_netmsg
, g_netmaster
,
487 charbuff
: packed array [0..15] of AnsiChar = (
488 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
491 function Translit (const S
: AnsiString): AnsiString;
496 for i
:= 1 to Length(Result
) do
499 #
$C9: Result
[i
] := 'Q';
500 #
$D6: Result
[i
] := 'W';
501 #
$D3: Result
[i
] := 'E';
502 #
$CA: Result
[i
] := 'R';
503 #
$C5: Result
[i
] := 'T';
504 #
$CD: Result
[i
] := 'Y';
505 #
$C3: Result
[i
] := 'U';
506 #
$D8: Result
[i
] := 'I';
507 #
$D9: Result
[i
] := 'O';
508 #
$C7: Result
[i
] := 'P';
509 #
$D5: Result
[i
] := '['; //Chr(219);
510 #
$DA: Result
[i
] := ']'; //Chr(221);
511 #
$D4: Result
[i
] := 'A';
512 #
$DB: Result
[i
] := 'S';
513 #
$C2: Result
[i
] := 'D';
514 #
$C0: Result
[i
] := 'F';
515 #
$CF: Result
[i
] := 'G';
516 #
$D0: Result
[i
] := 'H';
517 #
$CE: Result
[i
] := 'J';
518 #
$CB: Result
[i
] := 'K';
519 #
$C4: Result
[i
] := 'L';
520 #
$C6: Result
[i
] := ';'; //Chr(186);
521 #
$DD: Result
[i
] := #39; //Chr(222);
522 #
$DF: Result
[i
] := 'Z';
523 #
$D7: Result
[i
] := 'X';
524 #
$D1: Result
[i
] := 'C';
525 #
$CC: Result
[i
] := 'V';
526 #
$C8: Result
[i
] := 'B';
527 #
$D2: Result
[i
] := 'N';
528 #
$DC: Result
[i
] := 'M';
529 #
$C1: Result
[i
] := ','; //Chr(188);
530 #
$DE: Result
[i
] := '.'; //Chr(190);
536 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
541 ls2
:= Translit(CheatRus
[ct
]);
542 if length(ls1
) = 0 then ls1
:= '~';
543 if length(ls2
) = 0 then ls2
:= '~';
545 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
546 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
547 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
548 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
550 if ct = I_GAME_CHEAT_JETPACK then
552 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
553 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
554 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
555 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
556 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
557 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
573 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
574 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
575 or g_Game_IsNet then Exit;
577 if not gGameOn
then exit
;
578 if not conIsCheatsEnabled
then exit
;
580 s
:= 'SOUND_GAME_RADIO';
583 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
585 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
586 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
590 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
592 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
593 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
597 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
599 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
600 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
604 if CheckCheat(I_GAME_CHEAT_DEATH
) then
606 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
607 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
608 s
:= 'SOUND_MONSTER_HAHA';
612 if CheckCheat(I_GAME_CHEAT_DOORS
) then
614 g_Triggers_OpenAll();
618 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
620 if gTriggers
<> nil then
621 for a
:= 0 to High(gTriggers
) do
622 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
624 gExitByTrigger
:= True;
625 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
626 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
632 s2
:= Copy(charbuff
, 15, 2);
633 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
635 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
643 if CheckCheat(I_GAME_CHEAT_FLY
) then
649 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
651 VEL_JUMP
:= 30-VEL_JUMP
;
655 if CheckCheat(I_GAME_CHEAT_SPEED
) then
657 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
661 if CheckCheat(I_GAME_CHEAT_SUIT
) then
663 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
664 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
668 if CheckCheat(I_GAME_CHEAT_AIR
) then
670 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
671 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
675 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
677 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
678 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
682 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
684 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
685 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
689 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
691 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
692 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
696 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
698 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
699 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
703 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
705 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
706 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
709 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
711 gAimLine
:= not gAimLine
;
714 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
716 gShowMap
:= not gShowMap
;
727 procedure KeyPress (K
: Word);
728 var Msg
: g_gui
.TMessage
;
733 if (g_ActiveWindow
<> nil) then
735 Msg
.Msg
:= WM_KEYDOWN
;
736 Msg
.WParam
:= VK_ESCAPE
;
737 g_ActiveWindow
.OnMessage(Msg
);
738 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
740 else if (gState
<> STATE_FOLD
) then
742 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
744 g_Game_InGameMenu(True);
746 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
748 if (gState
<> STATE_MENU
) then
750 if (NetMode
<> NET_NONE
) then
752 g_Game_StopAllSounds(True);
754 gState
:= STATE_MENU
;
758 g_GUI_ShowWindow('MainMenu');
759 g_Sound_PlayEx('MENU_OPEN');
764 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
765 begin // <F2> .. <F6> � <F12>
766 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
768 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
769 if (not g_Game_IsNet
) then g_Game_Pause(True);
771 IK_F2
: g_Menu_Show_SaveMenu();
772 IK_F3
: g_Menu_Show_LoadMenu();
773 IK_F4
: g_Menu_Show_GameSetGame();
774 IK_F5
: g_Menu_Show_OptionsVideo();
775 IK_F6
: g_Menu_Show_OptionsSound();
776 IK_F7
: g_Menu_Show_EndGameMenu();
777 IK_F10
: g_Menu_Show_QuitGameMenu();
784 gJustChatted
:= False;
785 if gConsoleShow
or gChatShow
then
787 g_Console_Control(K
);
789 else if (g_ActiveWindow
<> nil) then
791 Msg
.Msg
:= WM_KEYDOWN
;
793 g_ActiveWindow
.OnMessage(Msg
);
795 else if (gState
= STATE_MENU
) then
797 g_GUI_ShowWindow('MainMenu');
798 g_Sound_PlayEx('MENU_OPEN');
804 procedure KeyPress (K
: Word);
806 gJustChatted
:= False;
807 if gConsoleShow
or gChatShow
then
809 g_Console_Control(K
);
815 procedure CharPress (C
: AnsiChar);
817 var Msg
: g_gui
.TMessage
;
821 if gConsoleShow
or gChatShow
then
826 else if g_ActiveWindow
<> nil then
829 Msg
.WParam
:= Ord(C
);
830 g_ActiveWindow
.OnMessage(Msg
);
837 charbuff
[a
] := charbuff
[a
+ 1];
839 charbuff
[15] := upcase1251(C
);
846 // ////////////////////////////////////////////////////////////////////////// //
847 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
849 procedure g_ResetDynlights ();
853 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
855 for idx
:= 0 to g_dynLightCount
-1 do
857 if g_dynLights
[idx
].exploCount
= -666 then
864 Inc(g_dynLights
[idx
].exploCount
);
865 if (g_dynLights
[idx
].exploCount
< 10) then
867 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
868 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
869 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
870 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
875 g_dynLightCount
:= lnum
;
878 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
880 if not gwin_has_stencil
then exit
;
881 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
882 g_dynLights
[g_dynLightCount
].x
:= x
;
883 g_dynLights
[g_dynLightCount
].y
:= y
;
884 g_dynLights
[g_dynLightCount
].radius
:= radius
;
885 g_dynLights
[g_dynLightCount
].r
:= r
;
886 g_dynLights
[g_dynLightCount
].g
:= g
;
887 g_dynLights
[g_dynLightCount
].b
:= b
;
888 g_dynLights
[g_dynLightCount
].a
:= a
;
889 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
890 Inc(g_dynLightCount
);
893 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
895 if not gwin_has_stencil
then exit
;
896 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
897 g_dynLights
[g_dynLightCount
].x
:= x
;
898 g_dynLights
[g_dynLightCount
].y
:= y
;
899 g_dynLights
[g_dynLightCount
].radius
:= 0;
900 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
901 g_dynLights
[g_dynLightCount
].r
:= r
;
902 g_dynLights
[g_dynLightCount
].g
:= g
;
903 g_dynLights
[g_dynLightCount
].b
:= b
;
904 g_dynLights
[g_dynLightCount
].a
:= 0;
905 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
906 Inc(g_dynLightCount
);
909 // ////////////////////////////////////////////////////////////////////////// //
910 function conIsCheatsEnabled (): Boolean; inline;
913 if g_Game_IsNet
then exit
;
914 if not gDebugMode
then
916 //if not gCheats then exit;
917 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
918 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
923 // ////////////////////////////////////////////////////////////////////////// //
925 TParamStrValue
= record
930 TParamStrValues
= Array of TParamStrValue
;
933 INTER_ACTION_TEXT
= 1;
934 INTER_ACTION_PIC
= 2;
935 INTER_ACTION_MUSIC
= 3;
940 DataLoaded
: Boolean = False;
942 MapList
: SSArray
= nil;
943 MapIndex
: Integer = -1;
944 InterReadyTime
: Integer = -1;
945 StatDate
: string = '';
960 function Compare(a
, b
: TPlayerStat
): Integer;
962 if a
.Spectator
then Result
:= 1
963 else if b
.Spectator
then Result
:= -1
964 else if a
.Frags
< b
.Frags
then Result
:= 1
965 else if a
.Frags
> b
.Frags
then Result
:= -1
966 else if a
.Deaths
< b
.Deaths
then Result
:= -1
967 else if a
.Deaths
> b
.Deaths
then Result
:= 1
968 else if a
.Kills
< b
.Kills
then Result
:= -1
972 procedure SortGameStat(var stat
: TPlayerStatArray
);
977 if stat
= nil then Exit
;
979 for I
:= High(stat
) downto Low(stat
) do
980 for J
:= Low(stat
) to High(stat
) - 1 do
981 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
984 stat
[J
] := stat
[J
+ 1];
989 // saves a shitty CSV containing the game stats passed to it
990 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
993 dir
, fname
, map
, mode
, etime
: String;
997 dir
:= e_GetWriteableDir(StatsDirs
);
998 // stats are placed in stats/yy/mm/dd/*.csv
999 fname
:= e_CatPath(dir
, Path
);
1000 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
1001 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
1002 AssignFile(s
, fname
);
1004 SetTextCodePage(s
, CP_UTF8
);
1006 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
1007 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
1008 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
1009 mode
:= g_Game_ModeToText(Stat
.GameMode
);
1010 etime
:= Format('%d:%.2d:%.2d', [
1011 Stat
.GameTime
div 1000 div 3600,
1012 (Stat
.GameTime
div 1000 div 60) mod 60,
1013 Stat
.GameTime
div 1000 mod 60
1015 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
1016 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
1022 gGameSettings
.TimeLimit
,
1023 gGameSettings
.ScoreLimit
,
1024 gGameSettings
.Options
,
1026 Length(Stat
.PlayerStat
)
1028 // line 2: game specific shit
1029 // if it's a team game: red score, blue score
1030 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1031 // otherwise nothing
1032 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1034 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
1035 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1037 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1038 // lines 3-...: team, player name, frags, deaths
1039 WriteLn(s
, 'team,name,frags,deaths');
1040 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1041 with Stat
.PlayerStat
[I
] do
1042 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1044 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1047 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1052 procedure ClearDebugCvars();
1054 g_debug_Sounds
:= False;
1055 g_debug_Frames
:= False;
1056 g_debug_WinMsgs
:= False;
1057 g_debug_MonsterOff
:= False;
1058 g_debug_BotAIOff
:= 0;
1059 g_debug_HealthBar
:= False;
1060 g_Debug_Player
:= False;
1063 function g_Game_ModeToText(Mode
: Byte): string;
1067 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1068 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1069 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1070 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1071 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1075 function g_Game_TextToMode(Mode
: string): Byte;
1078 Mode
:= UpperCase(Mode
);
1079 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1084 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1089 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1094 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1099 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1101 Result
:= GM_SINGLE
;
1106 function g_Game_IsNet(): Boolean;
1108 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1111 function g_Game_IsServer(): Boolean;
1113 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1116 function g_Game_IsClient(): Boolean;
1118 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1121 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1128 Result
.name
:= ExtractFileName(WAD
);
1129 Result
.description
:= '';
1130 Result
.author
:= '';
1132 w
:= TWADFile
.Create();
1135 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1141 cfg
:= TConfig
.CreateMem(p
, len
);
1142 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1143 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1144 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1145 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1151 procedure g_Game_FreeWAD
;
1154 g_Sound_Delete('MUSIC_endmus');
1155 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1156 gGameSettings
.WAD
:= '';
1159 procedure g_Game_LoadWAD(WAD
: string);
1168 gGameSettings
.WAD
:= WAD
;
1169 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1172 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1174 w
:= TWADFile
.Create();
1177 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1183 cfg
:= TConfig
.CreateMem(p
, len
);
1186 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1187 if MegaWAD
.endpic
<> '' then
1188 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1190 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1191 if MegaWAD
.endmus
<> '' then
1193 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1194 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1202 {procedure start_trigger(t: string);
1206 function next_trigger(): Boolean;
1210 procedure DisableCheats();
1216 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1217 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1218 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1219 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1221 {$IF DEFINED(D2F_DEBUG)}
1222 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1223 gAimLine
:= g_dbg_aimline_on
;
1227 procedure g_Game_ExecuteEvent(Name
: String);
1233 if gEvents
= nil then
1235 for a
:= 0 to High(gEvents
) do
1236 if gEvents
[a
].Name
= Name
then
1238 if gEvents
[a
].Command
<> '' then
1239 g_Console_Process(gEvents
[a
].Command
, True);
1244 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1249 if gDelayedEvents
<> nil then
1250 for a
:= 0 to High(gDelayedEvents
) do
1251 if not gDelayedEvents
[a
].Pending
then
1258 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1259 n
:= High(gDelayedEvents
);
1261 gDelayedEvents
[n
].Pending
:= True;
1262 gDelayedEvents
[n
].DEType
:= DEType
;
1263 gDelayedEvents
[n
].DENum
:= Num
;
1264 gDelayedEvents
[n
].DEStr
:= Str
;
1265 if DEType
= DE_GLOBEVENT
then
1266 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1268 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1272 procedure EndGame();
1278 if g_Game_IsNet
and g_Game_IsServer
then
1279 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1282 gPauseMain
:= false;
1283 gPauseHolmes
:= false;
1286 g_Game_StopAllSounds(False);
1291 EndingGameCounter
:= 0;
1293 {$IFDEF ENABLE_MENU}
1294 g_ActiveWindow
:= nil;
1297 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1298 gLMSRespawnTime
:= 0;
1301 EXIT_SIMPLE
: // Выход через меню или конец теста
1305 begin // Это был тест
1309 begin // Выход в главное меню
1310 {$IFDEF DISABLE_MENU}
1311 gState
:= STATE_MENU
; // ???
1313 gMusic
.SetByName('MUSIC_MENU');
1315 if gState
<> STATE_SLIST
then
1317 g_GUI_ShowWindow('MainMenu');
1318 gState
:= STATE_MENU
;
1322 // Обновляем список серверов
1323 slReturnPressed
:= True;
1324 if g_Net_Slist_Fetch(slCurrent
) then
1326 if slCurrent
= nil then
1327 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1330 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1331 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1334 g_Game_ExecuteEvent('ongameend');
1338 EXIT_RESTART
: // Начать уровень сначала
1340 if not g_Game_IsClient
then g_Game_Restart();
1343 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1345 // Статистика Своей игры:
1346 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1348 CustomStat
.GameTime
:= gTime
;
1349 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1350 CustomStat
.MapName
:= gMapInfo
.Name
;
1351 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1352 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1353 CustomStat
.TeamStat
:= gTeamStat
;
1355 CustomStat
.PlayerStat
:= nil;
1357 // Статистика игроков:
1358 if gPlayers
<> nil then
1360 for a
:= 0 to High(gPlayers
) do
1361 if gPlayers
[a
] <> nil then
1363 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1364 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1367 Name
:= gPlayers
[a
].Name
;
1368 Frags
:= gPlayers
[a
].Frags
;
1369 Deaths
:= gPlayers
[a
].Death
;
1370 Kills
:= gPlayers
[a
].Kills
;
1371 Team
:= gPlayers
[a
].Team
;
1372 Color
:= gPlayers
[a
].Model
.Color
;
1373 Spectator
:= gPlayers
[a
].FSpectator
;
1377 SortGameStat(CustomStat
.PlayerStat
);
1379 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1382 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1383 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1384 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1385 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1387 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1390 StatShotDone
:= False;
1393 g_Game_ExecuteEvent('onmapend');
1394 if not g_Game_IsClient
then g_Player_ResetReady
;
1395 gInterReadyCount
:= 0;
1397 // Затухающий экран:
1398 EndingGameCounter
:= 255;
1399 gState
:= STATE_FOLD
;
1401 if gDefInterTime
< 0 then
1402 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1404 gInterEndTime
:= gDefInterTime
* 1000;
1407 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1409 // Статистика Одиночной игры:
1410 SingleStat
.GameTime
:= gTime
;
1411 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1412 SingleStat
.TotalSecrets
:= gSecretsCount
;
1413 // Статистика первого игрока:
1414 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1415 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1416 // Статистика второго игрока (если есть):
1417 if SingleStat
.TwoPlayers
then
1419 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1420 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1423 g_Game_ExecuteEvent('onmapend');
1426 if gNextMap
<> '' then
1428 gMusic
.SetByName('MUSIC_INTERMUS');
1430 gState
:= STATE_INTERSINGLE
;
1433 g_Game_ExecuteEvent('oninter');
1435 else // Больше нет карт
1437 // Затухающий экран:
1438 EndingGameCounter
:= 255;
1439 gState
:= STATE_FOLD
;
1444 // Окончание обработано:
1445 if gExit
<> EXIT_QUIT
then
1449 procedure g_Game_Init();
1453 gTempDelete
:= False;
1455 sfsGCDisable(); // temporary disable removing of temporary volumes
1458 g_Game_ClearLoading();
1459 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1460 g_Game_SetLoadingText('', 0, False);
1462 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1465 gPauseMain
:= false;
1466 gPauseHolmes
:= false;
1469 {e_MouseInfo.Accel := 1.0;}
1471 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1474 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1475 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1476 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1477 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1478 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1480 gMusic
:= TMusic
.Create();
1481 gMusic
.SetByName('MUSIC_MENU');
1484 gGameSettings
.WarmupTime
:= 30;
1486 gState
:= STATE_MENU
;
1488 SetLength(gEvents
, 6);
1489 gEvents
[0].Name
:= 'ongamestart';
1490 gEvents
[1].Name
:= 'ongameend';
1491 gEvents
[2].Name
:= 'onmapstart';
1492 gEvents
[3].Name
:= 'onmapend';
1493 gEvents
[4].Name
:= 'oninter';
1494 gEvents
[5].Name
:= 'onwadend';
1496 sfsGCEnable(); // enable releasing unused volumes
1500 procedure g_Game_Free(freeTextures
: Boolean=true);
1502 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1503 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1505 g_Map_Free(freeTextures
);
1508 {$IFDEF ENABLE_GIBS}
1511 {$IFDEF ENALBE_SHELLS}
1514 {$IFDEF ENABLE_CORPSES}
1515 g_Corpses_RemoveAll
;
1518 gGameSettings
.GameType
:= GT_NONE
;
1519 if gGameSettings
.GameMode
= GM_SINGLE
then
1520 gGameSettings
.GameMode
:= GM_DM
;
1521 gSwitchGameMode
:= gGameSettings
.GameMode
;
1524 gExitByTrigger
:= False;
1527 function IsActivePlayer(p
: TPlayer
): Boolean;
1532 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1535 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1541 if gPlayers
= nil then
1545 for a
:= Low(gPlayers
) to High(gPlayers
) do
1546 if IsActivePlayer(gPlayers
[a
]) then
1548 SetLength(ids
, Length(ids
) + 1);
1549 ids
[High(ids
)] := gPlayers
[a
].UID
;
1550 if gPlayers
[a
].UID
= Skip
then
1553 if Length(ids
) = 0 then
1558 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1561 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1567 if gPlayers
= nil then
1571 for a
:= Low(gPlayers
) to High(gPlayers
) do
1572 if IsActivePlayer(gPlayers
[a
]) then
1574 SetLength(ids
, Length(ids
) + 1);
1575 ids
[High(ids
)] := gPlayers
[a
].UID
;
1576 if gPlayers
[a
].UID
= Skip
then
1579 if Length(ids
) = 0 then
1582 Result
:= ids
[Length(ids
) - 1]
1584 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1587 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1593 if gPlayers
= nil then
1597 for a
:= Low(gPlayers
) to High(gPlayers
) do
1598 if IsActivePlayer(gPlayers
[a
]) then
1600 SetLength(ids
, Length(ids
) + 1);
1601 ids
[High(ids
)] := gPlayers
[a
].UID
;
1602 if gPlayers
[a
].UID
= Skip
then
1605 if Length(ids
) = 0 then
1607 if Length(ids
) = 1 then
1612 Result
:= ids
[Random(Length(ids
))];
1614 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1616 Result
:= ids
[Random(Length(ids
))];
1621 function GetRandomSpectMode(Current
: Byte): Byte;
1628 0: Result
:= SPECT_STATS
;
1629 1: Result
:= SPECT_MAPVIEW
;
1630 2: Result
:= SPECT_MAPVIEW
;
1631 3: Result
:= SPECT_PLAYERS
;
1632 4: Result
:= SPECT_PLAYERS
;
1633 5: Result
:= SPECT_PLAYERS
;
1634 6: Result
:= SPECT_PLAYERS
;
1636 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1640 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1646 if (plr
= nil) then exit
;
1647 if (p
= 2) then time
:= 1000 else time
:= 1;
1648 strafeDir
:= MoveButton
shr 4;
1649 MoveButton
:= MoveButton
and $0F;
1651 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1652 MoveButton
:= 1 // Нажата только "Влево"
1653 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1654 MoveButton
:= 2 // Нажата только "Вправо"
1655 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1656 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1658 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1659 if MoveButton
= 1 then
1660 plr
.PressKey(KEY_LEFT
, time
)
1661 else if MoveButton
= 2 then
1662 plr
.PressKey(KEY_RIGHT
, time
);
1664 // if we have "strafe" key, turn off old strafe mechanics
1665 if gPlayerAction
[p
, ACTION_STRAFE
] then
1667 // new strafe mechanics
1668 if (strafeDir
= 0) then
1669 strafeDir
:= MoveButton
; // start strafing
1670 // now set direction according to strafe (reversed)
1671 if (strafeDir
= 2) then
1672 plr
.SetDirection(TDirection
.D_LEFT
)
1673 else if (strafeDir
= 1) then
1674 plr
.SetDirection(TDirection
.D_RIGHT
)
1678 strafeDir
:= 0; // not strafing anymore
1679 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1680 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1681 plr
.SetDirection(TDirection
.D_LEFT
)
1682 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1683 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1684 plr
.SetDirection(TDirection
.D_RIGHT
)
1685 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1686 else if MoveButton
<> 0 then
1687 plr
.SetDirection(TDirection(MoveButton
-1))
1690 // fix movebutton state
1691 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1693 // Остальные клавиши:
1694 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1695 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1696 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1697 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1698 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1700 for i
:= WP_FACT
to WP_LACT
do
1702 if gWeaponAction
[p
, i
] then
1704 plr
.ProcessWeaponAction(i
);
1705 gWeaponAction
[p
, i
] := False
1709 for i
:= WP_FIRST
to WP_LAST
do
1711 if gSelectWeapon
[p
, i
] then
1713 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1714 gSelectWeapon
[p
, i
] := False
1718 {$IFDEF ENABLE_MENU}
1719 // HACK: add dynlight here
1720 if gwin_k8_enable_light_experiments
then
1722 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1724 g_playerLight
:= true;
1726 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1728 g_playerLight
:= false;
1732 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1736 // HACK: don't have a "key was pressed" function
1737 procedure InterReady();
1739 if InterReadyTime
> gTime
then Exit
;
1740 InterReadyTime
:= gTime
+ 3000;
1741 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1744 procedure g_Game_PreUpdate();
1746 // these are in separate PreUpdate functions because they can interact during Update()
1747 // and are synced over the net
1748 // we don't care that much about corpses and gibs
1749 g_Player_PreUpdate();
1750 g_Monsters_PreUpdate();
1751 g_Items_PreUpdate();
1752 g_Weapon_PreUpdate();
1755 procedure g_Game_Update();
1757 {$IFDEF ENABLE_MENU}
1758 Msg
: g_gui
.TMessage
;
1765 function sendMonsPos (mon
: TMonster
): Boolean;
1767 result
:= false; // don't stop
1768 // this will also reset "need-send" flag
1769 if mon
.gncNeedSend
then
1771 MH_SEND_MonsterPos(mon
.UID
);
1773 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1775 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1777 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1779 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1783 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1785 result
:= false; // don't stop
1786 // this will also reset "need-send" flag
1787 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1790 function sendItemPos (it
: PItem
): Boolean;
1792 result
:= false; // don't stop
1795 MH_SEND_ItemPos(it
.myId
);
1796 it
.needSend
:= False;
1801 reliableUpdate
: Boolean;
1806 // Пора выключать игру:
1807 if gExit
= EXIT_QUIT
then
1809 // Игра закончилась - обрабатываем:
1813 if gExit
= EXIT_QUIT
then
1817 // Читаем клавиатуру и джойстик, если окно активно
1818 // no need to, as we'll do it in event handler
1820 // Обновляем консоль (движение и сообщения):
1823 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1825 gExit
:= EXIT_SIMPLE
;
1830 // process master server communications
1831 g_Net_Slist_Pulse();
1834 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1835 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1836 STATE_INTERTEXT
, // Текст между уровнями
1837 STATE_INTERPIC
: // Картинка между уровнями
1839 if g_Game_IsNet
and g_Game_IsServer
then
1841 gInterTime
:= gInterTime
+ GAME_TICK
;
1842 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1843 if a
<> gServInterTime
then
1845 gServInterTime
:= a
;
1846 MH_SEND_TimeSync(gServInterTime
);
1850 if (not g_Game_IsClient
) and
1854 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1855 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1856 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1857 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1859 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1860 {$IFDEF ENABLE_MENU}
1861 and (g_ActiveWindow
= nil)
1864 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1867 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1868 g_Game_StopAllSounds(True);
1870 if gMapOnce
then // Это был тест
1871 gExit
:= EXIT_SIMPLE
1873 if gNextMap
<> '' then // Переходим на следующую карту
1874 g_Game_ChangeMap(gNextMap
)
1875 else // Следующей карты нет
1877 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1879 // Выход в главное меню:
1881 {$IFDEF ENABLE_MENU}
1882 g_GUI_ShowWindow('MainMenu');
1883 gMusic
.SetByName('MUSIC_MENU');
1886 gState
:= STATE_MENU
;
1889 // Финальная картинка:
1890 g_Game_ExecuteEvent('onwadend');
1892 if not gMusic
.SetByName('MUSIC_endmus') then
1893 gMusic
.SetByName('MUSIC_STDENDMUS');
1895 gState
:= STATE_ENDPIC
;
1897 g_Game_ExecuteEvent('ongameend');
1902 else if g_Game_IsClient
and
1905 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1906 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1907 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1908 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1910 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1911 {$IFDEF ENABLE_MENU}
1912 and (g_ActiveWindow
= nil)
1921 if gState
= STATE_INTERTEXT
then
1922 if InterText
.counter
> 0 then
1923 InterText
.counter
:= InterText
.counter
- 1;
1926 STATE_FOLD
: // Затухание экрана
1928 if EndingGameCounter
= 0 then
1930 // Закончился уровень в Своей игре:
1931 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1933 gState
:= STATE_INTERCUSTOM
;
1934 InterReadyTime
:= -1;
1935 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1937 g_Game_ExecuteEvent('onwadend');
1938 if not gMusic
.SetByName('MUSIC_endmus') then
1939 gMusic
.SetByName('MUSIC_STDENDMUS');
1942 gMusic
.SetByName('MUSIC_ROUNDMUS');
1946 else // Закончилась последняя карта в Одиночной игре
1948 gMusic
.SetByName('MUSIC_INTERMUS');
1950 gState
:= STATE_INTERSINGLE
;
1953 g_Game_ExecuteEvent('oninter');
1956 DecMin(EndingGameCounter
, 6, 0);
1959 STATE_ENDPIC
: // Картинка окончания мегаВада
1961 if gMapOnce
then // Это был тест
1963 gExit
:= EXIT_SIMPLE
;
1969 g_Serverlist_Control(slCurrent
, slTable
);
1972 // Статистика по Tab:
1974 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1977 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1979 // Время += 28 миллисекунд:
1980 gTime
:= gTime
+ GAME_TICK
;
1982 // Сообщение посередине экрана:
1983 if MessageTime
= 0 then
1985 if MessageTime
> 0 then
1986 MessageTime
:= MessageTime
- 1;
1988 if (g_Game_IsServer
) then
1990 // Был задан лимит времени:
1991 if (gGameSettings
.TimeLimit
> 0) then
1992 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1993 begin // Он прошел => конец уровня
1998 // Надо респавнить игроков в LMS:
1999 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
2000 g_Game_RestartRound(gLMSSoftSpawn
);
2002 // Проверим результат голосования, если время прошло
2003 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2005 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2007 g_Console_Process(gVoteCommand
);
2009 gVotePassed
:= False;
2012 // Замеряем время захвата флагов
2013 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2014 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2015 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2016 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2018 // Был задан лимит побед:
2019 if (gGameSettings
.ScoreLimit
> 0) then
2023 if gGameSettings
.GameMode
= GM_DM
then
2024 begin // В DM ищем игрока с max фрагами
2025 for i
:= 0 to High(gPlayers
) do
2026 if gPlayers
[i
] <> nil then
2027 if gPlayers
[i
].Frags
> b
then
2028 b
:= gPlayers
[i
].Frags
;
2031 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2032 begin // В CTF/TDM выбираем команду с наибольшим счетом
2033 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2036 // Лимит побед набран => конец уровня:
2037 if b
>= gGameSettings
.ScoreLimit
then
2044 // Обрабатываем клавиши игроков:
2045 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2046 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2047 {$IFDEF DISABLE_MENU}
2048 if (not gConsoleShow
) and (not gChatShow
) then
2050 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2053 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2054 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2055 end // if not console
2058 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2060 // process weapon switch queue
2064 if (gPlayer1
= nil) and (gPlayer2
= nil)
2065 and (not gConsoleShow
) and (not gChatShow
)
2066 {$IFDEF ENABLE_MENU}
2067 and (g_ActiveWindow
= nil)
2071 if not gSpectKeyPress
then
2073 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2075 // switch spect mode
2077 SPECT_NONE
: ; // not spectator
2079 SPECT_MAPVIEW
: Inc(gSpectMode
);
2080 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2082 gSpectKeyPress
:= True;
2084 if (gSpectMode
= SPECT_MAPVIEW
)
2085 and (not gSpectAuto
) then
2087 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2088 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2089 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2090 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2091 if gPlayerAction
[0, ACTION_LOOKUP
] then
2092 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2093 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2094 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2095 if gWeaponAction
[0, WP_PREV
] then
2098 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2099 gWeaponAction
[0, WP_PREV
] := False;
2101 if gWeaponAction
[0, WP_NEXT
] then
2104 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2105 gWeaponAction
[0, WP_NEXT
] := False;
2108 if (gSpectMode
= SPECT_PLAYERS
)
2109 and (not gSpectAuto
) then
2111 if gPlayerAction
[0, ACTION_LOOKUP
] then
2114 gSpectViewTwo
:= True;
2115 gSpectKeyPress
:= True;
2117 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2119 // remove second view
2120 gSpectViewTwo
:= False;
2121 gSpectKeyPress
:= True;
2123 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2125 // prev player (view 1)
2126 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2127 gSpectKeyPress
:= True;
2129 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2131 // next player (view 1)
2132 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2133 gSpectKeyPress
:= True;
2135 if gWeaponAction
[0, WP_PREV
] then
2137 // prev player (view 2)
2138 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2139 gWeaponAction
[0, WP_PREV
] := False;
2141 if gWeaponAction
[0, WP_NEXT
] then
2143 // next player (view 2)
2144 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2145 gWeaponAction
[0, WP_NEXT
] := False;
2148 if gPlayerAction
[0, ACTION_ATTACK
] then
2150 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2153 gSpectAutoNext
:= 0;
2154 gSpectViewTwo
:= False;
2155 gSpectKeyPress
:= True;
2160 gSpectMode
:= SPECT_STATS
;
2161 gSpectAuto
:= False;
2162 gSpectKeyPress
:= True;
2167 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2168 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2169 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2170 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2171 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2172 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2173 gSpectKeyPress
:= False;
2177 if gSpectMode
= SPECT_MAPVIEW
then
2179 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2181 gSpectAutoNext
:= gTime
2184 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2186 gSpectAutoNext
:= gTime
2190 if gSpectAutoNext
<= gTime
then
2192 if gSpectAutoNext
> 0 then
2194 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2198 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2199 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2200 gSpectAutoStepX
:= Random(9) - 4;
2201 gSpectAutoStepY
:= Random(9) - 4;
2202 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2203 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2204 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2205 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2206 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2207 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2211 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2216 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2217 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2218 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2224 // Обновляем все остальное:
2227 g_Triggers_Update();
2229 g_Monsters_Update();
2233 g_Player_UpdateAll();
2234 {$IFDEF ENABLE_GIBS}
2237 {$IFDEF ENABLE_CORPSES}
2240 {$IFDEF ENABLE_SHELLS}
2244 // server: send newly spawned monsters unconditionally
2245 if (gGameSettings
.GameType
= GT_SERVER
) then
2247 if (Length(gMonstersSpawned
) > 0) then
2249 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2250 SetLength(gMonstersSpawned
, 0);
2254 if (gSoundTriggerTime
> 8) then
2256 g_Game_UpdateTriggerSounds();
2257 gSoundTriggerTime
:= 0;
2261 Inc(gSoundTriggerTime
);
2264 if (NetMode
= NET_SERVER
) then
2266 Inc(NetTimeToUpdate
);
2267 Inc(NetTimeToReliable
);
2269 // send monster updates
2270 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2272 // send all monsters (periodic sync)
2273 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2275 for I
:= 0 to High(gPlayers
) do
2277 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2280 g_Mons_ForEach(sendMonsPos
);
2282 // update flags that aren't stationary
2283 if gGameSettings
.GameMode
= GM_CTF
then
2284 for I
:= FLAG_RED
to FLAG_BLUE
do
2285 if gFlags
[I
].NeedSend
then
2287 gFlags
[I
].NeedSend
:= False;
2291 // update items that aren't stationary
2292 g_Items_ForEachAlive(sendItemPos
);
2294 if reliableUpdate
then
2296 NetTimeToReliable
:= 0;
2297 NetTimeToUpdate
:= NetUpdateRate
;
2301 NetTimeToUpdate
:= 0;
2306 // send only mosters with some unexpected changes
2307 g_Mons_ForEach(sendMonsPosUnexpected
);
2310 // send unexpected platform changes
2311 g_Map_NetSendInterestingPanels();
2313 g_Net_Slist_ServerUpdate();
2315 if NetUseMaster then
2317 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2319 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2321 NetTimeToMaster := gTime + NetMasterRate;
2326 else if (NetMode
= NET_CLIENT
) then
2328 MC_SEND_PlayerPos();
2330 end; // if gameOn ...
2332 // Активно окно интерфейса - передаем клавиши ему:
2333 {$IFDEF ENABLE_MENU}
2334 if g_ActiveWindow
<> nil then
2336 w
:= e_GetFirstKeyPressed();
2338 if (w
<> IK_INVALID
) then
2340 Msg
.Msg
:= MESSAGE_DIKEY
;
2342 g_ActiveWindow
.OnMessage(Msg
);
2345 // Если оно от этого не закрылось, то обновляем:
2346 if g_ActiveWindow
<> nil then
2347 g_ActiveWindow
.Update();
2349 // Нужно сменить разрешение:
2350 if gResolutionChange
then
2353 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2356 gResolutionChange
:= False;
2357 g_ActiveWindow
:= nil;
2360 // Нужно сменить язык:
2361 if gLanguageChange
then
2363 //e_WriteLog('Read language file', MSG_NOTIFY);
2364 //g_Language_Load(DataDir + gLanguage + '.txt');
2365 g_Language_Set(gLanguage
);
2367 gLanguageChange
:= False;
2371 // Горячая клавиша для вызова меню выхода из игры (F10):
2372 if e_KeyPressed(IK_F10
) and
2374 (not gConsoleShow
) and
2375 (g_ActiveWindow
= nil) then
2381 Time
:= GetTickCount64() {div 1000};
2383 // Обработка отложенных событий:
2384 if gDelayedEvents
<> nil then
2385 for a
:= 0 to High(gDelayedEvents
) do
2386 if gDelayedEvents
[a
].Pending
and
2388 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2389 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2392 case gDelayedEvents
[a
].DEType
of
2394 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2397 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2401 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2402 if g_Game_IsNet
and g_Game_IsServer
then
2403 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2407 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2409 gDelayedEvents
[a
].Pending
:= False;
2412 // Каждую секунду обновляем счетчик обновлений:
2413 UPSCounter
:= UPSCounter
+ 1;
2414 if Time
- UPSTime
>= 1000 then
2423 g_Weapon_AddDynLights();
2424 g_Items_AddDynLights();
2428 procedure g_Game_LoadChatSounds(Resource
: string);
2431 FileName
, Snd
: string;
2433 len
, cnt
, tags
, i
, j
: Integer;
2436 FileName
:= g_ExtractWadName(Resource
);
2438 WAD
:= TWADFile
.Create();
2439 WAD
.ReadFile(FileName
);
2441 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2448 cfg
:= TConfig
.CreateMem(p
, len
);
2449 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2451 SetLength(gChatSounds
, cnt
);
2452 for i
:= 0 to Length(gChatSounds
) - 1 do
2454 gChatSounds
[i
].Sound
:= nil;
2455 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2456 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2457 if (Snd
= '') or (Tags
<= 0) then
2459 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2460 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2461 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2462 SetLength(gChatSounds
[i
].Tags
, tags
);
2463 for j
:= 0 to tags
- 1 do
2464 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2465 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2472 procedure g_Game_FreeChatSounds();
2476 for i
:= 0 to Length(gChatSounds
) - 1 do
2478 gChatSounds
[i
].Sound
.Free();
2479 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2481 SetLength(gChatSounds
, 0);
2485 procedure g_Game_LoadData();
2487 if DataLoaded
then Exit
;
2489 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2491 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2492 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2493 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2494 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2495 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2496 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2497 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2498 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2499 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2500 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2501 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2502 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2503 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2504 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2505 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2506 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2507 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2508 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2509 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2510 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2511 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2512 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2513 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2514 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2515 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2516 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2517 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2518 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2519 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2520 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2521 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2522 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2524 goodsnd
[0] := TPlayableSound
.Create();
2525 goodsnd
[1] := TPlayableSound
.Create();
2526 goodsnd
[2] := TPlayableSound
.Create();
2527 goodsnd
[3] := TPlayableSound
.Create();
2529 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2530 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2531 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2532 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2534 killsnd
[0] := TPlayableSound
.Create();
2535 killsnd
[1] := TPlayableSound
.Create();
2536 killsnd
[2] := TPlayableSound
.Create();
2537 killsnd
[3] := TPlayableSound
.Create();
2539 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2540 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2541 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2542 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2544 hahasnd
[0] := TPlayableSound
.Create();
2545 hahasnd
[1] := TPlayableSound
.Create();
2546 hahasnd
[2] := TPlayableSound
.Create();
2548 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2549 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2550 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2552 sound_get_flag
[0] := TPlayableSound
.Create();
2553 sound_get_flag
[1] := TPlayableSound
.Create();
2554 sound_lost_flag
[0] := TPlayableSound
.Create();
2555 sound_lost_flag
[1] := TPlayableSound
.Create();
2556 sound_ret_flag
[0] := TPlayableSound
.Create();
2557 sound_ret_flag
[1] := TPlayableSound
.Create();
2558 sound_cap_flag
[0] := TPlayableSound
.Create();
2559 sound_cap_flag
[1] := TPlayableSound
.Create();
2561 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2562 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2563 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2564 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2565 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2566 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2567 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2568 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2570 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2572 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2575 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2576 g_Weapon_LoadData();
2578 g_Monsters_LoadData();
2583 procedure g_Game_Quit();
2585 g_Game_StopAllSounds(True);
2588 g_PlayerModel_FreeData();
2590 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2593 if NetInitDone
then g_Net_Free
;
2595 // remove map after test
2596 if gMapToDelete
<> '' then
2597 g_Game_DeleteTestMap();
2601 {$IFDEF ENABLE_SYSTEM}
2606 procedure g_Game_FreeData();
2608 if not DataLoaded
then Exit
;
2611 g_Weapon_FreeData();
2612 g_Monsters_FreeData();
2614 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2616 g_Sound_Delete('SOUND_GAME_TELEPORT');
2617 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2618 g_Sound_Delete('SOUND_GAME_SECRET');
2619 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2620 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2621 g_Sound_Delete('SOUND_GAME_BULK1');
2622 g_Sound_Delete('SOUND_GAME_BULK2');
2623 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2624 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2625 g_Sound_Delete('SOUND_GAME_BURNING');
2626 g_Sound_Delete('SOUND_GAME_SWITCH1');
2627 g_Sound_Delete('SOUND_GAME_SWITCH0');
2634 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2635 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2636 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2637 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2644 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2645 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2646 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2647 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2653 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2654 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2655 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2657 sound_get_flag
[0].Free();
2658 sound_get_flag
[1].Free();
2659 sound_lost_flag
[0].Free();
2660 sound_lost_flag
[1].Free();
2661 sound_ret_flag
[0].Free();
2662 sound_ret_flag
[1].Free();
2663 sound_cap_flag
[0].Free();
2664 sound_cap_flag
[1].Free();
2666 g_Sound_Delete('SOUND_CTF_GET1');
2667 g_Sound_Delete('SOUND_CTF_GET2');
2668 g_Sound_Delete('SOUND_CTF_LOST1');
2669 g_Sound_Delete('SOUND_CTF_LOST2');
2670 g_Sound_Delete('SOUND_CTF_RETURN1');
2671 g_Sound_Delete('SOUND_CTF_RETURN2');
2672 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2673 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2675 g_Game_FreeChatSounds();
2677 DataLoaded
:= False;
2680 procedure g_FatalError(Text: String);
2682 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2683 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2685 gExit
:= EXIT_SIMPLE
;
2686 if gGameOn
then EndGame
;
2689 procedure g_SimpleError(Text: String);
2691 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2692 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2695 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2697 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2698 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2701 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2704 if gPlayer1
= nil then
2706 if g_Game_IsClient
then
2708 if NetPlrUID1
> -1 then
2709 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2713 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2714 Team
:= gPlayer1Settings
.Team
;
2716 // Создание первого игрока:
2717 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2718 gPlayer1Settings
.Color
,
2720 if gPlayer1
= nil then
2721 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2724 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2725 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2726 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2727 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2728 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2729 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2730 if g_Game_IsServer
and g_Game_IsNet
then
2731 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2732 gPlayer1
.Respawn(False, True);
2733 g_Net_Slist_ServerPlayerComes();
2738 if gPlayer2
= nil then
2740 if g_Game_IsClient
then
2742 if NetPlrUID2
> -1 then
2743 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2747 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2748 Team
:= gPlayer2Settings
.Team
;
2750 // Создание второго игрока:
2751 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2752 gPlayer2Settings
.Color
,
2754 if gPlayer2
= nil then
2755 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2758 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2759 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2760 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2761 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2762 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2763 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2764 if g_Game_IsServer
and g_Game_IsNet
then
2765 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2766 gPlayer2
.Respawn(False, True);
2767 g_Net_Slist_ServerPlayerComes();
2774 procedure g_Game_RemovePlayer();
2778 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2779 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2784 if g_Game_IsServer
then
2787 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2788 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2789 g_Player_Remove(Pl
.UID
);
2790 g_Net_Slist_ServerPlayerLeaves();
2794 gSpectLatchPID2
:= Pl
.UID
;
2802 if g_Game_IsServer
then
2805 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2806 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2807 g_Player_Remove(Pl
.UID
);
2808 g_Net_Slist_ServerPlayerLeaves();
2811 gSpectLatchPID1
:= Pl
.UID
;
2813 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2817 g_Net_Slist_ServerPlayerLeaves();
2820 procedure g_Game_Spectate();
2822 g_Game_RemovePlayer();
2823 if gPlayer1
<> nil then
2824 g_Game_RemovePlayer();
2827 procedure g_Game_SpectateCenterView();
2829 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2830 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2833 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2840 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2842 g_Game_ClearLoading();
2845 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2848 gGameSettings
.GameType
:= GT_SINGLE
;
2849 gGameSettings
.MaxLives
:= 0;
2850 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2851 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2852 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2853 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2854 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2855 gSwitchGameMode
:= GM_SINGLE
;
2857 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2858 gLMSRespawnTime
:= 0;
2859 gSpectLatchPID1
:= 0;
2860 gSpectLatchPID2
:= 0;
2862 g_Game_ExecuteEvent('ongamestart');
2864 // Создание первого игрока:
2865 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2866 gPlayer1Settings
.Color
,
2867 gPlayer1Settings
.Team
, False));
2868 if gPlayer1
= nil then
2870 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2874 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2875 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2876 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2877 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2878 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2881 // Создание второго игрока, если есть:
2884 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2885 gPlayer2Settings
.Color
,
2886 gPlayer2Settings
.Team
, False));
2887 if gPlayer2
= nil then
2889 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2893 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2894 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2895 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2896 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2897 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2901 // Загрузка и запуск карты:
2902 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2904 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2905 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2909 // Настройки игроков и ботов:
2913 for i
:= nPl
+1 to nPlayers
do
2914 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2917 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2918 TimeLimit
, ScoreLimit
: Word;
2920 Options
: LongWord; nPlayers
: Byte);
2926 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2928 g_Game_ClearLoading();
2931 gGameSettings
.GameType
:= GT_CUSTOM
;
2932 gGameSettings
.GameMode
:= GameMode
;
2933 gSwitchGameMode
:= GameMode
;
2934 gGameSettings
.TimeLimit
:= TimeLimit
;
2935 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2936 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2937 gGameSettings
.Options
:= Options
;
2939 gCoopTotalMonstersKilled
:= 0;
2940 gCoopTotalSecretsFound
:= 0;
2941 gCoopTotalMonsters
:= 0;
2942 gCoopTotalSecrets
:= 0;
2946 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2947 gLMSRespawnTime
:= 0;
2948 gSpectLatchPID1
:= 0;
2949 gSpectLatchPID2
:= 0;
2951 g_Game_ExecuteEvent('ongamestart');
2953 // Режим наблюдателя:
2954 if nPlayers
= 0 then
2961 if nPlayers
>= 1 then
2963 // Создание первого игрока:
2964 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2965 gPlayer1Settings
.Color
,
2966 gPlayer1Settings
.Team
, False));
2967 if gPlayer1
= nil then
2969 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2973 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2974 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2975 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2976 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2977 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2981 if nPlayers
>= 2 then
2983 // Создание второго игрока:
2984 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2985 gPlayer2Settings
.Color
,
2986 gPlayer2Settings
.Team
, False));
2987 if gPlayer2
= nil then
2989 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2993 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2994 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2995 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2996 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2997 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3001 // Загрузка и запуск карты:
3002 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3004 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3008 // Нет точек появления:
3009 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3010 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3011 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3012 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3013 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3015 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3019 // Настройки игроков и ботов:
3023 for i
:= nPl
+1 to nPlayers
do
3024 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3027 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3028 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3029 Options
: LongWord; nPlayers
: Byte;
3030 IPAddr
: LongWord; Port
: Word);
3033 g_Net_Slist_ServerClosed();
3035 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3037 g_Game_ClearLoading();
3042 gGameSettings
.GameType
:= GT_SERVER
;
3043 gGameSettings
.GameMode
:= GameMode
;
3044 gSwitchGameMode
:= GameMode
;
3045 gGameSettings
.TimeLimit
:= TimeLimit
;
3046 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3047 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3048 gGameSettings
.Options
:= Options
;
3050 gCoopTotalMonstersKilled
:= 0;
3051 gCoopTotalSecretsFound
:= 0;
3052 gCoopTotalMonsters
:= 0;
3053 gCoopTotalSecrets
:= 0;
3057 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3058 gLMSRespawnTime
:= 0;
3059 gSpectLatchPID1
:= 0;
3060 gSpectLatchPID2
:= 0;
3062 g_Game_ExecuteEvent('ongamestart');
3064 // Режим наблюдателя:
3065 if nPlayers
= 0 then
3071 if nPlayers
>= 1 then
3073 // Создание первого игрока:
3074 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3075 gPlayer1Settings
.Color
,
3076 gPlayer1Settings
.Team
, False));
3077 if gPlayer1
= nil then
3079 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3083 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3084 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3085 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3086 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3087 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3090 if nPlayers
>= 2 then
3092 // Создание второго игрока:
3093 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3094 gPlayer2Settings
.Color
,
3095 gPlayer2Settings
.Team
, False));
3096 if gPlayer2
= nil then
3098 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3102 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3103 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3104 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3105 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3106 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3109 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3110 if NetForwardPorts
then
3111 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3114 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3116 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3120 g_Net_Slist_Set(NetMasterList
);
3122 g_Net_Slist_ServerStarted();
3124 // Загрузка и запуск карты:
3125 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3127 g_Net_Slist_ServerClosed();
3128 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3132 // Нет точек появления:
3133 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3134 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3135 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3136 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3137 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3139 g_Net_Slist_ServerClosed();
3140 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3144 // Настройки игроков и ботов:
3147 g_Net_Slist_ServerMapStarted();
3148 NetState
:= NET_STATE_GAME
;
3151 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3166 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3167 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3169 g_Game_ClearLoading();
3174 gGameSettings
.GameType
:= GT_CLIENT
;
3176 gCoopTotalMonstersKilled
:= 0;
3177 gCoopTotalSecretsFound
:= 0;
3178 gCoopTotalMonsters
:= 0;
3179 gCoopTotalSecrets
:= 0;
3183 g_Game_ExecuteEvent('ongamestart');
3185 NetState
:= NET_STATE_AUTH
;
3187 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3189 // create (or update) map/resource databases
3190 g_Res_CreateDatabases(true);
3192 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3193 gLMSRespawnTime
:= 0;
3194 gSpectLatchPID1
:= 0;
3195 gSpectLatchPID2
:= 0;
3198 if not g_Net_Connect(Addr
, Port
) then
3200 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3201 NetState
:= NET_STATE_NONE
;
3205 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3207 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3212 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3213 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3214 // thank you, enet. let's ignore failures altogether then.
3215 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3217 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3219 Ptr
:= NetEvent
.packet
^.data
;
3220 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3222 enet_packet_destroy(NetEvent
.packet
);
3226 InMsg
.ReadLongWord(); // skip size
3227 MID
:= InMsg
.ReadByte();
3229 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3231 NetMyID
:= InMsg
.ReadByte();
3232 NetPlrUID1
:= InMsg
.ReadWord();
3234 WadName
:= InMsg
.ReadString();
3235 Map
:= InMsg
.ReadString();
3237 gWADHash
:= InMsg
.ReadMD5();
3239 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3240 gSwitchGameMode
:= gGameSettings
.GameMode
;
3241 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3242 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3243 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3244 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3245 T
:= InMsg
.ReadLongWord();
3247 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3248 //if newResPath = '' then
3250 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3251 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3252 if newResPath
= '' then
3254 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3255 enet_packet_destroy(NetEvent
.packet
);
3256 NetState
:= NET_STATE_NONE
;
3259 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3261 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3264 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3265 gPlayer1Settings
.Color
,
3266 gPlayer1Settings
.Team
, False));
3268 if gPlayer1
= nil then
3270 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3272 enet_packet_destroy(NetEvent
.packet
);
3273 NetState
:= NET_STATE_NONE
;
3277 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3278 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3279 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3280 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3281 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3282 gPlayer1
.UID
:= NetPlrUID1
;
3283 gPlayer1
.Reset(True);
3285 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3287 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3289 enet_packet_destroy(NetEvent
.packet
);
3290 NetState
:= NET_STATE_NONE
;
3298 enet_packet_destroy(NetEvent
.packet
);
3302 enet_packet_destroy(NetEvent
.packet
);
3306 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3309 if (NetEvent
.data
<= NET_DISC_MAX
) then
3310 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3311 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3318 ProcessLoading(True);
3319 if g_Net_UserRequestExit() then
3328 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3329 NetState
:= NET_STATE_NONE
;
3334 NetState
:= NET_STATE_GAME
;
3335 MC_SEND_FullStateRequest
;
3336 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3340 lastAsMegaWad
: Boolean = false;
3342 procedure g_Game_ChangeMap(const MapPath
: String);
3346 g_Game_ClearLoading();
3348 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3349 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3350 if gExitByTrigger
then
3353 gExitByTrigger
:= False;
3355 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3356 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3359 procedure g_Game_Restart();
3363 if g_Game_IsClient
then
3365 map
:= g_ExtractFileName(gMapInfo
.Map
);
3366 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3370 g_Game_ClearLoading();
3371 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3374 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3376 NewWAD
, ResName
: String;
3380 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3382 {$IFDEF ENABLE_GIBS}
3385 {$IFDEF ENALBE_SHELLS}
3388 {$IFDEF ENABLE_CORPSES}
3389 g_Corpses_RemoveAll
;
3392 if (not g_Game_IsClient
) and
3393 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3394 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3396 if gSwitchGameMode
= GM_CTF
then
3397 gGameSettings
.MaxLives
:= 0;
3398 gGameSettings
.GameMode
:= gSwitchGameMode
;
3401 gSwitchGameMode
:= gGameSettings
.GameMode
;
3403 g_Player_ResetTeams();
3405 lastAsMegaWad
:= asMegawad
;
3406 if isWadPath(Map
) then
3408 NewWAD
:= g_ExtractWadName(Map
);
3409 ResName
:= g_ExtractFileName(Map
);
3410 if g_Game_IsServer
then
3412 nws
:= findDiskWad(NewWAD
);
3413 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3416 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3417 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3421 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3422 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3424 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3425 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3427 if (length(nws
) = 0) then
3429 ResName
:= ''; // failed
3434 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3435 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3436 g_Game_LoadWAD(NewWAD
);
3441 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3442 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3447 NewWAD
:= gGameSettings
.WAD
;
3453 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3455 if (ResName
<> '') and (NewWAD
<> '') then
3457 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3458 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3459 {$IFDEF ENABLE_RENDER}
3460 r_Render_LoadTextures
;
3465 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3467 gState
:= STATE_NONE
;
3468 {$IFDEF ENABLE_MENU}
3469 g_ActiveWindow
:= nil;
3474 wNeedTimeReset
:= True;
3476 if gGameSettings
.GameMode
= GM_CTF
then
3478 g_Map_ResetFlag(FLAG_RED
);
3479 g_Map_ResetFlag(FLAG_BLUE
);
3480 // CTF, а флагов нет:
3481 if not g_Map_HaveFlagPoints() then
3482 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3487 gState
:= STATE_MENU
;
3492 gPauseMain
:= false;
3493 gPauseHolmes
:= false;
3494 NetTimeToUpdate
:= 1;
3495 NetTimeToReliable
:= 0;
3496 NetTimeToMaster
:= NetMasterRate
;
3497 gSpectLatchPID1
:= 0;
3498 gSpectLatchPID2
:= 0;
3499 gMissionFailed
:= False;
3502 gCoopMonstersKilled
:= 0;
3503 gCoopSecretsFound
:= 0;
3505 gVoteInProgress
:= False;
3506 gVotePassed
:= False;
3512 if not gGameOn
then Exit
;
3514 g_Game_SpectateCenterView();
3516 if g_Game_IsServer
then
3518 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3520 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3521 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3522 gLMSSoftSpawn
:= True;
3523 if g_Game_IsNet
then
3524 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3528 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3529 gLMSRespawnTime
:= 0;
3533 if NetMode
= NET_SERVER
then
3535 // reset full state flags
3536 if NetClients
<> nil then
3537 for I
:= 0 to High(NetClients
) do
3538 NetClients
[I
].FullUpdateSent
:= False;
3540 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3543 g_Net_Slist_ServerMapStarted();
3545 if NetClients
<> nil then
3546 for I
:= 0 to High(NetClients
) do
3547 if NetClients
[I
].Used
then
3549 NetClients
[I
].Voted
:= False;
3550 if NetClients
[I
].RequestedFullUpdate
then
3552 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3553 NetClients
[I
].RequestedFullUpdate
:= False;
3557 g_Net_UnbanNonPermHosts();
3562 gCoopTotalMonstersKilled
:= 0;
3563 gCoopTotalSecretsFound
:= 0;
3564 gCoopTotalMonsters
:= 0;
3565 gCoopTotalSecrets
:= 0;
3569 g_Game_ExecuteEvent('onmapstart');
3572 procedure SetFirstLevel
;
3576 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3577 if MapList
= nil then
3580 SortSArray(MapList
);
3581 gNextMap
:= MapList
[Low(MapList
)];
3586 procedure g_Game_ExitLevel(const Map
: AnsiString);
3590 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3591 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3592 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3593 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3595 // Вышли в выход в Одиночной игре:
3596 if gGameSettings
.GameType
= GT_SINGLE
then
3597 gExit
:= EXIT_ENDLEVELSINGLE
3598 else // Вышли в выход в Своей игре
3600 gExit
:= EXIT_ENDLEVELCUSTOM
;
3601 if gGameSettings
.GameMode
= GM_COOP
then
3602 g_Player_RememberAll
;
3604 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3607 if gGameSettings
.GameMode
= GM_COOP
then
3610 gStatsPressed
:= True;
3611 gNextMap
:= 'MAP01';
3613 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3616 if g_Game_IsNet
then
3618 MH_SEND_GameStats();
3619 MH_SEND_CoopStats();
3625 procedure g_Game_RestartLevel();
3629 if gGameSettings
.GameMode
= GM_SINGLE
then
3634 gExit
:= EXIT_ENDLEVELCUSTOM
;
3635 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3639 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3641 gWAD
{, xwad}: String;
3644 if not g_Game_IsClient
then Exit
;
3645 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3647 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3652 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3656 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3659 g_Game_LoadWAD(NewWAD
);
3663 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3664 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3667 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3668 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3672 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3676 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3677 g_Game_LoadWAD(NewWAD);
3681 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3683 i
, n
, nb
, nr
: Integer;
3685 if not g_Game_IsServer
then Exit
;
3686 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3687 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3688 gLMSRespawnTime
:= 0;
3691 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3693 gMissionFailed
:= True;
3694 g_Game_RestartLevel
;
3698 n
:= 0; nb
:= 0; nr
:= 0;
3699 for i
:= Low(gPlayers
) to High(gPlayers
) do
3700 if (gPlayers
[i
] <> nil) and
3701 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3702 (gPlayers
[i
] is TBot
)) then
3705 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3706 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3709 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3711 // wait a second until the fuckers finally decide to join
3712 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3713 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3714 gLMSSoftSpawn
:= NoMapRestart
;
3715 if g_Game_IsNet
then
3716 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3720 {$IFDEF ENABLE_GIBS}
3723 {$IFDEF ENALBE_SHELLS}
3726 {$IFDEF ENABLE_CORPSES}
3727 g_Corpses_RemoveAll
;
3730 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3731 if g_Game_IsNet
then
3732 MH_SEND_GameEvent(NET_EV_LMS_START
);
3734 for i
:= Low(gPlayers
) to High(gPlayers
) do
3736 if gPlayers
[i
] = nil then continue
;
3737 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3738 // don't touch normal spectators
3739 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3741 gPlayers
[i
].FNoRespawn
:= True;
3742 gPlayers
[i
].Lives
:= 0;
3743 if g_Game_IsNet
then
3744 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3747 gPlayers
[i
].FNoRespawn
:= False;
3748 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3749 gPlayers
[i
].Respawn(False, True);
3750 if gGameSettings
.GameMode
= GM_COOP
then
3752 gPlayers
[i
].Frags
:= 0;
3753 gPlayers
[i
].RecallState
;
3755 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3756 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3757 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3758 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3761 g_Items_RestartRound();
3763 gLMSSoftSpawn
:= False;
3766 function g_Game_GetFirstMap(WAD
: String): String;
3770 MapList
:= g_Map_GetMapsList(WAD
);
3771 if MapList
= nil then
3774 SortSArray(MapList
);
3775 Result
:= MapList
[Low(MapList
)];
3777 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3783 function g_Game_GetNextMap(): String;
3790 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3791 if MapList
= nil then
3794 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3796 SortSArray(MapList
);
3798 for I
:= Low(MapList
) to High(MapList
) do
3799 if Map
= MapList
[I
] then
3805 if MapIndex
<> -255 then
3807 if MapIndex
= High(MapList
) then
3808 Result
:= MapList
[Low(MapList
)]
3810 Result
:= MapList
[MapIndex
+ 1];
3812 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3818 procedure g_Game_NextLevel();
3820 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3821 gExit
:= EXIT_ENDLEVELCUSTOM
3824 gExit
:= EXIT_ENDLEVELSINGLE
;
3828 if gNextMap
<> '' then Exit
;
3829 gNextMap
:= g_Game_GetNextMap();
3832 function g_Game_IsTestMap(): Boolean;
3834 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3837 procedure g_Game_DeleteTestMap();
3840 //MapName: AnsiString;
3848 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3849 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3850 if (a
= 0) then exit
;
3852 // Выделяем имя wad-файла и имя карты
3853 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3854 Delete(gMapToDelete
, 1, a
+5);
3855 gMapToDelete
:= UpperCase(gMapToDelete
);
3857 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3860 // Имя карты не стандартное тестовое:
3861 if MapName <> TEST_MAP_NAME then
3864 if not gTempDelete then
3866 time := g_GetFileTime(WadName);
3867 WAD := TWADFile.Create();
3870 if not WAD.ReadFile(WadName) then
3871 begin // Нет такого WAD-файла
3876 // Составляем список карт и ищем нужную:
3878 MapList := WAD.GetResourcesList('');
3880 if MapList <> nil then
3881 for a := 0 to High(MapList) do
3882 if MapList[a] = MapName then
3884 // Удаляем и сохраняем:
3885 WAD.RemoveResource('', MapName);
3886 WAD.SaveTo(WadName);
3891 g_SetFileTime(WadName, time);
3894 if gTempDelete
then DeleteFile(WadName
);
3897 procedure GameCVars(P
: SSArray
);
3900 stat
: TPlayerStatArray
;
3903 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3907 if Length(P
) > 1 then
3912 gsGameFlags
:= gsGameFlags
or Flag
3914 gsGameFlags
:= gsGameFlags
and (not Flag
);
3916 if g_Game_IsServer
then
3919 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3921 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3922 if g_Game_IsNet
then MH_SEND_GameSettings
;
3926 if LongBool(gsGameFlags
and Flag
) then
3927 g_Console_Add(_lc
[OnMsg
])
3929 g_Console_Add(_lc
[OffMsg
]);
3931 if OnMapChange
and g_Game_IsServer
then
3932 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3937 cmd
:= LowerCase(P
[0]);
3939 if cmd
= 'g_gamemode' then
3941 if (Length(P
) > 1) then
3943 a
:= g_Game_TextToMode(P
[1]);
3944 if a
= GM_SINGLE
then a
:= GM_COOP
;
3945 gsGameMode
:= g_Game_ModeToText(a
);
3946 if g_Game_IsServer
then
3948 gSwitchGameMode
:= a
;
3949 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3950 (gState
= STATE_INTERSINGLE
) then
3951 gSwitchGameMode
:= GM_SINGLE
;
3953 gGameSettings
.GameMode
:= gSwitchGameMode
;
3957 if gSwitchGameMode
= gGameSettings
.GameMode
then
3958 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3959 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3961 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3962 [g_Game_ModeToText(gGameSettings
.GameMode
),
3963 g_Game_ModeToText(gSwitchGameMode
)]));
3965 else if cmd
= 'g_friendlyfire' then
3967 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3969 else if cmd
= 'g_friendly_absorb_damage' then
3971 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
3973 else if cmd
= 'g_friendly_hit_trace' then
3975 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
3977 else if cmd
= 'g_friendly_hit_projectile' then
3979 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
3981 else if cmd
= 'g_weaponstay' then
3983 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3985 else if cmd
= 'g_allow_exit' then
3987 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3989 else if cmd
= 'g_allow_monsters' then
3991 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3993 else if cmd
= 'g_allow_dropflag' then
3995 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
3997 else if cmd
= 'g_throw_flag' then
3999 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
4001 else if cmd
= 'g_bot_vsplayers' then
4003 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4005 else if cmd
= 'g_bot_vsmonsters' then
4007 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4009 else if cmd
= 'g_dm_keys' then
4011 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4013 else if cmd
= 'g_gameflags' then
4015 if Length(P
) > 1 then
4017 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4018 if g_Game_IsServer
then
4020 gGameSettings
.Options
:= gsGameFlags
;
4021 if g_Game_IsNet
then MH_SEND_GameSettings
;
4025 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4027 else if cmd
= 'g_warmup_time' then
4029 if Length(P
) > 1 then
4031 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4032 if g_Game_IsServer
then
4034 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4035 // extend warmup if it's already going
4036 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4038 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4039 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4041 if g_Game_IsNet
then MH_SEND_GameSettings
;
4045 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4046 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4048 else if cmd
= 'g_spawn_invul' then
4050 if Length(P
) > 1 then
4052 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4053 if g_Game_IsServer
then
4055 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4056 if g_Game_IsNet
then MH_SEND_GameSettings
;
4060 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4062 else if cmd
= 'g_item_respawn_time' then
4064 if Length(P
) > 1 then
4066 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4067 if g_Game_IsServer
then
4069 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4070 if g_Game_IsNet
then MH_SEND_GameSettings
;
4074 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4075 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4077 else if cmd
= 'sv_intertime' then
4079 if (Length(P
) > 1) then
4080 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4082 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4084 else if cmd
= 'g_max_particles' then
4086 if Length(p
) = 2 then
4089 a
:= Max(0, StrToIntDef(p
[1], 0));
4093 else if Length(p
) = 1 then
4096 e_LogWritefln('%s', [g_GFX_GetMax()])
4098 e_LogWritefln('%s', [0])
4103 e_LogWritefln('usage: %s <n>', [cmd
])
4106 else if cmd
= 'g_max_shells' then
4108 if Length(p
) = 2 then
4110 {$IFDEF ENABLE_SHELLS}
4111 a
:= Max(0, StrToIntDef(p
[1], 0));
4115 else if Length(p
) = 1 then
4117 {$IFDEF ENABLE_SHELLS}
4118 e_LogWritefln('%s', [g_Shells_GetMax()])
4120 e_LogWritefln('%s', [0])
4125 e_LogWritefln('usage: %s <n>', [cmd
])
4128 else if cmd
= 'g_max_gibs' then
4130 if Length(p
) = 2 then
4132 {$IFDEF ENABLE_GIBS}
4133 a
:= Max(0, StrToIntDef(p
[1], 0));
4137 else if Length(p
) = 1 then
4139 {$IFDEF ENABLE_GIBS}
4140 e_LogWritefln('%s', [g_Gibs_GetMax()])
4142 e_LogWritefln('%s', [0])
4147 e_LogWritefln('usage: %s <n>', [cmd
])
4150 else if cmd
= 'g_max_corpses' then
4152 if Length(p
) = 2 then
4154 {$IFDEF ENABLE_CORPSES}
4155 a
:= Max(0, StrToIntDef(p
[1], 0));
4159 else if Length(p
) = 1 then
4161 {$IFDEF ENABLE_CORPSES}
4162 e_LogWritefln('%s', [g_Corpses_GetMax()])
4164 e_LogWritefln('%s', [0])
4169 e_LogWritefln('usage: %s <n>', [cmd
])
4172 else if cmd
= 'g_force_model' then
4174 if Length(p
) = 2 then
4176 a
:= StrToIntDef(p
[1], 0);
4177 g_Force_Model_Set(a
);
4178 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4180 for a
:= Low(gPlayers
) to High(gPlayers
) do
4182 if (gPlayers
[a
] <> nil) then
4184 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4186 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4188 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4192 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4194 for a
:= Low(gPlayers
) to High(gPlayers
) do
4196 if (gPlayers
[a
] <> nil) then
4198 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4200 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4202 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4208 else if cmd
= 'g_force_model_name' then
4210 if (Length(P
) > 1) then
4212 cmd
:= b_Text_Unformat(P
[1]);
4213 g_Forced_Model_SetName(cmd
);
4214 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4216 for a
:= Low(gPlayers
) to High(gPlayers
) do
4218 if (gPlayers
[a
] <> nil) then
4220 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4222 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4224 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4230 else if cmd
= 'g_scorelimit' then
4232 if Length(P
) > 1 then
4234 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4236 if g_Game_IsServer
then
4239 if gGameSettings
.GameMode
= GM_DM
then
4241 stat
:= g_Player_GetStats();
4243 for a
:= 0 to High(stat
) do
4244 if stat
[a
].Frags
> b
then
4248 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4250 // if someone has a higher score, set it to that instead
4251 gsScoreLimit
:= max(gsScoreLimit
, b
);
4252 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4254 if g_Game_IsNet
then MH_SEND_GameSettings
;
4258 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4260 else if cmd
= 'g_timelimit' then
4262 if Length(P
) > 1 then
4264 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4265 if g_Game_IsServer
then
4267 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4268 if g_Game_IsNet
then MH_SEND_GameSettings
;
4271 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4272 [gsTimeLimit
div 3600,
4273 (gsTimeLimit
div 60) mod 60,
4274 gsTimeLimit
mod 60]));
4276 else if cmd
= 'g_max_bots' then
4278 if Length(P
) > 1 then
4279 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4280 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4282 else if cmd
= 'g_maxlives' then
4284 if Length(P
) > 1 then
4286 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4287 if g_Game_IsServer
then
4289 gGameSettings
.MaxLives
:= gsMaxLives
;
4290 if g_Game_IsNet
then MH_SEND_GameSettings
;
4294 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4298 procedure PlayerSettingsCVars(P
: SSArray
);
4303 function ParseTeam(s
: string): Byte;
4307 'red', '1': result
:= TEAM_RED
;
4308 'blue', '2': result
:= TEAM_BLUE
;
4309 else result
:= TEAM_NONE
;
4313 cmd
:= LowerCase(P
[0]);
4317 if (Length(P
) > 1) then
4319 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4320 if g_Game_IsClient
then
4321 MC_SEND_PlayerSettings
4322 else if gGameOn
and (gPlayer1
<> nil) then
4324 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4325 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4331 if (Length(P
) > 1) then
4333 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4334 if g_Game_IsClient
then
4335 MC_SEND_PlayerSettings
4336 else if gGameOn
and (gPlayer2
<> nil) then
4338 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4339 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4345 if Length(P
) > 3 then
4347 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4348 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4349 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4350 if g_Game_IsClient
then
4351 MC_SEND_PlayerSettings
4352 else if gGameOn
and (gPlayer1
<> nil) then
4354 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4355 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4361 if Length(P
) > 3 then
4363 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4364 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4365 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4366 if g_Game_IsClient
then
4367 MC_SEND_PlayerSettings
4368 else if gGameOn
and (gPlayer2
<> nil) then
4370 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4371 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4377 if (Length(P
) > 1) then
4379 gPlayer1Settings
.Model
:= P
[1];
4380 if g_Game_IsClient
then
4381 MC_SEND_PlayerSettings
4382 else if gGameOn
and (gPlayer1
<> nil) then
4384 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4385 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4386 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4392 if (Length(P
) > 1) then
4394 gPlayer2Settings
.Model
:= P
[1];
4395 if g_Game_IsClient
then
4396 MC_SEND_PlayerSettings
4397 else if gGameOn
and (gPlayer2
<> nil) then
4399 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4400 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4401 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4407 // TODO: switch teams if in game or store this separately
4408 if (Length(P
) > 1) then
4410 team
:= ParseTeam(P
[1]);
4411 if team
= TEAM_NONE
then
4412 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4413 else if not gGameOn
and not g_Game_IsNet
then
4414 gPlayer1Settings
.Team
:= team
4416 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4421 // TODO: switch teams if in game or store this separately
4422 if (Length(P
) > 1) then
4424 team
:= ParseTeam(P
[1]);
4425 if team
= TEAM_NONE
then
4426 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4427 else if not gGameOn
and not g_Game_IsNet
then
4428 gPlayer2Settings
.Team
:= team
4430 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4435 if (Length(P
) = 2) then
4436 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4440 if (Length(P
) = 2) then
4441 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4445 if (Length(P
) = 2) then
4446 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4450 if (Length(P
) = 2) then
4451 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4455 if (Length(P
) = 2) then
4456 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4460 if (Length(P
) = 2) then
4461 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4463 'p1_priority_kastet':
4465 if (Length(P
) = 2) then
4466 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4468 'p2_priority_kastet':
4470 if (Length(P
) = 2) then
4471 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4475 if (Length(P
) = 2) then
4476 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4480 if (Length(P
) = 2) then
4481 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4483 'p1_priority_pistol':
4485 if (Length(P
) = 2) then
4486 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4488 'p2_priority_pistol':
4490 if (Length(P
) = 2) then
4491 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4493 'p1_priority_shotgun1':
4495 if (Length(P
) = 2) then
4496 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4498 'p2_priority_shotgun1':
4500 if (Length(P
) = 2) then
4501 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4503 'p1_priority_shotgun2':
4505 if (Length(P
) = 2) then
4506 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4508 'p2_priority_shotgun2':
4510 if (Length(P
) = 2) then
4511 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4513 'p1_priority_chaingun':
4515 if (Length(P
) = 2) then
4516 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4518 'p2_priority_chaingun':
4520 if (Length(P
) = 2) then
4521 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4523 'p1_priority_rocketlauncher':
4525 if (Length(P
) = 2) then
4526 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4528 'p2_priority_rocketlauncher':
4530 if (Length(P
) = 2) then
4531 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4533 'p1_priority_plasma':
4535 if (Length(P
) = 2) then
4536 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4538 'p2_priority_plasma':
4540 if (Length(P
) = 2) then
4541 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4545 if (Length(P
) = 2) then
4546 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4550 if (Length(P
) = 2) then
4551 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4553 'p1_priority_super':
4555 if (Length(P
) = 2) then
4556 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4558 'p2_priority_super':
4560 if (Length(P
) = 2) then
4561 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4563 'p1_priority_flamethrower':
4565 if (Length(P
) = 2) then
4566 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4568 'p2_priority_flamethrower':
4570 if (Length(P
) = 2) then
4571 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4573 'p1_priority_berserk':
4575 if (Length(P
) = 2) then
4576 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4578 'p2_priority_berserk':
4580 if (Length(P
) = 2) then
4581 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4586 procedure PrintHeapStats();
4590 hs
:= GetFPCHeapStatus();
4591 e_LogWriteLn ('v===== heap status =====v');
4592 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4593 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4594 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4595 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4596 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4597 e_LogWriteLn ('^=======================^');
4600 procedure DebugCommands(P
: SSArray
);
4607 // Команды отладочного режима:
4608 if {gDebugMode}conIsCheatsEnabled
then
4610 cmd
:= LowerCase(P
[0]);
4611 if cmd
= 'd_window' then
4613 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4614 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4616 else if cmd
= 'd_sounds' then
4618 if (Length(P
) > 1) and
4619 ((P
[1] = '1') or (P
[1] = '0')) then
4620 g_Debug_Sounds
:= (P
[1][1] = '1');
4622 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4624 else if cmd
= 'd_frames' then
4626 if (Length(P
) > 1) and
4627 ((P
[1] = '1') or (P
[1] = '0')) then
4628 g_Debug_Frames
:= (P
[1][1] = '1');
4630 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4632 else if cmd
= 'd_winmsg' then
4634 if (Length(P
) > 1) and
4635 ((P
[1] = '1') or (P
[1] = '0')) then
4636 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4638 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4640 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4642 if (Length(P
) > 1) and
4643 ((P
[1] = '1') or (P
[1] = '0')) then
4644 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4646 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4648 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4650 if Length(P
) > 1 then
4652 '0': g_debug_BotAIOff
:= 0;
4653 '1': g_debug_BotAIOff
:= 1;
4654 '2': g_debug_BotAIOff
:= 2;
4655 '3': g_debug_BotAIOff
:= 3;
4658 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4660 else if cmd
= 'd_monster' then
4662 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4663 if Length(P
) < 2 then
4665 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4666 g_Console_Add('ID | Name');
4667 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4668 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4669 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4672 a
:= StrToIntDef(P
[1], 0);
4673 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4674 a
:= g_Mons_TypeIdByName(P
[1]);
4676 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4677 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4680 with gPlayer1
.Obj
do
4682 mon
:= g_Monsters_Create(a
,
4683 X
+ Rect
.X
+ (Rect
.Width
div 2),
4684 Y
+ Rect
.Y
+ Rect
.Height
,
4685 gPlayer1
.Direction
, True);
4687 if (Length(P
) > 2) and (mon
<> nil) then
4689 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4690 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4691 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4692 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4693 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4694 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4695 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4696 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4697 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4702 else if (cmd
= 'd_health') then
4704 if (Length(P
) > 1) and
4705 ((P
[1] = '1') or (P
[1] = '0')) then
4706 g_debug_HealthBar
:= (P
[1][1] = '1');
4708 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4710 else if (cmd
= 'd_player') then
4712 if (Length(P
) > 1) and
4713 ((P
[1] = '1') or (P
[1] = '0')) then
4714 g_debug_Player
:= (P
[1][1] = '1');
4716 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4718 else if (cmd
= 'd_mem') then
4724 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4728 procedure GameCheats(P
: SSArray
);
4734 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4736 g_Console_Add('not available');
4742 g_Console_Add('where is the player?!');
4745 cmd
:= LowerCase(P
[0]);
4749 plr
.GodMode
:= not plr
.GodMode
;
4750 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4753 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4754 if cmd
= 'give' then
4756 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4757 for f
:= 1 to High(P
) do
4759 cmd
:= LowerCase(P
[f
]);
4760 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4761 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4762 if cmd
= 'exit' then
4764 if gTriggers
<> nil then
4766 for a
:= 0 to High(gTriggers
) do
4768 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4770 g_Console_Add('player left the map');
4771 gExitByTrigger
:= True;
4772 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4773 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4781 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4782 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4783 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4784 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4785 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4787 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4788 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4790 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4791 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;
4793 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4794 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4796 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4797 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4799 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4800 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4802 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4803 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4804 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4806 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4807 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4808 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4809 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;
4810 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4811 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4813 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;
4814 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;
4815 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;
4816 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;
4817 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;
4818 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;
4820 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4821 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;
4823 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;
4824 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;
4826 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4828 if cmd
= 'ammo' then
4830 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4831 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4832 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4833 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4834 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4835 g_Console_Add('player got some ammo');
4839 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4840 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4842 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4843 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4845 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4846 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4848 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4849 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4851 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4853 if cmd
= 'weapons' then
4855 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4856 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4857 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4858 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4859 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4860 plr
.GiveItem(ITEM_WEAPON_BFG
);
4861 g_Console_Add('player got weapons');
4865 if cmd
= 'keys' then
4867 plr
.GiveItem(ITEM_KEY_RED
);
4868 plr
.GiveItem(ITEM_KEY_GREEN
);
4869 plr
.GiveItem(ITEM_KEY_BLUE
);
4870 g_Console_Add('player got all keys');
4874 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4879 if cmd
= 'open' then
4881 g_Console_Add('player activated sesame');
4882 g_Triggers_OpenAll();
4889 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4893 if cmd
= 'noclip' then
4896 g_Console_Add('wall hardeness adjusted');
4900 if cmd
= 'notarget' then
4902 plr
.NoTarget
:= not plr
.NoTarget
;
4903 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4907 if cmd
= 'noreload' then
4909 plr
.NoReload
:= not plr
.NoReload
;
4910 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4914 if cmd
= 'speedy' then
4916 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4917 g_Console_Add('speed adjusted');
4921 if cmd
= 'jumpy' then
4923 VEL_JUMP
:= 30-VEL_JUMP
;
4924 g_Console_Add('jump height adjusted');
4928 if cmd
= 'automap' then
4930 gShowMap
:= not gShowMap
;
4931 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4935 if cmd
= 'aimline' then
4937 gAimLine
:= not gAimLine
;
4938 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4943 procedure GameCommands(P
: SSArray
);
4949 pl
: pTNetClient
= nil;
4957 cmd
:= LowerCase(P
[0]);
4959 if cmd
= 'pause' then
4961 {$IFDEF ENABLE_MENU}
4962 if (g_ActiveWindow
= nil) then
4963 g_Game_Pause(not gPauseMain
);
4965 g_Game_Pause(not gPauseMain
);
4968 else if cmd
= 'endgame' then
4969 gExit
:= EXIT_SIMPLE
4970 else if cmd
= 'restart' then
4972 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4974 if g_Game_IsClient
then
4976 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4981 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4983 else if cmd
= 'kick' then
4985 if g_Game_IsServer
then
4987 if Length(P
) < 2 then
4989 g_Console_Add('kick <name>');
4994 g_Console_Add('kick <name>');
4998 if g_Game_IsNet
then
4999 pl
:= g_Net_Client_ByName(P
[1]);
5002 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5003 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5004 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5005 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5006 g_Net_Slist_ServerPlayerLeaves();
5007 end else if gPlayers
<> nil then
5008 for a
:= Low(gPlayers
) to High(gPlayers
) do
5009 if gPlayers
[a
] <> nil then
5010 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5012 // Не отключать основных игроков в сингле
5013 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5015 gPlayers
[a
].Lives
:= 0;
5016 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5017 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5018 g_Player_Remove(gPlayers
[a
].UID
);
5019 g_Net_Slist_ServerPlayerLeaves();
5020 // Если не перемешать, при добавлении новых ботов появятся старые
5024 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5026 else if cmd
= 'kick_id' then
5028 if g_Game_IsServer
and g_Game_IsNet
then
5030 if Length(P
) < 2 then
5032 g_Console_Add('kick_id <client ID>');
5037 g_Console_Add('kick_id <client ID>');
5041 a
:= StrToIntDef(P
[1], 0);
5042 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5044 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5046 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5047 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
5048 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5049 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5050 g_Net_Slist_ServerPlayerLeaves();
5054 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5056 else if cmd
= 'kick_pid' then
5058 if g_Game_IsServer
and g_Game_IsNet
then
5060 if Length(P
) < 2 then
5062 g_Console_Add('kick_pid <player ID>');
5067 g_Console_Add('kick_pid <player ID>');
5071 a
:= StrToIntDef(P
[1], 0);
5072 pl
:= g_Net_Client_ByPlayer(a
);
5073 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5075 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5076 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5077 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5078 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5079 g_Net_Slist_ServerPlayerLeaves();
5082 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5084 else if cmd
= 'ban' then
5086 if g_Game_IsServer
and g_Game_IsNet
then
5088 if Length(P
) < 2 then
5090 g_Console_Add('ban <name>');
5095 g_Console_Add('ban <name>');
5099 pl
:= g_Net_Client_ByName(P
[1]);
5102 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5103 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5104 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5105 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5106 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5107 g_Net_Slist_ServerPlayerLeaves();
5109 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5111 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5113 else if cmd
= 'ban_id' then
5115 if g_Game_IsServer
and g_Game_IsNet
then
5117 if Length(P
) < 2 then
5119 g_Console_Add('ban_id <client ID>');
5124 g_Console_Add('ban_id <client ID>');
5128 a
:= StrToIntDef(P
[1], 0);
5129 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5130 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5132 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5133 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5134 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5135 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5136 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5137 g_Net_Slist_ServerPlayerLeaves();
5140 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5142 else if cmd
= 'ban_pid' then
5144 if g_Game_IsServer
and g_Game_IsNet
then
5146 if Length(P
) < 2 then
5148 g_Console_Add('ban_pid <player ID>');
5153 g_Console_Add('ban_pid <player ID>');
5157 a
:= StrToIntDef(P
[1], 0);
5158 pl
:= g_Net_Client_ByPlayer(a
);
5159 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5161 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5162 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5163 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5164 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5165 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5166 g_Net_Slist_ServerPlayerLeaves();
5169 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5171 else if cmd
= 'permban' then
5173 if g_Game_IsServer
and g_Game_IsNet
then
5175 if Length(P
) < 2 then
5177 g_Console_Add('permban <name>');
5182 g_Console_Add('permban <name>');
5186 pl
:= g_Net_Client_ByName(P
[1]);
5189 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5190 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5191 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5192 g_Net_SaveBanList();
5193 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5194 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5195 g_Net_Slist_ServerPlayerLeaves();
5197 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5199 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5201 else if cmd
= 'permban_id' then
5203 if g_Game_IsServer
and g_Game_IsNet
then
5205 if Length(P
) < 2 then
5207 g_Console_Add('permban_id <client ID>');
5212 g_Console_Add('permban_id <client ID>');
5216 a
:= StrToIntDef(P
[1], 0);
5217 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5218 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5220 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5221 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5222 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5223 g_Net_SaveBanList();
5224 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5225 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5226 g_Net_Slist_ServerPlayerLeaves();
5229 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5231 else if cmd
= 'permban_pid' then
5233 if g_Game_IsServer
and g_Game_IsNet
then
5235 if Length(P
) < 2 then
5237 g_Console_Add('permban_pid <player ID>');
5242 g_Console_Add('permban_pid <player ID>');
5246 a
:= StrToIntDef(P
[1], 0);
5247 pl
:= g_Net_Client_ByPlayer(a
);
5248 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5250 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5251 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5252 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5253 g_Net_SaveBanList();
5254 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5255 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5256 g_Net_Slist_ServerPlayerLeaves();
5259 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5261 else if cmd
= 'permban_ip' then
5263 if g_Game_IsServer
and g_Game_IsNet
then
5265 if Length(P
) < 2 then
5267 g_Console_Add('permban_ip <IP address>');
5272 g_Console_Add('permban_ip <IP address>');
5276 g_Net_BanHost(P
[1]);
5277 g_Net_SaveBanList();
5278 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5280 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5282 else if cmd
= 'unban' then
5284 if g_Game_IsServer
and g_Game_IsNet
then
5286 if Length(P
) < 2 then
5288 g_Console_Add('unban <IP Address>');
5293 g_Console_Add('unban <IP Address>');
5297 if g_Net_UnbanHost(P
[1]) then
5299 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5300 g_Net_SaveBanList();
5302 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5304 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5306 else if cmd
= 'clientlist' then
5308 if g_Game_IsServer
and g_Game_IsNet
then
5311 if NetClients
<> nil then
5312 for a
:= Low(NetClients
) to High(NetClients
) do
5313 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5315 plr
:= g_Player_Get(NetClients
[a
].Player
);
5316 if plr
= nil then continue
;
5318 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5319 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5322 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5324 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5326 else if cmd
= 'connect' then
5328 if (NetMode
= NET_NONE
) then
5330 if Length(P
) < 2 then
5332 g_Console_Add('connect <IP> [port] [password]');
5337 g_Console_Add('connect <IP> [port] [password]');
5341 if Length(P
) > 2 then
5342 prt
:= StrToIntDef(P
[2], 25666)
5346 if Length(P
) > 3 then
5351 g_Game_StartClient(P
[1], prt
, pw
);
5354 else if cmd
= 'disconnect' then
5356 if (NetMode
= NET_CLIENT
) then
5359 else if cmd
= 'reconnect' then
5361 if (NetMode
= NET_SERVER
) then
5364 if (NetMode
= NET_CLIENT
) then
5367 gExit
:= EXIT_SIMPLE
;
5371 //TODO: Use last successful password to reconnect, instead of ''
5372 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5374 else if (cmd
= 'addbot') or
5375 (cmd
= 'bot_add') then
5377 if Length(P
) > 2 then
5378 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5379 else if Length(P
) > 1 then
5380 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5382 g_Bot_Add(TEAM_NONE
, 2);
5384 else if cmd
= 'bot_addlist' then
5386 if Length(P
) > 1 then
5388 if Length(P
) = 2 then
5389 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5390 else if Length(P
) = 3 then
5391 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5393 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5396 else if cmd
= 'bot_removeall' then
5398 else if cmd
= 'chat' then
5400 if g_Game_IsNet
then
5402 if Length(P
) > 1 then
5404 for a
:= 1 to High(P
) do
5405 chstr
:= chstr
+ P
[a
] + ' ';
5407 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5409 if Length(chstr
) < 1 then
5411 g_Console_Add('chat <text>');
5415 chstr
:= b_Text_Format(chstr
);
5416 if g_Game_IsClient
then
5417 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5419 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5422 g_Console_Add('chat <text>');
5424 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5426 else if cmd
= 'teamchat' then
5428 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5430 if Length(P
) > 1 then
5432 for a
:= 1 to High(P
) do
5433 chstr
:= chstr
+ P
[a
] + ' ';
5435 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5437 if Length(chstr
) < 1 then
5439 g_Console_Add('teamchat <text>');
5443 chstr
:= b_Text_Format(chstr
);
5444 if g_Game_IsClient
then
5445 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5447 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5448 gPlayer1Settings
.Team
);
5451 g_Console_Add('teamchat <text>');
5453 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5455 else if (cmd
= 'an') or (cmd
= 'announce') then
5457 if g_Game_IsNet
then
5459 if Length(P
) > 1 then
5461 for a
:= 1 to High(P
) do
5462 chstr
:= chstr
+ P
[a
] + ' ';
5464 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5466 if Length(chstr
) < 1 then
5468 g_Console_Add('announce <text>');
5472 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5473 if g_Game_IsClient
then
5474 MC_SEND_RCONCommand(chstr
)
5476 g_Console_Process(chstr
, True);
5479 g_Console_Add('announce <text>');
5481 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5483 else if cmd
= 'game' then
5485 if gGameSettings
.GameType
<> GT_NONE
then
5487 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5490 if Length(P
) = 1 then
5492 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5495 // game not started yet, load fist map from some wad
5497 s
:= addWadExtension(P
[1]);
5498 found
:= e_FindResource(AllMapDirs
, s
);
5502 P
[1] := ExpandFileName(P
[1]);
5503 // if map not choosed then set first map
5504 if Length(P
) < 3 then
5507 P
[2] := g_Game_GetFirstMap(P
[1]);
5510 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5512 if g_Map_Exist(s
) then
5516 with gGameSettings
do
5518 Options
:= gsGameFlags
;
5519 GameMode
:= g_Game_TextToMode(gsGameMode
);
5520 if gSwitchGameMode
<> GM_NONE
then
5521 GameMode
:= gSwitchGameMode
;
5522 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5523 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5525 if Length(P
) >= 4 then
5526 b
:= StrToIntDef(P
[3], 1);
5527 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5528 ScoreLimit
, MaxLives
, Options
, b
);
5533 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5535 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5537 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5539 else if cmd
= 'host' then
5541 if gGameSettings
.GameType
<> GT_NONE
then
5543 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5546 if Length(P
) < 4 then
5548 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5551 if not StrToIp(P
[1], listen
) then
5553 prt
:= StrToIntDef(P
[2], 25666);
5555 s
:= addWadExtension(P
[3]);
5556 found
:= e_FindResource(AllMapDirs
, s
);
5560 // get first map in wad, if not specified
5561 if Length(P
) < 5 then
5564 P
[4] := g_Game_GetFirstMap(P
[1]);
5566 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5567 if g_Map_Exist(s
) then
5571 with gGameSettings
do
5573 Options
:= gsGameFlags
;
5574 GameMode
:= g_Game_TextToMode(gsGameMode
);
5575 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5576 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5577 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5579 if Length(P
) >= 6 then
5580 b
:= StrToIntDef(P
[5], 0);
5581 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5587 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5589 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5594 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5597 else if cmd
= 'map' then
5599 if Length(P
) = 1 then
5601 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5603 g_Console_Add(cmd
+ ' <MAP>');
5604 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5608 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5613 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5615 if Length(P
) < 3 then
5617 // first param is map or wad
5618 s
:= UpperCase(P
[1]);
5619 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5621 gExitByTrigger
:= False;
5624 // already in game, finish current map
5626 gExit
:= EXIT_ENDLEVELCUSTOM
;
5630 // intermission, so change map immediately
5637 found
:= e_FindResource(AllMapDirs
, s
);
5639 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5642 // no such map, found wad
5645 P
[1] := ExpandFileName(pw
);
5646 P
[2] := g_Game_GetFirstMap(P
[1]);
5647 s
:= P
[1] + ':\' + P
[2];
5648 if g_Map_Exist(s
) then
5650 gExitByTrigger
:= False;
5653 // already in game, finish current map
5655 gExit
:= EXIT_ENDLEVELCUSTOM
5659 // intermission, so change map immediately
5666 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5668 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5673 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5679 s
:= addWadExtension(P
[1]);
5680 found
:= e_FindResource(AllMapDirs
, s
);
5684 P
[2] := UpperCase(P
[2]);
5685 s
:= P
[1] + ':\' + P
[2];
5686 if g_Map_Exist(s
) then
5688 gExitByTrigger
:= False;
5692 gExit
:= EXIT_ENDLEVELCUSTOM
5701 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5706 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5712 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5716 else if cmd
= 'nextmap' then
5718 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5720 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5725 if Length(P
) = 1 then
5727 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5729 g_Console_Add(cmd
+ ' <MAP>');
5730 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5735 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5741 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5743 if Length(P
) < 3 then
5745 // first param is map or wad
5746 s
:= UpperCase(P
[1]);
5747 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5750 gExitByTrigger
:= False;
5756 // no such map, found wad
5757 pw
:= addWadExtension(P
[1]);
5758 found
:= e_FindResource(MapDirs
, pw
);
5760 found
:= e_FindResource(WadDirs
, pw
);
5762 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5765 // map not specified, select first map
5767 P
[2] := g_Game_GetFirstMap(P
[1]);
5768 s
:= P
[1] + ':\' + P
[2];
5769 if g_Map_Exist(s
) then
5771 gExitByTrigger
:= False;
5778 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5780 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5785 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5791 // specified two params wad + map
5792 pw
:= addWadExtension(P
[1]);
5793 found
:= e_FindResource(MapDirs
, pw
);
5795 found
:= e_FindResource(MapDirs
, pw
);
5799 P
[2] := UpperCase(P
[2]);
5800 s
:= P
[1] + ':\' + P
[2];
5801 if g_Map_Exist(s
) then
5803 gExitByTrigger
:= False;
5809 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5814 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5820 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5825 if gNextMap
= '' then
5826 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5828 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5832 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5836 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5840 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5842 gExitByTrigger
:= False;
5843 // next map not specified, try to find trigger EXIT
5844 if (gNextMap
= '') and (gTriggers
<> nil) then
5846 for a
:= 0 to High(gTriggers
) do
5848 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5850 gExitByTrigger
:= True;
5851 //gNextMap := gTriggers[a].Data.MapName;
5852 gNextMap
:= gTriggers
[a
].tgcMap
;
5857 if gNextMap
= '' then
5858 gNextMap
:= g_Game_GetNextMap();
5859 if not isWadPath(gNextMap
) then
5860 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5863 if g_Map_Exist(s
) then
5864 gExit
:= EXIT_ENDLEVELCUSTOM
5866 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5870 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5874 else if (cmd
= 'event') then
5876 if (Length(P
) <= 1) then
5878 for a
:= 0 to High(gEvents
) do
5879 if gEvents
[a
].Command
= '' then
5880 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5882 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5885 if (Length(P
) = 2) then
5887 for a
:= 0 to High(gEvents
) do
5888 if gEvents
[a
].Name
= P
[1] then
5889 if gEvents
[a
].Command
= '' then
5890 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5892 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5895 for a
:= 0 to High(gEvents
) do
5896 if gEvents
[a
].Name
= P
[1] then
5898 gEvents
[a
].Command
:= '';
5899 for b
:= 2 to High(P
) do
5900 if Pos(' ', P
[b
]) = 0 then
5901 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5903 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5904 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5908 else if cmd
= 'suicide' then
5912 if g_Game_IsClient
then
5913 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5916 if gPlayer1
<> nil then
5917 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5918 if gPlayer2
<> nil then
5919 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5923 else if cmd
= 'screenshot' then
5925 {$IFDEF ENABLE_RENDER}
5929 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5931 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5933 gWeaponAction
[0, WP_PREV
] := True;
5935 gWeaponAction
[0, WP_NEXT
] := True;
5937 else if cmd
= 'weapon' then
5939 if Length(p
) = 2 then
5941 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5942 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5943 gSelectWeapon
[0, a
] := True
5946 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5947 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5949 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5950 b
:= ord(cmd
[2]) - ord('1');
5952 gWeaponAction
[b
, WP_PREV
] := True;
5954 gWeaponAction
[b
, WP_NEXT
] := True;
5956 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5958 if Length(p
) = 2 then
5960 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5961 b
:= ord(cmd
[2]) - ord('1');
5962 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5963 gSelectWeapon
[b
, a
] := True
5966 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
5968 b
:= ord(cmd
[2]) - ord('1');
5970 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
5972 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
5974 else if (cmd
= 'dropflag') then
5976 if g_Game_IsServer
then
5978 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
5979 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
5982 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5984 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
5986 b
:= ord(cmd
[2]) - ord('1');
5987 if g_Game_IsServer
then
5989 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
5990 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
5993 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5995 // Команды Своей игры:
5996 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5998 if cmd
= 'bot_addred' then
6000 if Length(P
) > 1 then
6001 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6003 g_Bot_Add(TEAM_RED
, 2);
6005 else if cmd
= 'bot_addblue' then
6007 if Length(P
) > 1 then
6008 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6010 g_Bot_Add(TEAM_BLUE
, 2);
6012 else if cmd
= 'spectate' then
6018 else if cmd
= 'say' then
6020 if g_Game_IsServer
and g_Game_IsNet
then
6022 if Length(P
) > 1 then
6025 for a
:= 1 to High(P
) do
6026 chstr
:= chstr
+ P
[a
] + ' ';
6028 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6030 if Length(chstr
) < 1 then
6032 g_Console_Add('say <text>');
6036 chstr
:= b_Text_Format(chstr
);
6037 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6039 else g_Console_Add('say <text>');
6041 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6043 else if cmd
= 'tell' then
6045 if g_Game_IsServer
and g_Game_IsNet
then
6047 if (Length(P
) > 2) and (P
[1] <> '') then
6050 for a
:= 2 to High(P
) do
6051 chstr
:= chstr
+ P
[a
] + ' ';
6053 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6055 if Length(chstr
) < 1 then
6057 g_Console_Add('tell <playername> <text>');
6061 pl
:= g_Net_Client_ByName(P
[1]);
6063 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6065 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6067 else g_Console_Add('tell <playername> <text>');
6069 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6071 else if cmd
= 'centerprint' then
6073 if (Length(P
) > 2) and (P
[1] <> '') then
6076 for a
:= 2 to High(P
) do
6077 chstr
:= chstr
+ P
[a
] + ' ';
6079 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6081 if Length(chstr
) < 1 then
6083 g_Console_Add('centerprint <timeout> <text>');
6087 a
:= StrToIntDef(P
[1], 100);
6088 chstr
:= b_Text_Format(chstr
);
6089 g_Game_Message(chstr
, a
);
6090 if g_Game_IsNet
and g_Game_IsServer
then
6091 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6093 else g_Console_Add('centerprint <timeout> <text>');
6095 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6097 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6099 // Дополнительное время:
6100 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6102 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6103 [gGameSettings
.TimeLimit
div 3600,
6104 (gGameSettings
.TimeLimit
div 60) mod 60,
6105 gGameSettings
.TimeLimit
mod 60]));
6106 if g_Game_IsNet
then MH_SEND_GameSettings
;
6108 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6110 if (Length(P
) <= 1) then
6111 g_Console_Add('rcon_password <password>')
6113 MC_SEND_RCONPassword(P
[1]);
6115 else if cmd
= 'rcon' then
6117 if g_Game_IsClient
then
6119 if Length(P
) > 1 then
6122 for a
:= 1 to High(P
) do
6123 chstr
:= chstr
+ P
[a
] + ' ';
6125 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6127 if Length(chstr
) < 1 then
6129 g_Console_Add('rcon <command>');
6133 MC_SEND_RCONCommand(chstr
);
6135 else g_Console_Add('rcon <command>');
6138 else if cmd
= 'ready' then
6140 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6141 gLMSRespawnTime
:= gTime
+ 100;
6143 else if (cmd
= 'callvote') and g_Game_IsNet
then
6145 if Length(P
) > 1 then
6148 for a
:= 1 to High(P
) do begin
6149 if a
> 1 then chstr
:= chstr
+ ' ';
6150 chstr
:= chstr
+ P
[a
];
6153 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6155 if Length(chstr
) < 1 then
6157 g_Console_Add('callvote <command>');
6161 if g_Game_IsClient
then
6162 MC_SEND_Vote(True, chstr
)
6164 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6165 g_Console_Process('vote', True);
6168 g_Console_Add('callvote <command>');
6170 else if (cmd
= 'vote') and g_Game_IsNet
then
6172 if g_Game_IsClient
then
6174 else if gVoteInProgress
then
6176 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6177 a
:= Floor((NetClientCount
+1)/2.0) + 1
6179 a
:= Floor(NetClientCount
/2.0) + 1;
6184 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6185 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6191 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6192 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6200 procedure SystemCommands(P
: SSArray
);
6204 cmd
:= LowerCase(P
[0]);
6211 {$IFDEF ENABLE_RENDER}
6217 if Length(p
) = 2 then
6219 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6221 gFrameTime
:= 1000 div gMaxFPS
6225 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6229 if Length(p
) = 2 then
6231 gAskLanguage
:= true;
6232 gLanguage
:= LANGUAGE_ENGLISH
;
6233 case LowerCase(p
[1]) of
6236 gAskLanguage
:= false;
6237 gLanguage
:= LANGUAGE_ENGLISH
;
6241 gAskLanguage
:= false;
6242 gLanguage
:= LANGUAGE_RUSSIAN
;
6246 gAskLanguage
:= true;
6247 gLanguage
:= LANGUAGE_ENGLISH
;
6250 g_Language_Set(gLanguage
);
6254 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6260 {$IFDEF ENABLE_RENDER}
6261 procedure g_TakeScreenShot(Filename
: string = '');
6262 var t
: TDateTime
; dir
, date
, name
: String;
6264 if e_NoGraphics
then
6267 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6268 if Filename
= '' then
6271 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6272 Filename
:= 'screenshot-' + date
;
6275 name
:= e_CatPath(dir
, Filename
+ '.png');
6276 if r_Render_WriteScreenShot(name
) then
6277 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6279 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6283 {$IFDEF ENABLE_MENU}
6284 procedure g_Game_InGameMenu(Show
: Boolean);
6286 if (g_ActiveWindow
= nil) and Show
then
6288 if gGameSettings
.GameType
= GT_SINGLE
then
6289 g_GUI_ShowWindow('GameSingleMenu')
6292 if g_Game_IsClient
then
6293 g_GUI_ShowWindow('GameClientMenu')
6295 if g_Game_IsNet
then
6296 g_GUI_ShowWindow('GameServerMenu')
6298 g_GUI_ShowWindow('GameCustomMenu');
6300 g_Sound_PlayEx('MENU_OPEN');
6302 // Пауза при меню только в одиночной игре:
6303 if (not g_Game_IsNet
) then
6307 if (g_ActiveWindow
<> nil) and (not Show
) then
6309 // Пауза при меню только в одиночной игре:
6310 if (not g_Game_IsNet
) then
6311 g_Game_Pause(False);
6316 procedure g_Game_Pause (Enable
: Boolean);
6320 if not gGameOn
then exit
;
6322 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6325 gPauseMain
:= Enable
;
6327 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6330 procedure g_Game_HolmesPause (Enable
: Boolean);
6334 if not gGameOn
then exit
;
6335 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6338 gPauseHolmes
:= Enable
;
6340 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6343 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6348 if gTriggers
<> nil then
6349 for i
:= 0 to High(gTriggers
) do
6350 with gTriggers
[i
] do
6351 if (TriggerType
= TRIGGER_SOUND
) and
6353 Sound
.IsPlaying() then
6355 Sound
.Pause(Enable
);
6359 if gPlayers
<> nil then
6360 for i
:= 0 to High(gPlayers
) do
6361 if gPlayers
[i
] <> nil then
6362 gPlayers
[i
].PauseSounds(Enable
);
6365 if gMusic
<> nil then
6366 gMusic
.Pause(Enable
);
6369 procedure g_Game_StopAllSounds(all
: Boolean);
6373 if gTriggers
<> nil then
6374 for i
:= 0 to High(gTriggers
) do
6375 with gTriggers
[i
] do
6376 if (TriggerType
= TRIGGER_SOUND
) and
6380 if gMusic
<> nil then
6387 procedure g_Game_UpdateTriggerSounds
;
6390 if gTriggers
<> nil then
6391 for i
:= 0 to High(gTriggers
) do
6392 with gTriggers
[i
] do
6393 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6394 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6397 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6400 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6405 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6410 if gSpectMode
<> SPECT_PLAYERS
then
6412 if gSpectPID1
= UID
then
6417 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6424 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6429 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6434 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6439 if gSpectMode
<> SPECT_PLAYERS
then
6441 Pl
:= g_Player_Get(gSpectPID1
);
6442 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6447 if gSpectViewTwo
then
6449 Pl
:= g_Player_Get(gSpectPID2
);
6450 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6458 procedure g_Game_Message (Msg
: string; Time
: Word);
6461 MessageTime
:= Time
;
6464 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6466 punct
: Array[0..13] of String =
6467 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6473 function IsPunctuation(S
: String): Boolean;
6478 if Length(S
) <> 1 then
6480 for i
:= Low(punct
) to High(punct
) do
6481 if S
= punct
[i
] then
6487 function FilterPunctuation(S
: String): String;
6491 for i
:= Low(punct
) to High(punct
) do
6492 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6498 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6500 // remove player name
6501 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6502 // for FullWord check
6503 Text := toLowerCase1251(' ' + Text + ' ');
6504 fpText
:= FilterPunctuation(Text);
6506 for i
:= 0 to Length(gChatSounds
) - 1 do
6509 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6511 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6512 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6514 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6520 gChatSounds
[i
].Sound
.Play();
6526 g_Sound_PlayEx('SOUND_GAME_RADIO');
6529 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6538 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6542 if goodsnd
[a
].IsPlaying() then
6545 goodsnd
[Random(4)].Play();
6548 procedure g_Game_Announce_KillCombo(Param
: Integer);
6555 UID
:= Param
and $FFFF;
6560 Pl
:= g_Player_Get(UID
);
6569 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6573 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6577 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6581 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6589 if not g_Game_IsWatchedPlayer(UID
) then
6592 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6596 if killsnd
[n
].IsPlaying() then
6601 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6609 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6613 if hahasnd
[a
].IsPlaying() then
6616 hahasnd
[Random(3)].Play();
6619 procedure g_Game_StartVote(Command
, Initiator
: string);
6623 if not gVotesEnabled
then Exit
;
6624 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6625 if gVoteInProgress
or gVotePassed
then
6627 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6628 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6631 gVoteInProgress
:= True;
6632 gVotePassed
:= False;
6633 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6636 gVoteCommand
:= Command
;
6638 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6639 Need
:= Floor((NetClientCount
+1)/2.0)+1
6641 Need
:= Floor(NetClientCount
/2.0)+1;
6642 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6643 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6646 procedure g_Game_CheckVote
;
6650 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6651 if not gVoteInProgress
then Exit
;
6653 if (gTime
>= gVoteTimer
) then
6655 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6656 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6658 Need
:= Floor(NetClientCount
/2.0) + 1;
6659 if gVoteCount
>= Need
then
6661 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6662 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6663 gVotePassed
:= True;
6664 gVoteCmdTimer
:= gTime
+ 5000;
6668 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6669 MH_SEND_VoteEvent(NET_VE_FAILED
);
6671 if NetClients
<> nil then
6672 for I
:= Low(NetClients
) to High(NetClients
) do
6673 if NetClients
[i
].Used
then
6674 NetClients
[i
].Voted
:= False;
6675 gVoteInProgress
:= False;
6681 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6682 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6684 Need
:= Floor(NetClientCount
/2.0) + 1;
6685 if gVoteCount
>= Need
then
6687 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6688 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6689 gVoteInProgress
:= False;
6690 gVotePassed
:= True;
6691 gVoteCmdTimer
:= gTime
+ 5000;
6694 if NetClients
<> nil then
6695 for I
:= Low(NetClients
) to High(NetClients
) do
6696 if NetClients
[i
].Used
then
6697 NetClients
[i
].Voted
:= False;
6702 procedure g_Game_LoadMapList(FileName
: string);
6710 if not FileExists(FileName
) then Exit
;
6712 AssignFile(ListFile
, FileName
);
6714 while not EOF(ListFile
) do
6716 ReadLn(ListFile
, s
);
6719 if s
= '' then Continue
;
6721 SetLength(MapList
, Length(MapList
)+1);
6722 MapList
[High(MapList
)] := s
;
6724 CloseFile(ListFile
);
6727 procedure g_Game_SetDebugMode();
6730 // Читы (даже в своей игре):
6734 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6738 if Length(LoadingStat
.Msgs
) = 0 then
6744 begin // Переходим на следующую строку или скроллируем:
6745 if NextMsg
= Length(Msgs
) then
6747 for i
:= 0 to High(Msgs
)-1 do
6748 Msgs
[i
] := Msgs
[i
+1];
6756 Msgs
[NextMsg
-1] := Text;
6760 PBarWasHere
:= false;
6763 {$IFDEF ENABLE_MENU}
6764 g_ActiveWindow
:= nil;
6767 ProcessLoading(true);
6770 procedure g_Game_StepLoading(Value
: Integer = -1);
6782 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6785 ProcessLoading(False);
6790 procedure g_Game_ClearLoading();
6799 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6800 if len
< 1 then len
:= 1;
6801 SetLength(Msgs
, len
);
6802 for len
:= Low(Msgs
) to High(Msgs
) do
6805 PBarWasHere
:= false;
6809 procedure Parse_Params(var pars
: TParamStrValues
);
6816 while i
<= ParamCount
do
6819 if (Length(s
) > 1) and (s
[1] = '-') then
6821 if (Length(s
) > 2) and (s
[2] = '-') then
6822 begin // Одиночный параметр
6823 SetLength(pars
, Length(pars
) + 1);
6824 with pars
[High(pars
)] do
6826 Name
:= LowerCase(s
);
6831 if (i
< ParamCount
) then
6832 begin // Параметр со значением
6834 SetLength(pars
, Length(pars
) + 1);
6835 with pars
[High(pars
)] do
6837 Name
:= LowerCase(s
);
6838 Value
:= LowerCase(ParamStr(i
));
6847 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6852 for i
:= 0 to High(pars
) do
6853 if pars
[i
].Name
= aName
then
6855 Result
:= pars
[i
].Value
;
6860 procedure g_Game_Process_Params();
6862 pars
: TParamStrValues
;
6865 LimT
, LimS
: Integer;
6876 s
:= Find_Param_Value(pars
, '--debug');
6879 g_Game_SetDebugMode();
6880 s
:= Find_Param_Value(pars
, '--netdump');
6885 // Connect when game loads
6886 ip
:= Find_Param_Value(pars
, '-connect');
6890 s
:= Find_Param_Value(pars
, '-port');
6891 if (s
= '') or not TryStrToInt(s
, Port
) then
6894 s
:= Find_Param_Value(pars
, '-pw');
6896 g_Game_StartClient(ip
, Port
, s
);
6900 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6903 gDefaultMegawadStart
:= s
;
6906 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6907 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6909 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6912 // Start map when game loads:
6913 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6914 if isWadPath(map
) then
6917 s
:= Find_Param_Value(pars
, '-gm');
6918 GMode
:= g_Game_TextToMode(s
);
6919 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6920 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6923 s
:= Find_Param_Value(pars
, '-limt');
6924 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6930 s
:= Find_Param_Value(pars
, '-lims');
6931 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6937 s
:= Find_Param_Value(pars
, '-lives');
6938 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6944 s
:= Find_Param_Value(pars
, '-opt');
6948 Opt
:= StrToIntDef(s
, 0);
6951 s
:= Find_Param_Value(pars
, '--close');
6955 // Override map to test:
6956 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6959 if e_IsValidResourceName(s
) then
6960 e_FindResource(AllMapDirs
, s
);
6961 gTestMap
:= ExpandFileName(s
);
6964 // Delete test map after play:
6965 s
:= Find_Param_Value(pars
, '--testdelete');
6968 //gMapToDelete := MapsDir + map;
6969 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6973 // Delete temporary WAD after play:
6974 s
:= Find_Param_Value(pars
, '--tempdelete');
6975 if (s
<> '') and (gTestMap
<> '') then
6977 gMapToDelete
:= gTestMap
;
6978 gTempDelete
:= True;
6981 // Number of players:
6982 s
:= Find_Param_Value(pars
, '-pl');
6984 n
:= DEFAULT_PLAYERS
6986 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6989 s
:= Find_Param_Value(pars
, '-port');
6990 if (s
= '') or not TryStrToInt(s
, Port
) then
6991 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6993 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6996 // Execute script when game loads:
6997 s
:= Find_Param_Value(pars
, '-exec');
7000 // if not isWadPath(s) then
7001 // s := GameDir + '/' + s;
7006 if IOResult
<> 0 then
7008 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7009 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7013 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
7014 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7019 if IOResult
<> 0 then
7021 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7022 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7026 if Pos('#', s
) <> 1 then // script comment
7027 g_Console_Process(s
, True);
7038 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7039 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7040 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7041 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7043 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7044 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7045 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7046 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7049 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7050 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7053 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7054 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7056 {$IFDEF ENABLE_HOLMES}
7057 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7060 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7062 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7063 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7065 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7066 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7068 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
7069 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
7070 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
7071 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
7072 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7073 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7074 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7075 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7076 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');