1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
24 SysUtils
, Classes
, MAPDEF
,
25 g_base
, g_basic
, g_player
, g_res_downloader
,
26 g_sound
, utils
, md5
, mempool
, xprofiler
,
31 TGameSettings
= record
38 ItemRespawnTime
: Word;
49 TDelayedEvent
= record
58 Sound
: TPlayableSound
;
59 Tags
: Array of String;
63 TPlayerSettings
= record
68 // ones below are sent only to the server
70 WeaponPreferences
: Array[WP_FIRST
..WP_LAST
+1] of Byte;
87 function g_Game_IsNet(): Boolean;
88 function g_Game_IsServer(): Boolean;
89 function g_Game_IsClient(): Boolean;
90 procedure g_Game_Init();
91 procedure g_Game_Free (freeTextures
: Boolean=true);
92 procedure g_Game_LoadData();
93 procedure g_Game_FreeData();
94 procedure g_Game_Update();
95 procedure g_Game_PreUpdate();
96 procedure g_Game_Quit();
97 function g_Game_ModeToText(Mode
: Byte): string;
98 function g_Game_TextToMode(Mode
: string): Byte;
99 procedure g_Game_ExecuteEvent(Name
: String);
100 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
101 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
102 procedure g_Game_RemovePlayer();
103 procedure g_Game_Spectate();
104 procedure g_Game_SpectateCenterView();
105 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
106 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
107 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
108 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
109 procedure g_Game_Restart();
110 procedure g_Game_RestartLevel();
111 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
112 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
113 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
114 procedure g_Game_ChangeMap(const MapPath
: String);
115 procedure g_Game_ExitLevel(const Map
: AnsiString);
116 function g_Game_GetFirstMap(WAD
: String): String;
117 function g_Game_GetNextMap(): String;
118 procedure g_Game_NextLevel();
119 procedure g_Game_Pause(Enable
: Boolean);
120 procedure g_Game_HolmesPause(Enable
: Boolean);
121 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
122 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
123 procedure g_Game_Message(Msg
: String; Time
: Word);
124 procedure g_Game_LoadMapList(FileName
: String);
125 procedure g_Game_PauseAllSounds(Enable
: Boolean);
126 procedure g_Game_StopAllSounds(all
: Boolean);
127 procedure g_Game_UpdateTriggerSounds();
128 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
129 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
130 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
131 procedure g_Game_Announce_KillCombo(Param
: Integer);
132 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
133 procedure g_Game_StartVote(Command
, Initiator
: string);
134 procedure g_Game_CheckVote
;
136 procedure g_TakeScreenShot(Filename
: string = '');
138 procedure g_FatalError(Text: String);
139 procedure g_SimpleError(Text: String);
140 function g_Game_IsTestMap(): Boolean;
141 procedure g_Game_DeleteTestMap();
142 procedure GameCVars(P
: SSArray
);
143 procedure PlayerSettingsCVars(P
: SSArray
);
144 procedure SystemCommands(P
: SSArray
);
145 procedure GameCommands(P
: SSArray
);
146 procedure GameCheats(P
: SSArray
);
147 procedure DebugCommands(P
: SSArray
);
148 procedure g_Game_Process_Params
;
149 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
150 procedure g_Game_StepLoading(Value
: Integer = -1);
151 procedure g_Game_ClearLoading();
152 procedure g_Game_SetDebugMode();
154 function IsActivePlayer(p
: TPlayer
): Boolean;
155 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
156 procedure SortGameStat(var stat
: TPlayerStatArray
);
160 procedure g_Game_InGameMenu(Show
: Boolean);
163 procedure CharPress (C
: AnsiChar);
165 procedure KeyPress (K
: Word);
167 { procedure SetWinPause(Enable: Boolean); }
172 LOADING_SHOW_STEP
= 100;
173 LOADING_INTERLINE
= 20;
191 EXIT_ENDLEVELSINGLE
= 4;
192 EXIT_ENDLEVELCUSTOM
= 5;
194 GAME_OPTION_RESERVED
= 1;
195 GAME_OPTION_TEAMDAMAGE
= 2;
196 GAME_OPTION_ALLOWEXIT
= 4;
197 GAME_OPTION_WEAPONSTAY
= 8;
198 GAME_OPTION_MONSTERS
= 16;
199 GAME_OPTION_BOTVSPLAYER
= 32;
200 GAME_OPTION_BOTVSMONSTER
= 64;
201 GAME_OPTION_DMKEYS
= 128;
202 GAME_OPTION_TEAMHITTRACE
= 256;
203 GAME_OPTION_TEAMHITPROJECTILE
= 512;
204 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
205 GAME_OPTION_ALLOWDROPFLAG
= 2048;
206 GAME_OPTION_THROWFLAG
= 4096;
211 STATE_INTERCUSTOM
= 3;
212 STATE_INTERSINGLE
= 4;
218 LMS_RESPAWN_NONE
= 0;
219 LMS_RESPAWN_WARMUP
= 1;
220 LMS_RESPAWN_FINAL
= 2;
237 CONFIG_FILENAME
= 'Doom2DF.cfg';
239 TEST_MAP_NAME
= '$$$_TEST_$$$';
241 STD_PLAYER_MODEL
= 'Doomer';
249 STATFILE_VERSION
= $03;
252 gGameSettings
: TGameSettings
;
253 gPlayer1Settings
: TPlayerSettings
;
254 gPlayer2Settings
: TPlayerSettings
;
256 gPlayerScreenSize
: TDFPoint
;
257 gPlayer1ScreenCoord
: TDFPoint
;
258 gPlayer2ScreenCoord
: TDFPoint
;
259 gPlayer1
: TPlayer
= nil;
260 gPlayer2
: TPlayer
= nil;
261 gPlayerDrawn
: TPlayer
= nil;
263 gLerpFactor
: Single = 1.0;
264 gSwitchGameMode
: Byte = GM_DM
;
265 gHearPoint1
, gHearPoint2
: THearPoint
;
266 gSoundEffectsDF
: Boolean = False;
267 gSoundTriggerTime
: Word = 0;
268 gAnnouncer
: Integer = ANNOUNCE_NONE
;
269 goodsnd
: array[0..3] of TPlayableSound
;
270 killsnd
: array[0..3] of TPlayableSound
;
271 hahasnd
: array[0..2] of TPlayableSound
;
272 sound_get_flag
: array[0..1] of TPlayableSound
;
273 sound_lost_flag
: array[0..1] of TPlayableSound
;
274 sound_ret_flag
: array[0..1] of TPlayableSound
;
275 sound_cap_flag
: array[0..1] of TPlayableSound
;
276 gBodyKillEvent
: Integer = -1;
277 gDefInterTime
: ShortInt = -1;
278 gInterEndTime
: LongWord = 0;
279 gInterTime
: LongWord = 0;
280 gServInterTime
: Byte = 0;
281 gGameStartTime
: LongWord = 0;
282 gTotalMonsters
: Integer = 0;
283 gPauseMain
: Boolean = false;
284 gPauseHolmes
: Boolean = false;
285 gShowTime
: Boolean = False;
286 gShowFPS
: Boolean = False;
287 gShowScore
: Boolean = True;
288 gShowStat
: Boolean = True;
289 gShowPIDs
: Boolean = False;
290 gShowKillMsg
: Boolean = True;
291 gShowLives
: Boolean = True;
292 gShowPing
: Boolean = False;
293 gShowMap
: Boolean = False;
295 gState
: Byte = STATE_NONE
;
297 sWidth
, sHeight
: Word;
298 gSpectMode
: Byte = SPECT_NONE
;
299 gSpectHUD
: Boolean = True;
300 gSpectKeyPress
: Boolean = False;
301 gSpectX
: Integer = 0;
302 gSpectY
: Integer = 0;
303 gSpectStep
: Byte = 8;
304 gSpectViewTwo
: Boolean = False;
305 gSpectPID1
: Integer = -1;
306 gSpectPID2
: Integer = -1;
307 gSpectAuto
: Boolean = False;
308 gSpectAutoNext
: LongWord;
309 gSpectAutoStepX
: Integer;
310 gSpectAutoStepY
: Integer;
311 gMusic
: TMusic
= nil;
312 gLoadGameMode
: Boolean;
313 gCheats
: Boolean = False;
314 gMapOnce
: Boolean = False;
315 gMapToDelete
: String;
316 gTempDelete
: Boolean = False;
317 gLastMap
: Boolean = False;
320 gResolutionChange
: Boolean = False;
321 gRC_Width
, gRC_Height
: Integer;
322 gRC_FullScreen
, gRC_Maximized
: Boolean;
323 gLanguageChange
: Boolean = False;
324 gDebugMode
: Boolean = False;
325 g_debug_Sounds
: Boolean = False;
326 g_debug_Frames
: Boolean = False;
327 g_debug_WinMsgs
: Boolean = False;
328 g_debug_MonsterOff
: Boolean = False;
329 g_debug_BotAIOff
: Byte = 0;
330 g_debug_HealthBar
: Boolean = False;
331 g_Debug_Player
: Boolean = False;
332 gCoopMonstersKilled
: Word = 0;
333 gCoopSecretsFound
: Word = 0;
334 gCoopTotalMonstersKilled
: Word = 0;
335 gCoopTotalSecretsFound
: Word = 0;
336 gCoopTotalMonsters
: Word = 0;
337 gCoopTotalSecrets
: Word = 0;
338 gStatsOff
: Boolean = False;
339 gStatsPressed
: Boolean = False;
340 gExitByTrigger
: Boolean = False;
341 gNextMap
: String = '';
342 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
343 gLMSRespawnTime
: Cardinal = 0;
344 gLMSSoftSpawn
: Boolean = False;
345 gMissionFailed
: Boolean = False;
346 gVoteInProgress
: Boolean = False;
347 gVotePassed
: Boolean = False;
348 gVoteCommand
: string = '';
349 gVoteTimer
: Cardinal = 0;
350 gVoteCmdTimer
: Cardinal = 0;
351 gVoteCount
: Integer = 0;
352 gVoteTimeout
: Cardinal = 30;
353 gVoted
: Boolean = False;
354 gVotesEnabled
: Boolean = True;
355 gEvents
: Array of TGameEvent
;
356 gDelayedEvents
: Array of TDelayedEvent
;
357 gUseChatSounds
: Boolean = True;
358 gChatSounds
: Array of TChatSound
;
359 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
360 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
361 gInterReadyCount
: Integer = 0;
362 gMaxBots
: Integer = 127;
364 g_dbg_ignore_bounds
: Boolean = false;
365 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
366 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
368 // move button values:
369 // bits 0-1: l/r state:
370 // 0: neither left, nor right pressed
373 // bits 4-5: l/r state when strafe was pressed
374 P1MoveButton
: Byte = 0;
375 P2MoveButton
: Byte = 0;
377 g_profile_frame_update
: Boolean = false;
378 g_profile_frame_draw
: Boolean = false;
379 g_profile_collision
: Boolean = false;
380 g_profile_los
: Boolean = false;
381 g_profile_history_size
: Integer = 1000;
383 g_rlayer_back
: Boolean = true;
384 g_rlayer_step
: Boolean = true;
385 g_rlayer_wall
: Boolean = true;
386 g_rlayer_door
: Boolean = true;
387 g_rlayer_acid1
: Boolean = true;
388 g_rlayer_acid2
: Boolean = true;
389 g_rlayer_water
: Boolean = true;
390 g_rlayer_fore
: Boolean = true;
392 wNeedTimeReset
: Boolean = false;
394 procedure g_ResetDynlights ();
395 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
396 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
398 function conIsCheatsEnabled (): Boolean; inline;
399 function gPause (): Boolean; inline;
401 type (* private state *)
402 TEndCustomGameStat
= record
403 PlayerStat
: TPlayerStatArray
;
407 Map
, MapName
: String;
410 TEndSingleGameStat
= record
411 PlayerStat
: Array [0..1] of record
417 TotalSecrets
: Integer;
420 TLoadingStat
= record
424 Msgs
: Array of String;
426 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
430 x
, y
, radius
: Integer;
433 exploRadius
: Integer;
436 var (* private state *)
437 CustomStat
: TEndCustomGameStat
;
438 StatShotDone
: Boolean;
439 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
440 SingleStat
: TEndSingleGameStat
;
441 LoadingStat
: TLoadingStat
;
444 EndingGameCounter
: Byte;
446 g_playerLight
: Boolean;
447 g_dynLights
: array of TDynLight
= nil;
448 g_dynLightCount
: Integer = 0;
449 EndPicPath
: AnsiString; // full path, used by render
454 {$IFDEF ENABLE_HOLMES}
466 {$IFDEF ENABLE_SHELLS}
473 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
474 g_playermodel
, g_options
, Math
,
475 g_triggers
, g_monsters
, e_sound
, CONFIG
,
476 g_language
, g_net
, g_phys
,
477 ENet
, e_msg
, g_netmsg
, g_netmaster
,
481 charbuff
: packed array [0..15] of AnsiChar = (
482 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
485 function Translit (const S
: AnsiString): AnsiString;
490 for i
:= 1 to Length(Result
) do
493 #
$C9: Result
[i
] := 'Q';
494 #
$D6: Result
[i
] := 'W';
495 #
$D3: Result
[i
] := 'E';
496 #
$CA: Result
[i
] := 'R';
497 #
$C5: Result
[i
] := 'T';
498 #
$CD: Result
[i
] := 'Y';
499 #
$C3: Result
[i
] := 'U';
500 #
$D8: Result
[i
] := 'I';
501 #
$D9: Result
[i
] := 'O';
502 #
$C7: Result
[i
] := 'P';
503 #
$D5: Result
[i
] := '['; //Chr(219);
504 #
$DA: Result
[i
] := ']'; //Chr(221);
505 #
$D4: Result
[i
] := 'A';
506 #
$DB: Result
[i
] := 'S';
507 #
$C2: Result
[i
] := 'D';
508 #
$C0: Result
[i
] := 'F';
509 #
$CF: Result
[i
] := 'G';
510 #
$D0: Result
[i
] := 'H';
511 #
$CE: Result
[i
] := 'J';
512 #
$CB: Result
[i
] := 'K';
513 #
$C4: Result
[i
] := 'L';
514 #
$C6: Result
[i
] := ';'; //Chr(186);
515 #
$DD: Result
[i
] := #39; //Chr(222);
516 #
$DF: Result
[i
] := 'Z';
517 #
$D7: Result
[i
] := 'X';
518 #
$D1: Result
[i
] := 'C';
519 #
$CC: Result
[i
] := 'V';
520 #
$C8: Result
[i
] := 'B';
521 #
$D2: Result
[i
] := 'N';
522 #
$DC: Result
[i
] := 'M';
523 #
$C1: Result
[i
] := ','; //Chr(188);
524 #
$DE: Result
[i
] := '.'; //Chr(190);
530 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
535 ls2
:= Translit(CheatRus
[ct
]);
536 if length(ls1
) = 0 then ls1
:= '~';
537 if length(ls2
) = 0 then ls2
:= '~';
539 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
540 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
541 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
542 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
544 if ct = I_GAME_CHEAT_JETPACK then
546 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
547 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
548 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
549 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
550 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
551 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
567 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
568 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
569 or g_Game_IsNet then Exit;
571 if not gGameOn
then exit
;
572 if not conIsCheatsEnabled
then exit
;
574 s
:= 'SOUND_GAME_RADIO';
577 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
579 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
580 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
584 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
586 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
587 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
591 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
593 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
594 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
598 if CheckCheat(I_GAME_CHEAT_DEATH
) then
600 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
601 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
602 s
:= 'SOUND_MONSTER_HAHA';
606 if CheckCheat(I_GAME_CHEAT_DOORS
) then
608 g_Triggers_OpenAll();
612 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
614 if gTriggers
<> nil then
615 for a
:= 0 to High(gTriggers
) do
616 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
618 gExitByTrigger
:= True;
619 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
620 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
626 s2
:= Copy(charbuff
, 15, 2);
627 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
629 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
637 if CheckCheat(I_GAME_CHEAT_FLY
) then
643 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
645 VEL_JUMP
:= 30-VEL_JUMP
;
649 if CheckCheat(I_GAME_CHEAT_SPEED
) then
651 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
655 if CheckCheat(I_GAME_CHEAT_SUIT
) then
657 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
658 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
662 if CheckCheat(I_GAME_CHEAT_AIR
) then
664 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
665 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
669 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
671 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
672 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
676 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
678 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
679 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
683 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
685 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
686 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
690 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
692 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
693 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
697 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
699 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
700 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
703 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
705 gAimLine
:= not gAimLine
;
708 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
710 gShowMap
:= not gShowMap
;
721 procedure KeyPress (K
: Word);
722 var Msg
: g_gui
.TMessage
;
727 if (g_ActiveWindow
<> nil) then
729 Msg
.Msg
:= WM_KEYDOWN
;
730 Msg
.WParam
:= VK_ESCAPE
;
731 g_ActiveWindow
.OnMessage(Msg
);
732 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
734 else if (gState
<> STATE_FOLD
) then
736 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
738 g_Game_InGameMenu(True);
740 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
742 if (gState
<> STATE_MENU
) then
744 if (NetMode
<> NET_NONE
) then
746 g_Game_StopAllSounds(True);
748 gState
:= STATE_MENU
;
752 g_GUI_ShowWindow('MainMenu');
753 g_Sound_PlayEx('MENU_OPEN');
758 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
759 begin // <F2> .. <F6> � <F12>
760 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
762 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
763 if (not g_Game_IsNet
) then g_Game_Pause(True);
765 IK_F2
: g_Menu_Show_SaveMenu();
766 IK_F3
: g_Menu_Show_LoadMenu();
767 IK_F4
: g_Menu_Show_GameSetGame();
768 IK_F5
: g_Menu_Show_OptionsVideo();
769 IK_F6
: g_Menu_Show_OptionsSound();
770 IK_F7
: g_Menu_Show_EndGameMenu();
771 IK_F10
: g_Menu_Show_QuitGameMenu();
778 gJustChatted
:= False;
779 if gConsoleShow
or gChatShow
then
781 g_Console_Control(K
);
783 else if (g_ActiveWindow
<> nil) then
785 Msg
.Msg
:= WM_KEYDOWN
;
787 g_ActiveWindow
.OnMessage(Msg
);
789 else if (gState
= STATE_MENU
) then
791 g_GUI_ShowWindow('MainMenu');
792 g_Sound_PlayEx('MENU_OPEN');
798 procedure KeyPress (K
: Word);
800 gJustChatted
:= False;
801 if gConsoleShow
or gChatShow
then
803 g_Console_Control(K
);
809 procedure CharPress (C
: AnsiChar);
811 var Msg
: g_gui
.TMessage
;
815 if gConsoleShow
or gChatShow
then
820 else if g_ActiveWindow
<> nil then
823 Msg
.WParam
:= Ord(C
);
824 g_ActiveWindow
.OnMessage(Msg
);
831 charbuff
[a
] := charbuff
[a
+ 1];
833 charbuff
[15] := upcase1251(C
);
840 // ////////////////////////////////////////////////////////////////////////// //
841 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
843 procedure g_ResetDynlights ();
847 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
849 for idx
:= 0 to g_dynLightCount
-1 do
851 if g_dynLights
[idx
].exploCount
= -666 then
858 Inc(g_dynLights
[idx
].exploCount
);
859 if (g_dynLights
[idx
].exploCount
< 10) then
861 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
862 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
863 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
864 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
869 g_dynLightCount
:= lnum
;
872 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
874 if not gwin_has_stencil
then exit
;
875 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
876 g_dynLights
[g_dynLightCount
].x
:= x
;
877 g_dynLights
[g_dynLightCount
].y
:= y
;
878 g_dynLights
[g_dynLightCount
].radius
:= radius
;
879 g_dynLights
[g_dynLightCount
].r
:= r
;
880 g_dynLights
[g_dynLightCount
].g
:= g
;
881 g_dynLights
[g_dynLightCount
].b
:= b
;
882 g_dynLights
[g_dynLightCount
].a
:= a
;
883 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
884 Inc(g_dynLightCount
);
887 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
889 if not gwin_has_stencil
then exit
;
890 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
891 g_dynLights
[g_dynLightCount
].x
:= x
;
892 g_dynLights
[g_dynLightCount
].y
:= y
;
893 g_dynLights
[g_dynLightCount
].radius
:= 0;
894 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
895 g_dynLights
[g_dynLightCount
].r
:= r
;
896 g_dynLights
[g_dynLightCount
].g
:= g
;
897 g_dynLights
[g_dynLightCount
].b
:= b
;
898 g_dynLights
[g_dynLightCount
].a
:= 0;
899 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
900 Inc(g_dynLightCount
);
903 // ////////////////////////////////////////////////////////////////////////// //
904 function conIsCheatsEnabled (): Boolean; inline;
907 if g_Game_IsNet
then exit
;
908 if not gDebugMode
then
910 //if not gCheats then exit;
911 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
912 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
917 // ////////////////////////////////////////////////////////////////////////// //
919 TParamStrValue
= record
924 TParamStrValues
= Array of TParamStrValue
;
927 INTER_ACTION_TEXT
= 1;
928 INTER_ACTION_PIC
= 2;
929 INTER_ACTION_MUSIC
= 3;
934 DataLoaded
: Boolean = False;
936 MapList
: SSArray
= nil;
937 MapIndex
: Integer = -1;
938 InterReadyTime
: Integer = -1;
939 StatDate
: string = '';
954 function Compare(a
, b
: TPlayerStat
): Integer;
956 if a
.Spectator
then Result
:= 1
957 else if b
.Spectator
then Result
:= -1
958 else if a
.Frags
< b
.Frags
then Result
:= 1
959 else if a
.Frags
> b
.Frags
then Result
:= -1
960 else if a
.Deaths
< b
.Deaths
then Result
:= -1
961 else if a
.Deaths
> b
.Deaths
then Result
:= 1
962 else if a
.Kills
< b
.Kills
then Result
:= -1
966 procedure SortGameStat(var stat
: TPlayerStatArray
);
971 if stat
= nil then Exit
;
973 for I
:= High(stat
) downto Low(stat
) do
974 for J
:= Low(stat
) to High(stat
) - 1 do
975 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
978 stat
[J
] := stat
[J
+ 1];
983 // saves a shitty CSV containing the game stats passed to it
984 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
987 dir
, fname
, map
, mode
, etime
: String;
991 dir
:= e_GetWriteableDir(StatsDirs
);
992 // stats are placed in stats/yy/mm/dd/*.csv
993 fname
:= e_CatPath(dir
, Path
);
994 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
995 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
996 AssignFile(s
, fname
);
998 SetTextCodePage(s
, CP_UTF8
);
1000 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
1001 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
1002 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
1003 mode
:= g_Game_ModeToText(Stat
.GameMode
);
1004 etime
:= Format('%d:%.2d:%.2d', [
1005 Stat
.GameTime
div 1000 div 3600,
1006 (Stat
.GameTime
div 1000 div 60) mod 60,
1007 Stat
.GameTime
div 1000 mod 60
1009 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
1010 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
1016 gGameSettings
.TimeLimit
,
1017 gGameSettings
.ScoreLimit
,
1018 gGameSettings
.Options
,
1020 Length(Stat
.PlayerStat
)
1022 // line 2: game specific shit
1023 // if it's a team game: red score, blue score
1024 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1025 // otherwise nothing
1026 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1028 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
1029 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1031 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1032 // lines 3-...: team, player name, frags, deaths
1033 WriteLn(s
, 'team,name,frags,deaths');
1034 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1035 with Stat
.PlayerStat
[I
] do
1036 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1038 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1041 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1046 procedure ClearDebugCvars();
1048 g_debug_Sounds
:= False;
1049 g_debug_Frames
:= False;
1050 g_debug_WinMsgs
:= False;
1051 g_debug_MonsterOff
:= False;
1052 g_debug_BotAIOff
:= 0;
1053 g_debug_HealthBar
:= False;
1054 g_Debug_Player
:= False;
1057 function g_Game_ModeToText(Mode
: Byte): string;
1061 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1062 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1063 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1064 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1065 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1069 function g_Game_TextToMode(Mode
: string): Byte;
1072 Mode
:= UpperCase(Mode
);
1073 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1078 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1083 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1088 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1093 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1095 Result
:= GM_SINGLE
;
1100 function g_Game_IsNet(): Boolean;
1102 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1105 function g_Game_IsServer(): Boolean;
1107 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1110 function g_Game_IsClient(): Boolean;
1112 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1115 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1122 Result
.name
:= ExtractFileName(WAD
);
1123 Result
.description
:= '';
1124 Result
.author
:= '';
1126 w
:= TWADFile
.Create();
1129 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1135 cfg
:= TConfig
.CreateMem(p
, len
);
1136 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1137 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1138 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1139 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1145 procedure g_Game_FreeWAD
;
1148 g_Sound_Delete('MUSIC_endmus');
1149 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1150 gGameSettings
.WAD
:= '';
1153 procedure g_Game_LoadWAD(WAD
: string);
1162 gGameSettings
.WAD
:= WAD
;
1163 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1166 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1168 w
:= TWADFile
.Create();
1171 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1177 cfg
:= TConfig
.CreateMem(p
, len
);
1180 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1181 if MegaWAD
.endpic
<> '' then
1182 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1184 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1185 if MegaWAD
.endmus
<> '' then
1187 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1188 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1196 {procedure start_trigger(t: string);
1200 function next_trigger(): Boolean;
1204 procedure DisableCheats();
1210 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1211 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1212 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1213 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1215 {$IF DEFINED(D2F_DEBUG)}
1216 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1217 gAimLine
:= g_dbg_aimline_on
;
1221 procedure g_Game_ExecuteEvent(Name
: String);
1227 if gEvents
= nil then
1229 for a
:= 0 to High(gEvents
) do
1230 if gEvents
[a
].Name
= Name
then
1232 if gEvents
[a
].Command
<> '' then
1233 g_Console_Process(gEvents
[a
].Command
, True);
1238 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1243 if gDelayedEvents
<> nil then
1244 for a
:= 0 to High(gDelayedEvents
) do
1245 if not gDelayedEvents
[a
].Pending
then
1252 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1253 n
:= High(gDelayedEvents
);
1255 gDelayedEvents
[n
].Pending
:= True;
1256 gDelayedEvents
[n
].DEType
:= DEType
;
1257 gDelayedEvents
[n
].DENum
:= Num
;
1258 gDelayedEvents
[n
].DEStr
:= Str
;
1259 if DEType
= DE_GLOBEVENT
then
1260 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1262 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1266 procedure EndGame();
1272 if g_Game_IsNet
and g_Game_IsServer
then
1273 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1276 gPauseMain
:= false;
1277 gPauseHolmes
:= false;
1280 g_Game_StopAllSounds(False);
1285 EndingGameCounter
:= 0;
1287 {$IFDEF ENABLE_MENU}
1288 g_ActiveWindow
:= nil;
1291 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1292 gLMSRespawnTime
:= 0;
1295 EXIT_SIMPLE
: // Выход через меню или конец теста
1299 begin // Это был тест
1303 begin // Выход в главное меню
1304 {$IFDEF DISABLE_MENU}
1305 gState
:= STATE_MENU
; // ???
1307 gMusic
.SetByName('MUSIC_MENU');
1309 if gState
<> STATE_SLIST
then
1311 g_GUI_ShowWindow('MainMenu');
1312 gState
:= STATE_MENU
;
1316 // Обновляем список серверов
1317 slReturnPressed
:= True;
1318 if g_Net_Slist_Fetch(slCurrent
) then
1320 if slCurrent
= nil then
1321 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1324 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1325 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1328 g_Game_ExecuteEvent('ongameend');
1332 EXIT_RESTART
: // Начать уровень сначала
1334 if not g_Game_IsClient
then g_Game_Restart();
1337 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1339 // Статистика Своей игры:
1340 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1342 CustomStat
.GameTime
:= gTime
;
1343 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1344 CustomStat
.MapName
:= gMapInfo
.Name
;
1345 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1346 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1347 CustomStat
.TeamStat
:= gTeamStat
;
1349 CustomStat
.PlayerStat
:= nil;
1351 // Статистика игроков:
1352 if gPlayers
<> nil then
1354 for a
:= 0 to High(gPlayers
) do
1355 if gPlayers
[a
] <> nil then
1357 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1358 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1361 Name
:= gPlayers
[a
].Name
;
1362 Frags
:= gPlayers
[a
].Frags
;
1363 Deaths
:= gPlayers
[a
].Death
;
1364 Kills
:= gPlayers
[a
].Kills
;
1365 Team
:= gPlayers
[a
].Team
;
1366 Color
:= gPlayers
[a
].Model
.Color
;
1367 Spectator
:= gPlayers
[a
].FSpectator
;
1371 SortGameStat(CustomStat
.PlayerStat
);
1373 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1376 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1377 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1378 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1379 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1381 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1384 StatShotDone
:= False;
1387 g_Game_ExecuteEvent('onmapend');
1388 if not g_Game_IsClient
then g_Player_ResetReady
;
1389 gInterReadyCount
:= 0;
1391 // Затухающий экран:
1392 EndingGameCounter
:= 255;
1393 gState
:= STATE_FOLD
;
1395 if gDefInterTime
< 0 then
1396 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1398 gInterEndTime
:= gDefInterTime
* 1000;
1401 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1403 // Статистика Одиночной игры:
1404 SingleStat
.GameTime
:= gTime
;
1405 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1406 SingleStat
.TotalSecrets
:= gSecretsCount
;
1407 // Статистика первого игрока:
1408 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1409 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1410 // Статистика второго игрока (если есть):
1411 if SingleStat
.TwoPlayers
then
1413 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1414 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1417 g_Game_ExecuteEvent('onmapend');
1420 if gNextMap
<> '' then
1422 gMusic
.SetByName('MUSIC_INTERMUS');
1424 gState
:= STATE_INTERSINGLE
;
1427 g_Game_ExecuteEvent('oninter');
1429 else // Больше нет карт
1431 // Затухающий экран:
1432 EndingGameCounter
:= 255;
1433 gState
:= STATE_FOLD
;
1438 // Окончание обработано:
1439 if gExit
<> EXIT_QUIT
then
1443 procedure g_Game_Init();
1447 gTempDelete
:= False;
1449 sfsGCDisable(); // temporary disable removing of temporary volumes
1452 g_Game_ClearLoading();
1453 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1454 g_Game_SetLoadingText('', 0, False);
1456 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1459 gPauseMain
:= false;
1460 gPauseHolmes
:= false;
1463 {e_MouseInfo.Accel := 1.0;}
1465 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1468 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1469 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1470 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1471 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1472 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1474 gMusic
:= TMusic
.Create();
1475 gMusic
.SetByName('MUSIC_MENU');
1478 gGameSettings
.WarmupTime
:= 30;
1480 gState
:= STATE_MENU
;
1482 SetLength(gEvents
, 6);
1483 gEvents
[0].Name
:= 'ongamestart';
1484 gEvents
[1].Name
:= 'ongameend';
1485 gEvents
[2].Name
:= 'onmapstart';
1486 gEvents
[3].Name
:= 'onmapend';
1487 gEvents
[4].Name
:= 'oninter';
1488 gEvents
[5].Name
:= 'onwadend';
1490 sfsGCEnable(); // enable releasing unused volumes
1494 procedure g_Game_Free(freeTextures
: Boolean=true);
1496 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1497 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1499 g_Map_Free(freeTextures
);
1501 g_Player_RemoveAllCorpses();
1503 gGameSettings
.GameType
:= GT_NONE
;
1504 if gGameSettings
.GameMode
= GM_SINGLE
then
1505 gGameSettings
.GameMode
:= GM_DM
;
1506 gSwitchGameMode
:= gGameSettings
.GameMode
;
1509 gExitByTrigger
:= False;
1512 function IsActivePlayer(p
: TPlayer
): Boolean;
1517 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1520 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1526 if gPlayers
= nil then
1530 for a
:= Low(gPlayers
) to High(gPlayers
) do
1531 if IsActivePlayer(gPlayers
[a
]) then
1533 SetLength(ids
, Length(ids
) + 1);
1534 ids
[High(ids
)] := gPlayers
[a
].UID
;
1535 if gPlayers
[a
].UID
= Skip
then
1538 if Length(ids
) = 0 then
1543 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1546 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1552 if gPlayers
= nil then
1556 for a
:= Low(gPlayers
) to High(gPlayers
) do
1557 if IsActivePlayer(gPlayers
[a
]) then
1559 SetLength(ids
, Length(ids
) + 1);
1560 ids
[High(ids
)] := gPlayers
[a
].UID
;
1561 if gPlayers
[a
].UID
= Skip
then
1564 if Length(ids
) = 0 then
1567 Result
:= ids
[Length(ids
) - 1]
1569 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1572 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1578 if gPlayers
= nil then
1582 for a
:= Low(gPlayers
) to High(gPlayers
) do
1583 if IsActivePlayer(gPlayers
[a
]) then
1585 SetLength(ids
, Length(ids
) + 1);
1586 ids
[High(ids
)] := gPlayers
[a
].UID
;
1587 if gPlayers
[a
].UID
= Skip
then
1590 if Length(ids
) = 0 then
1592 if Length(ids
) = 1 then
1597 Result
:= ids
[Random(Length(ids
))];
1599 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1601 Result
:= ids
[Random(Length(ids
))];
1606 function GetRandomSpectMode(Current
: Byte): Byte;
1613 0: Result
:= SPECT_STATS
;
1614 1: Result
:= SPECT_MAPVIEW
;
1615 2: Result
:= SPECT_MAPVIEW
;
1616 3: Result
:= SPECT_PLAYERS
;
1617 4: Result
:= SPECT_PLAYERS
;
1618 5: Result
:= SPECT_PLAYERS
;
1619 6: Result
:= SPECT_PLAYERS
;
1621 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1625 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1631 if (plr
= nil) then exit
;
1632 if (p
= 2) then time
:= 1000 else time
:= 1;
1633 strafeDir
:= MoveButton
shr 4;
1634 MoveButton
:= MoveButton
and $0F;
1636 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1637 MoveButton
:= 1 // Нажата только "Влево"
1638 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1639 MoveButton
:= 2 // Нажата только "Вправо"
1640 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1641 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1643 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1644 if MoveButton
= 1 then
1645 plr
.PressKey(KEY_LEFT
, time
)
1646 else if MoveButton
= 2 then
1647 plr
.PressKey(KEY_RIGHT
, time
);
1649 // if we have "strafe" key, turn off old strafe mechanics
1650 if gPlayerAction
[p
, ACTION_STRAFE
] then
1652 // new strafe mechanics
1653 if (strafeDir
= 0) then
1654 strafeDir
:= MoveButton
; // start strafing
1655 // now set direction according to strafe (reversed)
1656 if (strafeDir
= 2) then
1657 plr
.SetDirection(TDirection
.D_LEFT
)
1658 else if (strafeDir
= 1) then
1659 plr
.SetDirection(TDirection
.D_RIGHT
)
1663 strafeDir
:= 0; // not strafing anymore
1664 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1665 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1666 plr
.SetDirection(TDirection
.D_LEFT
)
1667 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1668 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1669 plr
.SetDirection(TDirection
.D_RIGHT
)
1670 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1671 else if MoveButton
<> 0 then
1672 plr
.SetDirection(TDirection(MoveButton
-1))
1675 // fix movebutton state
1676 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1678 // Остальные клавиши:
1679 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1680 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1681 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1682 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1683 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1685 for i
:= WP_FACT
to WP_LACT
do
1687 if gWeaponAction
[p
, i
] then
1689 plr
.ProcessWeaponAction(i
);
1690 gWeaponAction
[p
, i
] := False
1694 for i
:= WP_FIRST
to WP_LAST
do
1696 if gSelectWeapon
[p
, i
] then
1698 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1699 gSelectWeapon
[p
, i
] := False
1703 {$IFDEF ENABLE_MENU}
1704 // HACK: add dynlight here
1705 if gwin_k8_enable_light_experiments
then
1707 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1709 g_playerLight
:= true;
1711 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1713 g_playerLight
:= false;
1717 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1721 // HACK: don't have a "key was pressed" function
1722 procedure InterReady();
1724 if InterReadyTime
> gTime
then Exit
;
1725 InterReadyTime
:= gTime
+ 3000;
1726 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1729 procedure g_Game_PreUpdate();
1731 // these are in separate PreUpdate functions because they can interact during Update()
1732 // and are synced over the net
1733 // we don't care that much about corpses and gibs
1734 g_Player_PreUpdate();
1735 g_Monsters_PreUpdate();
1736 g_Items_PreUpdate();
1737 g_Weapon_PreUpdate();
1740 procedure g_Game_Update();
1742 {$IFDEF ENABLE_MENU}
1743 Msg
: g_gui
.TMessage
;
1750 function sendMonsPos (mon
: TMonster
): Boolean;
1752 result
:= false; // don't stop
1753 // this will also reset "need-send" flag
1754 if mon
.gncNeedSend
then
1756 MH_SEND_MonsterPos(mon
.UID
);
1758 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1760 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1762 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1764 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1768 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1770 result
:= false; // don't stop
1771 // this will also reset "need-send" flag
1772 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1775 function sendItemPos (it
: PItem
): Boolean;
1777 result
:= false; // don't stop
1780 MH_SEND_ItemPos(it
.myId
);
1781 it
.needSend
:= False;
1786 reliableUpdate
: Boolean;
1791 // Пора выключать игру:
1792 if gExit
= EXIT_QUIT
then
1794 // Игра закончилась - обрабатываем:
1798 if gExit
= EXIT_QUIT
then
1802 // Читаем клавиатуру и джойстик, если окно активно
1803 // no need to, as we'll do it in event handler
1805 // Обновляем консоль (движение и сообщения):
1808 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1810 gExit
:= EXIT_SIMPLE
;
1815 // process master server communications
1816 g_Net_Slist_Pulse();
1819 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1820 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1821 STATE_INTERTEXT
, // Текст между уровнями
1822 STATE_INTERPIC
: // Картинка между уровнями
1824 if g_Game_IsNet
and g_Game_IsServer
then
1826 gInterTime
:= gInterTime
+ GAME_TICK
;
1827 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1828 if a
<> gServInterTime
then
1830 gServInterTime
:= a
;
1831 MH_SEND_TimeSync(gServInterTime
);
1835 if (not g_Game_IsClient
) and
1839 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1840 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1841 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1842 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1844 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1845 {$IFDEF ENABLE_MENU}
1846 and (g_ActiveWindow
= nil)
1849 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1852 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1853 g_Game_StopAllSounds(True);
1855 if gMapOnce
then // Это был тест
1856 gExit
:= EXIT_SIMPLE
1858 if gNextMap
<> '' then // Переходим на следующую карту
1859 g_Game_ChangeMap(gNextMap
)
1860 else // Следующей карты нет
1862 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1864 // Выход в главное меню:
1866 {$IFDEF ENABLE_MENU}
1867 g_GUI_ShowWindow('MainMenu');
1868 gMusic
.SetByName('MUSIC_MENU');
1871 gState
:= STATE_MENU
;
1874 // Финальная картинка:
1875 g_Game_ExecuteEvent('onwadend');
1877 if not gMusic
.SetByName('MUSIC_endmus') then
1878 gMusic
.SetByName('MUSIC_STDENDMUS');
1880 gState
:= STATE_ENDPIC
;
1882 g_Game_ExecuteEvent('ongameend');
1887 else if g_Game_IsClient
and
1890 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1891 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1892 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1893 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1895 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1896 {$IFDEF ENABLE_MENU}
1897 and (g_ActiveWindow
= nil)
1906 if gState
= STATE_INTERTEXT
then
1907 if InterText
.counter
> 0 then
1908 InterText
.counter
:= InterText
.counter
- 1;
1911 STATE_FOLD
: // Затухание экрана
1913 if EndingGameCounter
= 0 then
1915 // Закончился уровень в Своей игре:
1916 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1918 gState
:= STATE_INTERCUSTOM
;
1919 InterReadyTime
:= -1;
1920 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1922 g_Game_ExecuteEvent('onwadend');
1923 if not gMusic
.SetByName('MUSIC_endmus') then
1924 gMusic
.SetByName('MUSIC_STDENDMUS');
1927 gMusic
.SetByName('MUSIC_ROUNDMUS');
1931 else // Закончилась последняя карта в Одиночной игре
1933 gMusic
.SetByName('MUSIC_INTERMUS');
1935 gState
:= STATE_INTERSINGLE
;
1938 g_Game_ExecuteEvent('oninter');
1941 DecMin(EndingGameCounter
, 6, 0);
1944 STATE_ENDPIC
: // Картинка окончания мегаВада
1946 if gMapOnce
then // Это был тест
1948 gExit
:= EXIT_SIMPLE
;
1954 g_Serverlist_Control(slCurrent
, slTable
);
1957 // Статистика по Tab:
1959 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1962 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1964 // Время += 28 миллисекунд:
1965 gTime
:= gTime
+ GAME_TICK
;
1967 // Сообщение посередине экрана:
1968 if MessageTime
= 0 then
1970 if MessageTime
> 0 then
1971 MessageTime
:= MessageTime
- 1;
1973 if (g_Game_IsServer
) then
1975 // Был задан лимит времени:
1976 if (gGameSettings
.TimeLimit
> 0) then
1977 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1978 begin // Он прошел => конец уровня
1983 // Надо респавнить игроков в LMS:
1984 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1985 g_Game_RestartRound(gLMSSoftSpawn
);
1987 // Проверим результат голосования, если время прошло
1988 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1990 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1992 g_Console_Process(gVoteCommand
);
1994 gVotePassed
:= False;
1997 // Замеряем время захвата флагов
1998 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1999 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2000 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2001 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2003 // Был задан лимит побед:
2004 if (gGameSettings
.ScoreLimit
> 0) then
2008 if gGameSettings
.GameMode
= GM_DM
then
2009 begin // В DM ищем игрока с max фрагами
2010 for i
:= 0 to High(gPlayers
) do
2011 if gPlayers
[i
] <> nil then
2012 if gPlayers
[i
].Frags
> b
then
2013 b
:= gPlayers
[i
].Frags
;
2016 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2017 begin // В CTF/TDM выбираем команду с наибольшим счетом
2018 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2021 // Лимит побед набран => конец уровня:
2022 if b
>= gGameSettings
.ScoreLimit
then
2029 // Обрабатываем клавиши игроков:
2030 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2031 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2032 {$IFDEF DISABLE_MENU}
2033 if (not gConsoleShow
) and (not gChatShow
) then
2035 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2038 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2039 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2040 end // if not console
2043 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2045 // process weapon switch queue
2049 if (gPlayer1
= nil) and (gPlayer2
= nil)
2050 and (not gConsoleShow
) and (not gChatShow
)
2051 {$IFDEF ENABLE_MENU}
2052 and (g_ActiveWindow
= nil)
2056 if not gSpectKeyPress
then
2058 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2060 // switch spect mode
2062 SPECT_NONE
: ; // not spectator
2064 SPECT_MAPVIEW
: Inc(gSpectMode
);
2065 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2067 gSpectKeyPress
:= True;
2069 if (gSpectMode
= SPECT_MAPVIEW
)
2070 and (not gSpectAuto
) then
2072 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2073 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2074 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2075 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2076 if gPlayerAction
[0, ACTION_LOOKUP
] then
2077 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2078 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2079 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2080 if gWeaponAction
[0, WP_PREV
] then
2083 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2084 gWeaponAction
[0, WP_PREV
] := False;
2086 if gWeaponAction
[0, WP_NEXT
] then
2089 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2090 gWeaponAction
[0, WP_NEXT
] := False;
2093 if (gSpectMode
= SPECT_PLAYERS
)
2094 and (not gSpectAuto
) then
2096 if gPlayerAction
[0, ACTION_LOOKUP
] then
2099 gSpectViewTwo
:= True;
2100 gSpectKeyPress
:= True;
2102 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2104 // remove second view
2105 gSpectViewTwo
:= False;
2106 gSpectKeyPress
:= True;
2108 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2110 // prev player (view 1)
2111 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2112 gSpectKeyPress
:= True;
2114 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2116 // next player (view 1)
2117 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2118 gSpectKeyPress
:= True;
2120 if gWeaponAction
[0, WP_PREV
] then
2122 // prev player (view 2)
2123 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2124 gWeaponAction
[0, WP_PREV
] := False;
2126 if gWeaponAction
[0, WP_NEXT
] then
2128 // next player (view 2)
2129 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2130 gWeaponAction
[0, WP_NEXT
] := False;
2133 if gPlayerAction
[0, ACTION_ATTACK
] then
2135 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2138 gSpectAutoNext
:= 0;
2139 gSpectViewTwo
:= False;
2140 gSpectKeyPress
:= True;
2145 gSpectMode
:= SPECT_STATS
;
2146 gSpectAuto
:= False;
2147 gSpectKeyPress
:= True;
2152 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2153 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2154 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2155 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2156 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2157 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2158 gSpectKeyPress
:= False;
2162 if gSpectMode
= SPECT_MAPVIEW
then
2164 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2166 gSpectAutoNext
:= gTime
2169 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2171 gSpectAutoNext
:= gTime
2175 if gSpectAutoNext
<= gTime
then
2177 if gSpectAutoNext
> 0 then
2179 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2183 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2184 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2185 gSpectAutoStepX
:= Random(9) - 4;
2186 gSpectAutoStepY
:= Random(9) - 4;
2187 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2188 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2189 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2190 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2191 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2192 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2196 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2201 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2202 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2203 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2209 // Обновляем все остальное:
2212 g_Triggers_Update();
2214 g_Monsters_Update();
2218 g_Player_UpdateAll();
2219 {$IFDEF ENABLE_GIBS}
2222 g_Player_UpdatePhysicalObjects();
2223 {$IFDEF ENABLE_SHELLS}
2227 // server: send newly spawned monsters unconditionally
2228 if (gGameSettings
.GameType
= GT_SERVER
) then
2230 if (Length(gMonstersSpawned
) > 0) then
2232 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2233 SetLength(gMonstersSpawned
, 0);
2237 if (gSoundTriggerTime
> 8) then
2239 g_Game_UpdateTriggerSounds();
2240 gSoundTriggerTime
:= 0;
2244 Inc(gSoundTriggerTime
);
2247 if (NetMode
= NET_SERVER
) then
2249 Inc(NetTimeToUpdate
);
2250 Inc(NetTimeToReliable
);
2252 // send monster updates
2253 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2255 // send all monsters (periodic sync)
2256 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2258 for I
:= 0 to High(gPlayers
) do
2260 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2263 g_Mons_ForEach(sendMonsPos
);
2265 // update flags that aren't stationary
2266 if gGameSettings
.GameMode
= GM_CTF
then
2267 for I
:= FLAG_RED
to FLAG_BLUE
do
2268 if gFlags
[I
].NeedSend
then
2270 gFlags
[I
].NeedSend
:= False;
2274 // update items that aren't stationary
2275 g_Items_ForEachAlive(sendItemPos
);
2277 if reliableUpdate
then
2279 NetTimeToReliable
:= 0;
2280 NetTimeToUpdate
:= NetUpdateRate
;
2284 NetTimeToUpdate
:= 0;
2289 // send only mosters with some unexpected changes
2290 g_Mons_ForEach(sendMonsPosUnexpected
);
2293 // send unexpected platform changes
2294 g_Map_NetSendInterestingPanels();
2296 g_Net_Slist_ServerUpdate();
2298 if NetUseMaster then
2300 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2302 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2304 NetTimeToMaster := gTime + NetMasterRate;
2309 else if (NetMode
= NET_CLIENT
) then
2311 MC_SEND_PlayerPos();
2313 end; // if gameOn ...
2315 // Активно окно интерфейса - передаем клавиши ему:
2316 {$IFDEF ENABLE_MENU}
2317 if g_ActiveWindow
<> nil then
2319 w
:= e_GetFirstKeyPressed();
2321 if (w
<> IK_INVALID
) then
2323 Msg
.Msg
:= MESSAGE_DIKEY
;
2325 g_ActiveWindow
.OnMessage(Msg
);
2328 // Если оно от этого не закрылось, то обновляем:
2329 if g_ActiveWindow
<> nil then
2330 g_ActiveWindow
.Update();
2332 // Нужно сменить разрешение:
2333 if gResolutionChange
then
2336 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2339 gResolutionChange
:= False;
2340 g_ActiveWindow
:= nil;
2343 // Нужно сменить язык:
2344 if gLanguageChange
then
2346 //e_WriteLog('Read language file', MSG_NOTIFY);
2347 //g_Language_Load(DataDir + gLanguage + '.txt');
2348 g_Language_Set(gLanguage
);
2350 gLanguageChange
:= False;
2354 // Горячая клавиша для вызова меню выхода из игры (F10):
2355 if e_KeyPressed(IK_F10
) and
2357 (not gConsoleShow
) and
2358 (g_ActiveWindow
= nil) then
2364 Time
:= GetTickCount64() {div 1000};
2366 // Обработка отложенных событий:
2367 if gDelayedEvents
<> nil then
2368 for a
:= 0 to High(gDelayedEvents
) do
2369 if gDelayedEvents
[a
].Pending
and
2371 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2372 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2375 case gDelayedEvents
[a
].DEType
of
2377 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2380 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2384 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2385 if g_Game_IsNet
and g_Game_IsServer
then
2386 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2390 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2392 gDelayedEvents
[a
].Pending
:= False;
2395 // Каждую секунду обновляем счетчик обновлений:
2396 UPSCounter
:= UPSCounter
+ 1;
2397 if Time
- UPSTime
>= 1000 then
2406 g_Weapon_AddDynLights();
2407 g_Items_AddDynLights();
2411 procedure g_Game_LoadChatSounds(Resource
: string);
2414 FileName
, Snd
: string;
2416 len
, cnt
, tags
, i
, j
: Integer;
2419 FileName
:= g_ExtractWadName(Resource
);
2421 WAD
:= TWADFile
.Create();
2422 WAD
.ReadFile(FileName
);
2424 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2431 cfg
:= TConfig
.CreateMem(p
, len
);
2432 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2434 SetLength(gChatSounds
, cnt
);
2435 for i
:= 0 to Length(gChatSounds
) - 1 do
2437 gChatSounds
[i
].Sound
:= nil;
2438 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2439 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2440 if (Snd
= '') or (Tags
<= 0) then
2442 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2443 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2444 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2445 SetLength(gChatSounds
[i
].Tags
, tags
);
2446 for j
:= 0 to tags
- 1 do
2447 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2448 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2455 procedure g_Game_FreeChatSounds();
2459 for i
:= 0 to Length(gChatSounds
) - 1 do
2461 gChatSounds
[i
].Sound
.Free();
2462 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2464 SetLength(gChatSounds
, 0);
2468 procedure g_Game_LoadData();
2470 if DataLoaded
then Exit
;
2472 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2474 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2475 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2476 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2477 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2478 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2479 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2480 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2481 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2482 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2483 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2484 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2485 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2486 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2487 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2488 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2489 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2490 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2491 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2492 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2493 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2494 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2495 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2496 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2497 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2498 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2499 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2500 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2501 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2502 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2503 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2504 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2505 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2507 goodsnd
[0] := TPlayableSound
.Create();
2508 goodsnd
[1] := TPlayableSound
.Create();
2509 goodsnd
[2] := TPlayableSound
.Create();
2510 goodsnd
[3] := TPlayableSound
.Create();
2512 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2513 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2514 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2515 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2517 killsnd
[0] := TPlayableSound
.Create();
2518 killsnd
[1] := TPlayableSound
.Create();
2519 killsnd
[2] := TPlayableSound
.Create();
2520 killsnd
[3] := TPlayableSound
.Create();
2522 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2523 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2524 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2525 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2527 hahasnd
[0] := TPlayableSound
.Create();
2528 hahasnd
[1] := TPlayableSound
.Create();
2529 hahasnd
[2] := TPlayableSound
.Create();
2531 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2532 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2533 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2535 sound_get_flag
[0] := TPlayableSound
.Create();
2536 sound_get_flag
[1] := TPlayableSound
.Create();
2537 sound_lost_flag
[0] := TPlayableSound
.Create();
2538 sound_lost_flag
[1] := TPlayableSound
.Create();
2539 sound_ret_flag
[0] := TPlayableSound
.Create();
2540 sound_ret_flag
[1] := TPlayableSound
.Create();
2541 sound_cap_flag
[0] := TPlayableSound
.Create();
2542 sound_cap_flag
[1] := TPlayableSound
.Create();
2544 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2545 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2546 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2547 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2548 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2549 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2550 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2551 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2553 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2555 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2558 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2559 g_Weapon_LoadData();
2561 g_Monsters_LoadData();
2566 procedure g_Game_Quit();
2568 g_Game_StopAllSounds(True);
2571 g_PlayerModel_FreeData();
2573 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2576 if NetInitDone
then g_Net_Free
;
2578 // remove map after test
2579 if gMapToDelete
<> '' then
2580 g_Game_DeleteTestMap();
2589 procedure g_Game_FreeData();
2591 if not DataLoaded
then Exit
;
2594 g_Weapon_FreeData();
2595 g_Monsters_FreeData();
2597 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2599 g_Sound_Delete('SOUND_GAME_TELEPORT');
2600 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2601 g_Sound_Delete('SOUND_GAME_SECRET');
2602 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2603 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2604 g_Sound_Delete('SOUND_GAME_BULK1');
2605 g_Sound_Delete('SOUND_GAME_BULK2');
2606 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2607 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2608 g_Sound_Delete('SOUND_GAME_BURNING');
2609 g_Sound_Delete('SOUND_GAME_SWITCH1');
2610 g_Sound_Delete('SOUND_GAME_SWITCH0');
2617 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2618 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2619 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2620 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2627 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2628 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2629 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2630 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2636 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2637 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2638 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2640 sound_get_flag
[0].Free();
2641 sound_get_flag
[1].Free();
2642 sound_lost_flag
[0].Free();
2643 sound_lost_flag
[1].Free();
2644 sound_ret_flag
[0].Free();
2645 sound_ret_flag
[1].Free();
2646 sound_cap_flag
[0].Free();
2647 sound_cap_flag
[1].Free();
2649 g_Sound_Delete('SOUND_CTF_GET1');
2650 g_Sound_Delete('SOUND_CTF_GET2');
2651 g_Sound_Delete('SOUND_CTF_LOST1');
2652 g_Sound_Delete('SOUND_CTF_LOST2');
2653 g_Sound_Delete('SOUND_CTF_RETURN1');
2654 g_Sound_Delete('SOUND_CTF_RETURN2');
2655 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2656 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2658 g_Game_FreeChatSounds();
2660 DataLoaded
:= False;
2663 procedure g_FatalError(Text: String);
2665 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2666 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2668 gExit
:= EXIT_SIMPLE
;
2669 if gGameOn
then EndGame
;
2672 procedure g_SimpleError(Text: String);
2674 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2675 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2678 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2680 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2681 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2684 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2687 if gPlayer1
= nil then
2689 if g_Game_IsClient
then
2691 if NetPlrUID1
> -1 then
2692 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2696 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2697 Team
:= gPlayer1Settings
.Team
;
2699 // Создание первого игрока:
2700 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2701 gPlayer1Settings
.Color
,
2703 if gPlayer1
= nil then
2704 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2707 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2708 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2709 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2710 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2711 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2712 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2713 if g_Game_IsServer
and g_Game_IsNet
then
2714 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2715 gPlayer1
.Respawn(False, True);
2716 g_Net_Slist_ServerPlayerComes();
2721 if gPlayer2
= nil then
2723 if g_Game_IsClient
then
2725 if NetPlrUID2
> -1 then
2726 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2730 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2731 Team
:= gPlayer2Settings
.Team
;
2733 // Создание второго игрока:
2734 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2735 gPlayer2Settings
.Color
,
2737 if gPlayer2
= nil then
2738 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2741 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2742 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2743 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2744 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2745 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2746 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2747 if g_Game_IsServer
and g_Game_IsNet
then
2748 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2749 gPlayer2
.Respawn(False, True);
2750 g_Net_Slist_ServerPlayerComes();
2757 procedure g_Game_RemovePlayer();
2761 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2762 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2767 if g_Game_IsServer
then
2770 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2771 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2772 g_Player_Remove(Pl
.UID
);
2773 g_Net_Slist_ServerPlayerLeaves();
2777 gSpectLatchPID2
:= Pl
.UID
;
2785 if g_Game_IsServer
then
2788 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2789 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2790 g_Player_Remove(Pl
.UID
);
2791 g_Net_Slist_ServerPlayerLeaves();
2794 gSpectLatchPID1
:= Pl
.UID
;
2796 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2800 g_Net_Slist_ServerPlayerLeaves();
2803 procedure g_Game_Spectate();
2805 g_Game_RemovePlayer();
2806 if gPlayer1
<> nil then
2807 g_Game_RemovePlayer();
2810 procedure g_Game_SpectateCenterView();
2812 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2813 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2816 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2823 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2825 g_Game_ClearLoading();
2828 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2831 gGameSettings
.GameType
:= GT_SINGLE
;
2832 gGameSettings
.MaxLives
:= 0;
2833 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2834 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2835 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2836 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2837 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2838 gSwitchGameMode
:= GM_SINGLE
;
2840 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2841 gLMSRespawnTime
:= 0;
2842 gSpectLatchPID1
:= 0;
2843 gSpectLatchPID2
:= 0;
2845 g_Game_ExecuteEvent('ongamestart');
2847 // Создание первого игрока:
2848 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2849 gPlayer1Settings
.Color
,
2850 gPlayer1Settings
.Team
, False));
2851 if gPlayer1
= nil then
2853 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2857 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2858 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2859 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2860 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2861 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2864 // Создание второго игрока, если есть:
2867 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2868 gPlayer2Settings
.Color
,
2869 gPlayer2Settings
.Team
, False));
2870 if gPlayer2
= nil then
2872 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2876 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2877 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2878 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2879 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2880 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2884 // Загрузка и запуск карты:
2885 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2887 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2888 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2892 // Настройки игроков и ботов:
2896 for i
:= nPl
+1 to nPlayers
do
2897 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2900 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2901 TimeLimit
, ScoreLimit
: Word;
2903 Options
: LongWord; nPlayers
: Byte);
2909 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2911 g_Game_ClearLoading();
2914 gGameSettings
.GameType
:= GT_CUSTOM
;
2915 gGameSettings
.GameMode
:= GameMode
;
2916 gSwitchGameMode
:= GameMode
;
2917 gGameSettings
.TimeLimit
:= TimeLimit
;
2918 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2919 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2920 gGameSettings
.Options
:= Options
;
2922 gCoopTotalMonstersKilled
:= 0;
2923 gCoopTotalSecretsFound
:= 0;
2924 gCoopTotalMonsters
:= 0;
2925 gCoopTotalSecrets
:= 0;
2929 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2930 gLMSRespawnTime
:= 0;
2931 gSpectLatchPID1
:= 0;
2932 gSpectLatchPID2
:= 0;
2934 g_Game_ExecuteEvent('ongamestart');
2936 // Режим наблюдателя:
2937 if nPlayers
= 0 then
2944 if nPlayers
>= 1 then
2946 // Создание первого игрока:
2947 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2948 gPlayer1Settings
.Color
,
2949 gPlayer1Settings
.Team
, False));
2950 if gPlayer1
= nil then
2952 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2956 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2957 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2958 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2959 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2960 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2964 if nPlayers
>= 2 then
2966 // Создание второго игрока:
2967 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2968 gPlayer2Settings
.Color
,
2969 gPlayer2Settings
.Team
, False));
2970 if gPlayer2
= nil then
2972 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2976 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2977 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2978 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2979 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2980 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2984 // Загрузка и запуск карты:
2985 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
2987 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2991 // Нет точек появления:
2992 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2993 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2994 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2995 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2996 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2998 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3002 // Настройки игроков и ботов:
3006 for i
:= nPl
+1 to nPlayers
do
3007 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3010 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3011 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3012 Options
: LongWord; nPlayers
: Byte;
3013 IPAddr
: LongWord; Port
: Word);
3016 g_Net_Slist_ServerClosed();
3018 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3020 g_Game_ClearLoading();
3025 gGameSettings
.GameType
:= GT_SERVER
;
3026 gGameSettings
.GameMode
:= GameMode
;
3027 gSwitchGameMode
:= GameMode
;
3028 gGameSettings
.TimeLimit
:= TimeLimit
;
3029 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3030 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3031 gGameSettings
.Options
:= Options
;
3033 gCoopTotalMonstersKilled
:= 0;
3034 gCoopTotalSecretsFound
:= 0;
3035 gCoopTotalMonsters
:= 0;
3036 gCoopTotalSecrets
:= 0;
3040 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3041 gLMSRespawnTime
:= 0;
3042 gSpectLatchPID1
:= 0;
3043 gSpectLatchPID2
:= 0;
3045 g_Game_ExecuteEvent('ongamestart');
3047 // Режим наблюдателя:
3048 if nPlayers
= 0 then
3054 if nPlayers
>= 1 then
3056 // Создание первого игрока:
3057 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3058 gPlayer1Settings
.Color
,
3059 gPlayer1Settings
.Team
, False));
3060 if gPlayer1
= nil then
3062 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3066 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3067 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3068 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3069 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3070 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3073 if nPlayers
>= 2 then
3075 // Создание второго игрока:
3076 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3077 gPlayer2Settings
.Color
,
3078 gPlayer2Settings
.Team
, False));
3079 if gPlayer2
= nil then
3081 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3085 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3086 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3087 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3088 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3089 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3092 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3093 if NetForwardPorts
then
3094 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3097 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3099 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3103 g_Net_Slist_Set(NetMasterList
);
3105 g_Net_Slist_ServerStarted();
3107 // Загрузка и запуск карты:
3108 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3110 g_Net_Slist_ServerClosed();
3111 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3115 // Нет точек появления:
3116 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3117 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3118 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3119 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3120 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3122 g_Net_Slist_ServerClosed();
3123 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3127 // Настройки игроков и ботов:
3130 g_Net_Slist_ServerMapStarted();
3131 NetState
:= NET_STATE_GAME
;
3134 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3149 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3150 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3152 g_Game_ClearLoading();
3157 gGameSettings
.GameType
:= GT_CLIENT
;
3159 gCoopTotalMonstersKilled
:= 0;
3160 gCoopTotalSecretsFound
:= 0;
3161 gCoopTotalMonsters
:= 0;
3162 gCoopTotalSecrets
:= 0;
3166 g_Game_ExecuteEvent('ongamestart');
3168 NetState
:= NET_STATE_AUTH
;
3170 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3172 // create (or update) map/resource databases
3173 g_Res_CreateDatabases(true);
3175 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3176 gLMSRespawnTime
:= 0;
3177 gSpectLatchPID1
:= 0;
3178 gSpectLatchPID2
:= 0;
3181 if not g_Net_Connect(Addr
, Port
) then
3183 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3184 NetState
:= NET_STATE_NONE
;
3188 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3190 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3195 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3196 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3197 // thank you, enet. let's ignore failures altogether then.
3198 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3200 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3202 Ptr
:= NetEvent
.packet
^.data
;
3203 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3205 enet_packet_destroy(NetEvent
.packet
);
3209 InMsg
.ReadLongWord(); // skip size
3210 MID
:= InMsg
.ReadByte();
3212 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3214 NetMyID
:= InMsg
.ReadByte();
3215 NetPlrUID1
:= InMsg
.ReadWord();
3217 WadName
:= InMsg
.ReadString();
3218 Map
:= InMsg
.ReadString();
3220 gWADHash
:= InMsg
.ReadMD5();
3222 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3223 gSwitchGameMode
:= gGameSettings
.GameMode
;
3224 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3225 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3226 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3227 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3228 T
:= InMsg
.ReadLongWord();
3230 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3231 //if newResPath = '' then
3233 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3234 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3235 if newResPath
= '' then
3237 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3238 enet_packet_destroy(NetEvent
.packet
);
3239 NetState
:= NET_STATE_NONE
;
3242 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3244 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3247 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3248 gPlayer1Settings
.Color
,
3249 gPlayer1Settings
.Team
, False));
3251 if gPlayer1
= nil then
3253 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3255 enet_packet_destroy(NetEvent
.packet
);
3256 NetState
:= NET_STATE_NONE
;
3260 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3261 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3262 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3263 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3264 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3265 gPlayer1
.UID
:= NetPlrUID1
;
3266 gPlayer1
.Reset(True);
3268 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3270 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3272 enet_packet_destroy(NetEvent
.packet
);
3273 NetState
:= NET_STATE_NONE
;
3281 enet_packet_destroy(NetEvent
.packet
);
3285 enet_packet_destroy(NetEvent
.packet
);
3289 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3292 if (NetEvent
.data
<= NET_DISC_MAX
) then
3293 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3294 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3301 ProcessLoading(True);
3302 if g_Net_UserRequestExit() then
3311 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3312 NetState
:= NET_STATE_NONE
;
3317 NetState
:= NET_STATE_GAME
;
3318 MC_SEND_FullStateRequest
;
3319 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3323 lastAsMegaWad
: Boolean = false;
3325 procedure g_Game_ChangeMap(const MapPath
: String);
3329 g_Game_ClearLoading();
3331 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3332 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3333 if gExitByTrigger
then
3336 gExitByTrigger
:= False;
3338 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3339 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3342 procedure g_Game_Restart();
3346 if g_Game_IsClient
then
3348 map
:= g_ExtractFileName(gMapInfo
.Map
);
3349 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3353 g_Game_ClearLoading();
3354 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3357 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3359 NewWAD
, ResName
: String;
3363 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3364 g_Player_RemoveAllCorpses();
3366 if (not g_Game_IsClient
) and
3367 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3368 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3370 if gSwitchGameMode
= GM_CTF
then
3371 gGameSettings
.MaxLives
:= 0;
3372 gGameSettings
.GameMode
:= gSwitchGameMode
;
3375 gSwitchGameMode
:= gGameSettings
.GameMode
;
3377 g_Player_ResetTeams();
3379 lastAsMegaWad
:= asMegawad
;
3380 if isWadPath(Map
) then
3382 NewWAD
:= g_ExtractWadName(Map
);
3383 ResName
:= g_ExtractFileName(Map
);
3384 if g_Game_IsServer
then
3386 nws
:= findDiskWad(NewWAD
);
3387 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3390 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3391 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3395 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3396 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3398 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3399 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3401 if (length(nws
) = 0) then
3403 ResName
:= ''; // failed
3408 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3409 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3410 g_Game_LoadWAD(NewWAD
);
3415 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3416 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3421 NewWAD
:= gGameSettings
.WAD
;
3427 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3429 if (ResName
<> '') and (NewWAD
<> '') then
3431 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3432 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3434 r_Render_LoadTextures
;
3439 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3441 gState
:= STATE_NONE
;
3442 {$IFDEF ENABLE_MENU}
3443 g_ActiveWindow
:= nil;
3448 wNeedTimeReset
:= True;
3450 if gGameSettings
.GameMode
= GM_CTF
then
3452 g_Map_ResetFlag(FLAG_RED
);
3453 g_Map_ResetFlag(FLAG_BLUE
);
3454 // CTF, а флагов нет:
3455 if not g_Map_HaveFlagPoints() then
3456 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3461 gState
:= STATE_MENU
;
3466 gPauseMain
:= false;
3467 gPauseHolmes
:= false;
3468 NetTimeToUpdate
:= 1;
3469 NetTimeToReliable
:= 0;
3470 NetTimeToMaster
:= NetMasterRate
;
3471 gSpectLatchPID1
:= 0;
3472 gSpectLatchPID2
:= 0;
3473 gMissionFailed
:= False;
3476 gCoopMonstersKilled
:= 0;
3477 gCoopSecretsFound
:= 0;
3479 gVoteInProgress
:= False;
3480 gVotePassed
:= False;
3486 if not gGameOn
then Exit
;
3488 g_Game_SpectateCenterView();
3490 if g_Game_IsServer
then
3492 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3494 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3495 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3496 gLMSSoftSpawn
:= True;
3497 if g_Game_IsNet
then
3498 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3502 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3503 gLMSRespawnTime
:= 0;
3507 if NetMode
= NET_SERVER
then
3509 // reset full state flags
3510 if NetClients
<> nil then
3511 for I
:= 0 to High(NetClients
) do
3512 NetClients
[I
].FullUpdateSent
:= False;
3514 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3517 g_Net_Slist_ServerMapStarted();
3519 if NetClients
<> nil then
3520 for I
:= 0 to High(NetClients
) do
3521 if NetClients
[I
].Used
then
3523 NetClients
[I
].Voted
:= False;
3524 if NetClients
[I
].RequestedFullUpdate
then
3526 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3527 NetClients
[I
].RequestedFullUpdate
:= False;
3531 g_Net_UnbanNonPermHosts();
3536 gCoopTotalMonstersKilled
:= 0;
3537 gCoopTotalSecretsFound
:= 0;
3538 gCoopTotalMonsters
:= 0;
3539 gCoopTotalSecrets
:= 0;
3543 g_Game_ExecuteEvent('onmapstart');
3546 procedure SetFirstLevel
;
3550 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3551 if MapList
= nil then
3554 SortSArray(MapList
);
3555 gNextMap
:= MapList
[Low(MapList
)];
3560 procedure g_Game_ExitLevel(const Map
: AnsiString);
3564 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3565 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3566 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3567 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3569 // Вышли в выход в Одиночной игре:
3570 if gGameSettings
.GameType
= GT_SINGLE
then
3571 gExit
:= EXIT_ENDLEVELSINGLE
3572 else // Вышли в выход в Своей игре
3574 gExit
:= EXIT_ENDLEVELCUSTOM
;
3575 if gGameSettings
.GameMode
= GM_COOP
then
3576 g_Player_RememberAll
;
3578 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3581 if gGameSettings
.GameMode
= GM_COOP
then
3584 gStatsPressed
:= True;
3585 gNextMap
:= 'MAP01';
3587 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3590 if g_Game_IsNet
then
3592 MH_SEND_GameStats();
3593 MH_SEND_CoopStats();
3599 procedure g_Game_RestartLevel();
3603 if gGameSettings
.GameMode
= GM_SINGLE
then
3608 gExit
:= EXIT_ENDLEVELCUSTOM
;
3609 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3613 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3615 gWAD
{, xwad}: String;
3618 if not g_Game_IsClient
then Exit
;
3619 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3621 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3626 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3630 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3633 g_Game_LoadWAD(NewWAD
);
3637 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3638 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3641 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3642 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3646 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3650 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3651 g_Game_LoadWAD(NewWAD);
3655 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3657 i
, n
, nb
, nr
: Integer;
3659 if not g_Game_IsServer
then Exit
;
3660 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3661 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3662 gLMSRespawnTime
:= 0;
3665 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3667 gMissionFailed
:= True;
3668 g_Game_RestartLevel
;
3672 n
:= 0; nb
:= 0; nr
:= 0;
3673 for i
:= Low(gPlayers
) to High(gPlayers
) do
3674 if (gPlayers
[i
] <> nil) and
3675 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3676 (gPlayers
[i
] is TBot
)) then
3679 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3680 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3683 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3685 // wait a second until the fuckers finally decide to join
3686 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3687 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3688 gLMSSoftSpawn
:= NoMapRestart
;
3689 if g_Game_IsNet
then
3690 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3694 g_Player_RemoveAllCorpses
;
3695 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3696 if g_Game_IsNet
then
3697 MH_SEND_GameEvent(NET_EV_LMS_START
);
3699 for i
:= Low(gPlayers
) to High(gPlayers
) do
3701 if gPlayers
[i
] = nil then continue
;
3702 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3703 // don't touch normal spectators
3704 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3706 gPlayers
[i
].FNoRespawn
:= True;
3707 gPlayers
[i
].Lives
:= 0;
3708 if g_Game_IsNet
then
3709 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3712 gPlayers
[i
].FNoRespawn
:= False;
3713 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3714 gPlayers
[i
].Respawn(False, True);
3715 if gGameSettings
.GameMode
= GM_COOP
then
3717 gPlayers
[i
].Frags
:= 0;
3718 gPlayers
[i
].RecallState
;
3720 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3721 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3722 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3723 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3726 g_Items_RestartRound();
3728 gLMSSoftSpawn
:= False;
3731 function g_Game_GetFirstMap(WAD
: String): String;
3735 MapList
:= g_Map_GetMapsList(WAD
);
3736 if MapList
= nil then
3739 SortSArray(MapList
);
3740 Result
:= MapList
[Low(MapList
)];
3742 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3748 function g_Game_GetNextMap(): String;
3755 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3756 if MapList
= nil then
3759 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3761 SortSArray(MapList
);
3763 for I
:= Low(MapList
) to High(MapList
) do
3764 if Map
= MapList
[I
] then
3770 if MapIndex
<> -255 then
3772 if MapIndex
= High(MapList
) then
3773 Result
:= MapList
[Low(MapList
)]
3775 Result
:= MapList
[MapIndex
+ 1];
3777 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3783 procedure g_Game_NextLevel();
3785 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3786 gExit
:= EXIT_ENDLEVELCUSTOM
3789 gExit
:= EXIT_ENDLEVELSINGLE
;
3793 if gNextMap
<> '' then Exit
;
3794 gNextMap
:= g_Game_GetNextMap();
3797 function g_Game_IsTestMap(): Boolean;
3799 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3802 procedure g_Game_DeleteTestMap();
3805 //MapName: AnsiString;
3813 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3814 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3815 if (a
= 0) then exit
;
3817 // Выделяем имя wad-файла и имя карты
3818 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3819 Delete(gMapToDelete
, 1, a
+5);
3820 gMapToDelete
:= UpperCase(gMapToDelete
);
3822 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3825 // Имя карты не стандартное тестовое:
3826 if MapName <> TEST_MAP_NAME then
3829 if not gTempDelete then
3831 time := g_GetFileTime(WadName);
3832 WAD := TWADFile.Create();
3835 if not WAD.ReadFile(WadName) then
3836 begin // Нет такого WAD-файла
3841 // Составляем список карт и ищем нужную:
3843 MapList := WAD.GetResourcesList('');
3845 if MapList <> nil then
3846 for a := 0 to High(MapList) do
3847 if MapList[a] = MapName then
3849 // Удаляем и сохраняем:
3850 WAD.RemoveResource('', MapName);
3851 WAD.SaveTo(WadName);
3856 g_SetFileTime(WadName, time);
3859 if gTempDelete
then DeleteFile(WadName
);
3862 procedure GameCVars(P
: SSArray
);
3865 stat
: TPlayerStatArray
;
3868 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3872 if Length(P
) > 1 then
3877 gsGameFlags
:= gsGameFlags
or Flag
3879 gsGameFlags
:= gsGameFlags
and (not Flag
);
3881 if g_Game_IsServer
then
3884 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3886 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3887 if g_Game_IsNet
then MH_SEND_GameSettings
;
3891 if LongBool(gsGameFlags
and Flag
) then
3892 g_Console_Add(_lc
[OnMsg
])
3894 g_Console_Add(_lc
[OffMsg
]);
3896 if OnMapChange
and g_Game_IsServer
then
3897 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3902 cmd
:= LowerCase(P
[0]);
3904 if cmd
= 'g_gamemode' then
3906 if (Length(P
) > 1) then
3908 a
:= g_Game_TextToMode(P
[1]);
3909 if a
= GM_SINGLE
then a
:= GM_COOP
;
3910 gsGameMode
:= g_Game_ModeToText(a
);
3911 if g_Game_IsServer
then
3913 gSwitchGameMode
:= a
;
3914 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3915 (gState
= STATE_INTERSINGLE
) then
3916 gSwitchGameMode
:= GM_SINGLE
;
3918 gGameSettings
.GameMode
:= gSwitchGameMode
;
3922 if gSwitchGameMode
= gGameSettings
.GameMode
then
3923 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3924 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3926 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3927 [g_Game_ModeToText(gGameSettings
.GameMode
),
3928 g_Game_ModeToText(gSwitchGameMode
)]));
3930 else if cmd
= 'g_friendlyfire' then
3932 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3934 else if cmd
= 'g_friendly_absorb_damage' then
3936 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
3938 else if cmd
= 'g_friendly_hit_trace' then
3940 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
3942 else if cmd
= 'g_friendly_hit_projectile' then
3944 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
3946 else if cmd
= 'g_weaponstay' then
3948 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3950 else if cmd
= 'g_allow_exit' then
3952 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3954 else if cmd
= 'g_allow_monsters' then
3956 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3958 else if cmd
= 'g_allow_dropflag' then
3960 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
3962 else if cmd
= 'g_throw_flag' then
3964 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
3966 else if cmd
= 'g_bot_vsplayers' then
3968 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3970 else if cmd
= 'g_bot_vsmonsters' then
3972 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3974 else if cmd
= 'g_dm_keys' then
3976 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
3978 else if cmd
= 'g_gameflags' then
3980 if Length(P
) > 1 then
3982 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
3983 if g_Game_IsServer
then
3985 gGameSettings
.Options
:= gsGameFlags
;
3986 if g_Game_IsNet
then MH_SEND_GameSettings
;
3990 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
3992 else if cmd
= 'g_warmup_time' then
3994 if Length(P
) > 1 then
3996 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
3997 if g_Game_IsServer
then
3999 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4000 // extend warmup if it's already going
4001 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4003 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4004 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4006 if g_Game_IsNet
then MH_SEND_GameSettings
;
4010 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4011 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4013 else if cmd
= 'g_spawn_invul' then
4015 if Length(P
) > 1 then
4017 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4018 if g_Game_IsServer
then
4020 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4021 if g_Game_IsNet
then MH_SEND_GameSettings
;
4025 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4027 else if cmd
= 'g_item_respawn_time' then
4029 if Length(P
) > 1 then
4031 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4032 if g_Game_IsServer
then
4034 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4035 if g_Game_IsNet
then MH_SEND_GameSettings
;
4039 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4040 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4042 else if cmd
= 'sv_intertime' then
4044 if (Length(P
) > 1) then
4045 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4047 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4049 else if cmd
= 'g_max_particles' then
4051 if Length(p
) = 2 then
4054 a
:= Max(0, StrToIntDef(p
[1], 0));
4058 else if Length(p
) = 1 then
4061 e_LogWritefln('%s', [g_GFX_GetMax()])
4063 e_LogWritefln('%s', [0])
4068 e_LogWritefln('usage: %s <n>', [cmd
])
4071 else if cmd
= 'g_max_shells' then
4073 if Length(p
) = 2 then
4075 {$IFDEF ENABLE_SHELLS}
4076 a
:= Max(0, StrToIntDef(p
[1], 0));
4080 else if Length(p
) = 1 then
4082 {$IFDEF ENABLE_SHELLS}
4083 e_LogWritefln('%s', [g_Shells_GetMax()])
4085 e_LogWritefln('%s', [0])
4090 e_LogWritefln('usage: %s <n>', [cmd
])
4093 else if cmd
= 'g_max_gibs' then
4095 if Length(p
) = 2 then
4097 {$IFDEF ENABLE_GIBS}
4098 a
:= Max(0, StrToIntDef(p
[1], 0));
4102 else if Length(p
) = 1 then
4104 {$IFDEF ENABLE_GIBS}
4105 e_LogWritefln('%s', [g_Gibs_GetMax()])
4107 e_LogWritefln('%s', [0])
4112 e_LogWritefln('usage: %s <n>', [cmd
])
4115 else if cmd
= 'g_max_corpses' then
4117 if Length(p
) = 2 then
4119 a
:= Max(0, StrToIntDef(p
[1], 0));
4122 else if Length(p
) = 1 then
4124 e_LogWritefln('%s', [g_Corpses_GetMax()])
4128 e_LogWritefln('usage: %s <n>', [cmd
])
4131 else if cmd
= 'g_force_model' then
4133 if Length(p
) = 2 then
4135 a
:= StrToIntDef(p
[1], 0);
4136 g_Force_Model_Set(a
);
4137 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4139 for a
:= Low(gPlayers
) to High(gPlayers
) do
4141 if (gPlayers
[a
] <> nil) then
4143 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4145 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4147 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4151 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4153 for a
:= Low(gPlayers
) to High(gPlayers
) do
4155 if (gPlayers
[a
] <> nil) then
4157 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4159 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4161 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4167 else if cmd
= 'g_force_model_name' then
4169 if (Length(P
) > 1) then
4171 cmd
:= b_Text_Unformat(P
[1]);
4172 g_Forced_Model_SetName(cmd
);
4173 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4175 for a
:= Low(gPlayers
) to High(gPlayers
) do
4177 if (gPlayers
[a
] <> nil) then
4179 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4181 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4183 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4189 else if cmd
= 'g_scorelimit' then
4191 if Length(P
) > 1 then
4193 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4195 if g_Game_IsServer
then
4198 if gGameSettings
.GameMode
= GM_DM
then
4200 stat
:= g_Player_GetStats();
4202 for a
:= 0 to High(stat
) do
4203 if stat
[a
].Frags
> b
then
4207 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4209 // if someone has a higher score, set it to that instead
4210 gsScoreLimit
:= max(gsScoreLimit
, b
);
4211 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4213 if g_Game_IsNet
then MH_SEND_GameSettings
;
4217 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4219 else if cmd
= 'g_timelimit' then
4221 if Length(P
) > 1 then
4223 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4224 if g_Game_IsServer
then
4226 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4227 if g_Game_IsNet
then MH_SEND_GameSettings
;
4230 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4231 [gsTimeLimit
div 3600,
4232 (gsTimeLimit
div 60) mod 60,
4233 gsTimeLimit
mod 60]));
4235 else if cmd
= 'g_max_bots' then
4237 if Length(P
) > 1 then
4238 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4239 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4241 else if cmd
= 'g_maxlives' then
4243 if Length(P
) > 1 then
4245 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4246 if g_Game_IsServer
then
4248 gGameSettings
.MaxLives
:= gsMaxLives
;
4249 if g_Game_IsNet
then MH_SEND_GameSettings
;
4253 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4257 procedure PlayerSettingsCVars(P
: SSArray
);
4262 function ParseTeam(s
: string): Byte;
4266 'red', '1': result
:= TEAM_RED
;
4267 'blue', '2': result
:= TEAM_BLUE
;
4268 else result
:= TEAM_NONE
;
4272 cmd
:= LowerCase(P
[0]);
4276 if (Length(P
) > 1) then
4278 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4279 if g_Game_IsClient
then
4280 MC_SEND_PlayerSettings
4281 else if gGameOn
and (gPlayer1
<> nil) then
4283 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4284 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4290 if (Length(P
) > 1) then
4292 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4293 if g_Game_IsClient
then
4294 MC_SEND_PlayerSettings
4295 else if gGameOn
and (gPlayer2
<> nil) then
4297 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4298 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4304 if Length(P
) > 3 then
4306 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4307 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4308 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4309 if g_Game_IsClient
then
4310 MC_SEND_PlayerSettings
4311 else if gGameOn
and (gPlayer1
<> nil) then
4313 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4314 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4320 if Length(P
) > 3 then
4322 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4323 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4324 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4325 if g_Game_IsClient
then
4326 MC_SEND_PlayerSettings
4327 else if gGameOn
and (gPlayer2
<> nil) then
4329 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4330 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4336 if (Length(P
) > 1) then
4338 gPlayer1Settings
.Model
:= P
[1];
4339 if g_Game_IsClient
then
4340 MC_SEND_PlayerSettings
4341 else if gGameOn
and (gPlayer1
<> nil) then
4343 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4344 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4345 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4351 if (Length(P
) > 1) then
4353 gPlayer2Settings
.Model
:= P
[1];
4354 if g_Game_IsClient
then
4355 MC_SEND_PlayerSettings
4356 else if gGameOn
and (gPlayer2
<> nil) then
4358 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4359 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4360 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4366 // TODO: switch teams if in game or store this separately
4367 if (Length(P
) > 1) then
4369 team
:= ParseTeam(P
[1]);
4370 if team
= TEAM_NONE
then
4371 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4372 else if not gGameOn
and not g_Game_IsNet
then
4373 gPlayer1Settings
.Team
:= team
4375 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4380 // TODO: switch teams if in game or store this separately
4381 if (Length(P
) > 1) then
4383 team
:= ParseTeam(P
[1]);
4384 if team
= TEAM_NONE
then
4385 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4386 else if not gGameOn
and not g_Game_IsNet
then
4387 gPlayer2Settings
.Team
:= team
4389 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4394 if (Length(P
) = 2) then
4395 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4399 if (Length(P
) = 2) then
4400 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4404 if (Length(P
) = 2) then
4405 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4409 if (Length(P
) = 2) then
4410 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4414 if (Length(P
) = 2) then
4415 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4419 if (Length(P
) = 2) then
4420 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4422 'p1_priority_kastet':
4424 if (Length(P
) = 2) then
4425 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4427 'p2_priority_kastet':
4429 if (Length(P
) = 2) then
4430 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4434 if (Length(P
) = 2) then
4435 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4439 if (Length(P
) = 2) then
4440 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4442 'p1_priority_pistol':
4444 if (Length(P
) = 2) then
4445 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4447 'p2_priority_pistol':
4449 if (Length(P
) = 2) then
4450 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4452 'p1_priority_shotgun1':
4454 if (Length(P
) = 2) then
4455 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4457 'p2_priority_shotgun1':
4459 if (Length(P
) = 2) then
4460 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4462 'p1_priority_shotgun2':
4464 if (Length(P
) = 2) then
4465 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4467 'p2_priority_shotgun2':
4469 if (Length(P
) = 2) then
4470 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4472 'p1_priority_chaingun':
4474 if (Length(P
) = 2) then
4475 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4477 'p2_priority_chaingun':
4479 if (Length(P
) = 2) then
4480 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4482 'p1_priority_rocketlauncher':
4484 if (Length(P
) = 2) then
4485 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4487 'p2_priority_rocketlauncher':
4489 if (Length(P
) = 2) then
4490 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4492 'p1_priority_plasma':
4494 if (Length(P
) = 2) then
4495 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4497 'p2_priority_plasma':
4499 if (Length(P
) = 2) then
4500 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4504 if (Length(P
) = 2) then
4505 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4509 if (Length(P
) = 2) then
4510 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4512 'p1_priority_super':
4514 if (Length(P
) = 2) then
4515 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4517 'p2_priority_super':
4519 if (Length(P
) = 2) then
4520 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4522 'p1_priority_flamethrower':
4524 if (Length(P
) = 2) then
4525 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4527 'p2_priority_flamethrower':
4529 if (Length(P
) = 2) then
4530 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4532 'p1_priority_berserk':
4534 if (Length(P
) = 2) then
4535 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4537 'p2_priority_berserk':
4539 if (Length(P
) = 2) then
4540 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4545 procedure PrintHeapStats();
4549 hs
:= GetFPCHeapStatus();
4550 e_LogWriteLn ('v===== heap status =====v');
4551 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4552 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4553 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4554 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4555 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4556 e_LogWriteLn ('^=======================^');
4559 procedure DebugCommands(P
: SSArray
);
4566 // Команды отладочного режима:
4567 if {gDebugMode}conIsCheatsEnabled
then
4569 cmd
:= LowerCase(P
[0]);
4570 if cmd
= 'd_window' then
4572 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4573 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4575 else if cmd
= 'd_sounds' then
4577 if (Length(P
) > 1) and
4578 ((P
[1] = '1') or (P
[1] = '0')) then
4579 g_Debug_Sounds
:= (P
[1][1] = '1');
4581 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4583 else if cmd
= 'd_frames' then
4585 if (Length(P
) > 1) and
4586 ((P
[1] = '1') or (P
[1] = '0')) then
4587 g_Debug_Frames
:= (P
[1][1] = '1');
4589 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4591 else if cmd
= 'd_winmsg' then
4593 if (Length(P
) > 1) and
4594 ((P
[1] = '1') or (P
[1] = '0')) then
4595 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4597 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4599 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4601 if (Length(P
) > 1) and
4602 ((P
[1] = '1') or (P
[1] = '0')) then
4603 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4605 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4607 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4609 if Length(P
) > 1 then
4611 '0': g_debug_BotAIOff
:= 0;
4612 '1': g_debug_BotAIOff
:= 1;
4613 '2': g_debug_BotAIOff
:= 2;
4614 '3': g_debug_BotAIOff
:= 3;
4617 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4619 else if cmd
= 'd_monster' then
4621 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4622 if Length(P
) < 2 then
4624 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4625 g_Console_Add('ID | Name');
4626 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4627 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4628 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4631 a
:= StrToIntDef(P
[1], 0);
4632 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4633 a
:= g_Mons_TypeIdByName(P
[1]);
4635 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4636 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4639 with gPlayer1
.Obj
do
4641 mon
:= g_Monsters_Create(a
,
4642 X
+ Rect
.X
+ (Rect
.Width
div 2),
4643 Y
+ Rect
.Y
+ Rect
.Height
,
4644 gPlayer1
.Direction
, True);
4646 if (Length(P
) > 2) and (mon
<> nil) then
4648 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4649 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4650 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4651 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4652 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4653 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4654 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4655 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4656 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4661 else if (cmd
= 'd_health') then
4663 if (Length(P
) > 1) and
4664 ((P
[1] = '1') or (P
[1] = '0')) then
4665 g_debug_HealthBar
:= (P
[1][1] = '1');
4667 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4669 else if (cmd
= 'd_player') then
4671 if (Length(P
) > 1) and
4672 ((P
[1] = '1') or (P
[1] = '0')) then
4673 g_debug_Player
:= (P
[1][1] = '1');
4675 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4677 else if (cmd
= 'd_mem') then
4683 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4687 procedure GameCheats(P
: SSArray
);
4693 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4695 g_Console_Add('not available');
4701 g_Console_Add('where is the player?!');
4704 cmd
:= LowerCase(P
[0]);
4708 plr
.GodMode
:= not plr
.GodMode
;
4709 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4712 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4713 if cmd
= 'give' then
4715 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4716 for f
:= 1 to High(P
) do
4718 cmd
:= LowerCase(P
[f
]);
4719 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4720 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4721 if cmd
= 'exit' then
4723 if gTriggers
<> nil then
4725 for a
:= 0 to High(gTriggers
) do
4727 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4729 g_Console_Add('player left the map');
4730 gExitByTrigger
:= True;
4731 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4732 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4740 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4741 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4742 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4743 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4744 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4746 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4747 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4749 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4750 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;
4752 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4753 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4755 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4756 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4758 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4759 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4761 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4762 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4763 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4765 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4766 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4767 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4768 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;
4769 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4770 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4772 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;
4773 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;
4774 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;
4775 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;
4776 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;
4777 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;
4779 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4780 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;
4782 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;
4783 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;
4785 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4787 if cmd
= 'ammo' then
4789 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4790 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4791 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4792 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4793 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4794 g_Console_Add('player got some ammo');
4798 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4799 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4801 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4802 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4804 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4805 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4807 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4808 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4810 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4812 if cmd
= 'weapons' then
4814 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4815 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4816 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4817 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4818 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4819 plr
.GiveItem(ITEM_WEAPON_BFG
);
4820 g_Console_Add('player got weapons');
4824 if cmd
= 'keys' then
4826 plr
.GiveItem(ITEM_KEY_RED
);
4827 plr
.GiveItem(ITEM_KEY_GREEN
);
4828 plr
.GiveItem(ITEM_KEY_BLUE
);
4829 g_Console_Add('player got all keys');
4833 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4838 if cmd
= 'open' then
4840 g_Console_Add('player activated sesame');
4841 g_Triggers_OpenAll();
4848 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4852 if cmd
= 'noclip' then
4855 g_Console_Add('wall hardeness adjusted');
4859 if cmd
= 'notarget' then
4861 plr
.NoTarget
:= not plr
.NoTarget
;
4862 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4866 if cmd
= 'noreload' then
4868 plr
.NoReload
:= not plr
.NoReload
;
4869 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4873 if cmd
= 'speedy' then
4875 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4876 g_Console_Add('speed adjusted');
4880 if cmd
= 'jumpy' then
4882 VEL_JUMP
:= 30-VEL_JUMP
;
4883 g_Console_Add('jump height adjusted');
4887 if cmd
= 'automap' then
4889 gShowMap
:= not gShowMap
;
4890 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4894 if cmd
= 'aimline' then
4896 gAimLine
:= not gAimLine
;
4897 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4902 procedure GameCommands(P
: SSArray
);
4908 pl
: pTNetClient
= nil;
4916 cmd
:= LowerCase(P
[0]);
4918 if cmd
= 'pause' then
4920 {$IFDEF ENABLE_MENU}
4921 if (g_ActiveWindow
= nil) then
4922 g_Game_Pause(not gPauseMain
);
4924 g_Game_Pause(not gPauseMain
);
4927 else if cmd
= 'endgame' then
4928 gExit
:= EXIT_SIMPLE
4929 else if cmd
= 'restart' then
4931 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4933 if g_Game_IsClient
then
4935 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4940 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4942 else if cmd
= 'kick' then
4944 if g_Game_IsServer
then
4946 if Length(P
) < 2 then
4948 g_Console_Add('kick <name>');
4953 g_Console_Add('kick <name>');
4957 if g_Game_IsNet
then
4958 pl
:= g_Net_Client_ByName(P
[1]);
4961 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4962 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4963 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4964 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4965 g_Net_Slist_ServerPlayerLeaves();
4966 end else if gPlayers
<> nil then
4967 for a
:= Low(gPlayers
) to High(gPlayers
) do
4968 if gPlayers
[a
] <> nil then
4969 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4971 // Не отключать основных игроков в сингле
4972 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4974 gPlayers
[a
].Lives
:= 0;
4975 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4976 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4977 g_Player_Remove(gPlayers
[a
].UID
);
4978 g_Net_Slist_ServerPlayerLeaves();
4979 // Если не перемешать, при добавлении новых ботов появятся старые
4983 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4985 else if cmd
= 'kick_id' then
4987 if g_Game_IsServer
and g_Game_IsNet
then
4989 if Length(P
) < 2 then
4991 g_Console_Add('kick_id <client ID>');
4996 g_Console_Add('kick_id <client ID>');
5000 a
:= StrToIntDef(P
[1], 0);
5001 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5003 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5005 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5006 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
5007 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5008 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5009 g_Net_Slist_ServerPlayerLeaves();
5013 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5015 else if cmd
= 'kick_pid' then
5017 if g_Game_IsServer
and g_Game_IsNet
then
5019 if Length(P
) < 2 then
5021 g_Console_Add('kick_pid <player ID>');
5026 g_Console_Add('kick_pid <player ID>');
5030 a
:= StrToIntDef(P
[1], 0);
5031 pl
:= g_Net_Client_ByPlayer(a
);
5032 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5034 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5035 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5036 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5037 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5038 g_Net_Slist_ServerPlayerLeaves();
5041 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5043 else if cmd
= 'ban' then
5045 if g_Game_IsServer
and g_Game_IsNet
then
5047 if Length(P
) < 2 then
5049 g_Console_Add('ban <name>');
5054 g_Console_Add('ban <name>');
5058 pl
:= g_Net_Client_ByName(P
[1]);
5061 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5062 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5063 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5064 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5065 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5066 g_Net_Slist_ServerPlayerLeaves();
5068 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5070 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5072 else if cmd
= 'ban_id' then
5074 if g_Game_IsServer
and g_Game_IsNet
then
5076 if Length(P
) < 2 then
5078 g_Console_Add('ban_id <client ID>');
5083 g_Console_Add('ban_id <client ID>');
5087 a
:= StrToIntDef(P
[1], 0);
5088 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5089 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5091 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5092 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5093 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5094 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5095 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5096 g_Net_Slist_ServerPlayerLeaves();
5099 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5101 else if cmd
= 'ban_pid' then
5103 if g_Game_IsServer
and g_Game_IsNet
then
5105 if Length(P
) < 2 then
5107 g_Console_Add('ban_pid <player ID>');
5112 g_Console_Add('ban_pid <player ID>');
5116 a
:= StrToIntDef(P
[1], 0);
5117 pl
:= g_Net_Client_ByPlayer(a
);
5118 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5120 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5121 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5122 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5123 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5124 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5125 g_Net_Slist_ServerPlayerLeaves();
5128 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5130 else if cmd
= 'permban' then
5132 if g_Game_IsServer
and g_Game_IsNet
then
5134 if Length(P
) < 2 then
5136 g_Console_Add('permban <name>');
5141 g_Console_Add('permban <name>');
5145 pl
:= g_Net_Client_ByName(P
[1]);
5148 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5149 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5150 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5151 g_Net_SaveBanList();
5152 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5153 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5154 g_Net_Slist_ServerPlayerLeaves();
5156 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5158 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5160 else if cmd
= 'permban_id' then
5162 if g_Game_IsServer
and g_Game_IsNet
then
5164 if Length(P
) < 2 then
5166 g_Console_Add('permban_id <client ID>');
5171 g_Console_Add('permban_id <client ID>');
5175 a
:= StrToIntDef(P
[1], 0);
5176 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5177 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5179 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5180 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5181 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5182 g_Net_SaveBanList();
5183 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5184 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5185 g_Net_Slist_ServerPlayerLeaves();
5188 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5190 else if cmd
= 'permban_pid' then
5192 if g_Game_IsServer
and g_Game_IsNet
then
5194 if Length(P
) < 2 then
5196 g_Console_Add('permban_pid <player ID>');
5201 g_Console_Add('permban_pid <player ID>');
5205 a
:= StrToIntDef(P
[1], 0);
5206 pl
:= g_Net_Client_ByPlayer(a
);
5207 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5209 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5210 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5211 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5212 g_Net_SaveBanList();
5213 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5214 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5215 g_Net_Slist_ServerPlayerLeaves();
5218 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5220 else if cmd
= 'permban_ip' then
5222 if g_Game_IsServer
and g_Game_IsNet
then
5224 if Length(P
) < 2 then
5226 g_Console_Add('permban_ip <IP address>');
5231 g_Console_Add('permban_ip <IP address>');
5235 g_Net_BanHost(P
[1]);
5236 g_Net_SaveBanList();
5237 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5239 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5241 else if cmd
= 'unban' then
5243 if g_Game_IsServer
and g_Game_IsNet
then
5245 if Length(P
) < 2 then
5247 g_Console_Add('unban <IP Address>');
5252 g_Console_Add('unban <IP Address>');
5256 if g_Net_UnbanHost(P
[1]) then
5258 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5259 g_Net_SaveBanList();
5261 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5263 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5265 else if cmd
= 'clientlist' then
5267 if g_Game_IsServer
and g_Game_IsNet
then
5270 if NetClients
<> nil then
5271 for a
:= Low(NetClients
) to High(NetClients
) do
5272 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5274 plr
:= g_Player_Get(NetClients
[a
].Player
);
5275 if plr
= nil then continue
;
5277 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5278 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5281 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5283 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5285 else if cmd
= 'connect' then
5287 if (NetMode
= NET_NONE
) then
5289 if Length(P
) < 2 then
5291 g_Console_Add('connect <IP> [port] [password]');
5296 g_Console_Add('connect <IP> [port] [password]');
5300 if Length(P
) > 2 then
5301 prt
:= StrToIntDef(P
[2], 25666)
5305 if Length(P
) > 3 then
5310 g_Game_StartClient(P
[1], prt
, pw
);
5313 else if cmd
= 'disconnect' then
5315 if (NetMode
= NET_CLIENT
) then
5318 else if cmd
= 'reconnect' then
5320 if (NetMode
= NET_SERVER
) then
5323 if (NetMode
= NET_CLIENT
) then
5326 gExit
:= EXIT_SIMPLE
;
5330 //TODO: Use last successful password to reconnect, instead of ''
5331 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5333 else if (cmd
= 'addbot') or
5334 (cmd
= 'bot_add') then
5336 if Length(P
) > 2 then
5337 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5338 else if Length(P
) > 1 then
5339 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5341 g_Bot_Add(TEAM_NONE
, 2);
5343 else if cmd
= 'bot_addlist' then
5345 if Length(P
) > 1 then
5347 if Length(P
) = 2 then
5348 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5349 else if Length(P
) = 3 then
5350 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5352 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5355 else if cmd
= 'bot_removeall' then
5357 else if cmd
= 'chat' then
5359 if g_Game_IsNet
then
5361 if Length(P
) > 1 then
5363 for a
:= 1 to High(P
) do
5364 chstr
:= chstr
+ P
[a
] + ' ';
5366 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5368 if Length(chstr
) < 1 then
5370 g_Console_Add('chat <text>');
5374 chstr
:= b_Text_Format(chstr
);
5375 if g_Game_IsClient
then
5376 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5378 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5381 g_Console_Add('chat <text>');
5383 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5385 else if cmd
= 'teamchat' then
5387 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5389 if Length(P
) > 1 then
5391 for a
:= 1 to High(P
) do
5392 chstr
:= chstr
+ P
[a
] + ' ';
5394 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5396 if Length(chstr
) < 1 then
5398 g_Console_Add('teamchat <text>');
5402 chstr
:= b_Text_Format(chstr
);
5403 if g_Game_IsClient
then
5404 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5406 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5407 gPlayer1Settings
.Team
);
5410 g_Console_Add('teamchat <text>');
5412 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5414 else if (cmd
= 'an') or (cmd
= 'announce') then
5416 if g_Game_IsNet
then
5418 if Length(P
) > 1 then
5420 for a
:= 1 to High(P
) do
5421 chstr
:= chstr
+ P
[a
] + ' ';
5423 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5425 if Length(chstr
) < 1 then
5427 g_Console_Add('announce <text>');
5431 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5432 if g_Game_IsClient
then
5433 MC_SEND_RCONCommand(chstr
)
5435 g_Console_Process(chstr
, True);
5438 g_Console_Add('announce <text>');
5440 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5442 else if cmd
= 'game' then
5444 if gGameSettings
.GameType
<> GT_NONE
then
5446 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5449 if Length(P
) = 1 then
5451 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5454 // game not started yet, load fist map from some wad
5456 s
:= addWadExtension(P
[1]);
5457 found
:= e_FindResource(AllMapDirs
, s
);
5461 P
[1] := ExpandFileName(P
[1]);
5462 // if map not choosed then set first map
5463 if Length(P
) < 3 then
5466 P
[2] := g_Game_GetFirstMap(P
[1]);
5469 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5471 if g_Map_Exist(s
) then
5475 with gGameSettings
do
5477 Options
:= gsGameFlags
;
5478 GameMode
:= g_Game_TextToMode(gsGameMode
);
5479 if gSwitchGameMode
<> GM_NONE
then
5480 GameMode
:= gSwitchGameMode
;
5481 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5482 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5484 if Length(P
) >= 4 then
5485 b
:= StrToIntDef(P
[3], 1);
5486 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5487 ScoreLimit
, MaxLives
, Options
, b
);
5492 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5494 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5496 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5498 else if cmd
= 'host' then
5500 if gGameSettings
.GameType
<> GT_NONE
then
5502 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5505 if Length(P
) < 4 then
5507 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5510 if not StrToIp(P
[1], listen
) then
5512 prt
:= StrToIntDef(P
[2], 25666);
5514 s
:= addWadExtension(P
[3]);
5515 found
:= e_FindResource(AllMapDirs
, s
);
5519 // get first map in wad, if not specified
5520 if Length(P
) < 5 then
5523 P
[4] := g_Game_GetFirstMap(P
[1]);
5525 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5526 if g_Map_Exist(s
) then
5530 with gGameSettings
do
5532 Options
:= gsGameFlags
;
5533 GameMode
:= g_Game_TextToMode(gsGameMode
);
5534 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5535 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5536 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5538 if Length(P
) >= 6 then
5539 b
:= StrToIntDef(P
[5], 0);
5540 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5546 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5548 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5553 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5556 else if cmd
= 'map' then
5558 if Length(P
) = 1 then
5560 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5562 g_Console_Add(cmd
+ ' <MAP>');
5563 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5567 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5572 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5574 if Length(P
) < 3 then
5576 // first param is map or wad
5577 s
:= UpperCase(P
[1]);
5578 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5580 gExitByTrigger
:= False;
5583 // already in game, finish current map
5585 gExit
:= EXIT_ENDLEVELCUSTOM
;
5589 // intermission, so change map immediately
5596 found
:= e_FindResource(AllMapDirs
, s
);
5598 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5601 // no such map, found wad
5604 P
[1] := ExpandFileName(pw
);
5605 P
[2] := g_Game_GetFirstMap(P
[1]);
5606 s
:= P
[1] + ':\' + P
[2];
5607 if g_Map_Exist(s
) then
5609 gExitByTrigger
:= False;
5612 // already in game, finish current map
5614 gExit
:= EXIT_ENDLEVELCUSTOM
5618 // intermission, so change map immediately
5625 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5627 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5632 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5638 s
:= addWadExtension(P
[1]);
5639 found
:= e_FindResource(AllMapDirs
, s
);
5643 P
[2] := UpperCase(P
[2]);
5644 s
:= P
[1] + ':\' + P
[2];
5645 if g_Map_Exist(s
) then
5647 gExitByTrigger
:= False;
5651 gExit
:= EXIT_ENDLEVELCUSTOM
5660 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5665 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5671 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5675 else if cmd
= 'nextmap' then
5677 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5679 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5684 if Length(P
) = 1 then
5686 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5688 g_Console_Add(cmd
+ ' <MAP>');
5689 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5694 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5700 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5702 if Length(P
) < 3 then
5704 // first param is map or wad
5705 s
:= UpperCase(P
[1]);
5706 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5709 gExitByTrigger
:= False;
5715 // no such map, found wad
5716 pw
:= addWadExtension(P
[1]);
5717 found
:= e_FindResource(MapDirs
, pw
);
5719 found
:= e_FindResource(WadDirs
, pw
);
5721 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5724 // map not specified, select first map
5726 P
[2] := g_Game_GetFirstMap(P
[1]);
5727 s
:= P
[1] + ':\' + P
[2];
5728 if g_Map_Exist(s
) then
5730 gExitByTrigger
:= False;
5737 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5739 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5744 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5750 // specified two params wad + map
5751 pw
:= addWadExtension(P
[1]);
5752 found
:= e_FindResource(MapDirs
, pw
);
5754 found
:= e_FindResource(MapDirs
, pw
);
5758 P
[2] := UpperCase(P
[2]);
5759 s
:= P
[1] + ':\' + P
[2];
5760 if g_Map_Exist(s
) then
5762 gExitByTrigger
:= False;
5768 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5773 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5779 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5784 if gNextMap
= '' then
5785 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5787 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5791 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5795 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5799 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5801 gExitByTrigger
:= False;
5802 // next map not specified, try to find trigger EXIT
5803 if (gNextMap
= '') and (gTriggers
<> nil) then
5805 for a
:= 0 to High(gTriggers
) do
5807 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5809 gExitByTrigger
:= True;
5810 //gNextMap := gTriggers[a].Data.MapName;
5811 gNextMap
:= gTriggers
[a
].tgcMap
;
5816 if gNextMap
= '' then
5817 gNextMap
:= g_Game_GetNextMap();
5818 if not isWadPath(gNextMap
) then
5819 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5822 if g_Map_Exist(s
) then
5823 gExit
:= EXIT_ENDLEVELCUSTOM
5825 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5829 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5833 else if (cmd
= 'event') then
5835 if (Length(P
) <= 1) then
5837 for a
:= 0 to High(gEvents
) do
5838 if gEvents
[a
].Command
= '' then
5839 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5841 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5844 if (Length(P
) = 2) then
5846 for a
:= 0 to High(gEvents
) do
5847 if gEvents
[a
].Name
= P
[1] then
5848 if gEvents
[a
].Command
= '' then
5849 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5851 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5854 for a
:= 0 to High(gEvents
) do
5855 if gEvents
[a
].Name
= P
[1] then
5857 gEvents
[a
].Command
:= '';
5858 for b
:= 2 to High(P
) do
5859 if Pos(' ', P
[b
]) = 0 then
5860 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5862 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5863 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5867 else if cmd
= 'suicide' then
5871 if g_Game_IsClient
then
5872 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5875 if gPlayer1
<> nil then
5876 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5877 if gPlayer2
<> nil then
5878 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5882 else if cmd
= 'screenshot' then
5888 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5890 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5892 gWeaponAction
[0, WP_PREV
] := True;
5894 gWeaponAction
[0, WP_NEXT
] := True;
5896 else if cmd
= 'weapon' then
5898 if Length(p
) = 2 then
5900 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5901 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5902 gSelectWeapon
[0, a
] := True
5905 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5906 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5908 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5909 b
:= ord(cmd
[2]) - ord('1');
5911 gWeaponAction
[b
, WP_PREV
] := True;
5913 gWeaponAction
[b
, WP_NEXT
] := True;
5915 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5917 if Length(p
) = 2 then
5919 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5920 b
:= ord(cmd
[2]) - ord('1');
5921 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5922 gSelectWeapon
[b
, a
] := True
5925 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
5927 b
:= ord(cmd
[2]) - ord('1');
5929 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
5931 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
5933 else if (cmd
= 'dropflag') then
5935 if g_Game_IsServer
then
5937 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
5938 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
5941 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5943 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
5945 b
:= ord(cmd
[2]) - ord('1');
5946 if g_Game_IsServer
then
5948 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
5949 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
5952 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5954 // Команды Своей игры:
5955 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5957 if cmd
= 'bot_addred' then
5959 if Length(P
) > 1 then
5960 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5962 g_Bot_Add(TEAM_RED
, 2);
5964 else if cmd
= 'bot_addblue' then
5966 if Length(P
) > 1 then
5967 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5969 g_Bot_Add(TEAM_BLUE
, 2);
5971 else if cmd
= 'spectate' then
5977 else if cmd
= 'say' then
5979 if g_Game_IsServer
and g_Game_IsNet
then
5981 if Length(P
) > 1 then
5984 for a
:= 1 to High(P
) do
5985 chstr
:= chstr
+ P
[a
] + ' ';
5987 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5989 if Length(chstr
) < 1 then
5991 g_Console_Add('say <text>');
5995 chstr
:= b_Text_Format(chstr
);
5996 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5998 else g_Console_Add('say <text>');
6000 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6002 else if cmd
= 'tell' then
6004 if g_Game_IsServer
and g_Game_IsNet
then
6006 if (Length(P
) > 2) and (P
[1] <> '') then
6009 for a
:= 2 to High(P
) do
6010 chstr
:= chstr
+ P
[a
] + ' ';
6012 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6014 if Length(chstr
) < 1 then
6016 g_Console_Add('tell <playername> <text>');
6020 pl
:= g_Net_Client_ByName(P
[1]);
6022 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6024 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6026 else g_Console_Add('tell <playername> <text>');
6028 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6030 else if cmd
= 'centerprint' then
6032 if (Length(P
) > 2) and (P
[1] <> '') then
6035 for a
:= 2 to High(P
) do
6036 chstr
:= chstr
+ P
[a
] + ' ';
6038 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6040 if Length(chstr
) < 1 then
6042 g_Console_Add('centerprint <timeout> <text>');
6046 a
:= StrToIntDef(P
[1], 100);
6047 chstr
:= b_Text_Format(chstr
);
6048 g_Game_Message(chstr
, a
);
6049 if g_Game_IsNet
and g_Game_IsServer
then
6050 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6052 else g_Console_Add('centerprint <timeout> <text>');
6054 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6056 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6058 // Дополнительное время:
6059 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6061 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6062 [gGameSettings
.TimeLimit
div 3600,
6063 (gGameSettings
.TimeLimit
div 60) mod 60,
6064 gGameSettings
.TimeLimit
mod 60]));
6065 if g_Game_IsNet
then MH_SEND_GameSettings
;
6067 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6069 if (Length(P
) <= 1) then
6070 g_Console_Add('rcon_password <password>')
6072 MC_SEND_RCONPassword(P
[1]);
6074 else if cmd
= 'rcon' then
6076 if g_Game_IsClient
then
6078 if Length(P
) > 1 then
6081 for a
:= 1 to High(P
) do
6082 chstr
:= chstr
+ P
[a
] + ' ';
6084 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6086 if Length(chstr
) < 1 then
6088 g_Console_Add('rcon <command>');
6092 MC_SEND_RCONCommand(chstr
);
6094 else g_Console_Add('rcon <command>');
6097 else if cmd
= 'ready' then
6099 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6100 gLMSRespawnTime
:= gTime
+ 100;
6102 else if (cmd
= 'callvote') and g_Game_IsNet
then
6104 if Length(P
) > 1 then
6107 for a
:= 1 to High(P
) do begin
6108 if a
> 1 then chstr
:= chstr
+ ' ';
6109 chstr
:= chstr
+ P
[a
];
6112 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6114 if Length(chstr
) < 1 then
6116 g_Console_Add('callvote <command>');
6120 if g_Game_IsClient
then
6121 MC_SEND_Vote(True, chstr
)
6123 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6124 g_Console_Process('vote', True);
6127 g_Console_Add('callvote <command>');
6129 else if (cmd
= 'vote') and g_Game_IsNet
then
6131 if g_Game_IsClient
then
6133 else if gVoteInProgress
then
6135 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6136 a
:= Floor((NetClientCount
+1)/2.0) + 1
6138 a
:= Floor(NetClientCount
/2.0) + 1;
6143 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6144 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6150 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6151 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6159 procedure SystemCommands(P
: SSArray
);
6163 cmd
:= LowerCase(P
[0]);
6176 if Length(p
) = 2 then
6178 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6180 gFrameTime
:= 1000 div gMaxFPS
6184 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6188 if Length(p
) = 2 then
6190 gAskLanguage
:= true;
6191 gLanguage
:= LANGUAGE_ENGLISH
;
6192 case LowerCase(p
[1]) of
6195 gAskLanguage
:= false;
6196 gLanguage
:= LANGUAGE_ENGLISH
;
6200 gAskLanguage
:= false;
6201 gLanguage
:= LANGUAGE_RUSSIAN
;
6205 gAskLanguage
:= true;
6206 gLanguage
:= LANGUAGE_ENGLISH
;
6209 g_Language_Set(gLanguage
);
6213 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6220 procedure g_TakeScreenShot(Filename
: string = '');
6221 var t
: TDateTime
; dir
, date
, name
: String;
6223 if e_NoGraphics
then
6226 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6227 if Filename
= '' then
6230 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6231 Filename
:= 'screenshot-' + date
;
6234 name
:= e_CatPath(dir
, Filename
+ '.png');
6235 if r_Render_WriteScreenShot(name
) then
6236 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6238 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6242 {$IFDEF ENABLE_MENU}
6243 procedure g_Game_InGameMenu(Show
: Boolean);
6245 if (g_ActiveWindow
= nil) and Show
then
6247 if gGameSettings
.GameType
= GT_SINGLE
then
6248 g_GUI_ShowWindow('GameSingleMenu')
6251 if g_Game_IsClient
then
6252 g_GUI_ShowWindow('GameClientMenu')
6254 if g_Game_IsNet
then
6255 g_GUI_ShowWindow('GameServerMenu')
6257 g_GUI_ShowWindow('GameCustomMenu');
6259 g_Sound_PlayEx('MENU_OPEN');
6261 // Пауза при меню только в одиночной игре:
6262 if (not g_Game_IsNet
) then
6266 if (g_ActiveWindow
<> nil) and (not Show
) then
6268 // Пауза при меню только в одиночной игре:
6269 if (not g_Game_IsNet
) then
6270 g_Game_Pause(False);
6275 procedure g_Game_Pause (Enable
: Boolean);
6279 if not gGameOn
then exit
;
6281 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6284 gPauseMain
:= Enable
;
6286 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6289 procedure g_Game_HolmesPause (Enable
: Boolean);
6293 if not gGameOn
then exit
;
6294 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6297 gPauseHolmes
:= Enable
;
6299 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6302 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6307 if gTriggers
<> nil then
6308 for i
:= 0 to High(gTriggers
) do
6309 with gTriggers
[i
] do
6310 if (TriggerType
= TRIGGER_SOUND
) and
6312 Sound
.IsPlaying() then
6314 Sound
.Pause(Enable
);
6318 if gPlayers
<> nil then
6319 for i
:= 0 to High(gPlayers
) do
6320 if gPlayers
[i
] <> nil then
6321 gPlayers
[i
].PauseSounds(Enable
);
6324 if gMusic
<> nil then
6325 gMusic
.Pause(Enable
);
6328 procedure g_Game_StopAllSounds(all
: Boolean);
6332 if gTriggers
<> nil then
6333 for i
:= 0 to High(gTriggers
) do
6334 with gTriggers
[i
] do
6335 if (TriggerType
= TRIGGER_SOUND
) and
6339 if gMusic
<> nil then
6346 procedure g_Game_UpdateTriggerSounds
;
6349 if gTriggers
<> nil then
6350 for i
:= 0 to High(gTriggers
) do
6351 with gTriggers
[i
] do
6352 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6353 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6356 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6359 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6364 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6369 if gSpectMode
<> SPECT_PLAYERS
then
6371 if gSpectPID1
= UID
then
6376 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6383 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6388 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6393 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6398 if gSpectMode
<> SPECT_PLAYERS
then
6400 Pl
:= g_Player_Get(gSpectPID1
);
6401 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6406 if gSpectViewTwo
then
6408 Pl
:= g_Player_Get(gSpectPID2
);
6409 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6417 procedure g_Game_Message (Msg
: string; Time
: Word);
6420 MessageTime
:= Time
;
6423 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6425 punct
: Array[0..13] of String =
6426 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6432 function IsPunctuation(S
: String): Boolean;
6437 if Length(S
) <> 1 then
6439 for i
:= Low(punct
) to High(punct
) do
6440 if S
= punct
[i
] then
6446 function FilterPunctuation(S
: String): String;
6450 for i
:= Low(punct
) to High(punct
) do
6451 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6457 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6459 // remove player name
6460 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6461 // for FullWord check
6462 Text := toLowerCase1251(' ' + Text + ' ');
6463 fpText
:= FilterPunctuation(Text);
6465 for i
:= 0 to Length(gChatSounds
) - 1 do
6468 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6470 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6471 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6473 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6479 gChatSounds
[i
].Sound
.Play();
6485 g_Sound_PlayEx('SOUND_GAME_RADIO');
6488 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6497 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6501 if goodsnd
[a
].IsPlaying() then
6504 goodsnd
[Random(4)].Play();
6507 procedure g_Game_Announce_KillCombo(Param
: Integer);
6514 UID
:= Param
and $FFFF;
6519 Pl
:= g_Player_Get(UID
);
6528 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6532 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6536 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6540 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6548 if not g_Game_IsWatchedPlayer(UID
) then
6551 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6555 if killsnd
[n
].IsPlaying() then
6560 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6568 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6572 if hahasnd
[a
].IsPlaying() then
6575 hahasnd
[Random(3)].Play();
6578 procedure g_Game_StartVote(Command
, Initiator
: string);
6582 if not gVotesEnabled
then Exit
;
6583 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6584 if gVoteInProgress
or gVotePassed
then
6586 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6587 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6590 gVoteInProgress
:= True;
6591 gVotePassed
:= False;
6592 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6595 gVoteCommand
:= Command
;
6597 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6598 Need
:= Floor((NetClientCount
+1)/2.0)+1
6600 Need
:= Floor(NetClientCount
/2.0)+1;
6601 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6602 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6605 procedure g_Game_CheckVote
;
6609 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6610 if not gVoteInProgress
then Exit
;
6612 if (gTime
>= gVoteTimer
) then
6614 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6615 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6617 Need
:= Floor(NetClientCount
/2.0) + 1;
6618 if gVoteCount
>= Need
then
6620 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6621 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6622 gVotePassed
:= True;
6623 gVoteCmdTimer
:= gTime
+ 5000;
6627 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6628 MH_SEND_VoteEvent(NET_VE_FAILED
);
6630 if NetClients
<> nil then
6631 for I
:= Low(NetClients
) to High(NetClients
) do
6632 if NetClients
[i
].Used
then
6633 NetClients
[i
].Voted
:= False;
6634 gVoteInProgress
:= False;
6640 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6641 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6643 Need
:= Floor(NetClientCount
/2.0) + 1;
6644 if gVoteCount
>= Need
then
6646 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6647 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6648 gVoteInProgress
:= False;
6649 gVotePassed
:= True;
6650 gVoteCmdTimer
:= gTime
+ 5000;
6653 if NetClients
<> nil then
6654 for I
:= Low(NetClients
) to High(NetClients
) do
6655 if NetClients
[i
].Used
then
6656 NetClients
[i
].Voted
:= False;
6661 procedure g_Game_LoadMapList(FileName
: string);
6669 if not FileExists(FileName
) then Exit
;
6671 AssignFile(ListFile
, FileName
);
6673 while not EOF(ListFile
) do
6675 ReadLn(ListFile
, s
);
6678 if s
= '' then Continue
;
6680 SetLength(MapList
, Length(MapList
)+1);
6681 MapList
[High(MapList
)] := s
;
6683 CloseFile(ListFile
);
6686 procedure g_Game_SetDebugMode();
6689 // Читы (даже в своей игре):
6693 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6697 if Length(LoadingStat
.Msgs
) = 0 then
6703 begin // Переходим на следующую строку или скроллируем:
6704 if NextMsg
= Length(Msgs
) then
6706 for i
:= 0 to High(Msgs
)-1 do
6707 Msgs
[i
] := Msgs
[i
+1];
6715 Msgs
[NextMsg
-1] := Text;
6719 PBarWasHere
:= false;
6722 {$IFDEF ENABLE_MENU}
6723 g_ActiveWindow
:= nil;
6726 ProcessLoading(true);
6729 procedure g_Game_StepLoading(Value
: Integer = -1);
6741 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6744 ProcessLoading(False);
6749 procedure g_Game_ClearLoading();
6758 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6759 if len
< 1 then len
:= 1;
6760 SetLength(Msgs
, len
);
6761 for len
:= Low(Msgs
) to High(Msgs
) do
6764 PBarWasHere
:= false;
6768 procedure Parse_Params(var pars
: TParamStrValues
);
6775 while i
<= ParamCount
do
6778 if (Length(s
) > 1) and (s
[1] = '-') then
6780 if (Length(s
) > 2) and (s
[2] = '-') then
6781 begin // Одиночный параметр
6782 SetLength(pars
, Length(pars
) + 1);
6783 with pars
[High(pars
)] do
6785 Name
:= LowerCase(s
);
6790 if (i
< ParamCount
) then
6791 begin // Параметр со значением
6793 SetLength(pars
, Length(pars
) + 1);
6794 with pars
[High(pars
)] do
6796 Name
:= LowerCase(s
);
6797 Value
:= LowerCase(ParamStr(i
));
6806 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6811 for i
:= 0 to High(pars
) do
6812 if pars
[i
].Name
= aName
then
6814 Result
:= pars
[i
].Value
;
6819 procedure g_Game_Process_Params();
6821 pars
: TParamStrValues
;
6824 LimT
, LimS
: Integer;
6835 s
:= Find_Param_Value(pars
, '--debug');
6838 g_Game_SetDebugMode();
6839 s
:= Find_Param_Value(pars
, '--netdump');
6844 // Connect when game loads
6845 ip
:= Find_Param_Value(pars
, '-connect');
6849 s
:= Find_Param_Value(pars
, '-port');
6850 if (s
= '') or not TryStrToInt(s
, Port
) then
6853 s
:= Find_Param_Value(pars
, '-pw');
6855 g_Game_StartClient(ip
, Port
, s
);
6859 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6862 gDefaultMegawadStart
:= s
;
6865 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6866 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6868 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6871 // Start map when game loads:
6872 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6873 if isWadPath(map
) then
6876 s
:= Find_Param_Value(pars
, '-gm');
6877 GMode
:= g_Game_TextToMode(s
);
6878 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6879 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6882 s
:= Find_Param_Value(pars
, '-limt');
6883 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6889 s
:= Find_Param_Value(pars
, '-lims');
6890 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6896 s
:= Find_Param_Value(pars
, '-lives');
6897 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6903 s
:= Find_Param_Value(pars
, '-opt');
6907 Opt
:= StrToIntDef(s
, 0);
6910 s
:= Find_Param_Value(pars
, '--close');
6914 // Override map to test:
6915 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6918 if e_IsValidResourceName(s
) then
6919 e_FindResource(AllMapDirs
, s
);
6920 gTestMap
:= ExpandFileName(s
);
6923 // Delete test map after play:
6924 s
:= Find_Param_Value(pars
, '--testdelete');
6927 //gMapToDelete := MapsDir + map;
6928 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6932 // Delete temporary WAD after play:
6933 s
:= Find_Param_Value(pars
, '--tempdelete');
6934 if (s
<> '') and (gTestMap
<> '') then
6936 gMapToDelete
:= gTestMap
;
6937 gTempDelete
:= True;
6940 // Number of players:
6941 s
:= Find_Param_Value(pars
, '-pl');
6943 n
:= DEFAULT_PLAYERS
6945 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6948 s
:= Find_Param_Value(pars
, '-port');
6949 if (s
= '') or not TryStrToInt(s
, Port
) then
6950 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6952 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6955 // Execute script when game loads:
6956 s
:= Find_Param_Value(pars
, '-exec');
6959 // if not isWadPath(s) then
6960 // s := GameDir + '/' + s;
6965 if IOResult
<> 0 then
6967 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6968 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6972 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6973 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6978 if IOResult
<> 0 then
6980 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6981 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6985 if Pos('#', s
) <> 1 then // script comment
6986 g_Console_Process(s
, True);
6997 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6998 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6999 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7000 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7002 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7003 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7004 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7005 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7008 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7009 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7012 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7013 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7015 {$IFDEF ENABLE_HOLMES}
7016 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7019 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7021 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7022 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7024 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7025 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7027 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
7028 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
7029 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
7030 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
7031 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7032 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7033 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7034 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7035 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');