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}
23 g_base
, g_basic
, g_player
, g_res_downloader
,
24 g_sound
, g_gui
, utils
, md5
, mempool
, xprofiler
,
28 TGameSettings
= record
35 ItemRespawnTime
: Word;
46 TDelayedEvent
= record
55 Sound
: TPlayableSound
;
56 Tags
: Array of String;
60 TPlayerSettings
= record
79 function g_Game_IsNet(): Boolean;
80 function g_Game_IsServer(): Boolean;
81 function g_Game_IsClient(): Boolean;
82 procedure g_Game_Init();
83 procedure g_Game_Free (freeTextures
: Boolean=true);
84 procedure g_Game_LoadData();
85 procedure g_Game_FreeData();
86 procedure g_Game_Update();
87 procedure g_Game_PreUpdate();
88 procedure g_Game_Quit();
89 function g_Game_ModeToText(Mode
: Byte): string;
90 function g_Game_TextToMode(Mode
: string): Byte;
91 procedure g_Game_ExecuteEvent(Name
: String);
92 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
93 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
94 procedure g_Game_RemovePlayer();
95 procedure g_Game_Spectate();
96 procedure g_Game_SpectateCenterView();
97 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
98 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
99 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
100 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
101 procedure g_Game_Restart();
102 procedure g_Game_RestartLevel();
103 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
104 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
105 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
106 procedure g_Game_ChangeMap(const MapPath
: String);
107 procedure g_Game_ExitLevel(const Map
: AnsiString);
108 function g_Game_GetFirstMap(WAD
: String): String;
109 function g_Game_GetNextMap(): String;
110 procedure g_Game_NextLevel();
111 procedure g_Game_Pause(Enable
: Boolean);
112 procedure g_Game_HolmesPause(Enable
: Boolean);
113 procedure g_Game_InGameMenu(Show
: Boolean);
114 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
115 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
116 procedure g_Game_Message(Msg
: String; Time
: Word);
117 procedure g_Game_LoadMapList(FileName
: String);
118 procedure g_Game_PauseAllSounds(Enable
: Boolean);
119 procedure g_Game_StopAllSounds(all
: Boolean);
120 procedure g_Game_UpdateTriggerSounds();
121 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
122 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
123 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
124 procedure g_Game_Announce_KillCombo(Param
: Integer);
125 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
126 procedure g_Game_StartVote(Command
, Initiator
: string);
127 procedure g_Game_CheckVote
;
128 procedure g_TakeScreenShot(Filename
: string = '');
129 procedure g_FatalError(Text: String);
130 procedure g_SimpleError(Text: String);
131 function g_Game_IsTestMap(): Boolean;
132 procedure g_Game_DeleteTestMap();
133 procedure GameCVars(P
: SSArray
);
134 procedure PlayerSettingsCVars(P
: SSArray
);
135 procedure SystemCommands(P
: SSArray
);
136 procedure GameCommands(P
: SSArray
);
137 procedure GameCheats(P
: SSArray
);
138 procedure DebugCommands(P
: SSArray
);
139 procedure g_Game_Process_Params
;
140 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
141 procedure g_Game_StepLoading(Value
: Integer = -1);
142 procedure g_Game_ClearLoading();
143 procedure g_Game_SetDebugMode();
145 function IsActivePlayer(p
: TPlayer
): Boolean;
146 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
147 procedure SortGameStat(var stat
: TPlayerStatArray
);
149 procedure KeyPress (K
: Word);
150 procedure CharPress (C
: AnsiChar);
152 { procedure SetWinPause(Enable: Boolean); }
157 LOADING_SHOW_STEP
= 100;
158 LOADING_INTERLINE
= 20;
173 MESSAGE_DIKEY
= WM_USER
+ 1;
178 EXIT_ENDLEVELSINGLE
= 4;
179 EXIT_ENDLEVELCUSTOM
= 5;
181 GAME_OPTION_RESERVED
= 1;
182 GAME_OPTION_TEAMDAMAGE
= 2;
183 GAME_OPTION_ALLOWEXIT
= 4;
184 GAME_OPTION_WEAPONSTAY
= 8;
185 GAME_OPTION_MONSTERS
= 16;
186 GAME_OPTION_BOTVSPLAYER
= 32;
187 GAME_OPTION_BOTVSMONSTER
= 64;
188 GAME_OPTION_DMKEYS
= 128;
189 GAME_OPTION_TEAMHITTRACE
= 256;
190 GAME_OPTION_TEAMHITPROJECTILE
= 512;
191 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
196 STATE_INTERCUSTOM
= 3;
197 STATE_INTERSINGLE
= 4;
203 LMS_RESPAWN_NONE
= 0;
204 LMS_RESPAWN_WARMUP
= 1;
205 LMS_RESPAWN_FINAL
= 2;
222 CONFIG_FILENAME
= 'Doom2DF.cfg';
224 TEST_MAP_NAME
= '$$$_TEST_$$$';
226 STD_PLAYER_MODEL
= 'Doomer';
234 STATFILE_VERSION
= $03;
237 gGameSettings
: TGameSettings
;
238 gPlayer1Settings
: TPlayerSettings
;
239 gPlayer2Settings
: TPlayerSettings
;
241 gPlayerScreenSize
: TDFPoint
;
242 gPlayer1ScreenCoord
: TDFPoint
;
243 gPlayer2ScreenCoord
: TDFPoint
;
244 gPlayer1
: TPlayer
= nil;
245 gPlayer2
: TPlayer
= nil;
246 gPlayerDrawn
: TPlayer
= nil;
248 gLerpFactor
: Single = 1.0;
249 gSwitchGameMode
: Byte = GM_DM
;
250 gHearPoint1
, gHearPoint2
: THearPoint
;
251 gSoundEffectsDF
: Boolean = False;
252 gSoundTriggerTime
: Word = 0;
253 gAnnouncer
: Integer = ANNOUNCE_NONE
;
254 goodsnd
: array[0..3] of TPlayableSound
;
255 killsnd
: array[0..3] of TPlayableSound
;
256 hahasnd
: array[0..2] of TPlayableSound
;
257 sound_get_flag
: array[0..1] of TPlayableSound
;
258 sound_lost_flag
: array[0..1] of TPlayableSound
;
259 sound_ret_flag
: array[0..1] of TPlayableSound
;
260 sound_cap_flag
: array[0..1] of TPlayableSound
;
261 gBodyKillEvent
: Integer = -1;
262 gDefInterTime
: ShortInt = -1;
263 gInterEndTime
: LongWord = 0;
264 gInterTime
: LongWord = 0;
265 gServInterTime
: Byte = 0;
266 gGameStartTime
: LongWord = 0;
267 gTotalMonsters
: Integer = 0;
268 gPauseMain
: Boolean = false;
269 gPauseHolmes
: Boolean = false;
270 gShowTime
: Boolean = False;
271 gShowFPS
: Boolean = False;
272 gShowGoals
: Boolean = True;
273 gShowStat
: Boolean = True;
274 gShowPIDs
: Boolean = False;
275 gShowKillMsg
: Boolean = True;
276 gShowLives
: Boolean = True;
277 gShowPing
: Boolean = False;
278 gShowMap
: Boolean = False;
280 gState
: Byte = STATE_NONE
;
282 sWidth
, sHeight
: Word;
283 gSpectMode
: Byte = SPECT_NONE
;
284 gSpectHUD
: Boolean = True;
285 gSpectKeyPress
: Boolean = False;
286 gSpectX
: Integer = 0;
287 gSpectY
: Integer = 0;
288 gSpectStep
: Byte = 8;
289 gSpectViewTwo
: Boolean = False;
290 gSpectPID1
: Integer = -1;
291 gSpectPID2
: Integer = -1;
292 gSpectAuto
: Boolean = False;
293 gSpectAutoNext
: LongWord;
294 gSpectAutoStepX
: Integer;
295 gSpectAutoStepY
: Integer;
296 gMusic
: TMusic
= nil;
297 gLoadGameMode
: Boolean;
298 gCheats
: Boolean = False;
299 gMapOnce
: Boolean = False;
300 gMapToDelete
: String;
301 gTempDelete
: Boolean = False;
302 gLastMap
: Boolean = False;
305 gResolutionChange
: Boolean = False;
306 gRC_Width
, gRC_Height
: Integer;
307 gRC_FullScreen
, gRC_Maximized
: Boolean;
308 gLanguageChange
: Boolean = False;
309 gDebugMode
: Boolean = False;
310 g_debug_Sounds
: Boolean = False;
311 g_debug_Frames
: Boolean = False;
312 g_debug_WinMsgs
: Boolean = False;
313 g_debug_MonsterOff
: Boolean = False;
314 g_debug_BotAIOff
: Byte = 0;
315 g_debug_HealthBar
: Boolean = False;
316 g_Debug_Player
: Boolean = False;
317 gCoopMonstersKilled
: Word = 0;
318 gCoopSecretsFound
: Word = 0;
319 gCoopTotalMonstersKilled
: Word = 0;
320 gCoopTotalSecretsFound
: Word = 0;
321 gCoopTotalMonsters
: Word = 0;
322 gCoopTotalSecrets
: Word = 0;
323 gStatsOff
: Boolean = False;
324 gStatsPressed
: Boolean = False;
325 gExitByTrigger
: Boolean = False;
326 gNextMap
: String = '';
327 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
328 gLMSRespawnTime
: Cardinal = 0;
329 gLMSSoftSpawn
: Boolean = False;
330 gMissionFailed
: Boolean = False;
331 gVoteInProgress
: Boolean = False;
332 gVotePassed
: Boolean = False;
333 gVoteCommand
: string = '';
334 gVoteTimer
: Cardinal = 0;
335 gVoteCmdTimer
: Cardinal = 0;
336 gVoteCount
: Integer = 0;
337 gVoteTimeout
: Cardinal = 30;
338 gVoted
: Boolean = False;
339 gVotesEnabled
: Boolean = True;
340 gEvents
: Array of TGameEvent
;
341 gDelayedEvents
: Array of TDelayedEvent
;
342 gUseChatSounds
: Boolean = True;
343 gChatSounds
: Array of TChatSound
;
344 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
345 gInterReadyCount
: Integer = 0;
347 g_dbg_ignore_bounds
: Boolean = false;
348 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
349 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
351 // move button values:
352 // bits 0-1: l/r state:
353 // 0: neither left, nor right pressed
356 // bits 4-5: l/r state when strafe was pressed
357 P1MoveButton
: Byte = 0;
358 P2MoveButton
: Byte = 0;
360 g_profile_frame_update
: Boolean = false;
361 g_profile_frame_draw
: Boolean = false;
362 g_profile_collision
: Boolean = false;
363 g_profile_los
: Boolean = false;
364 g_profile_history_size
: Integer = 1000;
366 g_rlayer_back
: Boolean = true;
367 g_rlayer_step
: Boolean = true;
368 g_rlayer_wall
: Boolean = true;
369 g_rlayer_door
: Boolean = true;
370 g_rlayer_acid1
: Boolean = true;
371 g_rlayer_acid2
: Boolean = true;
372 g_rlayer_water
: Boolean = true;
373 g_rlayer_fore
: Boolean = true;
375 wNeedTimeReset
: Boolean = false;
377 procedure g_ResetDynlights ();
378 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
379 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
381 function conIsCheatsEnabled (): Boolean; inline;
382 function gPause (): Boolean; inline;
384 type (* private state *)
385 TEndCustomGameStat
= record
386 PlayerStat
: TPlayerStatArray
;
390 Map
, MapName
: String;
393 TEndSingleGameStat
= record
394 PlayerStat
: Array [0..1] of record
400 TotalSecrets
: Integer;
403 TLoadingStat
= record
407 Msgs
: Array of String;
409 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
413 x
, y
, radius
: Integer;
416 exploRadius
: Integer;
419 var (* private state *)
420 CustomStat
: TEndCustomGameStat
;
421 StatShotDone
: Boolean;
422 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
423 SingleStat
: TEndSingleGameStat
;
424 LoadingStat
: TLoadingStat
;
427 EndingGameCounter
: Byte;
429 g_playerLight
: Boolean;
430 g_dynLights
: array of TDynLight
= nil;
431 g_dynLightCount
: Integer = 0;
432 EndPicPath
: AnsiString; // full path, used by render
437 {$IFDEF ENABLE_HOLMES}
440 e_res
, g_window
, g_menu
, r_render
, r_gfx
,
441 e_input
, e_log
, g_console
, r_console
, g_items
, g_map
, g_panel
,
442 g_playermodel
, g_gfx
, g_options
, Math
,
443 g_triggers
, g_monsters
, e_sound
, CONFIG
,
444 g_language
, g_net
, g_phys
,
445 ENet
, e_msg
, g_netmsg
, g_netmaster
,
446 sfs
, wadreader
, g_system
, r_playermodel
;
449 charbuff
: packed array [0..15] of AnsiChar = (
450 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
453 function Translit (const S
: AnsiString): AnsiString;
458 for i
:= 1 to Length(Result
) do
461 #
$C9: Result
[i
] := 'Q';
462 #
$D6: Result
[i
] := 'W';
463 #
$D3: Result
[i
] := 'E';
464 #
$CA: Result
[i
] := 'R';
465 #
$C5: Result
[i
] := 'T';
466 #
$CD: Result
[i
] := 'Y';
467 #
$C3: Result
[i
] := 'U';
468 #
$D8: Result
[i
] := 'I';
469 #
$D9: Result
[i
] := 'O';
470 #
$C7: Result
[i
] := 'P';
471 #
$D5: Result
[i
] := '['; //Chr(219);
472 #
$DA: Result
[i
] := ']'; //Chr(221);
473 #
$D4: Result
[i
] := 'A';
474 #
$DB: Result
[i
] := 'S';
475 #
$C2: Result
[i
] := 'D';
476 #
$C0: Result
[i
] := 'F';
477 #
$CF: Result
[i
] := 'G';
478 #
$D0: Result
[i
] := 'H';
479 #
$CE: Result
[i
] := 'J';
480 #
$CB: Result
[i
] := 'K';
481 #
$C4: Result
[i
] := 'L';
482 #
$C6: Result
[i
] := ';'; //Chr(186);
483 #
$DD: Result
[i
] := #39; //Chr(222);
484 #
$DF: Result
[i
] := 'Z';
485 #
$D7: Result
[i
] := 'X';
486 #
$D1: Result
[i
] := 'C';
487 #
$CC: Result
[i
] := 'V';
488 #
$C8: Result
[i
] := 'B';
489 #
$D2: Result
[i
] := 'N';
490 #
$DC: Result
[i
] := 'M';
491 #
$C1: Result
[i
] := ','; //Chr(188);
492 #
$DE: Result
[i
] := '.'; //Chr(190);
498 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
503 ls2
:= Translit(CheatRus
[ct
]);
504 if length(ls1
) = 0 then ls1
:= '~';
505 if length(ls2
) = 0 then ls2
:= '~';
507 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
508 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
509 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
510 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
512 if ct = I_GAME_CHEAT_JETPACK then
514 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
515 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
516 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
517 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
518 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
519 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
535 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
536 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
537 or g_Game_IsNet then Exit;
539 if not gGameOn
then exit
;
540 if not conIsCheatsEnabled
then exit
;
542 s
:= 'SOUND_GAME_RADIO';
545 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
547 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
548 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
552 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
554 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
555 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
559 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
561 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
562 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
566 if CheckCheat(I_GAME_CHEAT_DEATH
) then
568 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
569 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
570 s
:= 'SOUND_MONSTER_HAHA';
574 if CheckCheat(I_GAME_CHEAT_DOORS
) then
576 g_Triggers_OpenAll();
580 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
582 if gTriggers
<> nil then
583 for a
:= 0 to High(gTriggers
) do
584 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
586 gExitByTrigger
:= True;
587 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
588 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
594 s2
:= Copy(charbuff
, 15, 2);
595 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
597 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
605 if CheckCheat(I_GAME_CHEAT_FLY
) then
611 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
613 VEL_JUMP
:= 30-VEL_JUMP
;
617 if CheckCheat(I_GAME_CHEAT_SPEED
) then
619 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
623 if CheckCheat(I_GAME_CHEAT_SUIT
) then
625 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
626 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
630 if CheckCheat(I_GAME_CHEAT_AIR
) then
632 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
633 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
637 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
639 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
640 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
644 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
646 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
647 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
651 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
653 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
654 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
658 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
660 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
661 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
665 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
667 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
668 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
671 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
673 gAimLine
:= not gAimLine
;
676 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
678 gShowMap
:= not gShowMap
;
688 procedure KeyPress (K
: Word);
698 if (g_ActiveWindow
<> nil) then
700 Msg
.Msg
:= WM_KEYDOWN
;
701 Msg
.WParam
:= VK_ESCAPE
;
702 g_ActiveWindow
.OnMessage(Msg
);
703 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
705 else if (gState
<> STATE_FOLD
) then
707 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
709 g_Game_InGameMenu(True);
711 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
713 if (gState
<> STATE_MENU
) then
715 if (NetMode
<> NET_NONE
) then
717 g_Game_StopAllSounds(True);
719 gState
:= STATE_MENU
;
723 g_GUI_ShowWindow('MainMenu');
724 g_Sound_PlayEx('MENU_OPEN');
729 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
730 begin // <F2> .. <F6> � <F12>
731 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
733 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
734 if (not g_Game_IsNet
) then g_Game_Pause(True);
736 IK_F2
: g_Menu_Show_SaveMenu();
737 IK_F3
: g_Menu_Show_LoadMenu();
738 IK_F4
: g_Menu_Show_GameSetGame();
739 IK_F5
: g_Menu_Show_OptionsVideo();
740 IK_F6
: g_Menu_Show_OptionsSound();
741 IK_F7
: g_Menu_Show_EndGameMenu();
742 IK_F10
: g_Menu_Show_QuitGameMenu();
749 gJustChatted
:= False;
750 if gConsoleShow
or gChatShow
then
752 g_Console_Control(K
);
754 else if (g_ActiveWindow
<> nil) then
756 Msg
.Msg
:= WM_KEYDOWN
;
758 g_ActiveWindow
.OnMessage(Msg
);
760 else if (gState
= STATE_MENU
) then
762 g_GUI_ShowWindow('MainMenu');
763 g_Sound_PlayEx('MENU_OPEN');
770 procedure CharPress (C
: AnsiChar);
775 if gConsoleShow
or gChatShow
then
779 else if (g_ActiveWindow
<> nil) then
782 Msg
.WParam
:= Ord(C
);
783 g_ActiveWindow
.OnMessage(Msg
);
787 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
788 charbuff
[15] := upcase1251(C
);
794 // ////////////////////////////////////////////////////////////////////////// //
795 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
797 procedure g_ResetDynlights ();
801 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
803 for idx
:= 0 to g_dynLightCount
-1 do
805 if g_dynLights
[idx
].exploCount
= -666 then
812 Inc(g_dynLights
[idx
].exploCount
);
813 if (g_dynLights
[idx
].exploCount
< 10) then
815 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
816 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
817 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
818 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
823 g_dynLightCount
:= lnum
;
826 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
828 if not gwin_has_stencil
then exit
;
829 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
830 g_dynLights
[g_dynLightCount
].x
:= x
;
831 g_dynLights
[g_dynLightCount
].y
:= y
;
832 g_dynLights
[g_dynLightCount
].radius
:= radius
;
833 g_dynLights
[g_dynLightCount
].r
:= r
;
834 g_dynLights
[g_dynLightCount
].g
:= g
;
835 g_dynLights
[g_dynLightCount
].b
:= b
;
836 g_dynLights
[g_dynLightCount
].a
:= a
;
837 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
838 Inc(g_dynLightCount
);
841 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
843 if not gwin_has_stencil
then exit
;
844 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
845 g_dynLights
[g_dynLightCount
].x
:= x
;
846 g_dynLights
[g_dynLightCount
].y
:= y
;
847 g_dynLights
[g_dynLightCount
].radius
:= 0;
848 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
849 g_dynLights
[g_dynLightCount
].r
:= r
;
850 g_dynLights
[g_dynLightCount
].g
:= g
;
851 g_dynLights
[g_dynLightCount
].b
:= b
;
852 g_dynLights
[g_dynLightCount
].a
:= 0;
853 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
854 Inc(g_dynLightCount
);
857 // ////////////////////////////////////////////////////////////////////////// //
858 function conIsCheatsEnabled (): Boolean; inline;
861 if g_Game_IsNet
then exit
;
862 if not gDebugMode
then
864 //if not gCheats then exit;
865 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
866 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
871 // ////////////////////////////////////////////////////////////////////////// //
873 TParamStrValue
= record
878 TParamStrValues
= Array of TParamStrValue
;
881 INTER_ACTION_TEXT
= 1;
882 INTER_ACTION_PIC
= 2;
883 INTER_ACTION_MUSIC
= 3;
888 DataLoaded
: Boolean = False;
890 MapList
: SSArray
= nil;
891 MapIndex
: Integer = -1;
892 InterReadyTime
: Integer = -1;
893 StatDate
: string = '';
908 function Compare(a
, b
: TPlayerStat
): Integer;
910 if a
.Spectator
then Result
:= 1
911 else if b
.Spectator
then Result
:= -1
912 else if a
.Frags
< b
.Frags
then Result
:= 1
913 else if a
.Frags
> b
.Frags
then Result
:= -1
914 else if a
.Deaths
< b
.Deaths
then Result
:= -1
915 else if a
.Deaths
> b
.Deaths
then Result
:= 1
916 else if a
.Kills
< b
.Kills
then Result
:= -1
920 procedure SortGameStat(var stat
: TPlayerStatArray
);
925 if stat
= nil then Exit
;
927 for I
:= High(stat
) downto Low(stat
) do
928 for J
:= Low(stat
) to High(stat
) - 1 do
929 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
932 stat
[J
] := stat
[J
+ 1];
937 // saves a shitty CSV containing the game stats passed to it
938 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
941 dir
, fname
, map
, mode
, etime
: String;
945 dir
:= e_GetWriteableDir(StatsDirs
);
946 // stats are placed in stats/yy/mm/dd/*.csv
947 fname
:= e_CatPath(dir
, Path
);
948 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
949 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
950 AssignFile(s
, fname
);
953 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
954 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
955 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
956 mode
:= g_Game_ModeToText(Stat
.GameMode
);
957 etime
:= Format('%d:%.2d:%.2d', [
958 Stat
.GameTime
div 1000 div 3600,
959 (Stat
.GameTime
div 1000 div 60) mod 60,
960 Stat
.GameTime
div 1000 mod 60
962 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
963 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
969 gGameSettings
.TimeLimit
,
970 gGameSettings
.GoalLimit
,
971 gGameSettings
.Options
,
973 Length(Stat
.PlayerStat
)
975 // line 2: game specific shit
976 // if it's a team game: red score, blue score
977 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
979 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
981 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
982 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
984 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
985 // lines 3-...: team, player name, frags, deaths
986 WriteLn(s
, 'team,name,frags,deaths');
987 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
988 with Stat
.PlayerStat
[I
] do
989 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
991 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
994 g_Console_Add('could not create gamestats file "' + fname
+ '"');
999 function g_Game_ModeToText(Mode
: Byte): string;
1003 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1004 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1005 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1006 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1007 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1011 function g_Game_TextToMode(Mode
: string): Byte;
1014 Mode
:= UpperCase(Mode
);
1015 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1020 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1025 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1030 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1035 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1037 Result
:= GM_SINGLE
;
1042 function g_Game_IsNet(): Boolean;
1044 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1047 function g_Game_IsServer(): Boolean;
1049 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1052 function g_Game_IsClient(): Boolean;
1054 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1057 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1064 Result
.name
:= ExtractFileName(WAD
);
1065 Result
.description
:= '';
1066 Result
.author
:= '';
1068 w
:= TWADFile
.Create();
1071 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1077 cfg
:= TConfig
.CreateMem(p
, len
);
1078 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1079 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1080 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1081 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1087 procedure g_Game_FreeWAD
;
1090 g_Sound_Delete('MUSIC_endmus');
1091 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1092 gGameSettings
.WAD
:= '';
1095 procedure g_Game_LoadWAD(WAD
: string);
1104 gGameSettings
.WAD
:= WAD
;
1105 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1108 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1110 w
:= TWADFile
.Create();
1113 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1119 cfg
:= TConfig
.CreateMem(p
, len
);
1122 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1123 if MegaWAD
.endpic
<> '' then
1124 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1126 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1127 if MegaWAD
.endmus
<> '' then
1129 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1130 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1138 {procedure start_trigger(t: string);
1142 function next_trigger(): Boolean;
1146 procedure DisableCheats();
1152 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1153 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1154 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1155 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1157 {$IF DEFINED(D2F_DEBUG)}
1158 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1159 gAimLine
:= g_dbg_aimline_on
;
1163 procedure g_Game_ExecuteEvent(Name
: String);
1169 if gEvents
= nil then
1171 for a
:= 0 to High(gEvents
) do
1172 if gEvents
[a
].Name
= Name
then
1174 if gEvents
[a
].Command
<> '' then
1175 g_Console_Process(gEvents
[a
].Command
, True);
1180 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1185 if gDelayedEvents
<> nil then
1186 for a
:= 0 to High(gDelayedEvents
) do
1187 if not gDelayedEvents
[a
].Pending
then
1194 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1195 n
:= High(gDelayedEvents
);
1197 gDelayedEvents
[n
].Pending
:= True;
1198 gDelayedEvents
[n
].DEType
:= DEType
;
1199 gDelayedEvents
[n
].DENum
:= Num
;
1200 gDelayedEvents
[n
].DEStr
:= Str
;
1201 if DEType
= DE_GLOBEVENT
then
1202 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1204 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1208 procedure EndGame();
1214 if g_Game_IsNet
and g_Game_IsServer
then
1215 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1218 gPauseMain
:= false;
1219 gPauseHolmes
:= false;
1222 g_Game_StopAllSounds(False);
1227 EndingGameCounter
:= 0;
1228 g_ActiveWindow
:= nil;
1230 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1231 gLMSRespawnTime
:= 0;
1234 EXIT_SIMPLE
: // Выход через меню или конец теста
1239 begin // Это был тест
1243 begin // Выход в главное меню
1244 gMusic
.SetByName('MUSIC_MENU');
1246 if gState
<> STATE_SLIST
then
1248 g_GUI_ShowWindow('MainMenu');
1249 gState
:= STATE_MENU
;
1252 // Обновляем список серверов
1253 slReturnPressed
:= True;
1254 if g_Net_Slist_Fetch(slCurrent
) then
1256 if slCurrent
= nil then
1257 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1260 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1261 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1264 g_Game_ExecuteEvent('ongameend');
1268 EXIT_RESTART
: // Начать уровень сначала
1270 if not g_Game_IsClient
then g_Game_Restart();
1273 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1275 // Статистика Своей игры:
1276 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1278 CustomStat
.GameTime
:= gTime
;
1279 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1280 CustomStat
.MapName
:= gMapInfo
.Name
;
1281 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1282 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1283 CustomStat
.TeamStat
:= gTeamStat
;
1285 CustomStat
.PlayerStat
:= nil;
1287 // Статистика игроков:
1288 if gPlayers
<> nil then
1290 for a
:= 0 to High(gPlayers
) do
1291 if gPlayers
[a
] <> nil then
1293 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1294 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1297 Name
:= gPlayers
[a
].Name
;
1298 Frags
:= gPlayers
[a
].Frags
;
1299 Deaths
:= gPlayers
[a
].Death
;
1300 Kills
:= gPlayers
[a
].Kills
;
1301 Team
:= gPlayers
[a
].Team
;
1302 Color
:= gPlayers
[a
].Model
.Color
;
1303 Spectator
:= gPlayers
[a
].FSpectator
;
1307 SortGameStat(CustomStat
.PlayerStat
);
1309 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1312 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1313 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1314 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1315 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1317 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1320 StatShotDone
:= False;
1323 g_Game_ExecuteEvent('onmapend');
1324 if not g_Game_IsClient
then g_Player_ResetReady
;
1325 gInterReadyCount
:= 0;
1327 // Затухающий экран:
1328 EndingGameCounter
:= 255;
1329 gState
:= STATE_FOLD
;
1331 if gDefInterTime
< 0 then
1332 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1334 gInterEndTime
:= gDefInterTime
* 1000;
1337 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1339 // Статистика Одиночной игры:
1340 SingleStat
.GameTime
:= gTime
;
1341 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1342 SingleStat
.TotalSecrets
:= gSecretsCount
;
1343 // Статистика первого игрока:
1344 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1345 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1346 // Статистика второго игрока (если есть):
1347 if SingleStat
.TwoPlayers
then
1349 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1350 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1353 g_Game_ExecuteEvent('onmapend');
1356 if gNextMap
<> '' then
1358 gMusic
.SetByName('MUSIC_INTERMUS');
1360 gState
:= STATE_INTERSINGLE
;
1363 g_Game_ExecuteEvent('oninter');
1365 else // Больше нет карт
1367 // Затухающий экран:
1368 EndingGameCounter
:= 255;
1369 gState
:= STATE_FOLD
;
1374 // Окончание обработано:
1375 if gExit
<> EXIT_QUIT
then
1379 procedure g_Game_Init();
1383 gTempDelete
:= False;
1385 sfsGCDisable(); // temporary disable removing of temporary volumes
1388 g_Game_ClearLoading();
1389 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1390 g_Game_SetLoadingText('', 0, False);
1392 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1395 gPauseMain
:= false;
1396 gPauseHolmes
:= false;
1399 {e_MouseInfo.Accel := 1.0;}
1401 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1404 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1405 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1406 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1407 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1408 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1410 gMusic
:= TMusic
.Create();
1411 gMusic
.SetByName('MUSIC_MENU');
1414 gGameSettings
.WarmupTime
:= 30;
1416 gState
:= STATE_MENU
;
1418 SetLength(gEvents
, 6);
1419 gEvents
[0].Name
:= 'ongamestart';
1420 gEvents
[1].Name
:= 'ongameend';
1421 gEvents
[2].Name
:= 'onmapstart';
1422 gEvents
[3].Name
:= 'onmapend';
1423 gEvents
[4].Name
:= 'oninter';
1424 gEvents
[5].Name
:= 'onwadend';
1426 sfsGCEnable(); // enable releasing unused volumes
1430 procedure g_Game_Free(freeTextures
: Boolean=true);
1432 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1433 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1435 g_Map_Free(freeTextures
);
1437 g_Player_RemoveAllCorpses();
1439 gGameSettings
.GameType
:= GT_NONE
;
1440 if gGameSettings
.GameMode
= GM_SINGLE
then
1441 gGameSettings
.GameMode
:= GM_DM
;
1442 gSwitchGameMode
:= gGameSettings
.GameMode
;
1445 gExitByTrigger
:= False;
1448 function IsActivePlayer(p
: TPlayer
): Boolean;
1453 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1456 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1462 if gPlayers
= nil then
1466 for a
:= Low(gPlayers
) to High(gPlayers
) do
1467 if IsActivePlayer(gPlayers
[a
]) then
1469 SetLength(ids
, Length(ids
) + 1);
1470 ids
[High(ids
)] := gPlayers
[a
].UID
;
1471 if gPlayers
[a
].UID
= Skip
then
1474 if Length(ids
) = 0 then
1479 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1482 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1488 if gPlayers
= nil then
1492 for a
:= Low(gPlayers
) to High(gPlayers
) do
1493 if IsActivePlayer(gPlayers
[a
]) then
1495 SetLength(ids
, Length(ids
) + 1);
1496 ids
[High(ids
)] := gPlayers
[a
].UID
;
1497 if gPlayers
[a
].UID
= Skip
then
1500 if Length(ids
) = 0 then
1503 Result
:= ids
[Length(ids
) - 1]
1505 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1508 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1514 if gPlayers
= nil then
1518 for a
:= Low(gPlayers
) to High(gPlayers
) do
1519 if IsActivePlayer(gPlayers
[a
]) then
1521 SetLength(ids
, Length(ids
) + 1);
1522 ids
[High(ids
)] := gPlayers
[a
].UID
;
1523 if gPlayers
[a
].UID
= Skip
then
1526 if Length(ids
) = 0 then
1528 if Length(ids
) = 1 then
1533 Result
:= ids
[Random(Length(ids
))];
1535 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1537 Result
:= ids
[Random(Length(ids
))];
1542 function GetRandomSpectMode(Current
: Byte): Byte;
1549 0: Result
:= SPECT_STATS
;
1550 1: Result
:= SPECT_MAPVIEW
;
1551 2: Result
:= SPECT_MAPVIEW
;
1552 3: Result
:= SPECT_PLAYERS
;
1553 4: Result
:= SPECT_PLAYERS
;
1554 5: Result
:= SPECT_PLAYERS
;
1555 6: Result
:= SPECT_PLAYERS
;
1557 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1561 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1567 if (plr
= nil) then exit
;
1568 if (p
= 2) then time
:= 1000 else time
:= 1;
1569 strafeDir
:= MoveButton
shr 4;
1570 MoveButton
:= MoveButton
and $0F;
1572 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1573 MoveButton
:= 1 // Нажата только "Влево"
1574 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1575 MoveButton
:= 2 // Нажата только "Вправо"
1576 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1577 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1579 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1580 if MoveButton
= 1 then
1581 plr
.PressKey(KEY_LEFT
, time
)
1582 else if MoveButton
= 2 then
1583 plr
.PressKey(KEY_RIGHT
, time
);
1585 // if we have "strafe" key, turn off old strafe mechanics
1586 if gPlayerAction
[p
, ACTION_STRAFE
] then
1588 // new strafe mechanics
1589 if (strafeDir
= 0) then
1590 strafeDir
:= MoveButton
; // start strafing
1591 // now set direction according to strafe (reversed)
1592 if (strafeDir
= 2) then
1593 plr
.SetDirection(TDirection
.D_LEFT
)
1594 else if (strafeDir
= 1) then
1595 plr
.SetDirection(TDirection
.D_RIGHT
)
1599 strafeDir
:= 0; // not strafing anymore
1600 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1601 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1602 plr
.SetDirection(TDirection
.D_LEFT
)
1603 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1604 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1605 plr
.SetDirection(TDirection
.D_RIGHT
)
1606 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1607 else if MoveButton
<> 0 then
1608 plr
.SetDirection(TDirection(MoveButton
-1))
1611 // fix movebutton state
1612 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1614 // Остальные клавиши:
1615 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1616 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1617 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1618 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1619 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1620 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1621 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1623 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1624 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1626 for i
:= WP_FIRST
to WP_LAST
do
1628 if gSelectWeapon
[p
, i
] then
1630 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1631 gSelectWeapon
[p
, i
] := False
1635 // HACK: add dynlight here
1636 if gwin_k8_enable_light_experiments
then
1638 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1640 g_playerLight
:= true;
1642 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1644 g_playerLight
:= false;
1648 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1651 // HACK: don't have a "key was pressed" function
1652 procedure InterReady();
1654 if InterReadyTime
> gTime
then Exit
;
1655 InterReadyTime
:= gTime
+ 3000;
1656 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1659 procedure g_Game_PreUpdate();
1661 // these are in separate PreUpdate functions because they can interact during Update()
1662 // and are synced over the net
1663 // we don't care that much about corpses and gibs
1664 g_Player_PreUpdate();
1665 g_Monsters_PreUpdate();
1666 g_Items_PreUpdate();
1667 g_Weapon_PreUpdate();
1670 procedure g_Game_Update();
1672 Msg
: g_gui
.TMessage
;
1678 function sendMonsPos (mon
: TMonster
): Boolean;
1680 result
:= false; // don't stop
1681 // this will also reset "need-send" flag
1682 if mon
.gncNeedSend
then
1684 MH_SEND_MonsterPos(mon
.UID
);
1686 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1688 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1690 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1692 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1696 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1698 result
:= false; // don't stop
1699 // this will also reset "need-send" flag
1700 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1704 reliableUpdate
: Boolean;
1709 // Пора выключать игру:
1710 if gExit
= EXIT_QUIT
then
1712 // Игра закончилась - обрабатываем:
1716 if gExit
= EXIT_QUIT
then
1720 // Читаем клавиатуру и джойстик, если окно активно
1721 // no need to, as we'll do it in event handler
1723 // Обновляем консоль (движение и сообщения):
1727 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1729 gExit
:= EXIT_SIMPLE
;
1734 // process master server communications
1735 g_Net_Slist_Pulse();
1738 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1739 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1740 STATE_INTERTEXT
, // Текст между уровнями
1741 STATE_INTERPIC
: // Картинка между уровнями
1743 if g_Game_IsNet
and g_Game_IsServer
then
1745 gInterTime
:= gInterTime
+ GAME_TICK
;
1746 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1747 if a
<> gServInterTime
then
1749 gServInterTime
:= a
;
1750 MH_SEND_TimeSync(gServInterTime
);
1754 if (not g_Game_IsClient
) and
1758 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1759 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1760 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1761 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1763 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1764 and (g_ActiveWindow
= nil)
1766 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1769 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1770 g_Game_StopAllSounds(True);
1772 if gMapOnce
then // Это был тест
1773 gExit
:= EXIT_SIMPLE
1775 if gNextMap
<> '' then // Переходим на следующую карту
1776 g_Game_ChangeMap(gNextMap
)
1777 else // Следующей карты нет
1779 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1781 // Выход в главное меню:
1783 g_GUI_ShowWindow('MainMenu');
1784 gMusic
.SetByName('MUSIC_MENU');
1786 gState
:= STATE_MENU
;
1789 // Финальная картинка:
1790 g_Game_ExecuteEvent('onwadend');
1792 if not gMusic
.SetByName('MUSIC_endmus') then
1793 gMusic
.SetByName('MUSIC_STDENDMUS');
1795 gState
:= STATE_ENDPIC
;
1797 g_Game_ExecuteEvent('ongameend');
1802 else if g_Game_IsClient
and
1805 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1806 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1807 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1808 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1810 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1811 and (g_ActiveWindow
= nil)
1819 if gState
= STATE_INTERTEXT
then
1820 if InterText
.counter
> 0 then
1821 InterText
.counter
:= InterText
.counter
- 1;
1824 STATE_FOLD
: // Затухание экрана
1826 if EndingGameCounter
= 0 then
1828 // Закончился уровень в Своей игре:
1829 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1831 InterReadyTime
:= -1;
1832 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1834 g_Game_ExecuteEvent('onwadend');
1835 if not gMusic
.SetByName('MUSIC_endmus') then
1836 gMusic
.SetByName('MUSIC_STDENDMUS');
1839 gMusic
.SetByName('MUSIC_ROUNDMUS');
1842 gState
:= STATE_INTERCUSTOM
;
1845 else // Закончилась последняя карта в Одиночной игре
1847 gMusic
.SetByName('MUSIC_INTERMUS');
1849 gState
:= STATE_INTERSINGLE
;
1852 g_Game_ExecuteEvent('oninter');
1855 DecMin(EndingGameCounter
, 6, 0);
1858 STATE_ENDPIC
: // Картинка окончания мегаВада
1860 if gMapOnce
then // Это был тест
1862 gExit
:= EXIT_SIMPLE
;
1868 g_Serverlist_Control(slCurrent
, slTable
);
1871 // Статистика по Tab:
1873 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1876 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1878 // Время += 28 миллисекунд:
1879 gTime
:= gTime
+ GAME_TICK
;
1881 // Сообщение посередине экрана:
1882 if MessageTime
= 0 then
1884 if MessageTime
> 0 then
1885 MessageTime
:= MessageTime
- 1;
1887 if (g_Game_IsServer
) then
1889 // Был задан лимит времени:
1890 if (gGameSettings
.TimeLimit
> 0) then
1891 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1892 begin // Он прошел => конец уровня
1897 // Надо респавнить игроков в LMS:
1898 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1899 g_Game_RestartRound(gLMSSoftSpawn
);
1901 // Проверим результат голосования, если время прошло
1902 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1904 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1906 g_Console_Process(gVoteCommand
);
1908 gVotePassed
:= False;
1911 // Замеряем время захвата флагов
1912 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1913 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1914 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1915 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1917 // Был задан лимит побед:
1918 if (gGameSettings
.GoalLimit
> 0) then
1922 if gGameSettings
.GameMode
= GM_DM
then
1923 begin // В DM ищем игрока с max фрагами
1924 for i
:= 0 to High(gPlayers
) do
1925 if gPlayers
[i
] <> nil then
1926 if gPlayers
[i
].Frags
> b
then
1927 b
:= gPlayers
[i
].Frags
;
1930 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1931 begin // В CTF/TDM выбираем команду с наибольшим счетом
1932 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1935 // Лимит побед набран => конец уровня:
1936 if b
>= gGameSettings
.GoalLimit
then
1943 // Обрабатываем клавиши игроков:
1944 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1945 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1946 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1948 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1949 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1950 end // if not console
1953 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1955 // process weapon switch queue
1959 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1960 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1962 if not gSpectKeyPress
then
1964 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
1966 // switch spect mode
1968 SPECT_NONE
: ; // not spectator
1970 SPECT_MAPVIEW
: Inc(gSpectMode
);
1971 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1973 gSpectKeyPress
:= True;
1975 if (gSpectMode
= SPECT_MAPVIEW
)
1976 and (not gSpectAuto
) then
1978 if gPlayerAction
[0, ACTION_MOVELEFT
] then
1979 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1980 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
1981 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1982 if gPlayerAction
[0, ACTION_LOOKUP
] then
1983 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1984 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
1985 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1986 if gPlayerAction
[0, ACTION_WEAPPREV
] then
1989 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1990 gSpectKeyPress
:= True;
1992 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
1995 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1996 gSpectKeyPress
:= True;
1999 if (gSpectMode
= SPECT_PLAYERS
)
2000 and (not gSpectAuto
) then
2002 if gPlayerAction
[0, ACTION_LOOKUP
] then
2005 gSpectViewTwo
:= True;
2006 gSpectKeyPress
:= True;
2008 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2010 // remove second view
2011 gSpectViewTwo
:= False;
2012 gSpectKeyPress
:= True;
2014 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2016 // prev player (view 1)
2017 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2018 gSpectKeyPress
:= True;
2020 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2022 // next player (view 1)
2023 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2024 gSpectKeyPress
:= True;
2026 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2028 // prev player (view 2)
2029 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2030 gSpectKeyPress
:= True;
2032 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2034 // next player (view 2)
2035 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2036 gSpectKeyPress
:= True;
2039 if gPlayerAction
[0, ACTION_ATTACK
] then
2041 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2044 gSpectAutoNext
:= 0;
2045 gSpectViewTwo
:= False;
2046 gSpectKeyPress
:= True;
2051 gSpectMode
:= SPECT_STATS
;
2052 gSpectAuto
:= False;
2053 gSpectKeyPress
:= True;
2058 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2059 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2060 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2061 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2062 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2063 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2064 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2065 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2066 gSpectKeyPress
:= False;
2070 if gSpectMode
= SPECT_MAPVIEW
then
2072 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2074 gSpectAutoNext
:= gTime
2077 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2079 gSpectAutoNext
:= gTime
2083 if gSpectAutoNext
<= gTime
then
2085 if gSpectAutoNext
> 0 then
2087 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2091 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2092 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2093 gSpectAutoStepX
:= Random(9) - 4;
2094 gSpectAutoStepY
:= Random(9) - 4;
2095 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2096 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2097 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2098 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2099 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2100 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2104 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2109 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2110 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2111 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2117 // Обновляем все остальное:
2120 g_Triggers_Update();
2122 g_Monsters_Update();
2125 g_Player_UpdateAll();
2126 g_Player_UpdatePhysicalObjects();
2128 // server: send newly spawned monsters unconditionally
2129 if (gGameSettings
.GameType
= GT_SERVER
) then
2131 if (Length(gMonstersSpawned
) > 0) then
2133 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2134 SetLength(gMonstersSpawned
, 0);
2138 if (gSoundTriggerTime
> 8) then
2140 g_Game_UpdateTriggerSounds();
2141 gSoundTriggerTime
:= 0;
2145 Inc(gSoundTriggerTime
);
2148 if (NetMode
= NET_SERVER
) then
2150 Inc(NetTimeToUpdate
);
2151 Inc(NetTimeToReliable
);
2153 // send monster updates
2154 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2156 // send all monsters (periodic sync)
2157 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2159 for I
:= 0 to High(gPlayers
) do
2161 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2164 g_Mons_ForEach(sendMonsPos
);
2166 if reliableUpdate
then
2168 NetTimeToReliable
:= 0;
2169 NetTimeToUpdate
:= NetUpdateRate
;
2173 NetTimeToUpdate
:= 0;
2178 // send only mosters with some unexpected changes
2179 g_Mons_ForEach(sendMonsPosUnexpected
);
2182 // send unexpected platform changes
2183 g_Map_NetSendInterestingPanels();
2185 g_Net_Slist_ServerUpdate();
2187 if NetUseMaster then
2189 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2191 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2193 NetTimeToMaster := gTime + NetMasterRate;
2198 else if (NetMode
= NET_CLIENT
) then
2200 MC_SEND_PlayerPos();
2202 end; // if gameOn ...
2204 // Активно окно интерфейса - передаем клавиши ему:
2205 if g_ActiveWindow
<> nil then
2207 w
:= e_GetFirstKeyPressed();
2209 if (w
<> IK_INVALID
) then
2211 Msg
.Msg
:= MESSAGE_DIKEY
;
2213 g_ActiveWindow
.OnMessage(Msg
);
2216 // Если оно от этого не закрылось, то обновляем:
2217 if g_ActiveWindow
<> nil then
2218 g_ActiveWindow
.Update();
2220 // Нужно сменить разрешение:
2221 if gResolutionChange
then
2223 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2225 gResolutionChange
:= False;
2226 g_ActiveWindow
:= nil;
2229 // Нужно сменить язык:
2230 if gLanguageChange
then
2232 //e_WriteLog('Read language file', MSG_NOTIFY);
2233 //g_Language_Load(DataDir + gLanguage + '.txt');
2234 g_Language_Set(gLanguage
);
2238 gLanguageChange
:= False;
2242 // Горячая клавиша для вызова меню выхода из игры (F10):
2243 if e_KeyPressed(IK_F10
) and
2245 (not gConsoleShow
) and
2246 (g_ActiveWindow
= nil) then
2251 Time
:= GetTickCount64() {div 1000};
2253 // Обработка отложенных событий:
2254 if gDelayedEvents
<> nil then
2255 for a
:= 0 to High(gDelayedEvents
) do
2256 if gDelayedEvents
[a
].Pending
and
2258 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2259 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2262 case gDelayedEvents
[a
].DEType
of
2264 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2267 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2271 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2272 if g_Game_IsNet
and g_Game_IsServer
then
2273 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2277 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2279 gDelayedEvents
[a
].Pending
:= False;
2282 // Каждую секунду обновляем счетчик обновлений:
2283 UPSCounter
:= UPSCounter
+ 1;
2284 if Time
- UPSTime
>= 1000 then
2293 g_Weapon_AddDynLights();
2294 g_Items_AddDynLights();
2298 procedure g_Game_LoadChatSounds(Resource
: string);
2301 FileName
, Snd
: string;
2303 len
, cnt
, tags
, i
, j
: Integer;
2306 FileName
:= g_ExtractWadName(Resource
);
2308 WAD
:= TWADFile
.Create();
2309 WAD
.ReadFile(FileName
);
2311 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2318 cfg
:= TConfig
.CreateMem(p
, len
);
2319 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2321 SetLength(gChatSounds
, cnt
);
2322 for i
:= 0 to Length(gChatSounds
) - 1 do
2324 gChatSounds
[i
].Sound
:= nil;
2325 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2326 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2327 if (Snd
= '') or (Tags
<= 0) then
2329 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2330 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2331 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2332 SetLength(gChatSounds
[i
].Tags
, tags
);
2333 for j
:= 0 to tags
- 1 do
2334 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2335 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2342 procedure g_Game_FreeChatSounds();
2346 for i
:= 0 to Length(gChatSounds
) - 1 do
2348 gChatSounds
[i
].Sound
.Free();
2349 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2351 SetLength(gChatSounds
, 0);
2355 procedure g_Game_LoadData();
2357 if DataLoaded
then Exit
;
2359 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2361 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2362 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2363 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2364 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2365 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2366 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2367 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2368 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2369 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2370 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2371 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2372 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2373 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2374 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2375 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2376 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2377 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2378 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2379 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2380 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2381 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2382 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2383 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2384 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2385 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2386 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2387 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2388 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2389 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2390 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2391 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2392 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2394 goodsnd
[0] := TPlayableSound
.Create();
2395 goodsnd
[1] := TPlayableSound
.Create();
2396 goodsnd
[2] := TPlayableSound
.Create();
2397 goodsnd
[3] := TPlayableSound
.Create();
2399 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2400 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2401 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2402 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2404 killsnd
[0] := TPlayableSound
.Create();
2405 killsnd
[1] := TPlayableSound
.Create();
2406 killsnd
[2] := TPlayableSound
.Create();
2407 killsnd
[3] := TPlayableSound
.Create();
2409 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2410 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2411 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2412 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2414 hahasnd
[0] := TPlayableSound
.Create();
2415 hahasnd
[1] := TPlayableSound
.Create();
2416 hahasnd
[2] := TPlayableSound
.Create();
2418 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2419 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2420 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2422 sound_get_flag
[0] := TPlayableSound
.Create();
2423 sound_get_flag
[1] := TPlayableSound
.Create();
2424 sound_lost_flag
[0] := TPlayableSound
.Create();
2425 sound_lost_flag
[1] := TPlayableSound
.Create();
2426 sound_ret_flag
[0] := TPlayableSound
.Create();
2427 sound_ret_flag
[1] := TPlayableSound
.Create();
2428 sound_cap_flag
[0] := TPlayableSound
.Create();
2429 sound_cap_flag
[1] := TPlayableSound
.Create();
2431 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2432 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2433 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2434 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2435 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2436 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2437 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2438 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2440 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2442 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2445 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2446 g_Weapon_LoadData();
2448 g_Monsters_LoadData();
2453 procedure g_Game_Quit();
2455 g_Game_StopAllSounds(True);
2458 g_PlayerModel_FreeData();
2460 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2463 if NetInitDone
then g_Net_Free
;
2465 // remove map after test
2466 if gMapToDelete
<> '' then
2467 g_Game_DeleteTestMap();
2473 procedure g_Game_FreeData();
2475 if not DataLoaded
then Exit
;
2478 g_Weapon_FreeData();
2479 g_Monsters_FreeData();
2481 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2483 g_Sound_Delete('SOUND_GAME_TELEPORT');
2484 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2485 g_Sound_Delete('SOUND_GAME_SECRET');
2486 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2487 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2488 g_Sound_Delete('SOUND_GAME_BULK1');
2489 g_Sound_Delete('SOUND_GAME_BULK2');
2490 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2491 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2492 g_Sound_Delete('SOUND_GAME_BURNING');
2493 g_Sound_Delete('SOUND_GAME_SWITCH1');
2494 g_Sound_Delete('SOUND_GAME_SWITCH0');
2501 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2502 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2503 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2504 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2511 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2512 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2513 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2514 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2520 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2521 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2522 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2524 sound_get_flag
[0].Free();
2525 sound_get_flag
[1].Free();
2526 sound_lost_flag
[0].Free();
2527 sound_lost_flag
[1].Free();
2528 sound_ret_flag
[0].Free();
2529 sound_ret_flag
[1].Free();
2530 sound_cap_flag
[0].Free();
2531 sound_cap_flag
[1].Free();
2533 g_Sound_Delete('SOUND_CTF_GET1');
2534 g_Sound_Delete('SOUND_CTF_GET2');
2535 g_Sound_Delete('SOUND_CTF_LOST1');
2536 g_Sound_Delete('SOUND_CTF_LOST2');
2537 g_Sound_Delete('SOUND_CTF_RETURN1');
2538 g_Sound_Delete('SOUND_CTF_RETURN2');
2539 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2540 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2542 g_Game_FreeChatSounds();
2544 DataLoaded
:= False;
2547 procedure g_FatalError(Text: String);
2549 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2550 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2552 gExit
:= EXIT_SIMPLE
;
2553 if gGameOn
then EndGame
;
2556 procedure g_SimpleError(Text: String);
2558 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2559 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2562 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2564 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2565 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2568 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2571 if gPlayer1
= nil then
2573 if g_Game_IsClient
then
2575 if NetPlrUID1
> -1 then
2576 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2580 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2581 Team
:= gPlayer1Settings
.Team
;
2583 // Создание первого игрока:
2584 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2585 gPlayer1Settings
.Color
,
2587 if gPlayer1
= nil then
2588 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2591 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2592 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2593 if g_Game_IsServer
and g_Game_IsNet
then
2594 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2595 gPlayer1
.Respawn(False, True);
2596 g_Net_Slist_ServerPlayerComes();
2601 if gPlayer2
= nil then
2603 if g_Game_IsClient
then
2605 if NetPlrUID2
> -1 then
2606 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2610 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2611 Team
:= gPlayer2Settings
.Team
;
2613 // Создание второго игрока:
2614 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2615 gPlayer2Settings
.Color
,
2617 if gPlayer2
= nil then
2618 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2621 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2622 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2623 if g_Game_IsServer
and g_Game_IsNet
then
2624 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2625 gPlayer2
.Respawn(False, True);
2626 g_Net_Slist_ServerPlayerComes();
2633 procedure g_Game_RemovePlayer();
2637 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2638 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2643 if g_Game_IsServer
then
2646 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2647 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2648 g_Player_Remove(Pl
.UID
);
2649 g_Net_Slist_ServerPlayerLeaves();
2653 gSpectLatchPID2
:= Pl
.UID
;
2661 if g_Game_IsServer
then
2664 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2665 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2666 g_Player_Remove(Pl
.UID
);
2667 g_Net_Slist_ServerPlayerLeaves();
2670 gSpectLatchPID1
:= Pl
.UID
;
2672 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2676 g_Net_Slist_ServerPlayerLeaves();
2679 procedure g_Game_Spectate();
2681 g_Game_RemovePlayer();
2682 if gPlayer1
<> nil then
2683 g_Game_RemovePlayer();
2686 procedure g_Game_SpectateCenterView();
2688 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2689 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2692 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2699 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2701 g_Game_ClearLoading();
2704 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2707 gGameSettings
.GameType
:= GT_SINGLE
;
2708 gGameSettings
.MaxLives
:= 0;
2709 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2710 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2711 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2712 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2713 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2714 gSwitchGameMode
:= GM_SINGLE
;
2716 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2717 gLMSRespawnTime
:= 0;
2718 gSpectLatchPID1
:= 0;
2719 gSpectLatchPID2
:= 0;
2721 g_Game_ExecuteEvent('ongamestart');
2723 // Создание первого игрока:
2724 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2725 gPlayer1Settings
.Color
,
2726 gPlayer1Settings
.Team
, False));
2727 if gPlayer1
= nil then
2729 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2733 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2736 // Создание второго игрока, если есть:
2739 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2740 gPlayer2Settings
.Color
,
2741 gPlayer2Settings
.Team
, False));
2742 if gPlayer2
= nil then
2744 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2748 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2752 // Загрузка и запуск карты:
2753 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2755 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2756 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2760 // Настройки игроков и ботов:
2764 for i
:= nPl
+1 to nPlayers
do
2765 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2768 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2769 TimeLimit
, GoalLimit
: Word;
2771 Options
: LongWord; nPlayers
: Byte);
2777 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2779 g_Game_ClearLoading();
2782 gGameSettings
.GameType
:= GT_CUSTOM
;
2783 gGameSettings
.GameMode
:= GameMode
;
2784 gSwitchGameMode
:= GameMode
;
2785 gGameSettings
.TimeLimit
:= TimeLimit
;
2786 gGameSettings
.GoalLimit
:= GoalLimit
;
2787 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2788 gGameSettings
.Options
:= Options
;
2790 gCoopTotalMonstersKilled
:= 0;
2791 gCoopTotalSecretsFound
:= 0;
2792 gCoopTotalMonsters
:= 0;
2793 gCoopTotalSecrets
:= 0;
2797 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2798 gLMSRespawnTime
:= 0;
2799 gSpectLatchPID1
:= 0;
2800 gSpectLatchPID2
:= 0;
2802 g_Game_ExecuteEvent('ongamestart');
2804 // Режим наблюдателя:
2805 if nPlayers
= 0 then
2812 if nPlayers
>= 1 then
2814 // Создание первого игрока:
2815 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2816 gPlayer1Settings
.Color
,
2817 gPlayer1Settings
.Team
, False));
2818 if gPlayer1
= nil then
2820 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2824 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2828 if nPlayers
>= 2 then
2830 // Создание второго игрока:
2831 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2832 gPlayer2Settings
.Color
,
2833 gPlayer2Settings
.Team
, False));
2834 if gPlayer2
= nil then
2836 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2840 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2844 // Загрузка и запуск карты:
2845 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
2847 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2851 // Нет точек появления:
2852 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2853 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2854 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2855 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2856 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2858 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2862 // Настройки игроков и ботов:
2866 for i
:= nPl
+1 to nPlayers
do
2867 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2870 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
2871 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
2872 Options
: LongWord; nPlayers
: Byte;
2873 IPAddr
: LongWord; Port
: Word);
2876 g_Net_Slist_ServerClosed();
2878 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
2880 g_Game_ClearLoading();
2883 gGameSettings
.GameType
:= GT_SERVER
;
2884 gGameSettings
.GameMode
:= GameMode
;
2885 gSwitchGameMode
:= GameMode
;
2886 gGameSettings
.TimeLimit
:= TimeLimit
;
2887 gGameSettings
.GoalLimit
:= GoalLimit
;
2888 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2889 gGameSettings
.Options
:= Options
;
2891 gCoopTotalMonstersKilled
:= 0;
2892 gCoopTotalSecretsFound
:= 0;
2893 gCoopTotalMonsters
:= 0;
2894 gCoopTotalSecrets
:= 0;
2898 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2899 gLMSRespawnTime
:= 0;
2900 gSpectLatchPID1
:= 0;
2901 gSpectLatchPID2
:= 0;
2903 g_Game_ExecuteEvent('ongamestart');
2905 // Режим наблюдателя:
2906 if nPlayers
= 0 then
2912 if nPlayers
>= 1 then
2914 // Создание первого игрока:
2915 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2916 gPlayer1Settings
.Color
,
2917 gPlayer1Settings
.Team
, False));
2918 if gPlayer1
= nil then
2920 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2924 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2927 if nPlayers
>= 2 then
2929 // Создание второго игрока:
2930 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2931 gPlayer2Settings
.Color
,
2932 gPlayer2Settings
.Team
, False));
2933 if gPlayer2
= nil then
2935 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2939 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2942 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
2943 if NetForwardPorts
then
2944 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
2947 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
2949 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
2953 g_Net_Slist_Set(NetMasterList
);
2955 g_Net_Slist_ServerStarted();
2957 // Загрузка и запуск карты:
2958 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
2960 g_Net_Slist_ServerClosed();
2961 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2965 // Нет точек появления:
2966 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2967 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2968 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2969 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2970 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2972 g_Net_Slist_ServerClosed();
2973 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2977 // Настройки игроков и ботов:
2980 g_Net_Slist_ServerMapStarted();
2981 NetState
:= NET_STATE_GAME
;
2984 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
2999 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3000 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3002 g_Game_ClearLoading();
3005 gGameSettings
.GameType
:= GT_CLIENT
;
3007 gCoopTotalMonstersKilled
:= 0;
3008 gCoopTotalSecretsFound
:= 0;
3009 gCoopTotalMonsters
:= 0;
3010 gCoopTotalSecrets
:= 0;
3014 g_Game_ExecuteEvent('ongamestart');
3016 NetState
:= NET_STATE_AUTH
;
3018 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3020 // create (or update) map/resource databases
3021 g_Res_CreateDatabases(true);
3023 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3024 gLMSRespawnTime
:= 0;
3025 gSpectLatchPID1
:= 0;
3026 gSpectLatchPID2
:= 0;
3029 if not g_Net_Connect(Addr
, Port
) then
3031 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3032 NetState
:= NET_STATE_NONE
;
3036 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3038 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3043 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3044 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3045 // thank you, enet. let's ignore failures altogether then.
3046 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3048 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3050 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
3052 // ignore all download packets, they're processed by separate code
3053 enet_packet_destroy(NetEvent
.packet
);
3056 Ptr
:= NetEvent
.packet
^.data
;
3057 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3059 enet_packet_destroy(NetEvent
.packet
);
3063 InMsg
.ReadLongWord(); // skip size
3064 MID
:= InMsg
.ReadByte();
3066 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3068 NetMyID
:= InMsg
.ReadByte();
3069 NetPlrUID1
:= InMsg
.ReadWord();
3071 WadName
:= InMsg
.ReadString();
3072 Map
:= InMsg
.ReadString();
3074 gWADHash
:= InMsg
.ReadMD5();
3076 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3077 gSwitchGameMode
:= gGameSettings
.GameMode
;
3078 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
3079 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3080 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3081 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3082 T
:= InMsg
.ReadLongWord();
3084 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3085 //if newResPath = '' then
3087 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3088 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3089 if newResPath
= '' then
3091 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3092 enet_packet_destroy(NetEvent
.packet
);
3093 NetState
:= NET_STATE_NONE
;
3096 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3098 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3101 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3102 gPlayer1Settings
.Color
,
3103 gPlayer1Settings
.Team
, False));
3105 if gPlayer1
= nil then
3107 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3109 enet_packet_destroy(NetEvent
.packet
);
3110 NetState
:= NET_STATE_NONE
;
3114 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3115 gPlayer1
.UID
:= NetPlrUID1
;
3116 gPlayer1
.Reset(True);
3118 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3120 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3122 enet_packet_destroy(NetEvent
.packet
);
3123 NetState
:= NET_STATE_NONE
;
3131 enet_packet_destroy(NetEvent
.packet
);
3135 enet_packet_destroy(NetEvent
.packet
);
3139 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3142 if (NetEvent
.data
<= NET_DISC_MAX
) then
3143 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3144 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3151 ProcessLoading(true);
3153 if g_Net_UserRequestExit() then
3162 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3163 NetState
:= NET_STATE_NONE
;
3168 NetState
:= NET_STATE_GAME
;
3169 MC_SEND_FullStateRequest
;
3170 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3174 lastAsMegaWad
: Boolean = false;
3176 procedure g_Game_ChangeMap(const MapPath
: String);
3180 g_Game_ClearLoading();
3182 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3183 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3184 if gExitByTrigger
then
3187 gExitByTrigger
:= False;
3189 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3190 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3193 procedure g_Game_Restart();
3197 if g_Game_IsClient
then
3199 map
:= g_ExtractFileName(gMapInfo
.Map
);
3200 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3204 g_Game_ClearLoading();
3205 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3208 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3210 NewWAD
, ResName
: String;
3214 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3215 g_Player_RemoveAllCorpses();
3217 if (not g_Game_IsClient
) and
3218 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3219 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3221 if gSwitchGameMode
= GM_CTF
then
3222 gGameSettings
.MaxLives
:= 0;
3223 gGameSettings
.GameMode
:= gSwitchGameMode
;
3226 gSwitchGameMode
:= gGameSettings
.GameMode
;
3228 g_Player_ResetTeams();
3230 lastAsMegaWad
:= asMegawad
;
3231 if isWadPath(Map
) then
3233 NewWAD
:= g_ExtractWadName(Map
);
3234 ResName
:= g_ExtractFileName(Map
);
3235 if g_Game_IsServer
then
3237 nws
:= findDiskWad(NewWAD
);
3238 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3241 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3242 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3246 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3247 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3249 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3250 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3252 if (length(nws
) = 0) then
3254 ResName
:= ''; // failed
3259 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3260 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3261 g_Game_LoadWAD(NewWAD
);
3266 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3267 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3272 NewWAD
:= gGameSettings
.WAD
;
3278 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3280 if (ResName
<> '') and (NewWAD
<> '') then
3282 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3283 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3284 r_Render_LoadTextures
;
3288 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3290 gState
:= STATE_NONE
;
3291 g_ActiveWindow
:= nil;
3295 wNeedTimeReset
:= True;
3297 if gGameSettings
.GameMode
= GM_CTF
then
3299 g_Map_ResetFlag(FLAG_RED
);
3300 g_Map_ResetFlag(FLAG_BLUE
);
3301 // CTF, а флагов нет:
3302 if not g_Map_HaveFlagPoints() then
3303 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3308 gState
:= STATE_MENU
;
3313 gPauseMain
:= false;
3314 gPauseHolmes
:= false;
3315 NetTimeToUpdate
:= 1;
3316 NetTimeToReliable
:= 0;
3317 NetTimeToMaster
:= NetMasterRate
;
3318 gSpectLatchPID1
:= 0;
3319 gSpectLatchPID2
:= 0;
3320 gMissionFailed
:= False;
3323 gCoopMonstersKilled
:= 0;
3324 gCoopSecretsFound
:= 0;
3326 gVoteInProgress
:= False;
3327 gVotePassed
:= False;
3333 if not gGameOn
then Exit
;
3335 g_Game_SpectateCenterView();
3337 if g_Game_IsServer
then
3339 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3341 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3342 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3343 gLMSSoftSpawn
:= True;
3344 if g_Game_IsNet
then
3345 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3349 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3350 gLMSRespawnTime
:= 0;
3354 if NetMode
= NET_SERVER
then
3356 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3359 g_Net_Slist_ServerMapStarted();
3361 if NetClients
<> nil then
3362 for I
:= 0 to High(NetClients
) do
3363 if NetClients
[I
].Used
then
3365 NetClients
[I
].Voted
:= False;
3366 if NetClients
[I
].RequestedFullUpdate
then
3368 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3369 NetClients
[I
].RequestedFullUpdate
:= False;
3373 g_Net_UnbanNonPermHosts();
3378 gCoopTotalMonstersKilled
:= 0;
3379 gCoopTotalSecretsFound
:= 0;
3380 gCoopTotalMonsters
:= 0;
3381 gCoopTotalSecrets
:= 0;
3385 g_Game_ExecuteEvent('onmapstart');
3388 procedure SetFirstLevel
;
3392 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3393 if MapList
= nil then
3396 SortSArray(MapList
);
3397 gNextMap
:= MapList
[Low(MapList
)];
3402 procedure g_Game_ExitLevel(const Map
: AnsiString);
3406 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3407 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3408 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3409 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3411 // Вышли в выход в Одиночной игре:
3412 if gGameSettings
.GameType
= GT_SINGLE
then
3413 gExit
:= EXIT_ENDLEVELSINGLE
3414 else // Вышли в выход в Своей игре
3416 gExit
:= EXIT_ENDLEVELCUSTOM
;
3417 if gGameSettings
.GameMode
= GM_COOP
then
3418 g_Player_RememberAll
;
3420 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3423 if gGameSettings
.GameMode
= GM_COOP
then
3426 gStatsPressed
:= True;
3427 gNextMap
:= 'MAP01';
3429 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3432 if g_Game_IsNet
then
3434 MH_SEND_GameStats();
3435 MH_SEND_CoopStats();
3441 procedure g_Game_RestartLevel();
3445 if gGameSettings
.GameMode
= GM_SINGLE
then
3450 gExit
:= EXIT_ENDLEVELCUSTOM
;
3451 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3455 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3457 gWAD
{, xwad}: String;
3460 if not g_Game_IsClient
then Exit
;
3461 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3463 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3468 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3472 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3475 g_Game_LoadWAD(NewWAD
);
3479 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3480 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3483 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3484 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3488 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3492 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3493 g_Game_LoadWAD(NewWAD);
3497 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3499 i
, n
, nb
, nr
: Integer;
3501 if not g_Game_IsServer
then Exit
;
3502 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3503 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3504 gLMSRespawnTime
:= 0;
3507 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3509 gMissionFailed
:= True;
3510 g_Game_RestartLevel
;
3514 n
:= 0; nb
:= 0; nr
:= 0;
3515 for i
:= Low(gPlayers
) to High(gPlayers
) do
3516 if (gPlayers
[i
] <> nil) and
3517 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3518 (gPlayers
[i
] is TBot
)) then
3521 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3522 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3525 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3527 // wait a second until the fuckers finally decide to join
3528 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3529 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3530 gLMSSoftSpawn
:= NoMapRestart
;
3531 if g_Game_IsNet
then
3532 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3536 g_Player_RemoveAllCorpses
;
3537 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3538 if g_Game_IsNet
then
3539 MH_SEND_GameEvent(NET_EV_LMS_START
);
3541 for i
:= Low(gPlayers
) to High(gPlayers
) do
3543 if gPlayers
[i
] = nil then continue
;
3544 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3545 // don't touch normal spectators
3546 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3548 gPlayers
[i
].FNoRespawn
:= True;
3549 gPlayers
[i
].Lives
:= 0;
3550 if g_Game_IsNet
then
3551 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3554 gPlayers
[i
].FNoRespawn
:= False;
3555 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3556 gPlayers
[i
].Respawn(False, True);
3557 if gGameSettings
.GameMode
= GM_COOP
then
3559 gPlayers
[i
].Frags
:= 0;
3560 gPlayers
[i
].RecallState
;
3562 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3563 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3564 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3565 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3568 g_Items_RestartRound();
3570 gLMSSoftSpawn
:= False;
3573 function g_Game_GetFirstMap(WAD
: String): String;
3577 MapList
:= g_Map_GetMapsList(WAD
);
3578 if MapList
= nil then
3581 SortSArray(MapList
);
3582 Result
:= MapList
[Low(MapList
)];
3584 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3590 function g_Game_GetNextMap(): String;
3597 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3598 if MapList
= nil then
3601 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3603 SortSArray(MapList
);
3605 for I
:= Low(MapList
) to High(MapList
) do
3606 if Map
= MapList
[I
] then
3612 if MapIndex
<> -255 then
3614 if MapIndex
= High(MapList
) then
3615 Result
:= MapList
[Low(MapList
)]
3617 Result
:= MapList
[MapIndex
+ 1];
3619 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3625 procedure g_Game_NextLevel();
3627 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3628 gExit
:= EXIT_ENDLEVELCUSTOM
3631 gExit
:= EXIT_ENDLEVELSINGLE
;
3635 if gNextMap
<> '' then Exit
;
3636 gNextMap
:= g_Game_GetNextMap();
3639 function g_Game_IsTestMap(): Boolean;
3641 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3644 procedure g_Game_DeleteTestMap();
3647 //MapName: AnsiString;
3655 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3656 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3657 if (a
= 0) then exit
;
3659 // Выделяем имя wad-файла и имя карты
3660 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3661 Delete(gMapToDelete
, 1, a
+5);
3662 gMapToDelete
:= UpperCase(gMapToDelete
);
3664 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3667 // Имя карты не стандартное тестовое:
3668 if MapName <> TEST_MAP_NAME then
3671 if not gTempDelete then
3673 time := g_GetFileTime(WadName);
3674 WAD := TWADFile.Create();
3677 if not WAD.ReadFile(WadName) then
3678 begin // Нет такого WAD-файла
3683 // Составляем список карт и ищем нужную:
3685 MapList := WAD.GetResourcesList('');
3687 if MapList <> nil then
3688 for a := 0 to High(MapList) do
3689 if MapList[a] = MapName then
3691 // Удаляем и сохраняем:
3692 WAD.RemoveResource('', MapName);
3693 WAD.SaveTo(WadName);
3698 g_SetFileTime(WadName, time);
3701 if gTempDelete
then DeleteFile(WadName
);
3704 procedure GameCVars(P
: SSArray
);
3707 stat
: TPlayerStatArray
;
3710 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3714 if Length(P
) > 1 then
3719 gsGameFlags
:= gsGameFlags
or Flag
3721 gsGameFlags
:= gsGameFlags
and (not Flag
);
3723 if g_Game_IsServer
then
3726 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3728 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3729 if g_Game_IsNet
then MH_SEND_GameSettings
;
3733 if LongBool(gsGameFlags
and Flag
) then
3734 g_Console_Add(_lc
[OnMsg
])
3736 g_Console_Add(_lc
[OffMsg
]);
3738 if OnMapChange
and g_Game_IsServer
then
3739 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3744 cmd
:= LowerCase(P
[0]);
3746 if cmd
= 'g_gamemode' then
3748 if (Length(P
) > 1) then
3750 a
:= g_Game_TextToMode(P
[1]);
3751 if a
= GM_SINGLE
then a
:= GM_COOP
;
3752 gsGameMode
:= g_Game_ModeToText(a
);
3753 if g_Game_IsServer
then
3755 gSwitchGameMode
:= a
;
3756 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3757 (gState
= STATE_INTERSINGLE
) then
3758 gSwitchGameMode
:= GM_SINGLE
;
3760 gGameSettings
.GameMode
:= gSwitchGameMode
;
3764 if gSwitchGameMode
= gGameSettings
.GameMode
then
3765 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3766 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3768 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3769 [g_Game_ModeToText(gGameSettings
.GameMode
),
3770 g_Game_ModeToText(gSwitchGameMode
)]));
3772 else if cmd
= 'g_friendlyfire' then
3774 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3776 else if cmd
= 'g_friendly_absorb_damage' then
3778 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3780 else if cmd
= 'g_friendly_hit_trace' then
3782 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3784 else if cmd
= 'g_friendly_hit_projectile' then
3786 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3788 else if cmd
= 'g_weaponstay' then
3790 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3792 else if cmd
= 'g_allow_exit' then
3794 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3796 else if cmd
= 'g_allow_monsters' then
3798 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3800 else if cmd
= 'g_bot_vsplayers' then
3802 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3804 else if cmd
= 'g_bot_vsmonsters' then
3806 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3808 else if cmd
= 'g_dm_keys' then
3810 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
3812 else if cmd
= 'g_gameflags' then
3814 if Length(P
) > 1 then
3816 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
3817 if g_Game_IsServer
then
3819 gGameSettings
.Options
:= gsGameFlags
;
3820 if g_Game_IsNet
then MH_SEND_GameSettings
;
3824 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
3826 else if cmd
= 'g_warmup_time' then
3828 if Length(P
) > 1 then
3830 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
3831 if g_Game_IsServer
then
3833 gGameSettings
.WarmupTime
:= gsWarmupTime
;
3834 // extend warmup if it's already going
3835 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
3837 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
3838 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3840 if g_Game_IsNet
then MH_SEND_GameSettings
;
3844 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
3845 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3847 else if cmd
= 'g_spawn_invul' then
3849 if Length(P
) > 1 then
3851 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
3852 if g_Game_IsServer
then
3854 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
3855 if g_Game_IsNet
then MH_SEND_GameSettings
;
3859 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
3861 else if cmd
= 'g_item_respawn_time' then
3863 if Length(P
) > 1 then
3865 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
3866 if g_Game_IsServer
then
3868 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
3869 if g_Game_IsNet
then MH_SEND_GameSettings
;
3873 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
3874 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3876 else if cmd
= 'sv_intertime' then
3878 if (Length(P
) > 1) then
3879 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
3881 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
3883 else if cmd
= 'g_max_particles' then
3885 if Length(p
) = 2 then
3887 a
:= Max(0, StrToInt(p
[1]));
3890 else if Length(p
) = 1 then
3892 e_LogWritefln('%s', [g_GFX_GetMax()])
3896 e_LogWritefln('usage: %s <n>', [cmd
])
3899 else if cmd
= 'g_max_shells' then
3901 if Length(p
) = 2 then
3903 a
:= Max(0, StrToInt(p
[1]));
3906 else if Length(p
) = 1 then
3908 e_LogWritefln('%s', [g_Shells_GetMax()])
3912 e_LogWritefln('usage: %s <n>', [cmd
])
3915 else if cmd
= 'g_max_gibs' then
3917 if Length(p
) = 2 then
3919 a
:= Max(0, StrToInt(p
[1]));
3922 else if Length(p
) = 1 then
3924 e_LogWritefln('%s', [g_Gibs_GetMax()])
3928 e_LogWritefln('usage: %s <n>', [cmd
])
3931 else if cmd
= 'g_max_corpses' then
3933 if Length(p
) = 2 then
3935 a
:= Max(0, StrToInt(p
[1]));
3938 else if Length(p
) = 1 then
3940 e_LogWritefln('%s', [g_Corpses_GetMax()])
3944 e_LogWritefln('usage: %s <n>', [cmd
])
3947 else if cmd
= 'g_scorelimit' then
3949 if Length(P
) > 1 then
3951 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
3953 if g_Game_IsServer
then
3956 if gGameSettings
.GameMode
= GM_DM
then
3958 stat
:= g_Player_GetStats();
3960 for a
:= 0 to High(stat
) do
3961 if stat
[a
].Frags
> b
then
3965 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
3967 // if someone has a higher score, set it to that instead
3968 gsGoalLimit
:= max(gsGoalLimit
, b
);
3969 gGameSettings
.GoalLimit
:= gsGoalLimit
;
3971 if g_Game_IsNet
then MH_SEND_GameSettings
;
3975 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
3977 else if cmd
= 'g_timelimit' then
3979 if Length(P
) > 1 then
3981 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
3982 if g_Game_IsServer
then
3984 gGameSettings
.TimeLimit
:= gsTimeLimit
;
3985 if g_Game_IsNet
then MH_SEND_GameSettings
;
3988 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
3989 [gsTimeLimit
div 3600,
3990 (gsTimeLimit
div 60) mod 60,
3991 gsTimeLimit
mod 60]));
3993 else if cmd
= 'g_maxlives' then
3995 if Length(P
) > 1 then
3997 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
3998 if g_Game_IsServer
then
4000 gGameSettings
.MaxLives
:= gsMaxLives
;
4001 if g_Game_IsNet
then MH_SEND_GameSettings
;
4005 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4009 procedure PlayerSettingsCVars(P
: SSArray
);
4014 function ParseTeam(s
: string): Byte;
4018 'red', '1': result
:= TEAM_RED
;
4019 'blue', '2': result
:= TEAM_BLUE
;
4020 else result
:= TEAM_NONE
;
4024 cmd
:= LowerCase(P
[0]);
4028 if (Length(P
) > 1) then
4030 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4031 if g_Game_IsClient
then
4032 MC_SEND_PlayerSettings
4033 else if gGameOn
and (gPlayer1
<> nil) then
4035 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4036 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4042 if (Length(P
) > 1) then
4044 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4045 if g_Game_IsClient
then
4046 MC_SEND_PlayerSettings
4047 else if gGameOn
and (gPlayer2
<> nil) then
4049 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4050 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4056 if Length(P
) > 3 then
4058 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4059 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4060 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4061 if g_Game_IsClient
then
4062 MC_SEND_PlayerSettings
4063 else if gGameOn
and (gPlayer1
<> nil) then
4065 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4066 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4072 if Length(P
) > 3 then
4074 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4075 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4076 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4077 if g_Game_IsClient
then
4078 MC_SEND_PlayerSettings
4079 else if gGameOn
and (gPlayer2
<> nil) then
4081 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4082 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4088 if (Length(P
) > 1) then
4090 gPlayer1Settings
.Model
:= P
[1];
4091 if g_Game_IsClient
then
4092 MC_SEND_PlayerSettings
4093 else if gGameOn
and (gPlayer1
<> nil) then
4095 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4096 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4097 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4103 if (Length(P
) > 1) then
4105 gPlayer2Settings
.Model
:= P
[1];
4106 if g_Game_IsClient
then
4107 MC_SEND_PlayerSettings
4108 else if gGameOn
and (gPlayer2
<> nil) then
4110 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4111 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4112 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4118 // TODO: switch teams if in game or store this separately
4119 if (Length(P
) > 1) then
4121 team
:= ParseTeam(P
[1]);
4122 if team
= TEAM_NONE
then
4123 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4124 else if not gGameOn
and not g_Game_IsNet
then
4125 gPlayer1Settings
.Team
:= team
4127 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4132 // TODO: switch teams if in game or store this separately
4133 if (Length(P
) > 1) then
4135 team
:= ParseTeam(P
[1]);
4136 if team
= TEAM_NONE
then
4137 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4138 else if not gGameOn
and not g_Game_IsNet
then
4139 gPlayer2Settings
.Team
:= team
4141 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4147 procedure PrintHeapStats();
4151 hs
:= GetFPCHeapStatus();
4152 e_LogWriteLn ('v===== heap status =====v');
4153 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4154 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4155 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4156 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4157 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4158 e_LogWriteLn ('^=======================^');
4161 procedure DebugCommands(P
: SSArray
);
4168 // Команды отладочного режима:
4169 if {gDebugMode}conIsCheatsEnabled
then
4171 cmd
:= LowerCase(P
[0]);
4172 if cmd
= 'd_window' then
4174 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4175 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4177 else if cmd
= 'd_sounds' then
4179 if (Length(P
) > 1) and
4180 ((P
[1] = '1') or (P
[1] = '0')) then
4181 g_Debug_Sounds
:= (P
[1][1] = '1');
4183 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4185 else if cmd
= 'd_frames' then
4187 if (Length(P
) > 1) and
4188 ((P
[1] = '1') or (P
[1] = '0')) then
4189 g_Debug_Frames
:= (P
[1][1] = '1');
4191 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4193 else if cmd
= 'd_winmsg' then
4195 if (Length(P
) > 1) and
4196 ((P
[1] = '1') or (P
[1] = '0')) then
4197 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4199 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4201 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4203 if (Length(P
) > 1) and
4204 ((P
[1] = '1') or (P
[1] = '0')) then
4205 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4207 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4209 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4211 if Length(P
) > 1 then
4213 '0': g_debug_BotAIOff
:= 0;
4214 '1': g_debug_BotAIOff
:= 1;
4215 '2': g_debug_BotAIOff
:= 2;
4216 '3': g_debug_BotAIOff
:= 3;
4219 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4221 else if cmd
= 'd_monster' then
4223 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4224 if Length(P
) < 2 then
4226 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4227 g_Console_Add('ID | Name');
4228 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4229 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4230 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4233 a
:= StrToIntDef(P
[1], 0);
4234 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4235 a
:= g_Mons_TypeIdByName(P
[1]);
4237 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4238 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4241 with gPlayer1
.Obj
do
4243 mon
:= g_Monsters_Create(a
,
4244 X
+ Rect
.X
+ (Rect
.Width
div 2),
4245 Y
+ Rect
.Y
+ Rect
.Height
,
4246 gPlayer1
.Direction
, True);
4248 if (Length(P
) > 2) and (mon
<> nil) then
4250 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4251 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4252 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4253 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4254 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4255 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4256 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4257 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4258 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4263 else if (cmd
= 'd_health') then
4265 if (Length(P
) > 1) and
4266 ((P
[1] = '1') or (P
[1] = '0')) then
4267 g_debug_HealthBar
:= (P
[1][1] = '1');
4269 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4271 else if (cmd
= 'd_player') then
4273 if (Length(P
) > 1) and
4274 ((P
[1] = '1') or (P
[1] = '0')) then
4275 g_debug_Player
:= (P
[1][1] = '1');
4277 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4279 else if (cmd
= 'd_mem') then
4285 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4289 procedure GameCheats(P
: SSArray
);
4295 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4297 g_Console_Add('not available');
4303 g_Console_Add('where is the player?!');
4306 cmd
:= LowerCase(P
[0]);
4310 plr
.GodMode
:= not plr
.GodMode
;
4311 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4314 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4315 if cmd
= 'give' then
4317 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4318 for f
:= 1 to High(P
) do
4320 cmd
:= LowerCase(P
[f
]);
4321 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4322 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4323 if cmd
= 'exit' then
4325 if gTriggers
<> nil then
4327 for a
:= 0 to High(gTriggers
) do
4329 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4331 g_Console_Add('player left the map');
4332 gExitByTrigger
:= True;
4333 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4334 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4342 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4343 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4344 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4345 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4346 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4348 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4349 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4351 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4352 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;
4354 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4355 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4357 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4358 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4360 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4361 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4363 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4364 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4365 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4367 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4368 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4369 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4370 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;
4371 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4372 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4374 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;
4375 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;
4376 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;
4377 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;
4378 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;
4379 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;
4381 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4382 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;
4384 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;
4385 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;
4387 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4389 if cmd
= 'ammo' then
4391 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4392 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4393 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4394 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4395 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4396 g_Console_Add('player got some ammo');
4400 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4401 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4403 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4404 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4406 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4407 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4409 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4410 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4412 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4414 if cmd
= 'weapons' then
4416 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4417 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4418 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4419 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4420 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4421 plr
.GiveItem(ITEM_WEAPON_BFG
);
4422 g_Console_Add('player got weapons');
4426 if cmd
= 'keys' then
4428 plr
.GiveItem(ITEM_KEY_RED
);
4429 plr
.GiveItem(ITEM_KEY_GREEN
);
4430 plr
.GiveItem(ITEM_KEY_BLUE
);
4431 g_Console_Add('player got all keys');
4435 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4440 if cmd
= 'open' then
4442 g_Console_Add('player activated sesame');
4443 g_Triggers_OpenAll();
4450 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4454 if cmd
= 'noclip' then
4457 g_Console_Add('wall hardeness adjusted');
4461 if cmd
= 'notarget' then
4463 plr
.NoTarget
:= not plr
.NoTarget
;
4464 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4468 if cmd
= 'noreload' then
4470 plr
.NoReload
:= not plr
.NoReload
;
4471 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4475 if cmd
= 'speedy' then
4477 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4478 g_Console_Add('speed adjusted');
4482 if cmd
= 'jumpy' then
4484 VEL_JUMP
:= 30-VEL_JUMP
;
4485 g_Console_Add('jump height adjusted');
4489 if cmd
= 'automap' then
4491 gShowMap
:= not gShowMap
;
4492 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4496 if cmd
= 'aimline' then
4498 gAimLine
:= not gAimLine
;
4499 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4504 procedure GameCommands(P
: SSArray
);
4510 pl
: pTNetClient
= nil;
4518 cmd
:= LowerCase(P
[0]);
4520 if cmd
= 'pause' then
4522 if (g_ActiveWindow
= nil) then
4523 g_Game_Pause(not gPauseMain
);
4525 else if cmd
= 'endgame' then
4526 gExit
:= EXIT_SIMPLE
4527 else if cmd
= 'restart' then
4529 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4531 if g_Game_IsClient
then
4533 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4538 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4540 else if cmd
= 'kick' then
4542 if g_Game_IsServer
then
4544 if Length(P
) < 2 then
4546 g_Console_Add('kick <name>');
4551 g_Console_Add('kick <name>');
4555 if g_Game_IsNet
then
4556 pl
:= g_Net_Client_ByName(P
[1]);
4559 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4560 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4561 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4562 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4563 g_Net_Slist_ServerPlayerLeaves();
4564 end else if gPlayers
<> nil then
4565 for a
:= Low(gPlayers
) to High(gPlayers
) do
4566 if gPlayers
[a
] <> nil then
4567 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4569 // Не отключать основных игроков в сингле
4570 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4572 gPlayers
[a
].Lives
:= 0;
4573 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4574 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4575 g_Player_Remove(gPlayers
[a
].UID
);
4576 g_Net_Slist_ServerPlayerLeaves();
4577 // Если не перемешать, при добавлении новых ботов появятся старые
4581 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4583 else if cmd
= 'kick_id' then
4585 if g_Game_IsServer
and g_Game_IsNet
then
4587 if Length(P
) < 2 then
4589 g_Console_Add('kick_id <client ID>');
4594 g_Console_Add('kick_id <client ID>');
4598 a
:= StrToIntDef(P
[1], 0);
4599 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4601 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4603 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4604 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
4605 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4606 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4607 g_Net_Slist_ServerPlayerLeaves();
4611 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4613 else if cmd
= 'kick_pid' then
4615 if g_Game_IsServer
and g_Game_IsNet
then
4617 if Length(P
) < 2 then
4619 g_Console_Add('kick_pid <player ID>');
4624 g_Console_Add('kick_pid <player ID>');
4628 a
:= StrToIntDef(P
[1], 0);
4629 pl
:= g_Net_Client_ByPlayer(a
);
4630 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4632 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4633 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4634 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4635 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4636 g_Net_Slist_ServerPlayerLeaves();
4639 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4641 else if cmd
= 'ban' then
4643 if g_Game_IsServer
and g_Game_IsNet
then
4645 if Length(P
) < 2 then
4647 g_Console_Add('ban <name>');
4652 g_Console_Add('ban <name>');
4656 pl
:= g_Net_Client_ByName(P
[1]);
4659 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4660 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4661 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4662 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4663 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4664 g_Net_Slist_ServerPlayerLeaves();
4666 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4668 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4670 else if cmd
= 'ban_id' then
4672 if g_Game_IsServer
and g_Game_IsNet
then
4674 if Length(P
) < 2 then
4676 g_Console_Add('ban_id <client ID>');
4681 g_Console_Add('ban_id <client ID>');
4685 a
:= StrToIntDef(P
[1], 0);
4686 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4687 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4689 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4690 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
4691 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
4692 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4693 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4694 g_Net_Slist_ServerPlayerLeaves();
4697 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4699 else if cmd
= 'ban_pid' then
4701 if g_Game_IsServer
and g_Game_IsNet
then
4703 if Length(P
) < 2 then
4705 g_Console_Add('ban_pid <player ID>');
4710 g_Console_Add('ban_pid <player ID>');
4714 a
:= StrToIntDef(P
[1], 0);
4715 pl
:= g_Net_Client_ByPlayer(a
);
4716 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4718 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4719 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4720 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4721 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4722 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4723 g_Net_Slist_ServerPlayerLeaves();
4726 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4728 else if cmd
= 'permban' then
4730 if g_Game_IsServer
and g_Game_IsNet
then
4732 if Length(P
) < 2 then
4734 g_Console_Add('permban <name>');
4739 g_Console_Add('permban <name>');
4743 pl
:= g_Net_Client_ByName(P
[1]);
4746 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4747 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4748 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
4749 g_Net_SaveBanList();
4750 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4751 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4752 g_Net_Slist_ServerPlayerLeaves();
4754 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4756 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4758 else if cmd
= 'permban_id' then
4760 if g_Game_IsServer
and g_Game_IsNet
then
4762 if Length(P
) < 2 then
4764 g_Console_Add('permban_id <client ID>');
4769 g_Console_Add('permban_id <client ID>');
4773 a
:= StrToIntDef(P
[1], 0);
4774 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4775 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4777 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4778 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
4779 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
4780 g_Net_SaveBanList();
4781 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4782 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4783 g_Net_Slist_ServerPlayerLeaves();
4786 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4788 else if cmd
= 'permban_pid' then
4790 if g_Game_IsServer
and g_Game_IsNet
then
4792 if Length(P
) < 2 then
4794 g_Console_Add('permban_pid <player ID>');
4799 g_Console_Add('permban_pid <player ID>');
4803 a
:= StrToIntDef(P
[1], 0);
4804 pl
:= g_Net_Client_ByPlayer(a
);
4805 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4807 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4808 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4809 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
4810 g_Net_SaveBanList();
4811 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4812 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4813 g_Net_Slist_ServerPlayerLeaves();
4816 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4818 else if cmd
= 'permban_ip' then
4820 if g_Game_IsServer
and g_Game_IsNet
then
4822 if Length(P
) < 2 then
4824 g_Console_Add('permban_ip <IP address>');
4829 g_Console_Add('permban_ip <IP address>');
4833 g_Net_BanHost(P
[1]);
4834 g_Net_SaveBanList();
4835 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
4837 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4839 else if cmd
= 'unban' then
4841 if g_Game_IsServer
and g_Game_IsNet
then
4843 if Length(P
) < 2 then
4845 g_Console_Add('unban <IP Address>');
4850 g_Console_Add('unban <IP Address>');
4854 if g_Net_UnbanHost(P
[1]) then
4856 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
4857 g_Net_SaveBanList();
4859 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
4861 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4863 else if cmd
= 'clientlist' then
4865 if g_Game_IsServer
and g_Game_IsNet
then
4868 if NetClients
<> nil then
4869 for a
:= Low(NetClients
) to High(NetClients
) do
4870 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4872 plr
:= g_Player_Get(NetClients
[a
].Player
);
4873 if plr
= nil then continue
;
4875 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
4876 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
4879 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
4881 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4883 else if cmd
= 'connect' then
4885 if (NetMode
= NET_NONE
) then
4887 if Length(P
) < 2 then
4889 g_Console_Add('connect <IP> [port] [password]');
4894 g_Console_Add('connect <IP> [port] [password]');
4898 if Length(P
) > 2 then
4899 prt
:= StrToIntDef(P
[2], 25666)
4903 if Length(P
) > 3 then
4908 g_Game_StartClient(P
[1], prt
, pw
);
4911 else if cmd
= 'disconnect' then
4913 if (NetMode
= NET_CLIENT
) then
4916 else if cmd
= 'reconnect' then
4918 if (NetMode
= NET_SERVER
) then
4921 if (NetMode
= NET_CLIENT
) then
4924 gExit
:= EXIT_SIMPLE
;
4928 //TODO: Use last successful password to reconnect, instead of ''
4929 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
4931 else if (cmd
= 'addbot') or
4932 (cmd
= 'bot_add') then
4934 if Length(P
) > 2 then
4935 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
4936 else if Length(P
) > 1 then
4937 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
4939 g_Bot_Add(TEAM_NONE
, 2);
4941 else if cmd
= 'bot_addlist' then
4943 if Length(P
) > 1 then
4945 if Length(P
) = 2 then
4946 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
4947 else if Length(P
) = 3 then
4948 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
4950 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
4953 else if cmd
= 'bot_removeall' then
4955 else if cmd
= 'chat' then
4957 if g_Game_IsNet
then
4959 if Length(P
) > 1 then
4961 for a
:= 1 to High(P
) do
4962 chstr
:= chstr
+ P
[a
] + ' ';
4964 if Length(chstr
) > 200 then SetLength(chstr
, 200);
4966 if Length(chstr
) < 1 then
4968 g_Console_Add('chat <text>');
4972 chstr
:= b_Text_Format(chstr
);
4973 if g_Game_IsClient
then
4974 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
4976 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
4979 g_Console_Add('chat <text>');
4981 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4983 else if cmd
= 'teamchat' then
4985 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
4987 if Length(P
) > 1 then
4989 for a
:= 1 to High(P
) do
4990 chstr
:= chstr
+ P
[a
] + ' ';
4992 if Length(chstr
) > 200 then SetLength(chstr
, 200);
4994 if Length(chstr
) < 1 then
4996 g_Console_Add('teamchat <text>');
5000 chstr
:= b_Text_Format(chstr
);
5001 if g_Game_IsClient
then
5002 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5004 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5005 gPlayer1Settings
.Team
);
5008 g_Console_Add('teamchat <text>');
5010 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5012 else if cmd
= 'game' then
5014 if gGameSettings
.GameType
<> GT_NONE
then
5016 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5019 if Length(P
) = 1 then
5021 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5024 // game not started yet, load fist map from some wad
5026 s
:= addWadExtension(P
[1]);
5027 found
:= e_FindResource(AllMapDirs
, s
);
5031 P
[1] := ExpandFileName(P
[1]);
5032 // if map not choosed then set first map
5033 if Length(P
) < 3 then
5036 P
[2] := g_Game_GetFirstMap(P
[1]);
5039 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5041 if g_Map_Exist(s
) then
5045 with gGameSettings
do
5047 Options
:= gsGameFlags
;
5048 GameMode
:= g_Game_TextToMode(gsGameMode
);
5049 if gSwitchGameMode
<> GM_NONE
then
5050 GameMode
:= gSwitchGameMode
;
5051 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5052 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5054 if Length(P
) >= 4 then
5055 b
:= StrToIntDef(P
[3], 1);
5056 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5057 GoalLimit
, MaxLives
, Options
, b
);
5062 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5064 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5066 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5068 else if cmd
= 'host' then
5070 if gGameSettings
.GameType
<> GT_NONE
then
5072 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5075 if Length(P
) < 4 then
5077 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5080 if not StrToIp(P
[1], listen
) then
5082 prt
:= StrToIntDef(P
[2], 25666);
5084 s
:= addWadExtension(P
[3]);
5085 found
:= e_FindResource(AllMapDirs
, s
);
5089 // get first map in wad, if not specified
5090 if Length(P
) < 5 then
5093 P
[4] := g_Game_GetFirstMap(P
[1]);
5095 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5096 if g_Map_Exist(s
) then
5100 with gGameSettings
do
5102 Options
:= gsGameFlags
;
5103 GameMode
:= g_Game_TextToMode(gsGameMode
);
5104 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5105 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5106 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5108 if Length(P
) >= 6 then
5109 b
:= StrToIntDef(P
[5], 0);
5110 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
5116 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5118 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5123 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5126 else if cmd
= 'map' then
5128 if Length(P
) = 1 then
5130 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5132 g_Console_Add(cmd
+ ' <MAP>');
5133 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5137 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5142 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5144 if Length(P
) < 3 then
5146 // first param is map or wad
5147 s
:= UpperCase(P
[1]);
5148 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5150 gExitByTrigger
:= False;
5153 // already in game, finish current map
5155 gExit
:= EXIT_ENDLEVELCUSTOM
;
5159 // intermission, so change map immediately
5166 found
:= e_FindResource(AllMapDirs
, s
);
5168 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5171 // no such map, found wad
5174 P
[1] := ExpandFileName(pw
);
5175 P
[2] := g_Game_GetFirstMap(P
[1]);
5176 s
:= P
[1] + ':\' + P
[2];
5177 if g_Map_Exist(s
) then
5179 gExitByTrigger
:= False;
5182 // already in game, finish current map
5184 gExit
:= EXIT_ENDLEVELCUSTOM
5188 // intermission, so change map immediately
5195 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5197 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5202 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5208 s
:= addWadExtension(P
[1]);
5209 found
:= e_FindResource(AllMapDirs
, s
);
5213 P
[2] := UpperCase(P
[2]);
5214 s
:= P
[1] + ':\' + P
[2];
5215 if g_Map_Exist(s
) then
5217 gExitByTrigger
:= False;
5221 gExit
:= EXIT_ENDLEVELCUSTOM
5230 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5235 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5241 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5245 else if cmd
= 'nextmap' then
5247 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5249 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5254 if Length(P
) = 1 then
5256 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5258 g_Console_Add(cmd
+ ' <MAP>');
5259 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5264 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5270 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5272 if Length(P
) < 3 then
5274 // first param is map or wad
5275 s
:= UpperCase(P
[1]);
5276 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5279 gExitByTrigger
:= False;
5285 // no such map, found wad
5286 pw
:= addWadExtension(P
[1]);
5287 found
:= e_FindResource(MapDirs
, pw
);
5289 found
:= e_FindResource(WadDirs
, pw
);
5291 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5294 // map not specified, select first map
5296 P
[2] := g_Game_GetFirstMap(P
[1]);
5297 s
:= P
[1] + ':\' + P
[2];
5298 if g_Map_Exist(s
) then
5300 gExitByTrigger
:= False;
5307 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5309 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5314 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5320 // specified two params wad + map
5321 pw
:= addWadExtension(P
[1]);
5322 found
:= e_FindResource(MapDirs
, pw
);
5324 found
:= e_FindResource(MapDirs
, pw
);
5328 P
[2] := UpperCase(P
[2]);
5329 s
:= P
[1] + ':\' + P
[2];
5330 if g_Map_Exist(s
) then
5332 gExitByTrigger
:= False;
5338 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5343 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5349 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5354 if gNextMap
= '' then
5355 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5357 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5361 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5365 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5369 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5371 gExitByTrigger
:= False;
5372 // next map not specified, try to find trigger EXIT
5373 if (gNextMap
= '') and (gTriggers
<> nil) then
5375 for a
:= 0 to High(gTriggers
) do
5377 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5379 gExitByTrigger
:= True;
5380 //gNextMap := gTriggers[a].Data.MapName;
5381 gNextMap
:= gTriggers
[a
].tgcMap
;
5386 if gNextMap
= '' then
5387 gNextMap
:= g_Game_GetNextMap();
5388 if not isWadPath(gNextMap
) then
5389 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5392 if g_Map_Exist(s
) then
5393 gExit
:= EXIT_ENDLEVELCUSTOM
5395 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5399 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5403 else if (cmd
= 'event') then
5405 if (Length(P
) <= 1) then
5407 for a
:= 0 to High(gEvents
) do
5408 if gEvents
[a
].Command
= '' then
5409 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5411 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5414 if (Length(P
) = 2) then
5416 for a
:= 0 to High(gEvents
) do
5417 if gEvents
[a
].Name
= P
[1] then
5418 if gEvents
[a
].Command
= '' then
5419 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5421 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5424 for a
:= 0 to High(gEvents
) do
5425 if gEvents
[a
].Name
= P
[1] then
5427 gEvents
[a
].Command
:= '';
5428 for b
:= 2 to High(P
) do
5429 if Pos(' ', P
[b
]) = 0 then
5430 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5432 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5433 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5437 else if cmd
= 'suicide' then
5441 if g_Game_IsClient
then
5442 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5445 if gPlayer1
<> nil then
5446 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5447 if gPlayer2
<> nil then
5448 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5452 else if cmd
= 'screenshot' then
5456 else if cmd
= 'weapon' then
5458 if Length(p
) = 2 then
5460 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
5461 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5462 gSelectWeapon
[0, a
] := True
5465 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5467 if Length(p
) = 2 then
5469 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
5470 b
:= ord(cmd
[2]) - ord('1');
5471 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5472 gSelectWeapon
[b
, a
] := True
5475 // Команды Своей игры:
5476 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5478 if cmd
= 'bot_addred' then
5480 if Length(P
) > 1 then
5481 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5483 g_Bot_Add(TEAM_RED
, 2);
5485 else if cmd
= 'bot_addblue' then
5487 if Length(P
) > 1 then
5488 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5490 g_Bot_Add(TEAM_BLUE
, 2);
5492 else if cmd
= 'spectate' then
5498 else if cmd
= 'say' then
5500 if g_Game_IsServer
and g_Game_IsNet
then
5502 if Length(P
) > 1 then
5505 for a
:= 1 to High(P
) do
5506 chstr
:= chstr
+ P
[a
] + ' ';
5508 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5510 if Length(chstr
) < 1 then
5512 g_Console_Add('say <text>');
5516 chstr
:= b_Text_Format(chstr
);
5517 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5519 else g_Console_Add('say <text>');
5521 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5523 else if cmd
= 'tell' then
5525 if g_Game_IsServer
and g_Game_IsNet
then
5527 if (Length(P
) > 2) and (P
[1] <> '') then
5530 for a
:= 2 to High(P
) do
5531 chstr
:= chstr
+ P
[a
] + ' ';
5533 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5535 if Length(chstr
) < 1 then
5537 g_Console_Add('tell <playername> <text>');
5541 pl
:= g_Net_Client_ByName(P
[1]);
5543 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5545 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5547 else g_Console_Add('tell <playername> <text>');
5549 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5551 else if cmd
= 'centerprint' then
5553 if (Length(P
) > 2) and (P
[1] <> '') then
5556 for a
:= 2 to High(P
) do
5557 chstr
:= chstr
+ P
[a
] + ' ';
5559 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5561 if Length(chstr
) < 1 then
5563 g_Console_Add('centerprint <timeout> <text>');
5567 a
:= StrToIntDef(P
[1], 100);
5568 chstr
:= b_Text_Format(chstr
);
5569 g_Game_Message(chstr
, a
);
5570 if g_Game_IsNet
and g_Game_IsServer
then
5571 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
5573 else g_Console_Add('centerprint <timeout> <text>');
5575 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5577 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5579 // Дополнительное время:
5580 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5582 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5583 [gGameSettings
.TimeLimit
div 3600,
5584 (gGameSettings
.TimeLimit
div 60) mod 60,
5585 gGameSettings
.TimeLimit
mod 60]));
5586 if g_Game_IsNet
then MH_SEND_GameSettings
;
5588 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5590 if (Length(P
) <= 1) then
5591 g_Console_Add('rcon_password <password>')
5593 MC_SEND_RCONPassword(P
[1]);
5595 else if cmd
= 'rcon' then
5597 if g_Game_IsClient
then
5599 if Length(P
) > 1 then
5602 for a
:= 1 to High(P
) do
5603 chstr
:= chstr
+ P
[a
] + ' ';
5605 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5607 if Length(chstr
) < 1 then
5609 g_Console_Add('rcon <command>');
5613 MC_SEND_RCONCommand(chstr
);
5615 else g_Console_Add('rcon <command>');
5618 else if cmd
= 'ready' then
5620 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5621 gLMSRespawnTime
:= gTime
+ 100;
5623 else if (cmd
= 'callvote') and g_Game_IsNet
then
5625 if Length(P
) > 1 then
5628 for a
:= 1 to High(P
) do begin
5629 if a
> 1 then chstr
:= chstr
+ ' ';
5630 chstr
:= chstr
+ P
[a
];
5633 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5635 if Length(chstr
) < 1 then
5637 g_Console_Add('callvote <command>');
5641 if g_Game_IsClient
then
5642 MC_SEND_Vote(True, chstr
)
5644 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5645 g_Console_Process('vote', True);
5648 g_Console_Add('callvote <command>');
5650 else if (cmd
= 'vote') and g_Game_IsNet
then
5652 if g_Game_IsClient
then
5654 else if gVoteInProgress
then
5656 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5657 a
:= Floor((NetClientCount
+1)/2.0) + 1
5659 a
:= Floor(NetClientCount
/2.0) + 1;
5664 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5665 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5671 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5672 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5680 procedure SystemCommands(P
: SSArray
);
5684 cmd
:= LowerCase(P
[0]);
5695 if Length(p
) = 2 then
5697 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
5699 gFrameTime
:= 1000 div gMaxFPS
5703 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
5707 if Length(p
) = 2 then
5709 gAskLanguage
:= true;
5710 gLanguage
:= LANGUAGE_ENGLISH
;
5711 case LowerCase(p
[1]) of
5714 gAskLanguage
:= false;
5715 gLanguage
:= LANGUAGE_ENGLISH
;
5719 gAskLanguage
:= false;
5720 gLanguage
:= LANGUAGE_RUSSIAN
;
5724 gAskLanguage
:= true;
5725 gLanguage
:= LANGUAGE_ENGLISH
;
5728 g_Language_Set(gLanguage
);
5732 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
5738 procedure g_TakeScreenShot(Filename
: string = '');
5739 var t
: TDateTime
; dir
, date
, name
: String;
5741 if e_NoGraphics
then
5744 dir
:= e_GetWriteableDir(ScreenshotDirs
);
5745 if Filename
= '' then
5748 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
5749 Filename
:= 'screenshot-' + date
;
5752 name
:= e_CatPath(dir
, Filename
+ '.png');
5753 if r_Render_WriteScreenShot(name
) then
5754 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
5756 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
5759 procedure g_Game_InGameMenu(Show
: Boolean);
5761 if (g_ActiveWindow
= nil) and Show
then
5763 if gGameSettings
.GameType
= GT_SINGLE
then
5764 g_GUI_ShowWindow('GameSingleMenu')
5767 if g_Game_IsClient
then
5768 g_GUI_ShowWindow('GameClientMenu')
5770 if g_Game_IsNet
then
5771 g_GUI_ShowWindow('GameServerMenu')
5773 g_GUI_ShowWindow('GameCustomMenu');
5775 g_Sound_PlayEx('MENU_OPEN');
5777 // Пауза при меню только в одиночной игре:
5778 if (not g_Game_IsNet
) then
5782 if (g_ActiveWindow
<> nil) and (not Show
) then
5784 // Пауза при меню только в одиночной игре:
5785 if (not g_Game_IsNet
) then
5786 g_Game_Pause(False);
5790 procedure g_Game_Pause (Enable
: Boolean);
5794 if not gGameOn
then exit
;
5796 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
5799 gPauseMain
:= Enable
;
5801 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
5804 procedure g_Game_HolmesPause (Enable
: Boolean);
5808 if not gGameOn
then exit
;
5809 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
5812 gPauseHolmes
:= Enable
;
5814 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
5817 procedure g_Game_PauseAllSounds(Enable
: Boolean);
5822 if gTriggers
<> nil then
5823 for i
:= 0 to High(gTriggers
) do
5824 with gTriggers
[i
] do
5825 if (TriggerType
= TRIGGER_SOUND
) and
5827 Sound
.IsPlaying() then
5829 Sound
.Pause(Enable
);
5833 if gPlayers
<> nil then
5834 for i
:= 0 to High(gPlayers
) do
5835 if gPlayers
[i
] <> nil then
5836 gPlayers
[i
].PauseSounds(Enable
);
5839 if gMusic
<> nil then
5840 gMusic
.Pause(Enable
);
5843 procedure g_Game_StopAllSounds(all
: Boolean);
5847 if gTriggers
<> nil then
5848 for i
:= 0 to High(gTriggers
) do
5849 with gTriggers
[i
] do
5850 if (TriggerType
= TRIGGER_SOUND
) and
5854 if gMusic
<> nil then
5861 procedure g_Game_UpdateTriggerSounds
;
5864 if gTriggers
<> nil then
5865 for i
:= 0 to High(gTriggers
) do
5866 with gTriggers
[i
] do
5867 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
5868 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
5871 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
5874 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
5879 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
5884 if gSpectMode
<> SPECT_PLAYERS
then
5886 if gSpectPID1
= UID
then
5891 if gSpectViewTwo
and (gSpectPID2
= UID
) then
5898 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
5903 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
5908 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
5913 if gSpectMode
<> SPECT_PLAYERS
then
5915 Pl
:= g_Player_Get(gSpectPID1
);
5916 if (Pl
<> nil) and (Pl
.Team
= Team
) then
5921 if gSpectViewTwo
then
5923 Pl
:= g_Player_Get(gSpectPID2
);
5924 if (Pl
<> nil) and (Pl
.Team
= Team
) then
5932 procedure g_Game_Message (Msg
: string; Time
: Word);
5935 MessageTime
:= Time
;
5938 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
5940 punct
: Array[0..13] of String =
5941 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
5947 function IsPunctuation(S
: String): Boolean;
5952 if Length(S
) <> 1 then
5954 for i
:= Low(punct
) to High(punct
) do
5955 if S
= punct
[i
] then
5961 function FilterPunctuation(S
: String): String;
5965 for i
:= Low(punct
) to High(punct
) do
5966 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
5972 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
5974 // remove player name
5975 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
5976 // for FullWord check
5977 Text := toLowerCase1251(' ' + Text + ' ');
5978 fpText
:= FilterPunctuation(Text);
5980 for i
:= 0 to Length(gChatSounds
) - 1 do
5983 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
5985 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
5986 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
5988 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
5994 gChatSounds
[i
].Sound
.Play();
6000 g_Sound_PlayEx('SOUND_GAME_RADIO');
6003 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6012 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6016 if goodsnd
[a
].IsPlaying() then
6019 goodsnd
[Random(4)].Play();
6022 procedure g_Game_Announce_KillCombo(Param
: Integer);
6029 UID
:= Param
and $FFFF;
6034 Pl
:= g_Player_Get(UID
);
6043 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6047 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6051 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6055 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6063 if not g_Game_IsWatchedPlayer(UID
) then
6066 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6070 if killsnd
[n
].IsPlaying() then
6075 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6083 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6087 if hahasnd
[a
].IsPlaying() then
6090 hahasnd
[Random(3)].Play();
6093 procedure g_Game_StartVote(Command
, Initiator
: string);
6097 if not gVotesEnabled
then Exit
;
6098 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6099 if gVoteInProgress
or gVotePassed
then
6101 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6102 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6105 gVoteInProgress
:= True;
6106 gVotePassed
:= False;
6107 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6110 gVoteCommand
:= Command
;
6112 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6113 Need
:= Floor((NetClientCount
+1)/2.0)+1
6115 Need
:= Floor(NetClientCount
/2.0)+1;
6116 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6117 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6120 procedure g_Game_CheckVote
;
6124 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6125 if not gVoteInProgress
then Exit
;
6127 if (gTime
>= gVoteTimer
) then
6129 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6130 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6132 Need
:= Floor(NetClientCount
/2.0) + 1;
6133 if gVoteCount
>= Need
then
6135 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6136 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6137 gVotePassed
:= True;
6138 gVoteCmdTimer
:= gTime
+ 5000;
6142 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6143 MH_SEND_VoteEvent(NET_VE_FAILED
);
6145 if NetClients
<> nil then
6146 for I
:= Low(NetClients
) to High(NetClients
) do
6147 if NetClients
[i
].Used
then
6148 NetClients
[i
].Voted
:= False;
6149 gVoteInProgress
:= False;
6155 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6156 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6158 Need
:= Floor(NetClientCount
/2.0) + 1;
6159 if gVoteCount
>= Need
then
6161 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6162 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6163 gVoteInProgress
:= False;
6164 gVotePassed
:= True;
6165 gVoteCmdTimer
:= gTime
+ 5000;
6168 if NetClients
<> nil then
6169 for I
:= Low(NetClients
) to High(NetClients
) do
6170 if NetClients
[i
].Used
then
6171 NetClients
[i
].Voted
:= False;
6176 procedure g_Game_LoadMapList(FileName
: string);
6184 if not FileExists(FileName
) then Exit
;
6186 AssignFile(ListFile
, FileName
);
6188 while not EOF(ListFile
) do
6190 ReadLn(ListFile
, s
);
6193 if s
= '' then Continue
;
6195 SetLength(MapList
, Length(MapList
)+1);
6196 MapList
[High(MapList
)] := s
;
6198 CloseFile(ListFile
);
6201 procedure g_Game_SetDebugMode();
6204 // Читы (даже в своей игре):
6208 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6212 if Length(LoadingStat
.Msgs
) = 0 then
6218 begin // Переходим на следующую строку или скроллируем:
6219 if NextMsg
= Length(Msgs
) then
6221 for i
:= 0 to High(Msgs
)-1 do
6222 Msgs
[i
] := Msgs
[i
+1];
6230 Msgs
[NextMsg
-1] := Text;
6234 PBarWasHere
:= false;
6237 g_ActiveWindow
:= nil;
6239 ProcessLoading(true);
6242 procedure g_Game_StepLoading(Value
: Integer = -1);
6253 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6261 procedure g_Game_ClearLoading();
6270 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6271 if len
< 1 then len
:= 1;
6272 SetLength(Msgs
, len
);
6273 for len
:= Low(Msgs
) to High(Msgs
) do
6276 PBarWasHere
:= false;
6280 procedure Parse_Params(var pars
: TParamStrValues
);
6287 while i
<= ParamCount
do
6290 if (s
[1] = '-') and (Length(s
) > 1) then
6292 if (s
[2] = '-') and (Length(s
) > 2) then
6293 begin // Одиночный параметр
6294 SetLength(pars
, Length(pars
) + 1);
6295 with pars
[High(pars
)] do
6297 Name
:= LowerCase(s
);
6302 if (i
< ParamCount
) then
6303 begin // Параметр со значением
6305 SetLength(pars
, Length(pars
) + 1);
6306 with pars
[High(pars
)] do
6308 Name
:= LowerCase(s
);
6309 Value
:= LowerCase(ParamStr(i
));
6318 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6323 for i
:= 0 to High(pars
) do
6324 if pars
[i
].Name
= aName
then
6326 Result
:= pars
[i
].Value
;
6331 procedure g_Game_Process_Params();
6333 pars
: TParamStrValues
;
6336 LimT
, LimS
: Integer;
6347 s
:= Find_Param_Value(pars
, '--debug');
6350 g_Game_SetDebugMode();
6351 s
:= Find_Param_Value(pars
, '--netdump');
6356 // Connect when game loads
6357 ip
:= Find_Param_Value(pars
, '-connect');
6361 s
:= Find_Param_Value(pars
, '-port');
6362 if (s
= '') or not TryStrToInt(s
, Port
) then
6365 s
:= Find_Param_Value(pars
, '-pw');
6367 g_Game_StartClient(ip
, Port
, s
);
6371 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6374 gDefaultMegawadStart
:= s
;
6377 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6378 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6380 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6383 // Start map when game loads:
6384 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6385 if isWadPath(map
) then
6388 s
:= Find_Param_Value(pars
, '-gm');
6389 GMode
:= g_Game_TextToMode(s
);
6390 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6391 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6394 s
:= Find_Param_Value(pars
, '-limt');
6395 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6401 s
:= Find_Param_Value(pars
, '-lims');
6402 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6408 s
:= Find_Param_Value(pars
, '-lives');
6409 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6415 s
:= Find_Param_Value(pars
, '-opt');
6419 Opt
:= StrToIntDef(s
, 0);
6422 s
:= Find_Param_Value(pars
, '--close');
6426 // Override map to test:
6427 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6430 if e_IsValidResourceName(s
) then
6431 e_FindResource(AllMapDirs
, s
);
6432 gTestMap
:= ExpandFileName(s
);
6435 // Delete test map after play:
6436 s
:= Find_Param_Value(pars
, '--testdelete');
6439 //gMapToDelete := MapsDir + map;
6440 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6444 // Delete temporary WAD after play:
6445 s
:= Find_Param_Value(pars
, '--tempdelete');
6446 if (s
<> '') and (gTestMap
<> '') then
6448 gMapToDelete
:= gTestMap
;
6449 gTempDelete
:= True;
6452 // Number of players:
6453 s
:= Find_Param_Value(pars
, '-pl');
6455 n
:= DEFAULT_PLAYERS
6457 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6460 s
:= Find_Param_Value(pars
, '-port');
6461 if (s
= '') or not TryStrToInt(s
, Port
) then
6462 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6464 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6467 // Execute script when game loads:
6468 s
:= Find_Param_Value(pars
, '-exec');
6471 // if not isWadPath(s) then
6472 // s := GameDir + '/' + s;
6477 if IOResult
<> 0 then
6479 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6480 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6484 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6485 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6490 if IOResult
<> 0 then
6492 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6493 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6497 if Pos('#', s
) <> 1 then // script comment
6498 g_Console_Process(s
, True);
6509 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6510 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6511 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6512 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6514 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6515 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6516 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6517 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6519 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6520 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6522 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6523 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6525 {$IFDEF ENABLE_HOLMES}
6526 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6529 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6531 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6532 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6534 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6535 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6537 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6538 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6539 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6540 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
6541 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6542 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6543 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6544 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6545 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');