1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
24 SysUtils
, Classes
, MAPDEF
,
25 g_base
, g_basic
, g_player
, g_res_downloader
,
26 g_sound
, utils
, md5
, mempool
, xprofiler
,
31 TGameSettings
= record
38 ItemRespawnTime
: Word;
49 TDelayedEvent
= record
58 Sound
: TPlayableSound
;
59 Tags
: Array of String;
63 TPlayerSettings
= record
68 // ones below are sent only to the server
70 WeaponPreferences
: Array[WP_FIRST
..WP_LAST
+1] of Byte;
87 function g_Game_IsNet(): Boolean;
88 function g_Game_IsServer(): Boolean;
89 function g_Game_IsClient(): Boolean;
90 procedure g_Game_Init();
91 procedure g_Game_Free (freeTextures
: Boolean=true);
92 procedure g_Game_LoadData();
93 procedure g_Game_FreeData();
94 procedure g_Game_Update();
95 procedure g_Game_PreUpdate();
96 procedure g_Game_Quit();
97 function g_Game_ModeToText(Mode
: Byte): string;
98 function g_Game_TextToMode(Mode
: string): Byte;
99 procedure g_Game_ExecuteEvent(Name
: String);
100 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
101 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
102 procedure g_Game_RemovePlayer();
103 procedure g_Game_Spectate();
104 procedure g_Game_SpectateCenterView();
105 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
106 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
107 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
108 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
109 procedure g_Game_Restart();
110 procedure g_Game_RestartLevel();
111 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
112 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
113 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
114 procedure g_Game_ChangeMap(const MapPath
: String);
115 procedure g_Game_ExitLevel(const Map
: AnsiString);
116 function g_Game_GetFirstMap(WAD
: String): String;
117 function g_Game_GetNextMap(): String;
118 procedure g_Game_NextLevel();
119 procedure g_Game_Pause(Enable
: Boolean);
120 procedure g_Game_HolmesPause(Enable
: Boolean);
121 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
122 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
123 procedure g_Game_Message(Msg
: String; Time
: Word);
124 procedure g_Game_LoadMapList(FileName
: String);
125 procedure g_Game_PauseAllSounds(Enable
: Boolean);
126 procedure g_Game_StopAllSounds(all
: Boolean);
127 procedure g_Game_UpdateTriggerSounds();
128 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
129 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
130 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
131 procedure g_Game_Announce_KillCombo(Param
: Integer);
132 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
133 procedure g_Game_StartVote(Command
, Initiator
: string);
134 procedure g_Game_CheckVote
;
135 {$IFDEF ENABLE_RENDER}
136 procedure g_TakeScreenShot(Filename
: string = '');
138 procedure g_FatalError(Text: String);
139 procedure g_SimpleError(Text: String);
140 function g_Game_IsTestMap(): Boolean;
141 procedure g_Game_DeleteTestMap();
142 procedure GameCVars(P
: SSArray
);
143 procedure PlayerSettingsCVars(P
: SSArray
);
144 procedure SystemCommands(P
: SSArray
);
145 procedure GameCommands(P
: SSArray
);
146 procedure GameCheats(P
: SSArray
);
147 procedure DebugCommands(P
: SSArray
);
148 procedure g_Game_Process_Params
;
149 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
150 procedure g_Game_StepLoading(Value
: Integer = -1);
151 procedure g_Game_ClearLoading();
152 procedure g_Game_SetDebugMode();
154 function IsActivePlayer(p
: TPlayer
): Boolean;
155 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
156 procedure SortGameStat(var stat
: TPlayerStatArray
);
160 procedure g_Game_InGameMenu(Show
: Boolean);
162 {$IFDEF ENABLE_SYSTEM}
163 procedure CharPress (C
: AnsiChar);
166 procedure KeyPress (K
: Word);
168 { procedure SetWinPause(Enable: Boolean); }
173 LOADING_SHOW_STEP
= 100;
174 LOADING_INTERLINE
= 20;
192 EXIT_ENDLEVELSINGLE
= 4;
193 EXIT_ENDLEVELCUSTOM
= 5;
195 GAME_OPTION_RESERVED
= 1;
196 GAME_OPTION_TEAMDAMAGE
= 2;
197 GAME_OPTION_ALLOWEXIT
= 4;
198 GAME_OPTION_WEAPONSTAY
= 8;
199 GAME_OPTION_MONSTERS
= 16;
200 GAME_OPTION_BOTVSPLAYER
= 32;
201 GAME_OPTION_BOTVSMONSTER
= 64;
202 GAME_OPTION_DMKEYS
= 128;
203 GAME_OPTION_TEAMHITTRACE
= 256;
204 GAME_OPTION_TEAMHITPROJECTILE
= 512;
205 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
206 GAME_OPTION_ALLOWDROPFLAG
= 2048;
207 GAME_OPTION_THROWFLAG
= 4096;
212 STATE_INTERCUSTOM
= 3;
213 STATE_INTERSINGLE
= 4;
219 LMS_RESPAWN_NONE
= 0;
220 LMS_RESPAWN_WARMUP
= 1;
221 LMS_RESPAWN_FINAL
= 2;
238 CONFIG_FILENAME
= 'Doom2DF.cfg';
240 TEST_MAP_NAME
= '$$$_TEST_$$$';
242 STD_PLAYER_MODEL
= 'Doomer';
250 STATFILE_VERSION
= $03;
253 gGameSettings
: TGameSettings
;
254 gPlayer1Settings
: TPlayerSettings
;
255 gPlayer2Settings
: TPlayerSettings
;
257 gPlayerScreenSize
: TDFPoint
;
258 gPlayer1
: TPlayer
= nil;
259 gPlayer2
: TPlayer
= nil;
261 gLerpFactor
: Single = 1.0;
262 gSwitchGameMode
: Byte = GM_DM
;
263 gHearPoint1
, gHearPoint2
: THearPoint
;
264 gMaxDist
: Integer = 1; // for sound
265 gSoundEffectsDF
: Boolean = False;
266 gSoundTriggerTime
: Word = 0;
267 gAnnouncer
: Integer = ANNOUNCE_NONE
;
268 goodsnd
: array[0..3] of TPlayableSound
;
269 killsnd
: array[0..3] of TPlayableSound
;
270 hahasnd
: array[0..2] of TPlayableSound
;
271 sound_get_flag
: array[0..1] of TPlayableSound
;
272 sound_lost_flag
: array[0..1] of TPlayableSound
;
273 sound_ret_flag
: array[0..1] of TPlayableSound
;
274 sound_cap_flag
: array[0..1] of TPlayableSound
;
275 gBodyKillEvent
: Integer = -1;
276 gDefInterTime
: ShortInt = -1;
277 gInterEndTime
: LongWord = 0;
278 gInterTime
: LongWord = 0;
279 gServInterTime
: Byte = 0;
280 gGameStartTime
: LongWord = 0;
281 gTotalMonsters
: Integer = 0;
282 gPauseMain
: Boolean = false;
283 gPauseHolmes
: Boolean = false;
284 gShowTime
: Boolean = False;
285 gShowFPS
: Boolean = False;
286 gShowScore
: Boolean = True;
287 gShowStat
: Boolean = True;
288 gShowPIDs
: Boolean = False;
289 gShowKillMsg
: Boolean = True;
290 gShowLives
: Boolean = True;
291 gShowPing
: Boolean = False;
292 gShowMap
: Boolean = False;
294 gState
: Byte = STATE_NONE
;
296 sWidth
, sHeight
: Word;
297 gSpectMode
: Byte = SPECT_NONE
;
298 gSpectHUD
: Boolean = True;
299 gSpectKeyPress
: Boolean = False;
300 gSpectX
: Integer = 0;
301 gSpectY
: Integer = 0;
302 gSpectStep
: Byte = 8;
303 gSpectViewTwo
: Boolean = False;
304 gSpectPID1
: Integer = -1;
305 gSpectPID2
: Integer = -1;
306 gSpectAuto
: Boolean = False;
307 gSpectAutoNext
: LongWord;
308 gSpectAutoStepX
: Integer;
309 gSpectAutoStepY
: Integer;
310 gMusic
: TMusic
= nil;
311 gLoadGameMode
: Boolean;
312 gCheats
: Boolean = False;
313 gMapOnce
: Boolean = False;
314 gMapToDelete
: String;
315 gTempDelete
: Boolean = False;
316 gLastMap
: Boolean = False;
319 gResolutionChange
: Boolean = False;
320 gRC_Width
, gRC_Height
: Integer;
321 gRC_FullScreen
, gRC_Maximized
: Boolean;
322 gLanguageChange
: Boolean = False;
323 gDebugMode
: Boolean = False;
324 g_debug_Sounds
: Boolean = False;
325 g_debug_Frames
: Boolean = False;
326 g_debug_WinMsgs
: Boolean = False;
327 g_debug_MonsterOff
: Boolean = False;
328 g_debug_BotAIOff
: Byte = 0;
329 g_debug_HealthBar
: Boolean = False;
330 g_Debug_Player
: Boolean = False;
331 gCoopMonstersKilled
: Word = 0;
332 gCoopSecretsFound
: Word = 0;
333 gCoopTotalMonstersKilled
: Word = 0;
334 gCoopTotalSecretsFound
: Word = 0;
335 gCoopTotalMonsters
: Word = 0;
336 gCoopTotalSecrets
: Word = 0;
337 gStatsOff
: Boolean = False;
338 gStatsPressed
: Boolean = False;
339 gExitByTrigger
: Boolean = False;
340 gNextMap
: String = '';
341 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
342 gLMSRespawnTime
: Cardinal = 0;
343 gLMSSoftSpawn
: Boolean = False;
344 gMissionFailed
: Boolean = False;
345 gVoteInProgress
: Boolean = False;
346 gVotePassed
: Boolean = False;
347 gVoteCommand
: string = '';
348 gVoteTimer
: Cardinal = 0;
349 gVoteCmdTimer
: Cardinal = 0;
350 gVoteCount
: Integer = 0;
351 gVoteTimeout
: Cardinal = 30;
352 gVoted
: Boolean = False;
353 gVotesEnabled
: Boolean = True;
354 gEvents
: Array of TGameEvent
;
355 gDelayedEvents
: Array of TDelayedEvent
;
356 gUseChatSounds
: Boolean = True;
357 gChatSounds
: Array of TChatSound
;
358 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
359 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
360 gInterReadyCount
: Integer = 0;
361 gMaxBots
: Integer = 127;
363 g_dbg_ignore_bounds
: Boolean = false;
364 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
365 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
367 // move button values:
368 // bits 0-1: l/r state:
369 // 0: neither left, nor right pressed
372 // bits 4-5: l/r state when strafe was pressed
373 P1MoveButton
: Byte = 0;
374 P2MoveButton
: Byte = 0;
376 g_profile_frame_update
: Boolean = false;
377 g_profile_frame_draw
: Boolean = false;
378 g_profile_collision
: Boolean = false;
379 g_profile_los
: Boolean = false;
380 g_profile_history_size
: Integer = 1000;
382 g_rlayer_back
: Boolean = true;
383 g_rlayer_step
: Boolean = true;
384 g_rlayer_wall
: Boolean = true;
385 g_rlayer_door
: Boolean = true;
386 g_rlayer_acid1
: Boolean = true;
387 g_rlayer_acid2
: Boolean = true;
388 g_rlayer_water
: Boolean = true;
389 g_rlayer_fore
: Boolean = true;
391 wNeedTimeReset
: Boolean = false;
393 procedure g_ResetDynlights ();
394 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
395 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
397 function conIsCheatsEnabled (): Boolean; inline;
398 function gPause (): Boolean; inline;
400 type (* private state *)
401 TEndCustomGameStat
= record
402 PlayerStat
: TPlayerStatArray
;
406 Map
, MapName
: String;
409 TEndSingleGameStat
= record
410 PlayerStat
: Array [0..1] of record
416 TotalSecrets
: Integer;
419 TLoadingStat
= record
423 Msgs
: Array of String;
425 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
429 x
, y
, radius
: Integer;
432 exploRadius
: Integer;
435 var (* private state *)
436 CustomStat
: TEndCustomGameStat
;
437 StatShotDone
: Boolean;
438 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
439 SingleStat
: TEndSingleGameStat
;
440 LoadingStat
: TLoadingStat
;
443 EndingGameCounter
: Byte;
445 g_playerLight
: Boolean;
446 g_dynLights
: array of TDynLight
= nil;
447 g_dynLightCount
: Integer = 0;
448 EndPicPath
: AnsiString; // full path, used by render
453 {$IFDEF ENABLE_HOLMES}
465 {$IFDEF ENABLE_SHELLS}
468 {$IFDEF ENABLE_CORPSES}
471 {$IFDEF ENABLE_RENDER}
474 {$IFDEF ENABLE_SYSTEM}
478 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
479 g_playermodel
, g_options
, Math
,
480 g_triggers
, g_monsters
, e_sound
, CONFIG
,
481 g_language
, g_net
, g_phys
,
482 ENet
, e_msg
, g_netmsg
, g_netmaster
,
486 charbuff
: packed array [0..15] of AnsiChar = (
487 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
490 function Translit (const S
: AnsiString): AnsiString;
495 for i
:= 1 to Length(Result
) do
498 #
$C9: Result
[i
] := 'Q';
499 #
$D6: Result
[i
] := 'W';
500 #
$D3: Result
[i
] := 'E';
501 #
$CA: Result
[i
] := 'R';
502 #
$C5: Result
[i
] := 'T';
503 #
$CD: Result
[i
] := 'Y';
504 #
$C3: Result
[i
] := 'U';
505 #
$D8: Result
[i
] := 'I';
506 #
$D9: Result
[i
] := 'O';
507 #
$C7: Result
[i
] := 'P';
508 #
$D5: Result
[i
] := '['; //Chr(219);
509 #
$DA: Result
[i
] := ']'; //Chr(221);
510 #
$D4: Result
[i
] := 'A';
511 #
$DB: Result
[i
] := 'S';
512 #
$C2: Result
[i
] := 'D';
513 #
$C0: Result
[i
] := 'F';
514 #
$CF: Result
[i
] := 'G';
515 #
$D0: Result
[i
] := 'H';
516 #
$CE: Result
[i
] := 'J';
517 #
$CB: Result
[i
] := 'K';
518 #
$C4: Result
[i
] := 'L';
519 #
$C6: Result
[i
] := ';'; //Chr(186);
520 #
$DD: Result
[i
] := #39; //Chr(222);
521 #
$DF: Result
[i
] := 'Z';
522 #
$D7: Result
[i
] := 'X';
523 #
$D1: Result
[i
] := 'C';
524 #
$CC: Result
[i
] := 'V';
525 #
$C8: Result
[i
] := 'B';
526 #
$D2: Result
[i
] := 'N';
527 #
$DC: Result
[i
] := 'M';
528 #
$C1: Result
[i
] := ','; //Chr(188);
529 #
$DE: Result
[i
] := '.'; //Chr(190);
535 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
540 ls2
:= Translit(CheatRus
[ct
]);
541 if length(ls1
) = 0 then ls1
:= '~';
542 if length(ls2
) = 0 then ls2
:= '~';
544 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
545 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
546 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
547 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
549 if ct = I_GAME_CHEAT_JETPACK then
551 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
552 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
553 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
554 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
555 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
556 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
572 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
573 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
574 or g_Game_IsNet then Exit;
576 if not gGameOn
then exit
;
577 if not conIsCheatsEnabled
then exit
;
579 s
:= 'SOUND_GAME_RADIO';
582 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
584 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
585 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
589 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
591 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
592 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
596 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
598 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
599 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
603 if CheckCheat(I_GAME_CHEAT_DEATH
) then
605 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
606 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
607 s
:= 'SOUND_MONSTER_HAHA';
611 if CheckCheat(I_GAME_CHEAT_DOORS
) then
613 g_Triggers_OpenAll();
617 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
619 if gTriggers
<> nil then
620 for a
:= 0 to High(gTriggers
) do
621 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
623 gExitByTrigger
:= True;
624 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
625 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
631 s2
:= Copy(charbuff
, 15, 2);
632 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
634 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
642 if CheckCheat(I_GAME_CHEAT_FLY
) then
648 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
650 VEL_JUMP
:= 30-VEL_JUMP
;
654 if CheckCheat(I_GAME_CHEAT_SPEED
) then
656 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
660 if CheckCheat(I_GAME_CHEAT_SUIT
) then
662 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
663 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
667 if CheckCheat(I_GAME_CHEAT_AIR
) then
669 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
670 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
674 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
676 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
677 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
681 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
683 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
684 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
688 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
690 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
691 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
695 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
697 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
698 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
702 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
704 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
705 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
708 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
710 gAimLine
:= not gAimLine
;
713 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
715 gShowMap
:= not gShowMap
;
726 procedure KeyPress (K
: Word);
727 var Msg
: g_gui
.TMessage
;
732 if (g_ActiveWindow
<> nil) then
734 Msg
.Msg
:= WM_KEYDOWN
;
735 Msg
.WParam
:= VK_ESCAPE
;
736 g_ActiveWindow
.OnMessage(Msg
);
737 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
739 else if (gState
<> STATE_FOLD
) then
741 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
743 g_Game_InGameMenu(True);
745 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
747 if (gState
<> STATE_MENU
) then
749 if (NetMode
<> NET_NONE
) then
751 g_Game_StopAllSounds(True);
753 gState
:= STATE_MENU
;
757 g_GUI_ShowWindow('MainMenu');
758 g_Sound_PlayEx('MENU_OPEN');
763 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
764 begin // <F2> .. <F6> � <F12>
765 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
767 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
768 if (not g_Game_IsNet
) then g_Game_Pause(True);
770 IK_F2
: g_Menu_Show_SaveMenu();
771 IK_F3
: g_Menu_Show_LoadMenu();
772 IK_F4
: g_Menu_Show_GameSetGame();
773 IK_F5
: g_Menu_Show_OptionsVideo();
774 IK_F6
: g_Menu_Show_OptionsSound();
775 IK_F7
: g_Menu_Show_EndGameMenu();
776 IK_F10
: g_Menu_Show_QuitGameMenu();
783 gJustChatted
:= False;
784 if gConsoleShow
or gChatShow
then
786 g_Console_Control(K
);
788 else if (g_ActiveWindow
<> nil) then
790 Msg
.Msg
:= WM_KEYDOWN
;
792 g_ActiveWindow
.OnMessage(Msg
);
794 else if (gState
= STATE_MENU
) then
796 g_GUI_ShowWindow('MainMenu');
797 g_Sound_PlayEx('MENU_OPEN');
803 procedure KeyPress (K
: Word);
805 gJustChatted
:= False;
806 if gConsoleShow
or gChatShow
then
808 g_Console_Control(K
);
813 {$IFDEF ENABLE_SYSTEM}
814 procedure CharPress (C
: AnsiChar);
816 var Msg
: g_gui
.TMessage
;
820 if gConsoleShow
or gChatShow
then
825 else if g_ActiveWindow
<> nil then
828 Msg
.WParam
:= Ord(C
);
829 g_ActiveWindow
.OnMessage(Msg
);
836 charbuff
[a
] := charbuff
[a
+ 1];
838 charbuff
[15] := upcase1251(C
);
845 // ////////////////////////////////////////////////////////////////////////// //
846 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
848 procedure g_ResetDynlights ();
852 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
854 for idx
:= 0 to g_dynLightCount
-1 do
856 if g_dynLights
[idx
].exploCount
= -666 then
863 Inc(g_dynLights
[idx
].exploCount
);
864 if (g_dynLights
[idx
].exploCount
< 10) then
866 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
867 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
868 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
869 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
874 g_dynLightCount
:= lnum
;
877 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
879 if not gwin_has_stencil
then exit
;
880 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
881 g_dynLights
[g_dynLightCount
].x
:= x
;
882 g_dynLights
[g_dynLightCount
].y
:= y
;
883 g_dynLights
[g_dynLightCount
].radius
:= radius
;
884 g_dynLights
[g_dynLightCount
].r
:= r
;
885 g_dynLights
[g_dynLightCount
].g
:= g
;
886 g_dynLights
[g_dynLightCount
].b
:= b
;
887 g_dynLights
[g_dynLightCount
].a
:= a
;
888 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
889 Inc(g_dynLightCount
);
892 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
894 if not gwin_has_stencil
then exit
;
895 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
896 g_dynLights
[g_dynLightCount
].x
:= x
;
897 g_dynLights
[g_dynLightCount
].y
:= y
;
898 g_dynLights
[g_dynLightCount
].radius
:= 0;
899 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
900 g_dynLights
[g_dynLightCount
].r
:= r
;
901 g_dynLights
[g_dynLightCount
].g
:= g
;
902 g_dynLights
[g_dynLightCount
].b
:= b
;
903 g_dynLights
[g_dynLightCount
].a
:= 0;
904 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
905 Inc(g_dynLightCount
);
908 // ////////////////////////////////////////////////////////////////////////// //
909 function conIsCheatsEnabled (): Boolean; inline;
912 if g_Game_IsNet
then exit
;
913 if not gDebugMode
then
915 //if not gCheats then exit;
916 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
917 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
922 // ////////////////////////////////////////////////////////////////////////// //
924 TParamStrValue
= record
929 TParamStrValues
= Array of TParamStrValue
;
932 INTER_ACTION_TEXT
= 1;
933 INTER_ACTION_PIC
= 2;
934 INTER_ACTION_MUSIC
= 3;
939 DataLoaded
: Boolean = False;
941 MapList
: SSArray
= nil;
942 MapIndex
: Integer = -1;
943 InterReadyTime
: Integer = -1;
944 StatDate
: string = '';
959 function Compare(a
, b
: TPlayerStat
): Integer;
961 if a
.Spectator
then Result
:= 1
962 else if b
.Spectator
then Result
:= -1
963 else if a
.Frags
< b
.Frags
then Result
:= 1
964 else if a
.Frags
> b
.Frags
then Result
:= -1
965 else if a
.Deaths
< b
.Deaths
then Result
:= -1
966 else if a
.Deaths
> b
.Deaths
then Result
:= 1
967 else if a
.Kills
< b
.Kills
then Result
:= -1
971 procedure SortGameStat(var stat
: TPlayerStatArray
);
976 if stat
= nil then Exit
;
978 for I
:= High(stat
) downto Low(stat
) do
979 for J
:= Low(stat
) to High(stat
) - 1 do
980 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
983 stat
[J
] := stat
[J
+ 1];
988 // saves a shitty CSV containing the game stats passed to it
989 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
992 dir
, fname
, map
, mode
, etime
: String;
996 dir
:= e_GetWriteableDir(StatsDirs
);
997 // stats are placed in stats/yy/mm/dd/*.csv
998 fname
:= e_CatPath(dir
, Path
);
999 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
1000 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
1001 AssignFile(s
, fname
);
1003 SetTextCodePage(s
, CP_UTF8
);
1005 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
1006 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
1007 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
1008 mode
:= g_Game_ModeToText(Stat
.GameMode
);
1009 etime
:= Format('%d:%.2d:%.2d', [
1010 Stat
.GameTime
div 1000 div 3600,
1011 (Stat
.GameTime
div 1000 div 60) mod 60,
1012 Stat
.GameTime
div 1000 mod 60
1014 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
1015 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
1021 gGameSettings
.TimeLimit
,
1022 gGameSettings
.ScoreLimit
,
1023 gGameSettings
.Options
,
1025 Length(Stat
.PlayerStat
)
1027 // line 2: game specific shit
1028 // if it's a team game: red score, blue score
1029 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1030 // otherwise nothing
1031 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1033 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
1034 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1036 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1037 // lines 3-...: team, player name, frags, deaths
1038 WriteLn(s
, 'team,name,frags,deaths');
1039 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1040 with Stat
.PlayerStat
[I
] do
1041 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1043 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1046 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1051 procedure ClearDebugCvars();
1053 g_debug_Sounds
:= False;
1054 g_debug_Frames
:= False;
1055 g_debug_WinMsgs
:= False;
1056 g_debug_MonsterOff
:= False;
1057 g_debug_BotAIOff
:= 0;
1058 g_debug_HealthBar
:= False;
1059 g_Debug_Player
:= False;
1062 function g_Game_ModeToText(Mode
: Byte): string;
1066 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1067 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1068 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1069 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1070 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1074 function g_Game_TextToMode(Mode
: string): Byte;
1077 Mode
:= UpperCase(Mode
);
1078 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1083 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1088 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1093 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1098 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1100 Result
:= GM_SINGLE
;
1105 function g_Game_IsNet(): Boolean;
1107 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1110 function g_Game_IsServer(): Boolean;
1112 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1115 function g_Game_IsClient(): Boolean;
1117 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1120 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1127 Result
.name
:= ExtractFileName(WAD
);
1128 Result
.description
:= '';
1129 Result
.author
:= '';
1131 w
:= TWADFile
.Create();
1134 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1140 cfg
:= TConfig
.CreateMem(p
, len
);
1141 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1142 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1143 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1144 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1150 procedure g_Game_FreeWAD
;
1153 g_Sound_Delete('MUSIC_endmus');
1154 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1155 gGameSettings
.WAD
:= '';
1158 procedure g_Game_LoadWAD(WAD
: string);
1167 gGameSettings
.WAD
:= WAD
;
1168 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1171 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1173 w
:= TWADFile
.Create();
1176 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1182 cfg
:= TConfig
.CreateMem(p
, len
);
1185 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1186 if MegaWAD
.endpic
<> '' then
1187 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1189 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1190 if MegaWAD
.endmus
<> '' then
1192 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1193 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1201 {procedure start_trigger(t: string);
1205 function next_trigger(): Boolean;
1209 procedure DisableCheats();
1215 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1216 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1217 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1218 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1220 {$IF DEFINED(D2F_DEBUG)}
1221 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1222 gAimLine
:= g_dbg_aimline_on
;
1226 procedure g_Game_ExecuteEvent(Name
: String);
1232 if gEvents
= nil then
1234 for a
:= 0 to High(gEvents
) do
1235 if gEvents
[a
].Name
= Name
then
1237 if gEvents
[a
].Command
<> '' then
1238 g_Console_Process(gEvents
[a
].Command
, True);
1243 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1248 if gDelayedEvents
<> nil then
1249 for a
:= 0 to High(gDelayedEvents
) do
1250 if not gDelayedEvents
[a
].Pending
then
1257 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1258 n
:= High(gDelayedEvents
);
1260 gDelayedEvents
[n
].Pending
:= True;
1261 gDelayedEvents
[n
].DEType
:= DEType
;
1262 gDelayedEvents
[n
].DENum
:= Num
;
1263 gDelayedEvents
[n
].DEStr
:= Str
;
1264 if DEType
= DE_GLOBEVENT
then
1265 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1267 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1271 procedure EndGame();
1277 if g_Game_IsNet
and g_Game_IsServer
then
1278 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1281 gPauseMain
:= false;
1282 gPauseHolmes
:= false;
1285 g_Game_StopAllSounds(False);
1290 EndingGameCounter
:= 0;
1292 {$IFDEF ENABLE_MENU}
1293 g_ActiveWindow
:= nil;
1296 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1297 gLMSRespawnTime
:= 0;
1300 EXIT_SIMPLE
: // Выход через меню или конец теста
1304 begin // Это был тест
1308 begin // Выход в главное меню
1309 {$IFDEF DISABLE_MENU}
1310 gState
:= STATE_MENU
; // ???
1312 gMusic
.SetByName('MUSIC_MENU');
1314 if gState
<> STATE_SLIST
then
1316 g_GUI_ShowWindow('MainMenu');
1317 gState
:= STATE_MENU
;
1321 // Обновляем список серверов
1322 slReturnPressed
:= True;
1323 if g_Net_Slist_Fetch(slCurrent
) then
1325 if slCurrent
= nil then
1326 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1329 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1330 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1333 g_Game_ExecuteEvent('ongameend');
1337 EXIT_RESTART
: // Начать уровень сначала
1339 if not g_Game_IsClient
then g_Game_Restart();
1342 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1344 // Статистика Своей игры:
1345 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1347 CustomStat
.GameTime
:= gTime
;
1348 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1349 CustomStat
.MapName
:= gMapInfo
.Name
;
1350 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1351 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1352 CustomStat
.TeamStat
:= gTeamStat
;
1354 CustomStat
.PlayerStat
:= nil;
1356 // Статистика игроков:
1357 if gPlayers
<> nil then
1359 for a
:= 0 to High(gPlayers
) do
1360 if gPlayers
[a
] <> nil then
1362 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1363 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1366 Name
:= gPlayers
[a
].Name
;
1367 Frags
:= gPlayers
[a
].Frags
;
1368 Deaths
:= gPlayers
[a
].Death
;
1369 Kills
:= gPlayers
[a
].Kills
;
1370 Team
:= gPlayers
[a
].Team
;
1371 Color
:= gPlayers
[a
].Model
.Color
;
1372 Spectator
:= gPlayers
[a
].FSpectator
;
1376 SortGameStat(CustomStat
.PlayerStat
);
1378 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1381 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1382 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1383 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1384 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1386 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1389 StatShotDone
:= False;
1392 g_Game_ExecuteEvent('onmapend');
1393 if not g_Game_IsClient
then g_Player_ResetReady
;
1394 gInterReadyCount
:= 0;
1396 // Затухающий экран:
1397 EndingGameCounter
:= 255;
1398 gState
:= STATE_FOLD
;
1400 if gDefInterTime
< 0 then
1401 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1403 gInterEndTime
:= gDefInterTime
* 1000;
1406 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1408 // Статистика Одиночной игры:
1409 SingleStat
.GameTime
:= gTime
;
1410 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1411 SingleStat
.TotalSecrets
:= gSecretsCount
;
1412 // Статистика первого игрока:
1413 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1414 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1415 // Статистика второго игрока (если есть):
1416 if SingleStat
.TwoPlayers
then
1418 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1419 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1422 g_Game_ExecuteEvent('onmapend');
1425 if gNextMap
<> '' then
1427 gMusic
.SetByName('MUSIC_INTERMUS');
1429 gState
:= STATE_INTERSINGLE
;
1432 g_Game_ExecuteEvent('oninter');
1434 else // Больше нет карт
1436 // Затухающий экран:
1437 EndingGameCounter
:= 255;
1438 gState
:= STATE_FOLD
;
1443 // Окончание обработано:
1444 if gExit
<> EXIT_QUIT
then
1448 procedure g_Game_Init();
1452 gTempDelete
:= False;
1454 sfsGCDisable(); // temporary disable removing of temporary volumes
1457 g_Game_ClearLoading();
1458 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1459 g_Game_SetLoadingText('', 0, False);
1461 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1464 gPauseMain
:= false;
1465 gPauseHolmes
:= false;
1468 {e_MouseInfo.Accel := 1.0;}
1470 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1473 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1474 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1475 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1476 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1477 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1479 gMusic
:= TMusic
.Create();
1480 gMusic
.SetByName('MUSIC_MENU');
1483 gGameSettings
.WarmupTime
:= 30;
1485 gState
:= STATE_MENU
;
1487 SetLength(gEvents
, 6);
1488 gEvents
[0].Name
:= 'ongamestart';
1489 gEvents
[1].Name
:= 'ongameend';
1490 gEvents
[2].Name
:= 'onmapstart';
1491 gEvents
[3].Name
:= 'onmapend';
1492 gEvents
[4].Name
:= 'oninter';
1493 gEvents
[5].Name
:= 'onwadend';
1495 sfsGCEnable(); // enable releasing unused volumes
1499 procedure g_Game_Free(freeTextures
: Boolean=true);
1501 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1502 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1504 g_Map_Free(freeTextures
);
1507 {$IFDEF ENABLE_GIBS}
1510 {$IFDEF ENALBE_SHELLS}
1513 {$IFDEF ENABLE_CORPSES}
1514 g_Corpses_RemoveAll
;
1517 gGameSettings
.GameType
:= GT_NONE
;
1518 if gGameSettings
.GameMode
= GM_SINGLE
then
1519 gGameSettings
.GameMode
:= GM_DM
;
1520 gSwitchGameMode
:= gGameSettings
.GameMode
;
1523 gExitByTrigger
:= False;
1526 function IsActivePlayer(p
: TPlayer
): Boolean;
1531 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1534 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1540 if gPlayers
= nil then
1544 for a
:= Low(gPlayers
) to High(gPlayers
) do
1545 if IsActivePlayer(gPlayers
[a
]) then
1547 SetLength(ids
, Length(ids
) + 1);
1548 ids
[High(ids
)] := gPlayers
[a
].UID
;
1549 if gPlayers
[a
].UID
= Skip
then
1552 if Length(ids
) = 0 then
1557 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1560 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1566 if gPlayers
= nil then
1570 for a
:= Low(gPlayers
) to High(gPlayers
) do
1571 if IsActivePlayer(gPlayers
[a
]) then
1573 SetLength(ids
, Length(ids
) + 1);
1574 ids
[High(ids
)] := gPlayers
[a
].UID
;
1575 if gPlayers
[a
].UID
= Skip
then
1578 if Length(ids
) = 0 then
1581 Result
:= ids
[Length(ids
) - 1]
1583 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1586 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1592 if gPlayers
= nil then
1596 for a
:= Low(gPlayers
) to High(gPlayers
) do
1597 if IsActivePlayer(gPlayers
[a
]) then
1599 SetLength(ids
, Length(ids
) + 1);
1600 ids
[High(ids
)] := gPlayers
[a
].UID
;
1601 if gPlayers
[a
].UID
= Skip
then
1604 if Length(ids
) = 0 then
1606 if Length(ids
) = 1 then
1611 Result
:= ids
[Random(Length(ids
))];
1613 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1615 Result
:= ids
[Random(Length(ids
))];
1620 function GetRandomSpectMode(Current
: Byte): Byte;
1627 0: Result
:= SPECT_STATS
;
1628 1: Result
:= SPECT_MAPVIEW
;
1629 2: Result
:= SPECT_MAPVIEW
;
1630 3: Result
:= SPECT_PLAYERS
;
1631 4: Result
:= SPECT_PLAYERS
;
1632 5: Result
:= SPECT_PLAYERS
;
1633 6: Result
:= SPECT_PLAYERS
;
1635 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1639 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1645 if (plr
= nil) then exit
;
1646 if (p
= 2) then time
:= 1000 else time
:= 1;
1647 strafeDir
:= MoveButton
shr 4;
1648 MoveButton
:= MoveButton
and $0F;
1650 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1651 MoveButton
:= 1 // Нажата только "Влево"
1652 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1653 MoveButton
:= 2 // Нажата только "Вправо"
1654 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1655 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1657 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1658 if MoveButton
= 1 then
1659 plr
.PressKey(KEY_LEFT
, time
)
1660 else if MoveButton
= 2 then
1661 plr
.PressKey(KEY_RIGHT
, time
);
1663 // if we have "strafe" key, turn off old strafe mechanics
1664 if gPlayerAction
[p
, ACTION_STRAFE
] then
1666 // new strafe mechanics
1667 if (strafeDir
= 0) then
1668 strafeDir
:= MoveButton
; // start strafing
1669 // now set direction according to strafe (reversed)
1670 if (strafeDir
= 2) then
1671 plr
.SetDirection(TDirection
.D_LEFT
)
1672 else if (strafeDir
= 1) then
1673 plr
.SetDirection(TDirection
.D_RIGHT
)
1677 strafeDir
:= 0; // not strafing anymore
1678 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1679 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1680 plr
.SetDirection(TDirection
.D_LEFT
)
1681 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1682 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1683 plr
.SetDirection(TDirection
.D_RIGHT
)
1684 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1685 else if MoveButton
<> 0 then
1686 plr
.SetDirection(TDirection(MoveButton
-1))
1689 // fix movebutton state
1690 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1692 // Остальные клавиши:
1693 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1694 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1695 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1696 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1697 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1699 for i
:= WP_FACT
to WP_LACT
do
1701 if gWeaponAction
[p
, i
] then
1703 plr
.ProcessWeaponAction(i
);
1704 gWeaponAction
[p
, i
] := False
1708 for i
:= WP_FIRST
to WP_LAST
do
1710 if gSelectWeapon
[p
, i
] then
1712 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1713 gSelectWeapon
[p
, i
] := False
1717 {$IFDEF ENABLE_MENU}
1718 // HACK: add dynlight here
1719 if gwin_k8_enable_light_experiments
then
1721 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1723 g_playerLight
:= true;
1725 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1727 g_playerLight
:= false;
1731 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1735 // HACK: don't have a "key was pressed" function
1736 procedure InterReady();
1738 if InterReadyTime
> gTime
then Exit
;
1739 InterReadyTime
:= gTime
+ 3000;
1740 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1743 procedure g_Game_PreUpdate();
1745 // these are in separate PreUpdate functions because they can interact during Update()
1746 // and are synced over the net
1747 // we don't care that much about corpses and gibs
1748 g_Player_PreUpdate();
1749 g_Monsters_PreUpdate();
1750 g_Items_PreUpdate();
1751 g_Weapon_PreUpdate();
1754 procedure g_Game_SetupHearPoints
;
1755 var p1
, p2
: TPlayer
; a
, b
: Integer;
1759 gHearPoint1
.Active
:= false;
1760 gHearPoint2
.Active
:= false;
1761 if gSpectMode
= SPECT_MAPVIEW
then
1763 // TODO something better (render dependency)
1764 gHearPoint1
.Active
:= true;
1765 gHearPoint1
.Coords
.X
:= gSpectX
+ gScreenWidth
div 2;
1766 gHearPoint1
.Coords
.Y
:= gSpectY
+ gScreenHeight
div 2;
1768 else if gSpectMode
= SPECT_PLAYERS
then
1770 p1
:= g_Player_Get(gSpectPID1
);
1771 if gSpectViewTwo
then
1772 p2
:= g_Player_Get(gSpectPID2
);
1774 else if gSpectMode
= SPECT_NONE
then
1781 gHearPoint1
.Active
:= true;
1782 gHearPoint1
.Coords
.X
:= p1
.obj
.x
+ p1
.obj
.rect
.width
div 2;
1783 gHearPoint1
.Coords
.Y
:= p1
.obj
.y
+ p1
.obj
.rect
.height
div 2;
1785 if (p2
<> nil) and (p1
<> p2
) then
1787 gHearPoint2
.Active
:= true;
1788 gHearPoint2
.Coords
.X
:= p2
.obj
.x
+ p2
.obj
.rect
.width
div 2;
1789 gHearPoint2
.Coords
.Y
:= p2
.obj
.y
+ p2
.obj
.rect
.height
div 2;
1791 // TODO something better (render dependency)
1792 if (p1
<> nil) and (p2
<> nil) then
1794 gPlayerScreenSize
.X
:= gScreenWidth
- 196;
1795 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
1799 gPlayerScreenSize
.X
:= gScreenWidth
- 196;
1800 gPlayerScreenSize
.Y
:= gScreenHeight
;
1803 if gMapInfo
.Height
> gPlayerScreenSize
.Y
then a
:= gMapInfo
.Height
- gPlayerScreenSize
.Y
else a
:= gMapInfo
.Height
;
1804 if gMapInfo
.Width
> gPlayerScreenSize
.X
then b
:= gMapInfo
.Width
- gPlayerScreenSize
.X
else b
:= gMapInfo
.Width
;
1805 gMaxDist
:= Trunc(Hypot(a
, b
));
1808 procedure g_Game_Update();
1810 {$IFDEF ENABLE_MENU}
1811 Msg
: g_gui
.TMessage
;
1818 function sendMonsPos (mon
: TMonster
): Boolean;
1820 result
:= false; // don't stop
1821 // this will also reset "need-send" flag
1822 if mon
.gncNeedSend
then
1824 MH_SEND_MonsterPos(mon
.UID
);
1826 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1828 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1830 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1832 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1836 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1838 result
:= false; // don't stop
1839 // this will also reset "need-send" flag
1840 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1843 function sendItemPos (it
: PItem
): Boolean;
1845 result
:= false; // don't stop
1848 MH_SEND_ItemPos(it
.myId
);
1849 it
.needSend
:= False;
1854 reliableUpdate
: Boolean;
1859 // Пора выключать игру:
1860 if gExit
= EXIT_QUIT
then
1862 // Игра закончилась - обрабатываем:
1866 if gExit
= EXIT_QUIT
then
1870 // Читаем клавиатуру и джойстик, если окно активно
1871 // no need to, as we'll do it in event handler
1873 // Обновляем консоль (движение и сообщения):
1876 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1878 gExit
:= EXIT_SIMPLE
;
1883 // process master server communications
1884 g_Net_Slist_Pulse();
1887 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1888 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1889 STATE_INTERTEXT
, // Текст между уровнями
1890 STATE_INTERPIC
: // Картинка между уровнями
1892 if g_Game_IsNet
and g_Game_IsServer
then
1894 gInterTime
:= gInterTime
+ GAME_TICK
;
1895 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1896 if a
<> gServInterTime
then
1898 gServInterTime
:= a
;
1899 MH_SEND_TimeSync(gServInterTime
);
1903 if (not g_Game_IsClient
) and
1907 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1908 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1909 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1910 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1912 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1913 {$IFDEF ENABLE_MENU}
1914 and (g_ActiveWindow
= nil)
1917 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1920 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1921 g_Game_StopAllSounds(True);
1923 if gMapOnce
then // Это был тест
1924 gExit
:= EXIT_SIMPLE
1926 if gNextMap
<> '' then // Переходим на следующую карту
1927 g_Game_ChangeMap(gNextMap
)
1928 else // Следующей карты нет
1930 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1932 // Выход в главное меню:
1934 {$IFDEF ENABLE_MENU}
1935 g_GUI_ShowWindow('MainMenu');
1936 gMusic
.SetByName('MUSIC_MENU');
1939 gState
:= STATE_MENU
;
1942 // Финальная картинка:
1943 g_Game_ExecuteEvent('onwadend');
1945 if not gMusic
.SetByName('MUSIC_endmus') then
1946 gMusic
.SetByName('MUSIC_STDENDMUS');
1948 gState
:= STATE_ENDPIC
;
1950 g_Game_ExecuteEvent('ongameend');
1955 else if g_Game_IsClient
and
1958 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1959 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1960 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1961 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1963 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1964 {$IFDEF ENABLE_MENU}
1965 and (g_ActiveWindow
= nil)
1974 if gState
= STATE_INTERTEXT
then
1975 if InterText
.counter
> 0 then
1976 InterText
.counter
:= InterText
.counter
- 1;
1979 STATE_FOLD
: // Затухание экрана
1981 if EndingGameCounter
= 0 then
1983 // Закончился уровень в Своей игре:
1984 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1986 gState
:= STATE_INTERCUSTOM
;
1987 InterReadyTime
:= -1;
1988 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1990 g_Game_ExecuteEvent('onwadend');
1991 if not gMusic
.SetByName('MUSIC_endmus') then
1992 gMusic
.SetByName('MUSIC_STDENDMUS');
1995 gMusic
.SetByName('MUSIC_ROUNDMUS');
1999 else // Закончилась последняя карта в Одиночной игре
2001 gMusic
.SetByName('MUSIC_INTERMUS');
2003 gState
:= STATE_INTERSINGLE
;
2006 g_Game_ExecuteEvent('oninter');
2009 DecMin(EndingGameCounter
, 6, 0);
2012 STATE_ENDPIC
: // Картинка окончания мегаВада
2014 if gMapOnce
then // Это был тест
2016 gExit
:= EXIT_SIMPLE
;
2022 g_Serverlist_Control(slCurrent
, slTable
);
2025 // Статистика по Tab:
2028 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
2032 if g_Console_Action(ACTION_SCORES
) then
2034 if not gStatsPressed
then
2036 gStatsOff
:= not gStatsOff
;
2037 gStatsPressed
:= True;
2041 gStatsPressed
:= False;
2045 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
2047 // Время += 28 миллисекунд:
2048 gTime
:= gTime
+ GAME_TICK
;
2050 // Сообщение посередине экрана:
2051 if MessageTime
= 0 then
2053 if MessageTime
> 0 then
2054 MessageTime
:= MessageTime
- 1;
2056 if (g_Game_IsServer
) then
2058 // Был задан лимит времени:
2059 if (gGameSettings
.TimeLimit
> 0) then
2060 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
2061 begin // Он прошел => конец уровня
2066 // Надо респавнить игроков в LMS:
2067 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
2068 g_Game_RestartRound(gLMSSoftSpawn
);
2070 // Проверим результат голосования, если время прошло
2071 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2073 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2075 g_Console_Process(gVoteCommand
);
2077 gVotePassed
:= False;
2080 // Замеряем время захвата флагов
2081 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2082 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2083 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2084 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2086 // Был задан лимит побед:
2087 if (gGameSettings
.ScoreLimit
> 0) then
2091 if gGameSettings
.GameMode
= GM_DM
then
2092 begin // В DM ищем игрока с max фрагами
2093 for i
:= 0 to High(gPlayers
) do
2094 if gPlayers
[i
] <> nil then
2095 if gPlayers
[i
].Frags
> b
then
2096 b
:= gPlayers
[i
].Frags
;
2099 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2100 begin // В CTF/TDM выбираем команду с наибольшим счетом
2101 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2104 // Лимит побед набран => конец уровня:
2105 if b
>= gGameSettings
.ScoreLimit
then
2112 // Обрабатываем клавиши игроков:
2113 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2114 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2115 {$IFDEF DISABLE_MENU}
2116 if (not gConsoleShow
) and (not gChatShow
) then
2118 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2121 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2122 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2123 end // if not console
2126 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2128 // process weapon switch queue
2132 if (gPlayer1
= nil) and (gPlayer2
= nil)
2133 and (not gConsoleShow
) and (not gChatShow
)
2134 {$IFDEF ENABLE_MENU}
2135 and (g_ActiveWindow
= nil)
2139 if not gSpectKeyPress
then
2141 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2143 // switch spect mode
2145 SPECT_NONE
: ; // not spectator
2147 SPECT_MAPVIEW
: Inc(gSpectMode
);
2148 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2150 gSpectKeyPress
:= True;
2152 if (gSpectMode
= SPECT_MAPVIEW
)
2153 and (not gSpectAuto
) then
2155 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2156 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2157 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2158 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2159 if gPlayerAction
[0, ACTION_LOOKUP
] then
2160 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2161 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2162 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2163 if gWeaponAction
[0, WP_PREV
] then
2166 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2167 gWeaponAction
[0, WP_PREV
] := False;
2169 if gWeaponAction
[0, WP_NEXT
] then
2172 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2173 gWeaponAction
[0, WP_NEXT
] := False;
2176 if (gSpectMode
= SPECT_PLAYERS
)
2177 and (not gSpectAuto
) then
2179 if gPlayerAction
[0, ACTION_LOOKUP
] then
2182 gSpectViewTwo
:= True;
2183 gSpectKeyPress
:= True;
2185 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2187 // remove second view
2188 gSpectViewTwo
:= False;
2189 gSpectKeyPress
:= True;
2191 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2193 // prev player (view 1)
2194 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2195 gSpectKeyPress
:= True;
2197 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2199 // next player (view 1)
2200 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2201 gSpectKeyPress
:= True;
2203 if gWeaponAction
[0, WP_PREV
] then
2205 // prev player (view 2)
2206 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2207 gWeaponAction
[0, WP_PREV
] := False;
2209 if gWeaponAction
[0, WP_NEXT
] then
2211 // next player (view 2)
2212 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2213 gWeaponAction
[0, WP_NEXT
] := False;
2216 if gPlayerAction
[0, ACTION_ATTACK
] then
2218 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2221 gSpectAutoNext
:= 0;
2222 gSpectViewTwo
:= False;
2223 gSpectKeyPress
:= True;
2228 gSpectMode
:= SPECT_STATS
;
2229 gSpectAuto
:= False;
2230 gSpectKeyPress
:= True;
2235 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2236 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2237 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2238 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2239 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2240 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2241 gSpectKeyPress
:= False;
2245 if gSpectMode
= SPECT_MAPVIEW
then
2247 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2249 gSpectAutoNext
:= gTime
2252 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2254 gSpectAutoNext
:= gTime
2258 if gSpectAutoNext
<= gTime
then
2260 if gSpectAutoNext
> 0 then
2262 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2266 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2267 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2268 gSpectAutoStepX
:= Random(9) - 4;
2269 gSpectAutoStepY
:= Random(9) - 4;
2270 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2271 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2272 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2273 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2274 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2275 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2279 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2284 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2285 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2286 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2292 (* spectator state check from render *)
2294 if (gPlayer1
= nil) and (gPlayer2
= nil) and (gSpectMode
= SPECT_NONE
) then
2295 gSpectMode
:= SPECT_STATS
;
2297 if IsActivePlayer(g_Player_Get(gSpectPID1
)) = false then
2298 gSpectPID1
:= GetActivePlayerID_Next();
2300 if IsActivePlayer(g_Player_Get(gSpectPID2
)) = false then
2301 gSpectPID2
:= GetActivePlayerID_Next();
2303 g_Game_SetupHearPoints
;
2305 // Обновляем все остальное:
2308 g_Triggers_Update();
2310 g_Monsters_Update();
2314 g_Player_UpdateAll();
2315 {$IFDEF ENABLE_GIBS}
2318 {$IFDEF ENABLE_CORPSES}
2321 {$IFDEF ENABLE_SHELLS}
2325 // server: send newly spawned monsters unconditionally
2326 if (gGameSettings
.GameType
= GT_SERVER
) then
2328 if (Length(gMonstersSpawned
) > 0) then
2330 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2331 SetLength(gMonstersSpawned
, 0);
2335 if (gSoundTriggerTime
> 8) then
2337 g_Game_UpdateTriggerSounds();
2338 gSoundTriggerTime
:= 0;
2342 Inc(gSoundTriggerTime
);
2345 if (NetMode
= NET_SERVER
) then
2347 Inc(NetTimeToUpdate
);
2348 Inc(NetTimeToReliable
);
2350 // send monster updates
2351 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2353 // send all monsters (periodic sync)
2354 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2356 for I
:= 0 to High(gPlayers
) do
2358 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2361 g_Mons_ForEach(sendMonsPos
);
2363 // update flags that aren't stationary
2364 if gGameSettings
.GameMode
= GM_CTF
then
2365 for I
:= FLAG_RED
to FLAG_BLUE
do
2366 if gFlags
[I
].NeedSend
then
2368 gFlags
[I
].NeedSend
:= False;
2372 // update items that aren't stationary
2373 g_Items_ForEachAlive(sendItemPos
);
2375 if reliableUpdate
then
2377 NetTimeToReliable
:= 0;
2378 NetTimeToUpdate
:= NetUpdateRate
;
2382 NetTimeToUpdate
:= 0;
2387 // send only mosters with some unexpected changes
2388 g_Mons_ForEach(sendMonsPosUnexpected
);
2391 // send unexpected platform changes
2392 g_Map_NetSendInterestingPanels();
2394 g_Net_Slist_ServerUpdate();
2396 if NetUseMaster then
2398 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2400 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2402 NetTimeToMaster := gTime + NetMasterRate;
2407 else if (NetMode
= NET_CLIENT
) then
2409 MC_SEND_PlayerPos();
2411 end; // if gameOn ...
2413 // Активно окно интерфейса - передаем клавиши ему:
2414 {$IFDEF ENABLE_MENU}
2415 if g_ActiveWindow
<> nil then
2417 w
:= e_GetFirstKeyPressed();
2419 if (w
<> IK_INVALID
) then
2421 Msg
.Msg
:= MESSAGE_DIKEY
;
2423 g_ActiveWindow
.OnMessage(Msg
);
2426 // Если оно от этого не закрылось, то обновляем:
2427 if g_ActiveWindow
<> nil then
2428 g_ActiveWindow
.Update();
2430 // Нужно сменить разрешение:
2431 if gResolutionChange
then
2433 {$IFDEF ENABLE_RENDER}
2434 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2437 gResolutionChange
:= False;
2438 g_ActiveWindow
:= nil;
2441 // Нужно сменить язык:
2442 if gLanguageChange
then
2444 //e_WriteLog('Read language file', MSG_NOTIFY);
2445 //g_Language_Load(DataDir + gLanguage + '.txt');
2446 g_Language_Set(gLanguage
);
2448 gLanguageChange
:= False;
2452 // Горячая клавиша для вызова меню выхода из игры (F10):
2453 if e_KeyPressed(IK_F10
) and
2455 (not gConsoleShow
) and
2456 (g_ActiveWindow
= nil) then
2462 Time
:= GetTickCount64() {div 1000};
2464 // Обработка отложенных событий:
2465 if gDelayedEvents
<> nil then
2466 for a
:= 0 to High(gDelayedEvents
) do
2467 if gDelayedEvents
[a
].Pending
and
2469 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2470 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2473 case gDelayedEvents
[a
].DEType
of
2475 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2478 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2482 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2483 if g_Game_IsNet
and g_Game_IsServer
then
2484 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2488 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2490 gDelayedEvents
[a
].Pending
:= False;
2493 // Каждую секунду обновляем счетчик обновлений:
2494 UPSCounter
:= UPSCounter
+ 1;
2495 if Time
- UPSTime
>= 1000 then
2504 g_Weapon_AddDynLights();
2505 g_Items_AddDynLights();
2509 procedure g_Game_LoadChatSounds(Resource
: string);
2512 FileName
, Snd
: string;
2514 len
, cnt
, tags
, i
, j
: Integer;
2517 FileName
:= g_ExtractWadName(Resource
);
2519 WAD
:= TWADFile
.Create();
2520 WAD
.ReadFile(FileName
);
2522 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2529 cfg
:= TConfig
.CreateMem(p
, len
);
2530 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2532 SetLength(gChatSounds
, cnt
);
2533 for i
:= 0 to Length(gChatSounds
) - 1 do
2535 gChatSounds
[i
].Sound
:= nil;
2536 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2537 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2538 if (Snd
= '') or (Tags
<= 0) then
2540 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2541 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2542 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2543 SetLength(gChatSounds
[i
].Tags
, tags
);
2544 for j
:= 0 to tags
- 1 do
2545 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2546 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2553 procedure g_Game_FreeChatSounds();
2557 for i
:= 0 to Length(gChatSounds
) - 1 do
2559 gChatSounds
[i
].Sound
.Free();
2560 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2562 SetLength(gChatSounds
, 0);
2566 procedure g_Game_LoadData();
2568 if DataLoaded
then Exit
;
2570 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2572 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2573 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2574 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2575 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2576 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2577 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2578 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2579 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2580 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2581 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2582 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2583 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2584 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2585 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2586 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2587 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2588 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2589 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2590 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2591 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2592 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2593 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2594 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2595 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2596 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2597 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2598 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2599 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2600 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2601 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2602 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2603 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2605 goodsnd
[0] := TPlayableSound
.Create();
2606 goodsnd
[1] := TPlayableSound
.Create();
2607 goodsnd
[2] := TPlayableSound
.Create();
2608 goodsnd
[3] := TPlayableSound
.Create();
2610 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2611 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2612 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2613 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2615 killsnd
[0] := TPlayableSound
.Create();
2616 killsnd
[1] := TPlayableSound
.Create();
2617 killsnd
[2] := TPlayableSound
.Create();
2618 killsnd
[3] := TPlayableSound
.Create();
2620 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2621 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2622 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2623 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2625 hahasnd
[0] := TPlayableSound
.Create();
2626 hahasnd
[1] := TPlayableSound
.Create();
2627 hahasnd
[2] := TPlayableSound
.Create();
2629 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2630 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2631 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2633 sound_get_flag
[0] := TPlayableSound
.Create();
2634 sound_get_flag
[1] := TPlayableSound
.Create();
2635 sound_lost_flag
[0] := TPlayableSound
.Create();
2636 sound_lost_flag
[1] := TPlayableSound
.Create();
2637 sound_ret_flag
[0] := TPlayableSound
.Create();
2638 sound_ret_flag
[1] := TPlayableSound
.Create();
2639 sound_cap_flag
[0] := TPlayableSound
.Create();
2640 sound_cap_flag
[1] := TPlayableSound
.Create();
2642 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2643 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2644 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2645 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2646 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2647 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2648 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2649 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2651 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2653 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2656 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2657 g_Weapon_LoadData();
2659 g_Monsters_LoadData();
2664 procedure g_Game_Quit();
2666 g_Game_StopAllSounds(True);
2669 g_PlayerModel_FreeData();
2670 {$IFDEF ENABLE_MENU}
2671 // g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2674 if NetInitDone
then g_Net_Free
;
2676 // remove map after test
2677 if gMapToDelete
<> '' then
2678 g_Game_DeleteTestMap();
2682 {$IFDEF ENABLE_SYSTEM}
2687 procedure g_Game_FreeData();
2689 if not DataLoaded
then Exit
;
2692 g_Weapon_FreeData();
2693 g_Monsters_FreeData();
2695 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2697 g_Sound_Delete('SOUND_GAME_TELEPORT');
2698 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2699 g_Sound_Delete('SOUND_GAME_SECRET');
2700 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2701 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2702 g_Sound_Delete('SOUND_GAME_BULK1');
2703 g_Sound_Delete('SOUND_GAME_BULK2');
2704 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2705 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2706 g_Sound_Delete('SOUND_GAME_BURNING');
2707 g_Sound_Delete('SOUND_GAME_SWITCH1');
2708 g_Sound_Delete('SOUND_GAME_SWITCH0');
2715 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2716 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2717 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2718 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2725 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2726 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2727 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2728 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2734 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2735 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2736 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2738 sound_get_flag
[0].Free();
2739 sound_get_flag
[1].Free();
2740 sound_lost_flag
[0].Free();
2741 sound_lost_flag
[1].Free();
2742 sound_ret_flag
[0].Free();
2743 sound_ret_flag
[1].Free();
2744 sound_cap_flag
[0].Free();
2745 sound_cap_flag
[1].Free();
2747 g_Sound_Delete('SOUND_CTF_GET1');
2748 g_Sound_Delete('SOUND_CTF_GET2');
2749 g_Sound_Delete('SOUND_CTF_LOST1');
2750 g_Sound_Delete('SOUND_CTF_LOST2');
2751 g_Sound_Delete('SOUND_CTF_RETURN1');
2752 g_Sound_Delete('SOUND_CTF_RETURN2');
2753 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2754 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2756 g_Game_FreeChatSounds();
2758 DataLoaded
:= False;
2761 procedure g_FatalError(Text: String);
2763 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2764 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2766 gExit
:= EXIT_SIMPLE
;
2767 if gGameOn
then EndGame
;
2770 procedure g_SimpleError(Text: String);
2772 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2773 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2776 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2778 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2779 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2782 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2785 if gPlayer1
= nil then
2787 if g_Game_IsClient
then
2789 if NetPlrUID1
> -1 then
2790 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2794 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2795 Team
:= gPlayer1Settings
.Team
;
2797 // Создание первого игрока:
2798 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2799 gPlayer1Settings
.Color
,
2801 if gPlayer1
= nil then
2802 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2805 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2806 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2807 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2808 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2809 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2810 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2811 if g_Game_IsServer
and g_Game_IsNet
then
2812 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2813 gPlayer1
.Respawn(False, True);
2814 g_Net_Slist_ServerPlayerComes();
2819 if gPlayer2
= nil then
2821 if g_Game_IsClient
then
2823 if NetPlrUID2
> -1 then
2824 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2828 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2829 Team
:= gPlayer2Settings
.Team
;
2831 // Создание второго игрока:
2832 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2833 gPlayer2Settings
.Color
,
2835 if gPlayer2
= nil then
2836 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2839 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2840 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2841 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2842 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2843 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2844 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2845 if g_Game_IsServer
and g_Game_IsNet
then
2846 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2847 gPlayer2
.Respawn(False, True);
2848 g_Net_Slist_ServerPlayerComes();
2855 procedure g_Game_RemovePlayer();
2859 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2860 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2865 if g_Game_IsServer
then
2868 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2869 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2870 g_Player_Remove(Pl
.UID
);
2871 g_Net_Slist_ServerPlayerLeaves();
2875 gSpectLatchPID2
:= Pl
.UID
;
2883 if g_Game_IsServer
then
2886 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2887 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2888 g_Player_Remove(Pl
.UID
);
2889 g_Net_Slist_ServerPlayerLeaves();
2892 gSpectLatchPID1
:= Pl
.UID
;
2894 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2898 g_Net_Slist_ServerPlayerLeaves();
2901 procedure g_Game_Spectate();
2903 g_Game_RemovePlayer();
2904 if gPlayer1
<> nil then
2905 g_Game_RemovePlayer();
2908 procedure g_Game_SpectateCenterView();
2910 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2911 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2914 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2921 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2923 g_Game_ClearLoading();
2926 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2929 gGameSettings
.GameType
:= GT_SINGLE
;
2930 gGameSettings
.MaxLives
:= 0;
2931 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2932 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2933 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2934 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2935 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2936 gSwitchGameMode
:= GM_SINGLE
;
2938 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2939 gLMSRespawnTime
:= 0;
2940 gSpectLatchPID1
:= 0;
2941 gSpectLatchPID2
:= 0;
2943 g_Game_ExecuteEvent('ongamestart');
2945 // Создание первого игрока:
2946 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2947 gPlayer1Settings
.Color
,
2948 gPlayer1Settings
.Team
, False));
2949 if gPlayer1
= nil then
2951 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2955 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2956 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2957 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2958 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2959 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2962 // Создание второго игрока, если есть:
2965 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2966 gPlayer2Settings
.Color
,
2967 gPlayer2Settings
.Team
, False));
2968 if gPlayer2
= nil then
2970 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2974 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2975 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2976 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2977 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2978 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2982 // Загрузка и запуск карты:
2983 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2985 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2986 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2990 // Настройки игроков и ботов:
2994 for i
:= nPl
+1 to nPlayers
do
2995 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2998 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2999 TimeLimit
, ScoreLimit
: Word;
3001 Options
: LongWord; nPlayers
: Byte);
3007 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
3009 g_Game_ClearLoading();
3012 gGameSettings
.GameType
:= GT_CUSTOM
;
3013 gGameSettings
.GameMode
:= GameMode
;
3014 gSwitchGameMode
:= GameMode
;
3015 gGameSettings
.TimeLimit
:= TimeLimit
;
3016 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3017 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3018 gGameSettings
.Options
:= Options
;
3020 gCoopTotalMonstersKilled
:= 0;
3021 gCoopTotalSecretsFound
:= 0;
3022 gCoopTotalMonsters
:= 0;
3023 gCoopTotalSecrets
:= 0;
3027 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3028 gLMSRespawnTime
:= 0;
3029 gSpectLatchPID1
:= 0;
3030 gSpectLatchPID2
:= 0;
3032 g_Game_ExecuteEvent('ongamestart');
3034 // Режим наблюдателя:
3035 if nPlayers
= 0 then
3042 if nPlayers
>= 1 then
3044 // Создание первого игрока:
3045 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3046 gPlayer1Settings
.Color
,
3047 gPlayer1Settings
.Team
, False));
3048 if gPlayer1
= nil then
3050 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3054 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3055 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3056 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3057 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3058 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3062 if nPlayers
>= 2 then
3064 // Создание второго игрока:
3065 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3066 gPlayer2Settings
.Color
,
3067 gPlayer2Settings
.Team
, False));
3068 if gPlayer2
= nil then
3070 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3074 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3075 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3076 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3077 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3078 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3082 // Загрузка и запуск карты:
3083 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3085 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3089 // Нет точек появления:
3090 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3091 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3092 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3093 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3094 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3096 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3100 // Настройки игроков и ботов:
3104 for i
:= nPl
+1 to nPlayers
do
3105 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3108 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3109 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3110 Options
: LongWord; nPlayers
: Byte;
3111 IPAddr
: LongWord; Port
: Word);
3114 g_Net_Slist_ServerClosed();
3116 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3118 g_Game_ClearLoading();
3123 gGameSettings
.GameType
:= GT_SERVER
;
3124 gGameSettings
.GameMode
:= GameMode
;
3125 gSwitchGameMode
:= GameMode
;
3126 gGameSettings
.TimeLimit
:= TimeLimit
;
3127 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3128 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3129 gGameSettings
.Options
:= Options
;
3131 gCoopTotalMonstersKilled
:= 0;
3132 gCoopTotalSecretsFound
:= 0;
3133 gCoopTotalMonsters
:= 0;
3134 gCoopTotalSecrets
:= 0;
3138 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3139 gLMSRespawnTime
:= 0;
3140 gSpectLatchPID1
:= 0;
3141 gSpectLatchPID2
:= 0;
3143 g_Game_ExecuteEvent('ongamestart');
3145 // Режим наблюдателя:
3146 if nPlayers
= 0 then
3152 if nPlayers
>= 1 then
3154 // Создание первого игрока:
3155 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3156 gPlayer1Settings
.Color
,
3157 gPlayer1Settings
.Team
, False));
3158 if gPlayer1
= nil then
3160 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3164 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3165 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3166 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3167 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3168 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3171 if nPlayers
>= 2 then
3173 // Создание второго игрока:
3174 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3175 gPlayer2Settings
.Color
,
3176 gPlayer2Settings
.Team
, False));
3177 if gPlayer2
= nil then
3179 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3183 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3184 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3185 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3186 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3187 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3190 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3191 if NetForwardPorts
then
3192 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3195 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3197 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3201 g_Net_Slist_Set(NetMasterList
);
3203 g_Net_Slist_ServerStarted();
3205 // Загрузка и запуск карты:
3206 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3208 g_Net_Slist_ServerClosed();
3209 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3213 // Нет точек появления:
3214 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3215 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3216 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3217 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3218 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3220 g_Net_Slist_ServerClosed();
3221 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3225 // Настройки игроков и ботов:
3228 g_Net_Slist_ServerMapStarted();
3229 NetState
:= NET_STATE_GAME
;
3232 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3247 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3248 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3250 g_Game_ClearLoading();
3255 gGameSettings
.GameType
:= GT_CLIENT
;
3257 gCoopTotalMonstersKilled
:= 0;
3258 gCoopTotalSecretsFound
:= 0;
3259 gCoopTotalMonsters
:= 0;
3260 gCoopTotalSecrets
:= 0;
3264 g_Game_ExecuteEvent('ongamestart');
3266 NetState
:= NET_STATE_AUTH
;
3268 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3270 // create (or update) map/resource databases
3271 g_Res_CreateDatabases(true);
3273 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3274 gLMSRespawnTime
:= 0;
3275 gSpectLatchPID1
:= 0;
3276 gSpectLatchPID2
:= 0;
3279 if not g_Net_Connect(Addr
, Port
) then
3281 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3282 NetState
:= NET_STATE_NONE
;
3286 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3288 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3293 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3294 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3295 // thank you, enet. let's ignore failures altogether then.
3296 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3298 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3300 Ptr
:= NetEvent
.packet
^.data
;
3301 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3303 enet_packet_destroy(NetEvent
.packet
);
3307 InMsg
.ReadLongWord(); // skip size
3308 MID
:= InMsg
.ReadByte();
3310 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3312 NetMyID
:= InMsg
.ReadByte();
3313 NetPlrUID1
:= InMsg
.ReadWord();
3315 WadName
:= InMsg
.ReadString();
3316 Map
:= InMsg
.ReadString();
3318 gWADHash
:= InMsg
.ReadMD5();
3320 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3321 gSwitchGameMode
:= gGameSettings
.GameMode
;
3322 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3323 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3324 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3325 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3326 T
:= InMsg
.ReadLongWord();
3328 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3329 //if newResPath = '' then
3331 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3332 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3333 if newResPath
= '' then
3335 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3336 enet_packet_destroy(NetEvent
.packet
);
3337 NetState
:= NET_STATE_NONE
;
3340 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3342 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3345 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3346 gPlayer1Settings
.Color
,
3347 gPlayer1Settings
.Team
, False));
3349 if gPlayer1
= nil then
3351 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3353 enet_packet_destroy(NetEvent
.packet
);
3354 NetState
:= NET_STATE_NONE
;
3358 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3359 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3360 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3361 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3362 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3363 gPlayer1
.UID
:= NetPlrUID1
;
3364 gPlayer1
.Reset(True);
3366 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3368 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3370 enet_packet_destroy(NetEvent
.packet
);
3371 NetState
:= NET_STATE_NONE
;
3379 enet_packet_destroy(NetEvent
.packet
);
3383 enet_packet_destroy(NetEvent
.packet
);
3387 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3390 if (NetEvent
.data
<= NET_DISC_MAX
) then
3391 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3392 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3399 ProcessLoading(True);
3400 if g_Net_UserRequestExit() then
3409 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3410 NetState
:= NET_STATE_NONE
;
3415 NetState
:= NET_STATE_GAME
;
3416 MC_SEND_FullStateRequest
;
3417 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3421 lastAsMegaWad
: Boolean = false;
3423 procedure g_Game_ChangeMap(const MapPath
: String);
3427 g_Game_ClearLoading();
3429 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3430 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3431 if gExitByTrigger
then
3434 gExitByTrigger
:= False;
3436 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3437 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3440 procedure g_Game_Restart();
3444 if g_Game_IsClient
then
3446 map
:= g_ExtractFileName(gMapInfo
.Map
);
3447 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3451 g_Game_ClearLoading();
3452 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3455 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3457 NewWAD
, ResName
: String;
3461 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3463 {$IFDEF ENABLE_GIBS}
3466 {$IFDEF ENALBE_SHELLS}
3469 {$IFDEF ENABLE_CORPSES}
3470 g_Corpses_RemoveAll
;
3473 if (not g_Game_IsClient
) and
3474 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3475 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3477 if gSwitchGameMode
= GM_CTF
then
3478 gGameSettings
.MaxLives
:= 0;
3479 gGameSettings
.GameMode
:= gSwitchGameMode
;
3482 gSwitchGameMode
:= gGameSettings
.GameMode
;
3484 g_Player_ResetTeams();
3486 lastAsMegaWad
:= asMegawad
;
3487 if isWadPath(Map
) then
3489 NewWAD
:= g_ExtractWadName(Map
);
3490 ResName
:= g_ExtractFileName(Map
);
3491 if g_Game_IsServer
then
3493 nws
:= findDiskWad(NewWAD
);
3494 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3497 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3498 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3502 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3503 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3505 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3506 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3508 if (length(nws
) = 0) then
3510 ResName
:= ''; // failed
3515 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3516 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3517 g_Game_LoadWAD(NewWAD
);
3522 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3523 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3528 NewWAD
:= gGameSettings
.WAD
;
3534 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3536 if (ResName
<> '') and (NewWAD
<> '') then
3538 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3539 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3540 {$IFDEF ENABLE_RENDER}
3541 r_Render_LoadTextures
;
3546 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3548 gState
:= STATE_NONE
;
3549 {$IFDEF ENABLE_MENU}
3550 g_ActiveWindow
:= nil;
3555 wNeedTimeReset
:= True;
3557 if gGameSettings
.GameMode
= GM_CTF
then
3559 g_Map_ResetFlag(FLAG_RED
);
3560 g_Map_ResetFlag(FLAG_BLUE
);
3561 // CTF, а флагов нет:
3562 if not g_Map_HaveFlagPoints() then
3563 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3568 gState
:= STATE_MENU
;
3573 gPauseMain
:= false;
3574 gPauseHolmes
:= false;
3575 NetTimeToUpdate
:= 1;
3576 NetTimeToReliable
:= 0;
3577 NetTimeToMaster
:= NetMasterRate
;
3578 gSpectLatchPID1
:= 0;
3579 gSpectLatchPID2
:= 0;
3580 gMissionFailed
:= False;
3583 gCoopMonstersKilled
:= 0;
3584 gCoopSecretsFound
:= 0;
3586 gVoteInProgress
:= False;
3587 gVotePassed
:= False;
3593 if not gGameOn
then Exit
;
3595 g_Game_SpectateCenterView();
3597 if g_Game_IsServer
then
3599 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3601 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3602 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3603 gLMSSoftSpawn
:= True;
3604 if g_Game_IsNet
then
3605 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3609 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3610 gLMSRespawnTime
:= 0;
3614 if NetMode
= NET_SERVER
then
3616 // reset full state flags
3617 if NetClients
<> nil then
3618 for I
:= 0 to High(NetClients
) do
3619 NetClients
[I
].FullUpdateSent
:= False;
3621 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3624 g_Net_Slist_ServerMapStarted();
3626 if NetClients
<> nil then
3627 for I
:= 0 to High(NetClients
) do
3628 if NetClients
[I
].Used
then
3630 NetClients
[I
].Voted
:= False;
3631 if NetClients
[I
].RequestedFullUpdate
then
3633 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3634 NetClients
[I
].RequestedFullUpdate
:= False;
3638 g_Net_UnbanNonPermHosts();
3643 gCoopTotalMonstersKilled
:= 0;
3644 gCoopTotalSecretsFound
:= 0;
3645 gCoopTotalMonsters
:= 0;
3646 gCoopTotalSecrets
:= 0;
3650 g_Game_ExecuteEvent('onmapstart');
3653 procedure SetFirstLevel
;
3657 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3658 if MapList
= nil then
3661 SortSArray(MapList
);
3662 gNextMap
:= MapList
[Low(MapList
)];
3667 procedure g_Game_ExitLevel(const Map
: AnsiString);
3671 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3672 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3673 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3674 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3676 // Вышли в выход в Одиночной игре:
3677 if gGameSettings
.GameType
= GT_SINGLE
then
3678 gExit
:= EXIT_ENDLEVELSINGLE
3679 else // Вышли в выход в Своей игре
3681 gExit
:= EXIT_ENDLEVELCUSTOM
;
3682 if gGameSettings
.GameMode
= GM_COOP
then
3683 g_Player_RememberAll
;
3685 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3688 if gGameSettings
.GameMode
= GM_COOP
then
3691 gStatsPressed
:= True;
3692 gNextMap
:= 'MAP01';
3694 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3697 if g_Game_IsNet
then
3699 MH_SEND_GameStats();
3700 MH_SEND_CoopStats();
3706 procedure g_Game_RestartLevel();
3710 if gGameSettings
.GameMode
= GM_SINGLE
then
3715 gExit
:= EXIT_ENDLEVELCUSTOM
;
3716 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3720 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3722 gWAD
{, xwad}: String;
3725 if not g_Game_IsClient
then Exit
;
3726 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3728 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3733 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3737 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3740 g_Game_LoadWAD(NewWAD
);
3744 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3745 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3748 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3749 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3753 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3757 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3758 g_Game_LoadWAD(NewWAD);
3762 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3764 i
, n
, nb
, nr
: Integer;
3766 if not g_Game_IsServer
then Exit
;
3767 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3768 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3769 gLMSRespawnTime
:= 0;
3772 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3774 gMissionFailed
:= True;
3775 g_Game_RestartLevel
;
3779 n
:= 0; nb
:= 0; nr
:= 0;
3780 for i
:= Low(gPlayers
) to High(gPlayers
) do
3781 if (gPlayers
[i
] <> nil) and
3782 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3783 (gPlayers
[i
] is TBot
)) then
3786 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3787 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3790 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3792 // wait a second until the fuckers finally decide to join
3793 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3794 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3795 gLMSSoftSpawn
:= NoMapRestart
;
3796 if g_Game_IsNet
then
3797 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3801 {$IFDEF ENABLE_GIBS}
3804 {$IFDEF ENALBE_SHELLS}
3807 {$IFDEF ENABLE_CORPSES}
3808 g_Corpses_RemoveAll
;
3811 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3812 if g_Game_IsNet
then
3813 MH_SEND_GameEvent(NET_EV_LMS_START
);
3815 for i
:= Low(gPlayers
) to High(gPlayers
) do
3817 if gPlayers
[i
] = nil then continue
;
3818 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3819 // don't touch normal spectators
3820 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3822 gPlayers
[i
].FNoRespawn
:= True;
3823 gPlayers
[i
].Lives
:= 0;
3824 if g_Game_IsNet
then
3825 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3828 gPlayers
[i
].FNoRespawn
:= False;
3829 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3830 gPlayers
[i
].Respawn(False, True);
3831 if gGameSettings
.GameMode
= GM_COOP
then
3833 gPlayers
[i
].Frags
:= 0;
3834 gPlayers
[i
].RecallState
;
3836 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3837 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3838 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3839 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3842 g_Items_RestartRound();
3844 gLMSSoftSpawn
:= False;
3847 function g_Game_GetFirstMap(WAD
: String): String;
3851 MapList
:= g_Map_GetMapsList(WAD
);
3852 if MapList
= nil then
3855 SortSArray(MapList
);
3856 Result
:= MapList
[Low(MapList
)];
3858 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3864 function g_Game_GetNextMap(): String;
3871 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3872 if MapList
= nil then
3875 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3877 SortSArray(MapList
);
3879 for I
:= Low(MapList
) to High(MapList
) do
3880 if Map
= MapList
[I
] then
3886 if MapIndex
<> -255 then
3888 if MapIndex
= High(MapList
) then
3889 Result
:= MapList
[Low(MapList
)]
3891 Result
:= MapList
[MapIndex
+ 1];
3893 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3899 procedure g_Game_NextLevel();
3901 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3902 gExit
:= EXIT_ENDLEVELCUSTOM
3905 gExit
:= EXIT_ENDLEVELSINGLE
;
3909 if gNextMap
<> '' then Exit
;
3910 gNextMap
:= g_Game_GetNextMap();
3913 function g_Game_IsTestMap(): Boolean;
3915 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3918 procedure g_Game_DeleteTestMap();
3921 //MapName: AnsiString;
3929 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3930 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3931 if (a
= 0) then exit
;
3933 // Выделяем имя wad-файла и имя карты
3934 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3935 Delete(gMapToDelete
, 1, a
+5);
3936 gMapToDelete
:= UpperCase(gMapToDelete
);
3938 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3941 // Имя карты не стандартное тестовое:
3942 if MapName <> TEST_MAP_NAME then
3945 if not gTempDelete then
3947 time := g_GetFileTime(WadName);
3948 WAD := TWADFile.Create();
3951 if not WAD.ReadFile(WadName) then
3952 begin // Нет такого WAD-файла
3957 // Составляем список карт и ищем нужную:
3959 MapList := WAD.GetResourcesList('');
3961 if MapList <> nil then
3962 for a := 0 to High(MapList) do
3963 if MapList[a] = MapName then
3965 // Удаляем и сохраняем:
3966 WAD.RemoveResource('', MapName);
3967 WAD.SaveTo(WadName);
3972 g_SetFileTime(WadName, time);
3975 if gTempDelete
then DeleteFile(WadName
);
3978 procedure GameCVars(P
: SSArray
);
3981 stat
: TPlayerStatArray
;
3984 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3988 if Length(P
) > 1 then
3993 gsGameFlags
:= gsGameFlags
or Flag
3995 gsGameFlags
:= gsGameFlags
and (not Flag
);
3997 if g_Game_IsServer
then
4000 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
4002 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
4003 if g_Game_IsNet
then MH_SEND_GameSettings
;
4007 if LongBool(gsGameFlags
and Flag
) then
4008 g_Console_Add(_lc
[OnMsg
])
4010 g_Console_Add(_lc
[OffMsg
]);
4012 if OnMapChange
and g_Game_IsServer
then
4013 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4018 cmd
:= LowerCase(P
[0]);
4020 if cmd
= 'g_gamemode' then
4022 if (Length(P
) > 1) then
4024 a
:= g_Game_TextToMode(P
[1]);
4025 if a
= GM_SINGLE
then a
:= GM_COOP
;
4026 gsGameMode
:= g_Game_ModeToText(a
);
4027 if g_Game_IsServer
then
4029 gSwitchGameMode
:= a
;
4030 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4031 (gState
= STATE_INTERSINGLE
) then
4032 gSwitchGameMode
:= GM_SINGLE
;
4034 gGameSettings
.GameMode
:= gSwitchGameMode
;
4038 if gSwitchGameMode
= gGameSettings
.GameMode
then
4039 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4040 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4042 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4043 [g_Game_ModeToText(gGameSettings
.GameMode
),
4044 g_Game_ModeToText(gSwitchGameMode
)]));
4046 else if cmd
= 'g_friendlyfire' then
4048 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4050 else if cmd
= 'g_friendly_absorb_damage' then
4052 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
4054 else if cmd
= 'g_friendly_hit_trace' then
4056 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
4058 else if cmd
= 'g_friendly_hit_projectile' then
4060 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
4062 else if cmd
= 'g_weaponstay' then
4064 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
4066 else if cmd
= 'g_allow_exit' then
4068 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
4070 else if cmd
= 'g_allow_monsters' then
4072 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
4074 else if cmd
= 'g_allow_dropflag' then
4076 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
4078 else if cmd
= 'g_throw_flag' then
4080 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
4082 else if cmd
= 'g_bot_vsplayers' then
4084 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4086 else if cmd
= 'g_bot_vsmonsters' then
4088 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4090 else if cmd
= 'g_dm_keys' then
4092 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4094 else if cmd
= 'g_gameflags' then
4096 if Length(P
) > 1 then
4098 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4099 if g_Game_IsServer
then
4101 gGameSettings
.Options
:= gsGameFlags
;
4102 if g_Game_IsNet
then MH_SEND_GameSettings
;
4106 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4108 else if cmd
= 'g_warmup_time' then
4110 if Length(P
) > 1 then
4112 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4113 if g_Game_IsServer
then
4115 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4116 // extend warmup if it's already going
4117 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4119 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4120 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4122 if g_Game_IsNet
then MH_SEND_GameSettings
;
4126 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4127 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4129 else if cmd
= 'g_spawn_invul' then
4131 if Length(P
) > 1 then
4133 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4134 if g_Game_IsServer
then
4136 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4137 if g_Game_IsNet
then MH_SEND_GameSettings
;
4141 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4143 else if cmd
= 'g_item_respawn_time' then
4145 if Length(P
) > 1 then
4147 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4148 if g_Game_IsServer
then
4150 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4151 if g_Game_IsNet
then MH_SEND_GameSettings
;
4155 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4156 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4158 else if cmd
= 'sv_intertime' then
4160 if (Length(P
) > 1) then
4161 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4163 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4165 else if cmd
= 'g_max_particles' then
4167 if Length(p
) = 2 then
4170 a
:= Max(0, StrToIntDef(p
[1], 0));
4174 else if Length(p
) = 1 then
4177 e_LogWritefln('%s', [g_GFX_GetMax()])
4179 e_LogWritefln('%s', [0])
4184 e_LogWritefln('usage: %s <n>', [cmd
])
4187 else if cmd
= 'g_max_shells' then
4189 if Length(p
) = 2 then
4191 {$IFDEF ENABLE_SHELLS}
4192 a
:= Max(0, StrToIntDef(p
[1], 0));
4196 else if Length(p
) = 1 then
4198 {$IFDEF ENABLE_SHELLS}
4199 e_LogWritefln('%s', [g_Shells_GetMax()])
4201 e_LogWritefln('%s', [0])
4206 e_LogWritefln('usage: %s <n>', [cmd
])
4209 else if cmd
= 'g_max_gibs' then
4211 if Length(p
) = 2 then
4213 {$IFDEF ENABLE_GIBS}
4214 a
:= Max(0, StrToIntDef(p
[1], 0));
4218 else if Length(p
) = 1 then
4220 {$IFDEF ENABLE_GIBS}
4221 e_LogWritefln('%s', [g_Gibs_GetMax()])
4223 e_LogWritefln('%s', [0])
4228 e_LogWritefln('usage: %s <n>', [cmd
])
4231 else if cmd
= 'g_max_corpses' then
4233 if Length(p
) = 2 then
4235 {$IFDEF ENABLE_CORPSES}
4236 a
:= Max(0, StrToIntDef(p
[1], 0));
4240 else if Length(p
) = 1 then
4242 {$IFDEF ENABLE_CORPSES}
4243 e_LogWritefln('%s', [g_Corpses_GetMax()])
4245 e_LogWritefln('%s', [0])
4250 e_LogWritefln('usage: %s <n>', [cmd
])
4253 else if cmd
= 'g_force_model' then
4255 if Length(p
) = 2 then
4257 a
:= StrToIntDef(p
[1], 0);
4258 g_Force_Model_Set(a
);
4259 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4261 for a
:= Low(gPlayers
) to High(gPlayers
) do
4263 if (gPlayers
[a
] <> nil) then
4265 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4267 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4269 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4273 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4275 for a
:= Low(gPlayers
) to High(gPlayers
) do
4277 if (gPlayers
[a
] <> nil) then
4279 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4281 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4283 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4289 else if cmd
= 'g_force_model_name' then
4291 if (Length(P
) > 1) then
4293 cmd
:= b_Text_Unformat(P
[1]);
4294 g_Forced_Model_SetName(cmd
);
4295 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4297 for a
:= Low(gPlayers
) to High(gPlayers
) do
4299 if (gPlayers
[a
] <> nil) then
4301 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4303 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4305 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4311 else if cmd
= 'g_scorelimit' then
4313 if Length(P
) > 1 then
4315 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4317 if g_Game_IsServer
then
4320 if gGameSettings
.GameMode
= GM_DM
then
4322 stat
:= g_Player_GetStats();
4324 for a
:= 0 to High(stat
) do
4325 if stat
[a
].Frags
> b
then
4329 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4331 // if someone has a higher score, set it to that instead
4332 gsScoreLimit
:= max(gsScoreLimit
, b
);
4333 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4335 if g_Game_IsNet
then MH_SEND_GameSettings
;
4339 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4341 else if cmd
= 'g_timelimit' then
4343 if Length(P
) > 1 then
4345 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4346 if g_Game_IsServer
then
4348 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4349 if g_Game_IsNet
then MH_SEND_GameSettings
;
4352 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4353 [gsTimeLimit
div 3600,
4354 (gsTimeLimit
div 60) mod 60,
4355 gsTimeLimit
mod 60]));
4357 else if cmd
= 'g_max_bots' then
4359 if Length(P
) > 1 then
4360 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4361 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4363 else if cmd
= 'g_maxlives' then
4365 if Length(P
) > 1 then
4367 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4368 if g_Game_IsServer
then
4370 gGameSettings
.MaxLives
:= gsMaxLives
;
4371 if g_Game_IsNet
then MH_SEND_GameSettings
;
4375 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4379 procedure PlayerSettingsCVars(P
: SSArray
);
4384 function ParseTeam(s
: string): Byte;
4388 'red', '1': result
:= TEAM_RED
;
4389 'blue', '2': result
:= TEAM_BLUE
;
4390 else result
:= TEAM_NONE
;
4394 cmd
:= LowerCase(P
[0]);
4398 if (Length(P
) > 1) then
4400 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4401 if g_Game_IsClient
then
4402 MC_SEND_PlayerSettings
4403 else if gGameOn
and (gPlayer1
<> nil) then
4405 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4406 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4412 if (Length(P
) > 1) then
4414 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4415 if g_Game_IsClient
then
4416 MC_SEND_PlayerSettings
4417 else if gGameOn
and (gPlayer2
<> nil) then
4419 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4420 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4426 if Length(P
) > 3 then
4428 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4429 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4430 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4431 if g_Game_IsClient
then
4432 MC_SEND_PlayerSettings
4433 else if gGameOn
and (gPlayer1
<> nil) then
4435 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4436 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4442 if Length(P
) > 3 then
4444 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4445 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4446 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4447 if g_Game_IsClient
then
4448 MC_SEND_PlayerSettings
4449 else if gGameOn
and (gPlayer2
<> nil) then
4451 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4452 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4458 if (Length(P
) > 1) then
4460 gPlayer1Settings
.Model
:= P
[1];
4461 if g_Game_IsClient
then
4462 MC_SEND_PlayerSettings
4463 else if gGameOn
and (gPlayer1
<> nil) then
4465 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4466 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4467 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4473 if (Length(P
) > 1) then
4475 gPlayer2Settings
.Model
:= P
[1];
4476 if g_Game_IsClient
then
4477 MC_SEND_PlayerSettings
4478 else if gGameOn
and (gPlayer2
<> nil) then
4480 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4481 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4482 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4488 // TODO: switch teams if in game or store this separately
4489 if (Length(P
) > 1) then
4491 team
:= ParseTeam(P
[1]);
4492 if team
= TEAM_NONE
then
4493 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4494 else if not gGameOn
and not g_Game_IsNet
then
4495 gPlayer1Settings
.Team
:= team
4497 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4502 // TODO: switch teams if in game or store this separately
4503 if (Length(P
) > 1) then
4505 team
:= ParseTeam(P
[1]);
4506 if team
= TEAM_NONE
then
4507 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4508 else if not gGameOn
and not g_Game_IsNet
then
4509 gPlayer2Settings
.Team
:= team
4511 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4516 if (Length(P
) = 2) then
4517 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4521 if (Length(P
) = 2) then
4522 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4526 if (Length(P
) = 2) then
4527 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4531 if (Length(P
) = 2) then
4532 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4536 if (Length(P
) = 2) then
4537 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4541 if (Length(P
) = 2) then
4542 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4544 'p1_priority_kastet':
4546 if (Length(P
) = 2) then
4547 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4549 'p2_priority_kastet':
4551 if (Length(P
) = 2) then
4552 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4556 if (Length(P
) = 2) then
4557 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4561 if (Length(P
) = 2) then
4562 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4564 'p1_priority_pistol':
4566 if (Length(P
) = 2) then
4567 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4569 'p2_priority_pistol':
4571 if (Length(P
) = 2) then
4572 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4574 'p1_priority_shotgun1':
4576 if (Length(P
) = 2) then
4577 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4579 'p2_priority_shotgun1':
4581 if (Length(P
) = 2) then
4582 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4584 'p1_priority_shotgun2':
4586 if (Length(P
) = 2) then
4587 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4589 'p2_priority_shotgun2':
4591 if (Length(P
) = 2) then
4592 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4594 'p1_priority_chaingun':
4596 if (Length(P
) = 2) then
4597 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4599 'p2_priority_chaingun':
4601 if (Length(P
) = 2) then
4602 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4604 'p1_priority_rocketlauncher':
4606 if (Length(P
) = 2) then
4607 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4609 'p2_priority_rocketlauncher':
4611 if (Length(P
) = 2) then
4612 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4614 'p1_priority_plasma':
4616 if (Length(P
) = 2) then
4617 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4619 'p2_priority_plasma':
4621 if (Length(P
) = 2) then
4622 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4626 if (Length(P
) = 2) then
4627 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4631 if (Length(P
) = 2) then
4632 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4634 'p1_priority_super':
4636 if (Length(P
) = 2) then
4637 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4639 'p2_priority_super':
4641 if (Length(P
) = 2) then
4642 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4644 'p1_priority_flamethrower':
4646 if (Length(P
) = 2) then
4647 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4649 'p2_priority_flamethrower':
4651 if (Length(P
) = 2) then
4652 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4654 'p1_priority_berserk':
4656 if (Length(P
) = 2) then
4657 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4659 'p2_priority_berserk':
4661 if (Length(P
) = 2) then
4662 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4667 procedure PrintHeapStats();
4671 hs
:= GetFPCHeapStatus();
4672 e_LogWriteLn ('v===== heap status =====v');
4673 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4674 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4675 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4676 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4677 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4678 e_LogWriteLn ('^=======================^');
4681 procedure DebugCommands(P
: SSArray
);
4688 // Команды отладочного режима:
4689 if {gDebugMode}conIsCheatsEnabled
then
4691 cmd
:= LowerCase(P
[0]);
4692 if cmd
= 'd_window' then
4694 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4695 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4697 else if cmd
= 'd_sounds' then
4699 if (Length(P
) > 1) and
4700 ((P
[1] = '1') or (P
[1] = '0')) then
4701 g_Debug_Sounds
:= (P
[1][1] = '1');
4703 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4705 else if cmd
= 'd_frames' then
4707 if (Length(P
) > 1) and
4708 ((P
[1] = '1') or (P
[1] = '0')) then
4709 g_Debug_Frames
:= (P
[1][1] = '1');
4711 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4713 else if cmd
= 'd_winmsg' then
4715 if (Length(P
) > 1) and
4716 ((P
[1] = '1') or (P
[1] = '0')) then
4717 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4719 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4721 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4723 if (Length(P
) > 1) and
4724 ((P
[1] = '1') or (P
[1] = '0')) then
4725 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4727 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4729 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4731 if Length(P
) > 1 then
4733 '0': g_debug_BotAIOff
:= 0;
4734 '1': g_debug_BotAIOff
:= 1;
4735 '2': g_debug_BotAIOff
:= 2;
4736 '3': g_debug_BotAIOff
:= 3;
4739 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4741 else if cmd
= 'd_monster' then
4743 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4744 if Length(P
) < 2 then
4746 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4747 g_Console_Add('ID | Name');
4748 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4749 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4750 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4753 a
:= StrToIntDef(P
[1], 0);
4754 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4755 a
:= g_Mons_TypeIdByName(P
[1]);
4757 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4758 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4761 with gPlayer1
.Obj
do
4763 mon
:= g_Monsters_Create(a
,
4764 X
+ Rect
.X
+ (Rect
.Width
div 2),
4765 Y
+ Rect
.Y
+ Rect
.Height
,
4766 gPlayer1
.Direction
, True);
4768 if (Length(P
) > 2) and (mon
<> nil) then
4770 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4771 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4772 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4773 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4774 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4775 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4776 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4777 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4778 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4783 else if (cmd
= 'd_health') then
4785 if (Length(P
) > 1) and
4786 ((P
[1] = '1') or (P
[1] = '0')) then
4787 g_debug_HealthBar
:= (P
[1][1] = '1');
4789 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4791 else if (cmd
= 'd_player') then
4793 if (Length(P
) > 1) and
4794 ((P
[1] = '1') or (P
[1] = '0')) then
4795 g_debug_Player
:= (P
[1][1] = '1');
4797 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4799 else if (cmd
= 'd_mem') then
4805 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4809 procedure GameCheats(P
: SSArray
);
4815 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4817 g_Console_Add('not available');
4823 g_Console_Add('where is the player?!');
4826 cmd
:= LowerCase(P
[0]);
4830 plr
.GodMode
:= not plr
.GodMode
;
4831 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4834 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4835 if cmd
= 'give' then
4837 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4838 for f
:= 1 to High(P
) do
4840 cmd
:= LowerCase(P
[f
]);
4841 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4842 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4843 if cmd
= 'exit' then
4845 if gTriggers
<> nil then
4847 for a
:= 0 to High(gTriggers
) do
4849 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4851 g_Console_Add('player left the map');
4852 gExitByTrigger
:= True;
4853 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4854 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4862 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4863 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4864 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4865 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4866 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4868 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4869 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4871 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4872 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;
4874 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4875 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4877 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4878 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4880 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4881 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4883 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4884 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4885 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4887 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4888 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4889 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4890 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;
4891 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4892 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4894 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;
4895 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;
4896 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;
4897 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;
4898 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;
4899 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;
4901 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4902 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;
4904 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;
4905 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;
4907 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4909 if cmd
= 'ammo' then
4911 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4912 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4913 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4914 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4915 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4916 g_Console_Add('player got some ammo');
4920 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4921 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4923 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4924 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4926 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4927 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4929 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4930 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4932 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4934 if cmd
= 'weapons' then
4936 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4937 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4938 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4939 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4940 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4941 plr
.GiveItem(ITEM_WEAPON_BFG
);
4942 g_Console_Add('player got weapons');
4946 if cmd
= 'keys' then
4948 plr
.GiveItem(ITEM_KEY_RED
);
4949 plr
.GiveItem(ITEM_KEY_GREEN
);
4950 plr
.GiveItem(ITEM_KEY_BLUE
);
4951 g_Console_Add('player got all keys');
4955 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4960 if cmd
= 'open' then
4962 g_Console_Add('player activated sesame');
4963 g_Triggers_OpenAll();
4970 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4974 if cmd
= 'noclip' then
4977 g_Console_Add('wall hardeness adjusted');
4981 if cmd
= 'notarget' then
4983 plr
.NoTarget
:= not plr
.NoTarget
;
4984 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4988 if cmd
= 'noreload' then
4990 plr
.NoReload
:= not plr
.NoReload
;
4991 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4995 if cmd
= 'speedy' then
4997 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4998 g_Console_Add('speed adjusted');
5002 if cmd
= 'jumpy' then
5004 VEL_JUMP
:= 30-VEL_JUMP
;
5005 g_Console_Add('jump height adjusted');
5009 if cmd
= 'automap' then
5011 gShowMap
:= not gShowMap
;
5012 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
5016 if cmd
= 'aimline' then
5018 gAimLine
:= not gAimLine
;
5019 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
5024 procedure GameCommands(P
: SSArray
);
5030 pl
: pTNetClient
= nil;
5038 cmd
:= LowerCase(P
[0]);
5040 if cmd
= 'pause' then
5042 {$IFDEF ENABLE_MENU}
5043 if (g_ActiveWindow
= nil) then
5044 g_Game_Pause(not gPauseMain
);
5046 g_Game_Pause(not gPauseMain
);
5049 else if cmd
= 'endgame' then
5050 gExit
:= EXIT_SIMPLE
5051 else if cmd
= 'restart' then
5053 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5055 if g_Game_IsClient
then
5057 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5062 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5064 else if cmd
= 'kick' then
5066 if g_Game_IsServer
then
5068 if Length(P
) < 2 then
5070 g_Console_Add('kick <name>');
5075 g_Console_Add('kick <name>');
5079 if g_Game_IsNet
then
5080 pl
:= g_Net_Client_ByName(P
[1]);
5083 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5084 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5085 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5086 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5087 g_Net_Slist_ServerPlayerLeaves();
5088 end else if gPlayers
<> nil then
5089 for a
:= Low(gPlayers
) to High(gPlayers
) do
5090 if gPlayers
[a
] <> nil then
5091 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5093 // Не отключать основных игроков в сингле
5094 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5096 gPlayers
[a
].Lives
:= 0;
5097 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5098 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5099 g_Player_Remove(gPlayers
[a
].UID
);
5100 g_Net_Slist_ServerPlayerLeaves();
5101 // Если не перемешать, при добавлении новых ботов появятся старые
5105 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5107 else if cmd
= 'kick_id' then
5109 if g_Game_IsServer
and g_Game_IsNet
then
5111 if Length(P
) < 2 then
5113 g_Console_Add('kick_id <client ID>');
5118 g_Console_Add('kick_id <client ID>');
5122 a
:= StrToIntDef(P
[1], 0);
5123 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5125 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5127 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5128 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
5129 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5130 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5131 g_Net_Slist_ServerPlayerLeaves();
5135 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5137 else if cmd
= 'kick_pid' then
5139 if g_Game_IsServer
and g_Game_IsNet
then
5141 if Length(P
) < 2 then
5143 g_Console_Add('kick_pid <player ID>');
5148 g_Console_Add('kick_pid <player ID>');
5152 a
:= StrToIntDef(P
[1], 0);
5153 pl
:= g_Net_Client_ByPlayer(a
);
5154 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5156 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5157 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5158 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5159 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5160 g_Net_Slist_ServerPlayerLeaves();
5163 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5165 else if cmd
= 'ban' then
5167 if g_Game_IsServer
and g_Game_IsNet
then
5169 if Length(P
) < 2 then
5171 g_Console_Add('ban <name>');
5176 g_Console_Add('ban <name>');
5180 pl
:= g_Net_Client_ByName(P
[1]);
5183 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5184 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5185 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5186 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5187 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5188 g_Net_Slist_ServerPlayerLeaves();
5190 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5192 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5194 else if cmd
= 'ban_id' then
5196 if g_Game_IsServer
and g_Game_IsNet
then
5198 if Length(P
) < 2 then
5200 g_Console_Add('ban_id <client ID>');
5205 g_Console_Add('ban_id <client ID>');
5209 a
:= StrToIntDef(P
[1], 0);
5210 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5211 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5213 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5214 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5215 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5216 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5217 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5218 g_Net_Slist_ServerPlayerLeaves();
5221 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5223 else if cmd
= 'ban_pid' then
5225 if g_Game_IsServer
and g_Game_IsNet
then
5227 if Length(P
) < 2 then
5229 g_Console_Add('ban_pid <player ID>');
5234 g_Console_Add('ban_pid <player ID>');
5238 a
:= StrToIntDef(P
[1], 0);
5239 pl
:= g_Net_Client_ByPlayer(a
);
5240 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5242 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5243 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5244 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5245 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5246 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5247 g_Net_Slist_ServerPlayerLeaves();
5250 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5252 else if cmd
= 'permban' then
5254 if g_Game_IsServer
and g_Game_IsNet
then
5256 if Length(P
) < 2 then
5258 g_Console_Add('permban <name>');
5263 g_Console_Add('permban <name>');
5267 pl
:= g_Net_Client_ByName(P
[1]);
5270 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5271 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5272 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5273 g_Net_SaveBanList();
5274 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5275 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5276 g_Net_Slist_ServerPlayerLeaves();
5278 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5280 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5282 else if cmd
= 'permban_id' then
5284 if g_Game_IsServer
and g_Game_IsNet
then
5286 if Length(P
) < 2 then
5288 g_Console_Add('permban_id <client ID>');
5293 g_Console_Add('permban_id <client ID>');
5297 a
:= StrToIntDef(P
[1], 0);
5298 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5299 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5301 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5302 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5303 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5304 g_Net_SaveBanList();
5305 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5306 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5307 g_Net_Slist_ServerPlayerLeaves();
5310 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5312 else if cmd
= 'permban_pid' then
5314 if g_Game_IsServer
and g_Game_IsNet
then
5316 if Length(P
) < 2 then
5318 g_Console_Add('permban_pid <player ID>');
5323 g_Console_Add('permban_pid <player ID>');
5327 a
:= StrToIntDef(P
[1], 0);
5328 pl
:= g_Net_Client_ByPlayer(a
);
5329 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5331 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5332 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5333 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5334 g_Net_SaveBanList();
5335 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5336 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5337 g_Net_Slist_ServerPlayerLeaves();
5340 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5342 else if cmd
= 'permban_ip' then
5344 if g_Game_IsServer
and g_Game_IsNet
then
5346 if Length(P
) < 2 then
5348 g_Console_Add('permban_ip <IP address>');
5353 g_Console_Add('permban_ip <IP address>');
5357 g_Net_BanHost(P
[1]);
5358 g_Net_SaveBanList();
5359 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5361 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5363 else if cmd
= 'unban' then
5365 if g_Game_IsServer
and g_Game_IsNet
then
5367 if Length(P
) < 2 then
5369 g_Console_Add('unban <IP Address>');
5374 g_Console_Add('unban <IP Address>');
5378 if g_Net_UnbanHost(P
[1]) then
5380 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5381 g_Net_SaveBanList();
5383 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5385 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5387 else if cmd
= 'clientlist' then
5389 if g_Game_IsServer
and g_Game_IsNet
then
5392 if NetClients
<> nil then
5393 for a
:= Low(NetClients
) to High(NetClients
) do
5394 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5396 plr
:= g_Player_Get(NetClients
[a
].Player
);
5397 if plr
= nil then continue
;
5399 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5400 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5403 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5405 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5407 else if cmd
= 'connect' then
5409 if (NetMode
= NET_NONE
) then
5411 if Length(P
) < 2 then
5413 g_Console_Add('connect <IP> [port] [password]');
5418 g_Console_Add('connect <IP> [port] [password]');
5422 if Length(P
) > 2 then
5423 prt
:= StrToIntDef(P
[2], 25666)
5427 if Length(P
) > 3 then
5432 g_Game_StartClient(P
[1], prt
, pw
);
5435 else if cmd
= 'disconnect' then
5437 if (NetMode
= NET_CLIENT
) then
5440 else if cmd
= 'reconnect' then
5442 if (NetMode
= NET_SERVER
) then
5445 if (NetMode
= NET_CLIENT
) then
5448 gExit
:= EXIT_SIMPLE
;
5452 //TODO: Use last successful password to reconnect, instead of ''
5453 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5455 else if (cmd
= 'addbot') or
5456 (cmd
= 'bot_add') then
5458 if Length(P
) > 2 then
5459 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5460 else if Length(P
) > 1 then
5461 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5463 g_Bot_Add(TEAM_NONE
, 2);
5465 else if cmd
= 'bot_addlist' then
5467 if Length(P
) > 1 then
5469 if Length(P
) = 2 then
5470 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5471 else if Length(P
) = 3 then
5472 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5474 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5477 else if cmd
= 'bot_removeall' then
5479 else if cmd
= 'chat' then
5481 if g_Game_IsNet
then
5483 if Length(P
) > 1 then
5485 for a
:= 1 to High(P
) do
5486 chstr
:= chstr
+ P
[a
] + ' ';
5488 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5490 if Length(chstr
) < 1 then
5492 g_Console_Add('chat <text>');
5496 chstr
:= b_Text_Format(chstr
);
5497 if g_Game_IsClient
then
5498 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5500 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5503 g_Console_Add('chat <text>');
5505 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5507 else if cmd
= 'teamchat' then
5509 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5511 if Length(P
) > 1 then
5513 for a
:= 1 to High(P
) do
5514 chstr
:= chstr
+ P
[a
] + ' ';
5516 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5518 if Length(chstr
) < 1 then
5520 g_Console_Add('teamchat <text>');
5524 chstr
:= b_Text_Format(chstr
);
5525 if g_Game_IsClient
then
5526 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5528 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5529 gPlayer1Settings
.Team
);
5532 g_Console_Add('teamchat <text>');
5534 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5536 else if (cmd
= 'an') or (cmd
= 'announce') then
5538 if g_Game_IsNet
then
5540 if Length(P
) > 1 then
5542 for a
:= 1 to High(P
) do
5543 chstr
:= chstr
+ P
[a
] + ' ';
5545 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5547 if Length(chstr
) < 1 then
5549 g_Console_Add('announce <text>');
5553 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5554 if g_Game_IsClient
then
5555 MC_SEND_RCONCommand(chstr
)
5557 g_Console_Process(chstr
, True);
5560 g_Console_Add('announce <text>');
5562 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5564 else if cmd
= 'game' then
5566 if gGameSettings
.GameType
<> GT_NONE
then
5568 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5571 if Length(P
) = 1 then
5573 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5576 // game not started yet, load fist map from some wad
5578 s
:= addWadExtension(P
[1]);
5579 found
:= e_FindResource(AllMapDirs
, s
);
5583 P
[1] := ExpandFileName(P
[1]);
5584 // if map not choosed then set first map
5585 if Length(P
) < 3 then
5588 P
[2] := g_Game_GetFirstMap(P
[1]);
5591 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5593 if g_Map_Exist(s
) then
5597 with gGameSettings
do
5599 Options
:= gsGameFlags
;
5600 GameMode
:= g_Game_TextToMode(gsGameMode
);
5601 if gSwitchGameMode
<> GM_NONE
then
5602 GameMode
:= gSwitchGameMode
;
5603 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5604 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5606 if Length(P
) >= 4 then
5607 b
:= StrToIntDef(P
[3], 1);
5608 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5609 ScoreLimit
, MaxLives
, Options
, b
);
5614 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5616 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5618 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5620 else if cmd
= 'host' then
5622 if gGameSettings
.GameType
<> GT_NONE
then
5624 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5627 if Length(P
) < 4 then
5629 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5632 if not StrToIp(P
[1], listen
) then
5634 prt
:= StrToIntDef(P
[2], 25666);
5636 s
:= addWadExtension(P
[3]);
5637 found
:= e_FindResource(AllMapDirs
, s
);
5641 // get first map in wad, if not specified
5642 if Length(P
) < 5 then
5645 P
[4] := g_Game_GetFirstMap(P
[1]);
5647 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5648 if g_Map_Exist(s
) then
5652 with gGameSettings
do
5654 Options
:= gsGameFlags
;
5655 GameMode
:= g_Game_TextToMode(gsGameMode
);
5656 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5657 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5658 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5660 if Length(P
) >= 6 then
5661 b
:= StrToIntDef(P
[5], 0);
5662 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5668 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5670 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5675 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5678 else if cmd
= 'map' then
5680 if Length(P
) = 1 then
5682 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5684 g_Console_Add(cmd
+ ' <MAP>');
5685 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5689 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5694 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5696 if Length(P
) < 3 then
5698 // first param is map or wad
5699 s
:= UpperCase(P
[1]);
5700 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5702 gExitByTrigger
:= False;
5705 // already in game, finish current map
5707 gExit
:= EXIT_ENDLEVELCUSTOM
;
5711 // intermission, so change map immediately
5718 found
:= e_FindResource(AllMapDirs
, s
);
5720 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5723 // no such map, found wad
5726 P
[1] := ExpandFileName(pw
);
5727 P
[2] := g_Game_GetFirstMap(P
[1]);
5728 s
:= P
[1] + ':\' + P
[2];
5729 if g_Map_Exist(s
) then
5731 gExitByTrigger
:= False;
5734 // already in game, finish current map
5736 gExit
:= EXIT_ENDLEVELCUSTOM
5740 // intermission, so change map immediately
5747 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5749 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5754 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5760 s
:= addWadExtension(P
[1]);
5761 found
:= e_FindResource(AllMapDirs
, s
);
5765 P
[2] := UpperCase(P
[2]);
5766 s
:= P
[1] + ':\' + P
[2];
5767 if g_Map_Exist(s
) then
5769 gExitByTrigger
:= False;
5773 gExit
:= EXIT_ENDLEVELCUSTOM
5782 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5787 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5793 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5797 else if cmd
= 'nextmap' then
5799 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5801 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5806 if Length(P
) = 1 then
5808 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5810 g_Console_Add(cmd
+ ' <MAP>');
5811 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5816 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5822 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5824 if Length(P
) < 3 then
5826 // first param is map or wad
5827 s
:= UpperCase(P
[1]);
5828 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5831 gExitByTrigger
:= False;
5837 // no such map, found wad
5838 pw
:= addWadExtension(P
[1]);
5839 found
:= e_FindResource(MapDirs
, pw
);
5841 found
:= e_FindResource(WadDirs
, pw
);
5843 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5846 // map not specified, select first map
5848 P
[2] := g_Game_GetFirstMap(P
[1]);
5849 s
:= P
[1] + ':\' + P
[2];
5850 if g_Map_Exist(s
) then
5852 gExitByTrigger
:= False;
5859 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5861 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5866 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5872 // specified two params wad + map
5873 pw
:= addWadExtension(P
[1]);
5874 found
:= e_FindResource(MapDirs
, pw
);
5876 found
:= e_FindResource(MapDirs
, pw
);
5880 P
[2] := UpperCase(P
[2]);
5881 s
:= P
[1] + ':\' + P
[2];
5882 if g_Map_Exist(s
) then
5884 gExitByTrigger
:= False;
5890 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5895 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5901 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5906 if gNextMap
= '' then
5907 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5909 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5913 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5917 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5921 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5923 gExitByTrigger
:= False;
5924 // next map not specified, try to find trigger EXIT
5925 if (gNextMap
= '') and (gTriggers
<> nil) then
5927 for a
:= 0 to High(gTriggers
) do
5929 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5931 gExitByTrigger
:= True;
5932 //gNextMap := gTriggers[a].Data.MapName;
5933 gNextMap
:= gTriggers
[a
].tgcMap
;
5938 if gNextMap
= '' then
5939 gNextMap
:= g_Game_GetNextMap();
5940 if not isWadPath(gNextMap
) then
5941 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5944 if g_Map_Exist(s
) then
5945 gExit
:= EXIT_ENDLEVELCUSTOM
5947 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5951 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5955 else if (cmd
= 'event') then
5957 if (Length(P
) <= 1) then
5959 for a
:= 0 to High(gEvents
) do
5960 if gEvents
[a
].Command
= '' then
5961 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5963 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5966 if (Length(P
) = 2) then
5968 for a
:= 0 to High(gEvents
) do
5969 if gEvents
[a
].Name
= P
[1] then
5970 if gEvents
[a
].Command
= '' then
5971 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5973 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5976 for a
:= 0 to High(gEvents
) do
5977 if gEvents
[a
].Name
= P
[1] then
5979 gEvents
[a
].Command
:= '';
5980 for b
:= 2 to High(P
) do
5981 if Pos(' ', P
[b
]) = 0 then
5982 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5984 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5985 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5989 else if cmd
= 'suicide' then
5993 if g_Game_IsClient
then
5994 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5997 if gPlayer1
<> nil then
5998 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5999 if gPlayer2
<> nil then
6000 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6004 else if cmd
= 'screenshot' then
6006 {$IFDEF ENABLE_RENDER}
6010 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
6012 a
:= 1 - (ord(cmd
[5]) - ord('n'));
6014 gWeaponAction
[0, WP_PREV
] := True;
6016 gWeaponAction
[0, WP_NEXT
] := True;
6018 else if cmd
= 'weapon' then
6020 if Length(p
) = 2 then
6022 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
6023 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6024 gSelectWeapon
[0, a
] := True
6027 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
6028 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
6030 a
:= 1 - (ord(cmd
[8]) - ord('n'));
6031 b
:= ord(cmd
[2]) - ord('1');
6033 gWeaponAction
[b
, WP_PREV
] := True;
6035 gWeaponAction
[b
, WP_NEXT
] := True;
6037 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
6039 if Length(p
) = 2 then
6041 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
6042 b
:= ord(cmd
[2]) - ord('1');
6043 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6044 gSelectWeapon
[b
, a
] := True
6047 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
6049 b
:= ord(cmd
[2]) - ord('1');
6051 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
6053 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
6055 else if (cmd
= 'dropflag') then
6057 if g_Game_IsServer
then
6059 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
6060 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
6063 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6065 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
6067 b
:= ord(cmd
[2]) - ord('1');
6068 if g_Game_IsServer
then
6070 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
6071 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
6074 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6076 // Команды Своей игры:
6077 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6079 if cmd
= 'bot_addred' then
6081 if Length(P
) > 1 then
6082 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6084 g_Bot_Add(TEAM_RED
, 2);
6086 else if cmd
= 'bot_addblue' then
6088 if Length(P
) > 1 then
6089 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6091 g_Bot_Add(TEAM_BLUE
, 2);
6093 else if cmd
= 'spectate' then
6099 else if cmd
= 'say' then
6101 if g_Game_IsServer
and g_Game_IsNet
then
6103 if Length(P
) > 1 then
6106 for a
:= 1 to High(P
) do
6107 chstr
:= chstr
+ P
[a
] + ' ';
6109 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6111 if Length(chstr
) < 1 then
6113 g_Console_Add('say <text>');
6117 chstr
:= b_Text_Format(chstr
);
6118 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6120 else g_Console_Add('say <text>');
6122 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6124 else if cmd
= 'tell' then
6126 if g_Game_IsServer
and g_Game_IsNet
then
6128 if (Length(P
) > 2) and (P
[1] <> '') then
6131 for a
:= 2 to High(P
) do
6132 chstr
:= chstr
+ P
[a
] + ' ';
6134 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6136 if Length(chstr
) < 1 then
6138 g_Console_Add('tell <playername> <text>');
6142 pl
:= g_Net_Client_ByName(P
[1]);
6144 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6146 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6148 else g_Console_Add('tell <playername> <text>');
6150 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6152 else if cmd
= 'centerprint' then
6154 if (Length(P
) > 2) and (P
[1] <> '') then
6157 for a
:= 2 to High(P
) do
6158 chstr
:= chstr
+ P
[a
] + ' ';
6160 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6162 if Length(chstr
) < 1 then
6164 g_Console_Add('centerprint <timeout> <text>');
6168 a
:= StrToIntDef(P
[1], 100);
6169 chstr
:= b_Text_Format(chstr
);
6170 g_Game_Message(chstr
, a
);
6171 if g_Game_IsNet
and g_Game_IsServer
then
6172 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6174 else g_Console_Add('centerprint <timeout> <text>');
6176 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6178 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6180 // Дополнительное время:
6181 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6183 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6184 [gGameSettings
.TimeLimit
div 3600,
6185 (gGameSettings
.TimeLimit
div 60) mod 60,
6186 gGameSettings
.TimeLimit
mod 60]));
6187 if g_Game_IsNet
then MH_SEND_GameSettings
;
6189 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6191 if (Length(P
) <= 1) then
6192 g_Console_Add('rcon_password <password>')
6194 MC_SEND_RCONPassword(P
[1]);
6196 else if cmd
= 'rcon' then
6198 if g_Game_IsClient
then
6200 if Length(P
) > 1 then
6203 for a
:= 1 to High(P
) do
6204 chstr
:= chstr
+ P
[a
] + ' ';
6206 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6208 if Length(chstr
) < 1 then
6210 g_Console_Add('rcon <command>');
6214 MC_SEND_RCONCommand(chstr
);
6216 else g_Console_Add('rcon <command>');
6219 else if cmd
= 'ready' then
6221 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6222 gLMSRespawnTime
:= gTime
+ 100;
6224 else if (cmd
= 'callvote') and g_Game_IsNet
then
6226 if Length(P
) > 1 then
6229 for a
:= 1 to High(P
) do begin
6230 if a
> 1 then chstr
:= chstr
+ ' ';
6231 chstr
:= chstr
+ P
[a
];
6234 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6236 if Length(chstr
) < 1 then
6238 g_Console_Add('callvote <command>');
6242 if g_Game_IsClient
then
6243 MC_SEND_Vote(True, chstr
)
6245 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6246 g_Console_Process('vote', True);
6249 g_Console_Add('callvote <command>');
6251 else if (cmd
= 'vote') and g_Game_IsNet
then
6253 if g_Game_IsClient
then
6255 else if gVoteInProgress
then
6257 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6258 a
:= Floor((NetClientCount
+1)/2.0) + 1
6260 a
:= Floor(NetClientCount
/2.0) + 1;
6265 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6266 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6272 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6273 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6281 procedure SystemCommands(P
: SSArray
);
6285 cmd
:= LowerCase(P
[0]);
6292 {$IFDEF ENABLE_RENDER}
6298 if Length(p
) = 2 then
6300 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6302 gFrameTime
:= 1000 div gMaxFPS
6306 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6310 if Length(p
) = 2 then
6312 gAskLanguage
:= true;
6313 gLanguage
:= LANGUAGE_ENGLISH
;
6314 case LowerCase(p
[1]) of
6317 gAskLanguage
:= false;
6318 gLanguage
:= LANGUAGE_ENGLISH
;
6322 gAskLanguage
:= false;
6323 gLanguage
:= LANGUAGE_RUSSIAN
;
6327 gAskLanguage
:= true;
6328 gLanguage
:= LANGUAGE_ENGLISH
;
6331 g_Language_Set(gLanguage
);
6335 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6341 {$IFDEF ENABLE_RENDER}
6342 procedure g_TakeScreenShot(Filename
: string = '');
6343 var t
: TDateTime
; dir
, date
, name
: String;
6345 if e_NoGraphics
then
6348 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6349 if Filename
= '' then
6352 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6353 Filename
:= 'screenshot-' + date
;
6356 name
:= e_CatPath(dir
, Filename
+ '.png');
6357 if r_Render_WriteScreenShot(name
) then
6358 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6360 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6364 {$IFDEF ENABLE_MENU}
6365 procedure g_Game_InGameMenu(Show
: Boolean);
6367 if (g_ActiveWindow
= nil) and Show
then
6369 if gGameSettings
.GameType
= GT_SINGLE
then
6370 g_GUI_ShowWindow('GameSingleMenu')
6373 if g_Game_IsClient
then
6374 g_GUI_ShowWindow('GameClientMenu')
6376 if g_Game_IsNet
then
6377 g_GUI_ShowWindow('GameServerMenu')
6379 g_GUI_ShowWindow('GameCustomMenu');
6381 g_Sound_PlayEx('MENU_OPEN');
6383 // Пауза при меню только в одиночной игре:
6384 if (not g_Game_IsNet
) then
6388 if (g_ActiveWindow
<> nil) and (not Show
) then
6390 // Пауза при меню только в одиночной игре:
6391 if (not g_Game_IsNet
) then
6392 g_Game_Pause(False);
6397 procedure g_Game_Pause (Enable
: Boolean);
6401 if not gGameOn
then exit
;
6403 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6406 gPauseMain
:= Enable
;
6408 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6411 procedure g_Game_HolmesPause (Enable
: Boolean);
6415 if not gGameOn
then exit
;
6416 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6419 gPauseHolmes
:= Enable
;
6421 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6424 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6429 if gTriggers
<> nil then
6430 for i
:= 0 to High(gTriggers
) do
6431 with gTriggers
[i
] do
6432 if (TriggerType
= TRIGGER_SOUND
) and
6434 Sound
.IsPlaying() then
6436 Sound
.Pause(Enable
);
6440 if gPlayers
<> nil then
6441 for i
:= 0 to High(gPlayers
) do
6442 if gPlayers
[i
] <> nil then
6443 gPlayers
[i
].PauseSounds(Enable
);
6446 if gMusic
<> nil then
6447 gMusic
.Pause(Enable
);
6450 procedure g_Game_StopAllSounds(all
: Boolean);
6454 if gTriggers
<> nil then
6455 for i
:= 0 to High(gTriggers
) do
6456 with gTriggers
[i
] do
6457 if (TriggerType
= TRIGGER_SOUND
) and
6461 if gMusic
<> nil then
6468 procedure g_Game_UpdateTriggerSounds
;
6471 if gTriggers
<> nil then
6472 for i
:= 0 to High(gTriggers
) do
6473 with gTriggers
[i
] do
6474 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6475 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6478 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6481 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6486 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6491 if gSpectMode
<> SPECT_PLAYERS
then
6493 if gSpectPID1
= UID
then
6498 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6505 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6510 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6515 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6520 if gSpectMode
<> SPECT_PLAYERS
then
6522 Pl
:= g_Player_Get(gSpectPID1
);
6523 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6528 if gSpectViewTwo
then
6530 Pl
:= g_Player_Get(gSpectPID2
);
6531 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6539 procedure g_Game_Message (Msg
: string; Time
: Word);
6542 MessageTime
:= Time
;
6545 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6547 punct
: Array[0..13] of String =
6548 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6554 function IsPunctuation(S
: String): Boolean;
6559 if Length(S
) <> 1 then
6561 for i
:= Low(punct
) to High(punct
) do
6562 if S
= punct
[i
] then
6568 function FilterPunctuation(S
: String): String;
6572 for i
:= Low(punct
) to High(punct
) do
6573 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6579 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6581 // remove player name
6582 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6583 // for FullWord check
6584 Text := toLowerCase1251(' ' + Text + ' ');
6585 fpText
:= FilterPunctuation(Text);
6587 for i
:= 0 to Length(gChatSounds
) - 1 do
6590 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6592 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6593 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6595 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6601 gChatSounds
[i
].Sound
.Play();
6607 g_Sound_PlayEx('SOUND_GAME_RADIO');
6610 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6619 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6623 if goodsnd
[a
].IsPlaying() then
6626 goodsnd
[Random(4)].Play();
6629 procedure g_Game_Announce_KillCombo(Param
: Integer);
6636 UID
:= Param
and $FFFF;
6641 Pl
:= g_Player_Get(UID
);
6650 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6654 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6658 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6662 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6670 if not g_Game_IsWatchedPlayer(UID
) then
6673 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6677 if killsnd
[n
].IsPlaying() then
6682 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6690 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6694 if hahasnd
[a
].IsPlaying() then
6697 hahasnd
[Random(3)].Play();
6700 procedure g_Game_StartVote(Command
, Initiator
: string);
6704 if not gVotesEnabled
then Exit
;
6705 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6706 if gVoteInProgress
or gVotePassed
then
6708 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6709 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6712 gVoteInProgress
:= True;
6713 gVotePassed
:= False;
6714 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6717 gVoteCommand
:= Command
;
6719 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6720 Need
:= Floor((NetClientCount
+1)/2.0)+1
6722 Need
:= Floor(NetClientCount
/2.0)+1;
6723 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6724 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6727 procedure g_Game_CheckVote
;
6731 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6732 if not gVoteInProgress
then Exit
;
6734 if (gTime
>= gVoteTimer
) then
6736 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6737 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6739 Need
:= Floor(NetClientCount
/2.0) + 1;
6740 if gVoteCount
>= Need
then
6742 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6743 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6744 gVotePassed
:= True;
6745 gVoteCmdTimer
:= gTime
+ 5000;
6749 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6750 MH_SEND_VoteEvent(NET_VE_FAILED
);
6752 if NetClients
<> nil then
6753 for I
:= Low(NetClients
) to High(NetClients
) do
6754 if NetClients
[i
].Used
then
6755 NetClients
[i
].Voted
:= False;
6756 gVoteInProgress
:= False;
6762 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6763 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6765 Need
:= Floor(NetClientCount
/2.0) + 1;
6766 if gVoteCount
>= Need
then
6768 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6769 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6770 gVoteInProgress
:= False;
6771 gVotePassed
:= True;
6772 gVoteCmdTimer
:= gTime
+ 5000;
6775 if NetClients
<> nil then
6776 for I
:= Low(NetClients
) to High(NetClients
) do
6777 if NetClients
[i
].Used
then
6778 NetClients
[i
].Voted
:= False;
6783 procedure g_Game_LoadMapList(FileName
: string);
6791 if not FileExists(FileName
) then Exit
;
6793 AssignFile(ListFile
, FileName
);
6795 while not EOF(ListFile
) do
6797 ReadLn(ListFile
, s
);
6800 if s
= '' then Continue
;
6802 SetLength(MapList
, Length(MapList
)+1);
6803 MapList
[High(MapList
)] := s
;
6805 CloseFile(ListFile
);
6808 procedure g_Game_SetDebugMode();
6811 // Читы (даже в своей игре):
6815 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6819 if Length(LoadingStat
.Msgs
) = 0 then
6825 begin // Переходим на следующую строку или скроллируем:
6826 if NextMsg
= Length(Msgs
) then
6828 for i
:= 0 to High(Msgs
)-1 do
6829 Msgs
[i
] := Msgs
[i
+1];
6837 Msgs
[NextMsg
-1] := Text;
6841 PBarWasHere
:= false;
6844 {$IFDEF ENABLE_MENU}
6845 g_ActiveWindow
:= nil;
6848 ProcessLoading(true);
6851 procedure g_Game_StepLoading(Value
: Integer = -1);
6863 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6866 ProcessLoading(False);
6871 procedure g_Game_ClearLoading();
6880 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6881 if len
< 1 then len
:= 1;
6882 SetLength(Msgs
, len
);
6883 for len
:= Low(Msgs
) to High(Msgs
) do
6886 PBarWasHere
:= false;
6890 procedure Parse_Params(var pars
: TParamStrValues
);
6897 while i
<= ParamCount
do
6900 if (Length(s
) > 1) and (s
[1] = '-') then
6902 if (Length(s
) > 2) and (s
[2] = '-') then
6903 begin // Одиночный параметр
6904 SetLength(pars
, Length(pars
) + 1);
6905 with pars
[High(pars
)] do
6907 Name
:= LowerCase(s
);
6912 if (i
< ParamCount
) then
6913 begin // Параметр со значением
6915 SetLength(pars
, Length(pars
) + 1);
6916 with pars
[High(pars
)] do
6918 Name
:= LowerCase(s
);
6919 Value
:= LowerCase(ParamStr(i
));
6928 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6933 for i
:= 0 to High(pars
) do
6934 if pars
[i
].Name
= aName
then
6936 Result
:= pars
[i
].Value
;
6941 procedure g_Game_Process_Params();
6943 pars
: TParamStrValues
;
6946 LimT
, LimS
: Integer;
6957 s
:= Find_Param_Value(pars
, '--debug');
6960 g_Game_SetDebugMode();
6961 s
:= Find_Param_Value(pars
, '--netdump');
6966 // Connect when game loads
6967 ip
:= Find_Param_Value(pars
, '-connect');
6971 s
:= Find_Param_Value(pars
, '-port');
6972 if (s
= '') or not TryStrToInt(s
, Port
) then
6975 s
:= Find_Param_Value(pars
, '-pw');
6977 g_Game_StartClient(ip
, Port
, s
);
6981 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6984 gDefaultMegawadStart
:= s
;
6987 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6988 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6990 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6993 // Start map when game loads:
6994 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6995 if isWadPath(map
) then
6998 s
:= Find_Param_Value(pars
, '-gm');
6999 GMode
:= g_Game_TextToMode(s
);
7000 if GMode
= GM_NONE
then GMode
:= GM_DM
;
7001 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
7004 s
:= Find_Param_Value(pars
, '-limt');
7005 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
7011 s
:= Find_Param_Value(pars
, '-lims');
7012 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
7018 s
:= Find_Param_Value(pars
, '-lives');
7019 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
7025 s
:= Find_Param_Value(pars
, '-opt');
7029 Opt
:= StrToIntDef(s
, 0);
7032 s
:= Find_Param_Value(pars
, '--close');
7036 // Override map to test:
7037 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
7040 if e_IsValidResourceName(s
) then
7041 e_FindResource(AllMapDirs
, s
);
7042 gTestMap
:= ExpandFileName(s
);
7045 // Delete test map after play:
7046 s
:= Find_Param_Value(pars
, '--testdelete');
7049 //gMapToDelete := MapsDir + map;
7050 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
7054 // Delete temporary WAD after play:
7055 s
:= Find_Param_Value(pars
, '--tempdelete');
7056 if (s
<> '') and (gTestMap
<> '') then
7058 gMapToDelete
:= gTestMap
;
7059 gTempDelete
:= True;
7062 // Number of players:
7063 s
:= Find_Param_Value(pars
, '-pl');
7065 n
:= DEFAULT_PLAYERS
7067 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
7070 s
:= Find_Param_Value(pars
, '-port');
7071 if (s
= '') or not TryStrToInt(s
, Port
) then
7072 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
7074 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
7077 // Execute script when game loads:
7078 s
:= Find_Param_Value(pars
, '-exec');
7081 // if not isWadPath(s) then
7082 // s := GameDir + '/' + s;
7087 if IOResult
<> 0 then
7089 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7090 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7094 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
7095 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7100 if IOResult
<> 0 then
7102 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7103 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7107 if Pos('#', s
) <> 1 then // script comment
7108 g_Console_Process(s
, True);
7119 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7120 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7121 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7122 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7124 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7125 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7126 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7127 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7130 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7131 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7134 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7135 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7137 {$IFDEF ENABLE_HOLMES}
7138 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7141 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7143 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7144 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7146 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7147 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7149 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
7150 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
7151 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
7152 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
7153 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7154 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7155 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7156 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7157 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');