1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
24 SysUtils
, Classes
, MAPDEF
,
25 g_base
, g_basic
, g_player
, g_res_downloader
,
26 g_sound
, utils
, md5
, mempool
, xprofiler
,
31 TGameSettings
= record
38 ItemRespawnTime
: Word;
49 TDelayedEvent
= record
58 Sound
: TPlayableSound
;
59 Tags
: Array of String;
63 TPlayerSettings
= record
68 // ones below are sent only to the server
70 WeaponPreferences
: Array[WP_FIRST
..WP_LAST
+1] of Byte;
87 function g_Game_IsNet(): Boolean;
88 function g_Game_IsServer(): Boolean;
89 function g_Game_IsClient(): Boolean;
90 procedure g_Game_Init();
91 procedure g_Game_Free (freeTextures
: Boolean=true);
92 procedure g_Game_LoadData();
93 procedure g_Game_FreeData();
94 procedure g_Game_Update();
95 procedure g_Game_PreUpdate();
96 procedure g_Game_Quit();
97 function g_Game_ModeToText(Mode
: Byte): string;
98 function g_Game_TextToMode(Mode
: string): Byte;
99 procedure g_Game_ExecuteEvent(Name
: String);
100 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
101 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
102 procedure g_Game_RemovePlayer();
103 procedure g_Game_Spectate();
104 procedure g_Game_SpectateCenterView();
105 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
106 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
107 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
108 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
109 procedure g_Game_Restart();
110 procedure g_Game_RestartLevel();
111 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
112 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
113 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
114 procedure g_Game_ChangeMap(const MapPath
: String);
115 procedure g_Game_ExitLevel(const Map
: AnsiString);
116 function g_Game_GetFirstMap(WAD
: String): String;
117 function g_Game_GetNextMap(): String;
118 procedure g_Game_NextLevel();
119 procedure g_Game_Pause(Enable
: Boolean);
120 procedure g_Game_HolmesPause(Enable
: Boolean);
121 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
122 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
123 procedure g_Game_Message(Msg
: String; Time
: Word);
124 procedure g_Game_LoadMapList(FileName
: String);
125 procedure g_Game_PauseAllSounds(Enable
: Boolean);
126 procedure g_Game_StopAllSounds(all
: Boolean);
127 procedure g_Game_UpdateTriggerSounds();
128 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
129 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
130 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
131 procedure g_Game_Announce_KillCombo(Param
: Integer);
132 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
133 procedure g_Game_StartVote(Command
, Initiator
: string);
134 procedure g_Game_CheckVote
;
135 {$IFDEF ENABLE_RENDER}
136 procedure g_TakeScreenShot(Filename
: string = '');
138 procedure g_FatalError(Text: String);
139 procedure g_SimpleError(Text: String);
140 function g_Game_IsTestMap(): Boolean;
141 procedure g_Game_DeleteTestMap();
142 procedure GameCVars(P
: SSArray
);
143 procedure PlayerSettingsCVars(P
: SSArray
);
144 procedure SystemCommands(P
: SSArray
);
145 procedure GameCommands(P
: SSArray
);
146 procedure GameCheats(P
: SSArray
);
147 procedure DebugCommands(P
: SSArray
);
148 procedure g_Game_Process_Params
;
149 procedure g_Game_SetDebugMode();
151 function IsActivePlayer(p
: TPlayer
): Boolean;
152 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
153 procedure SortGameStat(var stat
: TPlayerStatArray
);
157 procedure g_Game_InGameMenu(Show
: Boolean);
159 {$IFDEF ENABLE_SYSTEM}
160 procedure CharPress (C
: AnsiChar);
163 procedure KeyPress (K
: Word);
165 { procedure SetWinPause(Enable: Boolean); }
186 EXIT_ENDLEVELSINGLE
= 4;
187 EXIT_ENDLEVELCUSTOM
= 5;
189 GAME_OPTION_RESERVED
= 1;
190 GAME_OPTION_TEAMDAMAGE
= 2;
191 GAME_OPTION_ALLOWEXIT
= 4;
192 GAME_OPTION_WEAPONSTAY
= 8;
193 GAME_OPTION_MONSTERS
= 16;
194 GAME_OPTION_BOTVSPLAYER
= 32;
195 GAME_OPTION_BOTVSMONSTER
= 64;
196 GAME_OPTION_DMKEYS
= 128;
197 GAME_OPTION_TEAMHITTRACE
= 256;
198 GAME_OPTION_TEAMHITPROJECTILE
= 512;
199 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
200 GAME_OPTION_ALLOWDROPFLAG
= 2048;
201 GAME_OPTION_THROWFLAG
= 4096;
206 STATE_INTERCUSTOM
= 3;
207 STATE_INTERSINGLE
= 4;
213 LMS_RESPAWN_NONE
= 0;
214 LMS_RESPAWN_WARMUP
= 1;
215 LMS_RESPAWN_FINAL
= 2;
232 CONFIG_FILENAME
= 'Doom2DF.cfg';
234 TEST_MAP_NAME
= '$$$_TEST_$$$';
236 STD_PLAYER_MODEL
= 'Doomer';
244 STATFILE_VERSION
= $03;
247 gGameSettings
: TGameSettings
;
248 gPlayer1Settings
: TPlayerSettings
;
249 gPlayer2Settings
: TPlayerSettings
;
251 gPlayerScreenSize
: TDFPoint
;
252 gPlayer1
: TPlayer
= nil;
253 gPlayer2
: TPlayer
= nil;
255 gLerpFactor
: Single = 1.0;
256 gSwitchGameMode
: Byte = GM_DM
;
257 gHearPoint1
, gHearPoint2
: THearPoint
;
258 gMaxDist
: Integer = 1; // for sound
259 gSoundEffectsDF
: Boolean = False;
260 gSoundTriggerTime
: Word = 0;
261 gAnnouncer
: Integer = ANNOUNCE_NONE
;
262 goodsnd
: array[0..3] of TPlayableSound
;
263 killsnd
: array[0..3] of TPlayableSound
;
264 hahasnd
: array[0..2] of TPlayableSound
;
265 sound_get_flag
: array[0..1] of TPlayableSound
;
266 sound_lost_flag
: array[0..1] of TPlayableSound
;
267 sound_ret_flag
: array[0..1] of TPlayableSound
;
268 sound_cap_flag
: array[0..1] of TPlayableSound
;
269 gBodyKillEvent
: Integer = -1;
270 gDefInterTime
: ShortInt = -1;
271 gInterEndTime
: LongWord = 0;
272 gInterTime
: LongWord = 0;
273 gServInterTime
: Byte = 0;
274 gGameStartTime
: LongWord = 0;
275 gTotalMonsters
: Integer = 0;
276 gPauseMain
: Boolean = false;
277 gPauseHolmes
: Boolean = false;
278 gShowTime
: Boolean = False;
279 gShowFPS
: Boolean = False;
280 gShowScore
: Boolean = True;
281 gShowStat
: Boolean = True;
282 gShowPIDs
: Boolean = False;
283 gShowKillMsg
: Boolean = True;
284 gShowLives
: Boolean = True;
285 gShowPing
: Boolean = False;
286 gShowMap
: Boolean = False;
288 gState
: Byte = STATE_NONE
;
290 sWidth
, sHeight
: Word;
291 gSpectMode
: Byte = SPECT_NONE
;
292 gSpectHUD
: Boolean = True;
293 gSpectKeyPress
: Boolean = False;
294 gSpectX
: Integer = 0;
295 gSpectY
: Integer = 0;
296 gSpectStep
: Byte = 8;
297 gSpectViewTwo
: Boolean = False;
298 gSpectPID1
: Integer = -1;
299 gSpectPID2
: Integer = -1;
300 gSpectAuto
: Boolean = False;
301 gSpectAutoNext
: LongWord;
302 gSpectAutoStepX
: Integer;
303 gSpectAutoStepY
: Integer;
304 gMusic
: TMusic
= nil;
305 gLoadGameMode
: Boolean;
306 gCheats
: Boolean = False;
307 gMapOnce
: Boolean = False;
308 gMapToDelete
: String;
309 gTempDelete
: Boolean = False;
310 gLastMap
: Boolean = False;
313 gResolutionChange
: Boolean = False;
314 gRC_Width
, gRC_Height
: Integer;
315 gRC_FullScreen
, gRC_Maximized
: Boolean;
316 gLanguageChange
: Boolean = False;
317 gDebugMode
: Boolean = False;
318 g_debug_Sounds
: Boolean = False;
319 g_debug_Frames
: Boolean = False;
320 g_debug_WinMsgs
: Boolean = False;
321 g_debug_MonsterOff
: Boolean = False;
322 g_debug_BotAIOff
: Byte = 0;
323 g_debug_HealthBar
: Boolean = False;
324 g_Debug_Player
: Boolean = False;
325 gCoopMonstersKilled
: Word = 0;
326 gCoopSecretsFound
: Word = 0;
327 gCoopTotalMonstersKilled
: Word = 0;
328 gCoopTotalSecretsFound
: Word = 0;
329 gCoopTotalMonsters
: Word = 0;
330 gCoopTotalSecrets
: Word = 0;
331 gStatsOff
: Boolean = False;
332 gStatsPressed
: Boolean = False;
333 gExitByTrigger
: Boolean = False;
334 gNextMap
: String = '';
335 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
336 gLMSRespawnTime
: Cardinal = 0;
337 gLMSSoftSpawn
: Boolean = False;
338 gMissionFailed
: Boolean = False;
339 gVoteInProgress
: Boolean = False;
340 gVotePassed
: Boolean = False;
341 gVoteCommand
: string = '';
342 gVoteTimer
: Cardinal = 0;
343 gVoteCmdTimer
: Cardinal = 0;
344 gVoteCount
: Integer = 0;
345 gVoteTimeout
: Cardinal = 30;
346 gVoted
: Boolean = False;
347 gVotesEnabled
: Boolean = True;
348 gEvents
: Array of TGameEvent
;
349 gDelayedEvents
: Array of TDelayedEvent
;
350 gUseChatSounds
: Boolean = True;
351 gChatSounds
: Array of TChatSound
;
352 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
353 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
354 gInterReadyCount
: Integer = 0;
355 gMaxBots
: Integer = 127;
357 g_dbg_ignore_bounds
: Boolean = false;
358 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
359 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
361 // move button values:
362 // bits 0-1: l/r state:
363 // 0: neither left, nor right pressed
366 // bits 4-5: l/r state when strafe was pressed
367 P1MoveButton
: Byte = 0;
368 P2MoveButton
: Byte = 0;
370 g_profile_frame_update
: Boolean = false;
371 g_profile_frame_draw
: Boolean = false;
372 g_profile_collision
: Boolean = false;
373 g_profile_los
: Boolean = false;
374 g_profile_history_size
: Integer = 1000;
376 g_rlayer_back
: Boolean = true;
377 g_rlayer_step
: Boolean = true;
378 g_rlayer_wall
: Boolean = true;
379 g_rlayer_door
: Boolean = true;
380 g_rlayer_acid1
: Boolean = true;
381 g_rlayer_acid2
: Boolean = true;
382 g_rlayer_water
: Boolean = true;
383 g_rlayer_fore
: Boolean = true;
385 wNeedTimeReset
: Boolean = false;
387 procedure g_ResetDynlights ();
388 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
389 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
391 function conIsCheatsEnabled (): Boolean; inline;
392 function gPause (): Boolean; inline;
394 type (* private state *)
395 TEndCustomGameStat
= record
396 PlayerStat
: TPlayerStatArray
;
400 Map
, MapName
: String;
403 TEndSingleGameStat
= record
404 PlayerStat
: Array [0..1] of record
410 TotalSecrets
: Integer;
414 x
, y
, radius
: Integer;
417 exploRadius
: Integer;
420 var (* private state *)
421 CustomStat
: TEndCustomGameStat
;
422 StatShotDone
: Boolean;
423 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
424 SingleStat
: TEndSingleGameStat
;
427 EndingGameCounter
: Byte;
429 g_playerLight
: Boolean;
430 g_dynLights
: array of TDynLight
= nil;
431 g_dynLightCount
: Integer = 0;
432 EndPicPath
: AnsiString; // full path, used by render
437 {$IFDEF ENABLE_HOLMES}
449 {$IFDEF ENABLE_SHELLS}
452 {$IFDEF ENABLE_CORPSES}
455 {$IFDEF ENABLE_RENDER}
458 {$IFDEF ENABLE_SYSTEM}
462 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
463 g_playermodel
, g_options
, Math
,
464 g_triggers
, g_monsters
, e_sound
, CONFIG
,
465 g_language
, g_net
, g_phys
,
466 ENet
, e_msg
, g_netmsg
, g_netmaster
,
470 charbuff
: packed array [0..15] of AnsiChar = (
471 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
474 function Translit (const S
: AnsiString): AnsiString;
479 for i
:= 1 to Length(Result
) do
482 #
$C9: Result
[i
] := 'Q';
483 #
$D6: Result
[i
] := 'W';
484 #
$D3: Result
[i
] := 'E';
485 #
$CA: Result
[i
] := 'R';
486 #
$C5: Result
[i
] := 'T';
487 #
$CD: Result
[i
] := 'Y';
488 #
$C3: Result
[i
] := 'U';
489 #
$D8: Result
[i
] := 'I';
490 #
$D9: Result
[i
] := 'O';
491 #
$C7: Result
[i
] := 'P';
492 #
$D5: Result
[i
] := '['; //Chr(219);
493 #
$DA: Result
[i
] := ']'; //Chr(221);
494 #
$D4: Result
[i
] := 'A';
495 #
$DB: Result
[i
] := 'S';
496 #
$C2: Result
[i
] := 'D';
497 #
$C0: Result
[i
] := 'F';
498 #
$CF: Result
[i
] := 'G';
499 #
$D0: Result
[i
] := 'H';
500 #
$CE: Result
[i
] := 'J';
501 #
$CB: Result
[i
] := 'K';
502 #
$C4: Result
[i
] := 'L';
503 #
$C6: Result
[i
] := ';'; //Chr(186);
504 #
$DD: Result
[i
] := #39; //Chr(222);
505 #
$DF: Result
[i
] := 'Z';
506 #
$D7: Result
[i
] := 'X';
507 #
$D1: Result
[i
] := 'C';
508 #
$CC: Result
[i
] := 'V';
509 #
$C8: Result
[i
] := 'B';
510 #
$D2: Result
[i
] := 'N';
511 #
$DC: Result
[i
] := 'M';
512 #
$C1: Result
[i
] := ','; //Chr(188);
513 #
$DE: Result
[i
] := '.'; //Chr(190);
519 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
524 ls2
:= Translit(CheatRus
[ct
]);
525 if length(ls1
) = 0 then ls1
:= '~';
526 if length(ls2
) = 0 then ls2
:= '~';
528 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
529 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
530 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
531 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
533 if ct = I_GAME_CHEAT_JETPACK then
535 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
536 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
537 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
538 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
539 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
540 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
556 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
557 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
558 or g_Game_IsNet then Exit;
560 if not gGameOn
then exit
;
561 if not conIsCheatsEnabled
then exit
;
563 s
:= 'SOUND_GAME_RADIO';
566 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
568 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
569 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
573 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
575 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
576 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
580 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
582 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
583 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
587 if CheckCheat(I_GAME_CHEAT_DEATH
) then
589 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
590 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
591 s
:= 'SOUND_MONSTER_HAHA';
595 if CheckCheat(I_GAME_CHEAT_DOORS
) then
597 g_Triggers_OpenAll();
601 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
603 if gTriggers
<> nil then
604 for a
:= 0 to High(gTriggers
) do
605 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
607 gExitByTrigger
:= True;
608 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
609 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
615 s2
:= Copy(charbuff
, 15, 2);
616 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
618 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
626 if CheckCheat(I_GAME_CHEAT_FLY
) then
632 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
634 VEL_JUMP
:= 30-VEL_JUMP
;
638 if CheckCheat(I_GAME_CHEAT_SPEED
) then
640 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
644 if CheckCheat(I_GAME_CHEAT_SUIT
) then
646 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
647 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
651 if CheckCheat(I_GAME_CHEAT_AIR
) then
653 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
654 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
658 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
660 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
661 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
665 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
667 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
668 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
672 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
674 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
675 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
679 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
681 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
682 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
686 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
688 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
689 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
692 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
694 gAimLine
:= not gAimLine
;
697 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
699 gShowMap
:= not gShowMap
;
710 procedure KeyPress (K
: Word);
711 var Msg
: g_gui
.TMessage
;
716 if (g_ActiveWindow
<> nil) then
718 Msg
.Msg
:= WM_KEYDOWN
;
719 Msg
.WParam
:= VK_ESCAPE
;
720 g_ActiveWindow
.OnMessage(Msg
);
721 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
723 else if (gState
<> STATE_FOLD
) then
725 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
727 g_Game_InGameMenu(True);
729 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
731 if (gState
<> STATE_MENU
) then
733 if (NetMode
<> NET_NONE
) then
735 g_Game_StopAllSounds(True);
737 gState
:= STATE_MENU
;
741 g_GUI_ShowWindow('MainMenu');
742 g_Sound_PlayEx('MENU_OPEN');
747 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
748 begin // <F2> .. <F6> � <F12>
749 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
751 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
752 if (not g_Game_IsNet
) then g_Game_Pause(True);
754 IK_F2
: g_Menu_Show_SaveMenu();
755 IK_F3
: g_Menu_Show_LoadMenu();
756 IK_F4
: g_Menu_Show_GameSetGame();
757 IK_F5
: g_Menu_Show_OptionsVideo();
758 IK_F6
: g_Menu_Show_OptionsSound();
759 IK_F7
: g_Menu_Show_EndGameMenu();
760 IK_F10
: g_Menu_Show_QuitGameMenu();
767 gJustChatted
:= False;
768 if gConsoleShow
or gChatShow
then
770 g_Console_Control(K
);
772 else if (g_ActiveWindow
<> nil) then
774 Msg
.Msg
:= WM_KEYDOWN
;
776 g_ActiveWindow
.OnMessage(Msg
);
778 else if (gState
= STATE_MENU
) then
780 g_GUI_ShowWindow('MainMenu');
781 g_Sound_PlayEx('MENU_OPEN');
787 procedure KeyPress (K
: Word);
789 gJustChatted
:= False;
790 if gConsoleShow
or gChatShow
then
792 g_Console_Control(K
);
797 {$IFDEF ENABLE_SYSTEM}
798 procedure CharPress (C
: AnsiChar);
800 var Msg
: g_gui
.TMessage
;
804 if gConsoleShow
or gChatShow
then
809 else if g_ActiveWindow
<> nil then
812 Msg
.WParam
:= Ord(C
);
813 g_ActiveWindow
.OnMessage(Msg
);
820 charbuff
[a
] := charbuff
[a
+ 1];
822 charbuff
[15] := upcase1251(C
);
829 // ////////////////////////////////////////////////////////////////////////// //
830 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
832 procedure g_ResetDynlights ();
836 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
838 for idx
:= 0 to g_dynLightCount
-1 do
840 if g_dynLights
[idx
].exploCount
= -666 then
847 Inc(g_dynLights
[idx
].exploCount
);
848 if (g_dynLights
[idx
].exploCount
< 10) then
850 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
851 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
852 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
853 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
858 g_dynLightCount
:= lnum
;
861 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
863 if not gwin_has_stencil
then exit
;
864 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
865 g_dynLights
[g_dynLightCount
].x
:= x
;
866 g_dynLights
[g_dynLightCount
].y
:= y
;
867 g_dynLights
[g_dynLightCount
].radius
:= radius
;
868 g_dynLights
[g_dynLightCount
].r
:= r
;
869 g_dynLights
[g_dynLightCount
].g
:= g
;
870 g_dynLights
[g_dynLightCount
].b
:= b
;
871 g_dynLights
[g_dynLightCount
].a
:= a
;
872 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
873 Inc(g_dynLightCount
);
876 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
878 if not gwin_has_stencil
then exit
;
879 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
880 g_dynLights
[g_dynLightCount
].x
:= x
;
881 g_dynLights
[g_dynLightCount
].y
:= y
;
882 g_dynLights
[g_dynLightCount
].radius
:= 0;
883 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
884 g_dynLights
[g_dynLightCount
].r
:= r
;
885 g_dynLights
[g_dynLightCount
].g
:= g
;
886 g_dynLights
[g_dynLightCount
].b
:= b
;
887 g_dynLights
[g_dynLightCount
].a
:= 0;
888 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
889 Inc(g_dynLightCount
);
892 // ////////////////////////////////////////////////////////////////////////// //
893 function conIsCheatsEnabled (): Boolean; inline;
896 if g_Game_IsNet
then exit
;
897 if not gDebugMode
then
899 //if not gCheats then exit;
900 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
901 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
906 // ////////////////////////////////////////////////////////////////////////// //
908 TParamStrValue
= record
913 TParamStrValues
= Array of TParamStrValue
;
916 INTER_ACTION_TEXT
= 1;
917 INTER_ACTION_PIC
= 2;
918 INTER_ACTION_MUSIC
= 3;
923 DataLoaded
: Boolean = False;
925 MapList
: SSArray
= nil;
926 MapIndex
: Integer = -1;
927 InterReadyTime
: Integer = -1;
928 StatDate
: string = '';
943 function Compare(a
, b
: TPlayerStat
): Integer;
945 if a
.Spectator
then Result
:= 1
946 else if b
.Spectator
then Result
:= -1
947 else if a
.Frags
< b
.Frags
then Result
:= 1
948 else if a
.Frags
> b
.Frags
then Result
:= -1
949 else if a
.Deaths
< b
.Deaths
then Result
:= -1
950 else if a
.Deaths
> b
.Deaths
then Result
:= 1
951 else if a
.Kills
< b
.Kills
then Result
:= -1
955 procedure SortGameStat(var stat
: TPlayerStatArray
);
960 if stat
= nil then Exit
;
962 for I
:= High(stat
) downto Low(stat
) do
963 for J
:= Low(stat
) to High(stat
) - 1 do
964 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
967 stat
[J
] := stat
[J
+ 1];
972 // saves a shitty CSV containing the game stats passed to it
973 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
976 dir
, fname
, map
, mode
, etime
: String;
980 dir
:= e_GetWriteableDir(StatsDirs
);
981 // stats are placed in stats/yy/mm/dd/*.csv
982 fname
:= e_CatPath(dir
, Path
);
983 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
984 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
985 AssignFile(s
, fname
);
987 SetTextCodePage(s
, CP_UTF8
);
989 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
990 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
991 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
992 mode
:= g_Game_ModeToText(Stat
.GameMode
);
993 etime
:= Format('%d:%.2d:%.2d', [
994 Stat
.GameTime
div 1000 div 3600,
995 (Stat
.GameTime
div 1000 div 60) mod 60,
996 Stat
.GameTime
div 1000 mod 60
998 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
999 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
1005 gGameSettings
.TimeLimit
,
1006 gGameSettings
.ScoreLimit
,
1007 gGameSettings
.Options
,
1009 Length(Stat
.PlayerStat
)
1011 // line 2: game specific shit
1012 // if it's a team game: red score, blue score
1013 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1014 // otherwise nothing
1015 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1017 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
1018 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1020 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1021 // lines 3-...: team, player name, frags, deaths
1022 WriteLn(s
, 'team,name,frags,deaths');
1023 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1024 with Stat
.PlayerStat
[I
] do
1025 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1027 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1030 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1035 procedure ClearDebugCvars();
1037 g_debug_Sounds
:= False;
1038 g_debug_Frames
:= False;
1039 g_debug_WinMsgs
:= False;
1040 g_debug_MonsterOff
:= False;
1041 g_debug_BotAIOff
:= 0;
1042 g_debug_HealthBar
:= False;
1043 g_Debug_Player
:= False;
1046 function g_Game_ModeToText(Mode
: Byte): string;
1050 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1051 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1052 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1053 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1054 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1058 function g_Game_TextToMode(Mode
: string): Byte;
1061 Mode
:= UpperCase(Mode
);
1062 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1067 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1072 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1077 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1082 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1084 Result
:= GM_SINGLE
;
1089 function g_Game_IsNet(): Boolean;
1091 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1094 function g_Game_IsServer(): Boolean;
1096 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1099 function g_Game_IsClient(): Boolean;
1101 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1104 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1111 Result
.name
:= ExtractFileName(WAD
);
1112 Result
.description
:= '';
1113 Result
.author
:= '';
1115 w
:= TWADFile
.Create();
1118 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1124 cfg
:= TConfig
.CreateMem(p
, len
);
1125 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1126 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1127 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1128 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1134 procedure g_Game_FreeWAD
;
1137 g_Sound_Delete('MUSIC_endmus');
1138 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1139 gGameSettings
.WAD
:= '';
1142 procedure g_Game_LoadWAD(WAD
: string);
1151 gGameSettings
.WAD
:= WAD
;
1152 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1155 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1157 w
:= TWADFile
.Create();
1160 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1166 cfg
:= TConfig
.CreateMem(p
, len
);
1169 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1170 if MegaWAD
.endpic
<> '' then
1171 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1173 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1174 if MegaWAD
.endmus
<> '' then
1176 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1177 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1185 {procedure start_trigger(t: string);
1189 function next_trigger(): Boolean;
1193 procedure DisableCheats();
1199 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1200 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1201 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1202 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1204 {$IF DEFINED(D2F_DEBUG)}
1205 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1206 gAimLine
:= g_dbg_aimline_on
;
1210 procedure g_Game_ExecuteEvent(Name
: String);
1216 if gEvents
= nil then
1218 for a
:= 0 to High(gEvents
) do
1219 if gEvents
[a
].Name
= Name
then
1221 if gEvents
[a
].Command
<> '' then
1222 g_Console_Process(gEvents
[a
].Command
, True);
1227 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1232 if gDelayedEvents
<> nil then
1233 for a
:= 0 to High(gDelayedEvents
) do
1234 if not gDelayedEvents
[a
].Pending
then
1241 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1242 n
:= High(gDelayedEvents
);
1244 gDelayedEvents
[n
].Pending
:= True;
1245 gDelayedEvents
[n
].DEType
:= DEType
;
1246 gDelayedEvents
[n
].DENum
:= Num
;
1247 gDelayedEvents
[n
].DEStr
:= Str
;
1248 if DEType
= DE_GLOBEVENT
then
1249 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1251 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1255 procedure EndGame();
1261 if g_Game_IsNet
and g_Game_IsServer
then
1262 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1265 gPauseMain
:= false;
1266 gPauseHolmes
:= false;
1269 g_Game_StopAllSounds(False);
1274 EndingGameCounter
:= 0;
1276 {$IFDEF ENABLE_MENU}
1277 g_ActiveWindow
:= nil;
1280 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1281 gLMSRespawnTime
:= 0;
1284 EXIT_SIMPLE
: // Выход через меню или конец теста
1288 begin // Это был тест
1292 begin // Выход в главное меню
1293 {$IFDEF DISABLE_MENU}
1294 gState
:= STATE_MENU
; // ???
1296 gMusic
.SetByName('MUSIC_MENU');
1298 if gState
<> STATE_SLIST
then
1300 g_GUI_ShowWindow('MainMenu');
1301 gState
:= STATE_MENU
;
1305 // Обновляем список серверов
1306 slReturnPressed
:= True;
1307 if g_Net_Slist_Fetch(slCurrent
) then
1309 if slCurrent
= nil then
1310 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1313 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1314 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1317 g_Game_ExecuteEvent('ongameend');
1321 EXIT_RESTART
: // Начать уровень сначала
1323 if not g_Game_IsClient
then g_Game_Restart();
1326 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1328 // Статистика Своей игры:
1329 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1331 CustomStat
.GameTime
:= gTime
;
1332 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1333 CustomStat
.MapName
:= gMapInfo
.Name
;
1334 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1335 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1336 CustomStat
.TeamStat
:= gTeamStat
;
1338 CustomStat
.PlayerStat
:= nil;
1340 // Статистика игроков:
1341 if gPlayers
<> nil then
1343 for a
:= 0 to High(gPlayers
) do
1344 if gPlayers
[a
] <> nil then
1346 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1347 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1350 Name
:= gPlayers
[a
].Name
;
1351 Frags
:= gPlayers
[a
].Frags
;
1352 Deaths
:= gPlayers
[a
].Death
;
1353 Kills
:= gPlayers
[a
].Kills
;
1354 Team
:= gPlayers
[a
].Team
;
1355 Color
:= gPlayers
[a
].Model
.Color
;
1356 Spectator
:= gPlayers
[a
].FSpectator
;
1360 SortGameStat(CustomStat
.PlayerStat
);
1362 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1365 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1366 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1367 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1368 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1370 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1373 StatShotDone
:= False;
1376 g_Game_ExecuteEvent('onmapend');
1377 if not g_Game_IsClient
then g_Player_ResetReady
;
1378 gInterReadyCount
:= 0;
1380 // Затухающий экран:
1381 EndingGameCounter
:= 255;
1382 gState
:= STATE_FOLD
;
1384 if gDefInterTime
< 0 then
1385 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1387 gInterEndTime
:= gDefInterTime
* 1000;
1390 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1392 // Статистика Одиночной игры:
1393 SingleStat
.GameTime
:= gTime
;
1394 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1395 SingleStat
.TotalSecrets
:= gSecretsCount
;
1396 // Статистика первого игрока:
1397 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1398 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1399 // Статистика второго игрока (если есть):
1400 if SingleStat
.TwoPlayers
then
1402 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1403 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1406 g_Game_ExecuteEvent('onmapend');
1409 if gNextMap
<> '' then
1411 gMusic
.SetByName('MUSIC_INTERMUS');
1413 gState
:= STATE_INTERSINGLE
;
1416 g_Game_ExecuteEvent('oninter');
1418 else // Больше нет карт
1420 // Затухающий экран:
1421 EndingGameCounter
:= 255;
1422 gState
:= STATE_FOLD
;
1427 // Окончание обработано:
1428 if gExit
<> EXIT_QUIT
then
1432 procedure g_Game_Init();
1436 gTempDelete
:= False;
1438 sfsGCDisable(); // temporary disable removing of temporary volumes
1442 gPauseMain
:= false;
1443 gPauseHolmes
:= false;
1446 {e_MouseInfo.Accel := 1.0;}
1450 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1451 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1452 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1453 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1454 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1456 gMusic
:= TMusic
.Create();
1457 gMusic
.SetByName('MUSIC_MENU');
1460 gGameSettings
.WarmupTime
:= 30;
1462 gState
:= STATE_MENU
;
1464 SetLength(gEvents
, 6);
1465 gEvents
[0].Name
:= 'ongamestart';
1466 gEvents
[1].Name
:= 'ongameend';
1467 gEvents
[2].Name
:= 'onmapstart';
1468 gEvents
[3].Name
:= 'onmapend';
1469 gEvents
[4].Name
:= 'oninter';
1470 gEvents
[5].Name
:= 'onwadend';
1472 sfsGCEnable(); // enable releasing unused volumes
1476 procedure g_Game_Free(freeTextures
: Boolean=true);
1478 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1479 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1481 g_Map_Free(freeTextures
);
1484 {$IFDEF ENABLE_GIBS}
1487 {$IFDEF ENALBE_SHELLS}
1490 {$IFDEF ENABLE_CORPSES}
1491 g_Corpses_RemoveAll
;
1494 gGameSettings
.GameType
:= GT_NONE
;
1495 if gGameSettings
.GameMode
= GM_SINGLE
then
1496 gGameSettings
.GameMode
:= GM_DM
;
1497 gSwitchGameMode
:= gGameSettings
.GameMode
;
1500 gExitByTrigger
:= False;
1503 function IsActivePlayer(p
: TPlayer
): Boolean;
1508 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1511 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1517 if gPlayers
= nil then
1521 for a
:= Low(gPlayers
) to High(gPlayers
) do
1522 if IsActivePlayer(gPlayers
[a
]) then
1524 SetLength(ids
, Length(ids
) + 1);
1525 ids
[High(ids
)] := gPlayers
[a
].UID
;
1526 if gPlayers
[a
].UID
= Skip
then
1529 if Length(ids
) = 0 then
1534 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1537 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1543 if gPlayers
= nil then
1547 for a
:= Low(gPlayers
) to High(gPlayers
) do
1548 if IsActivePlayer(gPlayers
[a
]) then
1550 SetLength(ids
, Length(ids
) + 1);
1551 ids
[High(ids
)] := gPlayers
[a
].UID
;
1552 if gPlayers
[a
].UID
= Skip
then
1555 if Length(ids
) = 0 then
1558 Result
:= ids
[Length(ids
) - 1]
1560 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1563 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1569 if gPlayers
= nil then
1573 for a
:= Low(gPlayers
) to High(gPlayers
) do
1574 if IsActivePlayer(gPlayers
[a
]) then
1576 SetLength(ids
, Length(ids
) + 1);
1577 ids
[High(ids
)] := gPlayers
[a
].UID
;
1578 if gPlayers
[a
].UID
= Skip
then
1581 if Length(ids
) = 0 then
1583 if Length(ids
) = 1 then
1588 Result
:= ids
[Random(Length(ids
))];
1590 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1592 Result
:= ids
[Random(Length(ids
))];
1597 function GetRandomSpectMode(Current
: Byte): Byte;
1604 0: Result
:= SPECT_STATS
;
1605 1: Result
:= SPECT_MAPVIEW
;
1606 2: Result
:= SPECT_MAPVIEW
;
1607 3: Result
:= SPECT_PLAYERS
;
1608 4: Result
:= SPECT_PLAYERS
;
1609 5: Result
:= SPECT_PLAYERS
;
1610 6: Result
:= SPECT_PLAYERS
;
1612 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1616 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1622 if (plr
= nil) then exit
;
1623 if (p
= 2) then time
:= 1000 else time
:= 1;
1624 strafeDir
:= MoveButton
shr 4;
1625 MoveButton
:= MoveButton
and $0F;
1627 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1628 MoveButton
:= 1 // Нажата только "Влево"
1629 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1630 MoveButton
:= 2 // Нажата только "Вправо"
1631 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1632 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1634 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1635 if MoveButton
= 1 then
1636 plr
.PressKey(KEY_LEFT
, time
)
1637 else if MoveButton
= 2 then
1638 plr
.PressKey(KEY_RIGHT
, time
);
1640 // if we have "strafe" key, turn off old strafe mechanics
1641 if gPlayerAction
[p
, ACTION_STRAFE
] then
1643 // new strafe mechanics
1644 if (strafeDir
= 0) then
1645 strafeDir
:= MoveButton
; // start strafing
1646 // now set direction according to strafe (reversed)
1647 if (strafeDir
= 2) then
1648 plr
.SetDirection(TDirection
.D_LEFT
)
1649 else if (strafeDir
= 1) then
1650 plr
.SetDirection(TDirection
.D_RIGHT
)
1654 strafeDir
:= 0; // not strafing anymore
1655 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1656 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1657 plr
.SetDirection(TDirection
.D_LEFT
)
1658 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1659 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1660 plr
.SetDirection(TDirection
.D_RIGHT
)
1661 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1662 else if MoveButton
<> 0 then
1663 plr
.SetDirection(TDirection(MoveButton
-1))
1666 // fix movebutton state
1667 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1669 // Остальные клавиши:
1670 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1671 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1672 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1673 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1674 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1676 for i
:= WP_FACT
to WP_LACT
do
1678 if gWeaponAction
[p
, i
] then
1680 plr
.ProcessWeaponAction(i
);
1681 gWeaponAction
[p
, i
] := False
1685 for i
:= WP_FIRST
to WP_LAST
do
1687 if gSelectWeapon
[p
, i
] then
1689 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1690 gSelectWeapon
[p
, i
] := False
1694 {$IFDEF ENABLE_MENU}
1695 // HACK: add dynlight here
1696 if gwin_k8_enable_light_experiments
then
1698 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1700 g_playerLight
:= true;
1702 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1704 g_playerLight
:= false;
1708 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1712 // HACK: don't have a "key was pressed" function
1713 procedure InterReady();
1715 if InterReadyTime
> gTime
then Exit
;
1716 InterReadyTime
:= gTime
+ 3000;
1717 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1720 procedure g_Game_PreUpdate();
1722 // these are in separate PreUpdate functions because they can interact during Update()
1723 // and are synced over the net
1724 // we don't care that much about corpses and gibs
1725 g_Player_PreUpdate();
1726 g_Monsters_PreUpdate();
1727 g_Items_PreUpdate();
1728 g_Weapon_PreUpdate();
1731 procedure g_Game_SetupHearPoints
;
1732 var p1
, p2
: TPlayer
; a
, b
: Integer;
1736 gHearPoint1
.Active
:= false;
1737 gHearPoint2
.Active
:= false;
1738 if gSpectMode
= SPECT_MAPVIEW
then
1740 // TODO something better (render dependency)
1741 gHearPoint1
.Active
:= true;
1742 gHearPoint1
.Coords
.X
:= gSpectX
+ gScreenWidth
div 2;
1743 gHearPoint1
.Coords
.Y
:= gSpectY
+ gScreenHeight
div 2;
1745 else if gSpectMode
= SPECT_PLAYERS
then
1747 p1
:= g_Player_Get(gSpectPID1
);
1748 if gSpectViewTwo
then
1749 p2
:= g_Player_Get(gSpectPID2
);
1751 else if gSpectMode
= SPECT_NONE
then
1758 gHearPoint1
.Active
:= true;
1759 gHearPoint1
.Coords
.X
:= p1
.obj
.x
+ p1
.obj
.rect
.width
div 2;
1760 gHearPoint1
.Coords
.Y
:= p1
.obj
.y
+ p1
.obj
.rect
.height
div 2;
1762 if (p2
<> nil) and (p1
<> p2
) then
1764 gHearPoint2
.Active
:= true;
1765 gHearPoint2
.Coords
.X
:= p2
.obj
.x
+ p2
.obj
.rect
.width
div 2;
1766 gHearPoint2
.Coords
.Y
:= p2
.obj
.y
+ p2
.obj
.rect
.height
div 2;
1768 // TODO something better (render dependency)
1769 if (p1
<> nil) and (p2
<> nil) then
1771 gPlayerScreenSize
.X
:= gScreenWidth
- 196;
1772 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
1776 gPlayerScreenSize
.X
:= gScreenWidth
- 196;
1777 gPlayerScreenSize
.Y
:= gScreenHeight
;
1780 if gMapInfo
.Height
> gPlayerScreenSize
.Y
then a
:= gMapInfo
.Height
- gPlayerScreenSize
.Y
else a
:= gMapInfo
.Height
;
1781 if gMapInfo
.Width
> gPlayerScreenSize
.X
then b
:= gMapInfo
.Width
- gPlayerScreenSize
.X
else b
:= gMapInfo
.Width
;
1782 gMaxDist
:= Trunc(Hypot(a
, b
));
1785 procedure g_Game_Update();
1787 {$IFDEF ENABLE_MENU}
1788 Msg
: g_gui
.TMessage
;
1795 function sendMonsPos (mon
: TMonster
): Boolean;
1797 result
:= false; // don't stop
1798 // this will also reset "need-send" flag
1799 if mon
.gncNeedSend
then
1801 MH_SEND_MonsterPos(mon
.UID
);
1803 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1805 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1807 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1809 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1813 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1815 result
:= false; // don't stop
1816 // this will also reset "need-send" flag
1817 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1820 function sendItemPos (it
: PItem
): Boolean;
1822 result
:= false; // don't stop
1825 MH_SEND_ItemPos(it
.myId
);
1826 it
.needSend
:= False;
1831 reliableUpdate
: Boolean;
1836 // Пора выключать игру:
1837 if gExit
= EXIT_QUIT
then
1839 // Игра закончилась - обрабатываем:
1843 if gExit
= EXIT_QUIT
then
1847 // Читаем клавиатуру и джойстик, если окно активно
1848 // no need to, as we'll do it in event handler
1850 // Обновляем консоль (движение и сообщения):
1853 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1855 gExit
:= EXIT_SIMPLE
;
1860 // process master server communications
1861 g_Net_Slist_Pulse();
1864 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1865 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1866 STATE_INTERTEXT
, // Текст между уровнями
1867 STATE_INTERPIC
: // Картинка между уровнями
1869 if g_Game_IsNet
and g_Game_IsServer
then
1871 gInterTime
:= gInterTime
+ GAME_TICK
;
1872 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1873 if a
<> gServInterTime
then
1875 gServInterTime
:= a
;
1876 MH_SEND_TimeSync(gServInterTime
);
1880 if (not g_Game_IsClient
) and
1884 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1885 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1886 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1887 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1889 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1890 {$IFDEF ENABLE_MENU}
1891 and (g_ActiveWindow
= nil)
1894 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1897 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1898 g_Game_StopAllSounds(True);
1900 if gMapOnce
then // Это был тест
1901 gExit
:= EXIT_SIMPLE
1903 if gNextMap
<> '' then // Переходим на следующую карту
1904 g_Game_ChangeMap(gNextMap
)
1905 else // Следующей карты нет
1907 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1909 // Выход в главное меню:
1911 {$IFDEF ENABLE_MENU}
1912 g_GUI_ShowWindow('MainMenu');
1913 gMusic
.SetByName('MUSIC_MENU');
1916 gState
:= STATE_MENU
;
1919 // Финальная картинка:
1920 g_Game_ExecuteEvent('onwadend');
1922 if not gMusic
.SetByName('MUSIC_endmus') then
1923 gMusic
.SetByName('MUSIC_STDENDMUS');
1925 gState
:= STATE_ENDPIC
;
1927 g_Game_ExecuteEvent('ongameend');
1932 else if g_Game_IsClient
and
1935 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1936 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1937 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1938 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1940 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1941 {$IFDEF ENABLE_MENU}
1942 and (g_ActiveWindow
= nil)
1951 if gState
= STATE_INTERTEXT
then
1952 if InterText
.counter
> 0 then
1953 InterText
.counter
:= InterText
.counter
- 1;
1956 STATE_FOLD
: // Затухание экрана
1958 if EndingGameCounter
= 0 then
1960 // Закончился уровень в Своей игре:
1961 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1963 gState
:= STATE_INTERCUSTOM
;
1964 InterReadyTime
:= -1;
1965 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1967 g_Game_ExecuteEvent('onwadend');
1968 if not gMusic
.SetByName('MUSIC_endmus') then
1969 gMusic
.SetByName('MUSIC_STDENDMUS');
1972 gMusic
.SetByName('MUSIC_ROUNDMUS');
1976 else // Закончилась последняя карта в Одиночной игре
1978 gMusic
.SetByName('MUSIC_INTERMUS');
1980 gState
:= STATE_INTERSINGLE
;
1983 g_Game_ExecuteEvent('oninter');
1986 DecMin(EndingGameCounter
, 6, 0);
1989 STATE_ENDPIC
: // Картинка окончания мегаВада
1991 if gMapOnce
then // Это был тест
1993 gExit
:= EXIT_SIMPLE
;
1999 g_Serverlist_Control(slCurrent
, slTable
);
2002 // Статистика по Tab:
2005 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
2009 if g_Console_Action(ACTION_SCORES
) then
2011 if not gStatsPressed
then
2013 gStatsOff
:= not gStatsOff
;
2014 gStatsPressed
:= True;
2018 gStatsPressed
:= False;
2022 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
2024 // Время += 28 миллисекунд:
2025 gTime
:= gTime
+ GAME_TICK
;
2027 // Сообщение посередине экрана:
2028 if MessageTime
= 0 then
2030 if MessageTime
> 0 then
2031 MessageTime
:= MessageTime
- 1;
2033 if (g_Game_IsServer
) then
2035 // Был задан лимит времени:
2036 if (gGameSettings
.TimeLimit
> 0) then
2037 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
2038 begin // Он прошел => конец уровня
2043 // Надо респавнить игроков в LMS:
2044 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
2045 g_Game_RestartRound(gLMSSoftSpawn
);
2047 // Проверим результат голосования, если время прошло
2048 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2050 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2052 g_Console_Process(gVoteCommand
);
2054 gVotePassed
:= False;
2057 // Замеряем время захвата флагов
2058 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2059 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2060 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2061 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2063 // Был задан лимит побед:
2064 if (gGameSettings
.ScoreLimit
> 0) then
2068 if gGameSettings
.GameMode
= GM_DM
then
2069 begin // В DM ищем игрока с max фрагами
2070 for i
:= 0 to High(gPlayers
) do
2071 if gPlayers
[i
] <> nil then
2072 if gPlayers
[i
].Frags
> b
then
2073 b
:= gPlayers
[i
].Frags
;
2076 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2077 begin // В CTF/TDM выбираем команду с наибольшим счетом
2078 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2081 // Лимит побед набран => конец уровня:
2082 if b
>= gGameSettings
.ScoreLimit
then
2089 // Обрабатываем клавиши игроков:
2090 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2091 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2092 {$IFDEF DISABLE_MENU}
2093 if (not gConsoleShow
) and (not gChatShow
) then
2095 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2098 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2099 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2100 end // if not console
2103 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2105 // process weapon switch queue
2109 if (gPlayer1
= nil) and (gPlayer2
= nil)
2110 and (not gConsoleShow
) and (not gChatShow
)
2111 {$IFDEF ENABLE_MENU}
2112 and (g_ActiveWindow
= nil)
2116 if not gSpectKeyPress
then
2118 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2120 // switch spect mode
2122 SPECT_NONE
: ; // not spectator
2124 SPECT_MAPVIEW
: Inc(gSpectMode
);
2125 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2127 gSpectKeyPress
:= True;
2129 if (gSpectMode
= SPECT_MAPVIEW
)
2130 and (not gSpectAuto
) then
2132 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2133 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2134 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2135 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2136 if gPlayerAction
[0, ACTION_LOOKUP
] then
2137 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2138 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2139 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2140 if gWeaponAction
[0, WP_PREV
] then
2143 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2144 gWeaponAction
[0, WP_PREV
] := False;
2146 if gWeaponAction
[0, WP_NEXT
] then
2149 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2150 gWeaponAction
[0, WP_NEXT
] := False;
2153 if (gSpectMode
= SPECT_PLAYERS
)
2154 and (not gSpectAuto
) then
2156 if gPlayerAction
[0, ACTION_LOOKUP
] then
2159 gSpectViewTwo
:= True;
2160 gSpectKeyPress
:= True;
2162 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2164 // remove second view
2165 gSpectViewTwo
:= False;
2166 gSpectKeyPress
:= True;
2168 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2170 // prev player (view 1)
2171 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2172 gSpectKeyPress
:= True;
2174 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2176 // next player (view 1)
2177 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2178 gSpectKeyPress
:= True;
2180 if gWeaponAction
[0, WP_PREV
] then
2182 // prev player (view 2)
2183 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2184 gWeaponAction
[0, WP_PREV
] := False;
2186 if gWeaponAction
[0, WP_NEXT
] then
2188 // next player (view 2)
2189 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2190 gWeaponAction
[0, WP_NEXT
] := False;
2193 if gPlayerAction
[0, ACTION_ATTACK
] then
2195 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2198 gSpectAutoNext
:= 0;
2199 gSpectViewTwo
:= False;
2200 gSpectKeyPress
:= True;
2205 gSpectMode
:= SPECT_STATS
;
2206 gSpectAuto
:= False;
2207 gSpectKeyPress
:= True;
2212 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2213 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2214 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2215 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2216 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2217 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2218 gSpectKeyPress
:= False;
2222 if gSpectMode
= SPECT_MAPVIEW
then
2224 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2226 gSpectAutoNext
:= gTime
2229 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2231 gSpectAutoNext
:= gTime
2235 if gSpectAutoNext
<= gTime
then
2237 if gSpectAutoNext
> 0 then
2239 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2243 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2244 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2245 gSpectAutoStepX
:= Random(9) - 4;
2246 gSpectAutoStepY
:= Random(9) - 4;
2247 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2248 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2249 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2250 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2251 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2252 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2256 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2261 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2262 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2263 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2269 (* spectator state check from render *)
2271 if (gPlayer1
= nil) and (gPlayer2
= nil) and (gSpectMode
= SPECT_NONE
) then
2272 gSpectMode
:= SPECT_STATS
;
2274 if IsActivePlayer(g_Player_Get(gSpectPID1
)) = false then
2275 gSpectPID1
:= GetActivePlayerID_Next();
2277 if IsActivePlayer(g_Player_Get(gSpectPID2
)) = false then
2278 gSpectPID2
:= GetActivePlayerID_Next();
2280 g_Game_SetupHearPoints
;
2282 // Обновляем все остальное:
2285 g_Triggers_Update();
2287 g_Monsters_Update();
2291 g_Player_UpdateAll();
2292 {$IFDEF ENABLE_GIBS}
2295 {$IFDEF ENABLE_CORPSES}
2298 {$IFDEF ENABLE_SHELLS}
2302 // server: send newly spawned monsters unconditionally
2303 if (gGameSettings
.GameType
= GT_SERVER
) then
2305 if (Length(gMonstersSpawned
) > 0) then
2307 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2308 SetLength(gMonstersSpawned
, 0);
2312 if (gSoundTriggerTime
> 8) then
2314 g_Game_UpdateTriggerSounds();
2315 gSoundTriggerTime
:= 0;
2319 Inc(gSoundTriggerTime
);
2322 if (NetMode
= NET_SERVER
) then
2324 Inc(NetTimeToUpdate
);
2325 Inc(NetTimeToReliable
);
2327 // send monster updates
2328 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2330 // send all monsters (periodic sync)
2331 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2333 for I
:= 0 to High(gPlayers
) do
2335 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2338 g_Mons_ForEach(sendMonsPos
);
2340 // update flags that aren't stationary
2341 if gGameSettings
.GameMode
= GM_CTF
then
2342 for I
:= FLAG_RED
to FLAG_BLUE
do
2343 if gFlags
[I
].NeedSend
then
2345 gFlags
[I
].NeedSend
:= False;
2349 // update items that aren't stationary
2350 g_Items_ForEachAlive(sendItemPos
);
2352 if reliableUpdate
then
2354 NetTimeToReliable
:= 0;
2355 NetTimeToUpdate
:= NetUpdateRate
;
2359 NetTimeToUpdate
:= 0;
2364 // send only mosters with some unexpected changes
2365 g_Mons_ForEach(sendMonsPosUnexpected
);
2368 // send unexpected platform changes
2369 g_Map_NetSendInterestingPanels();
2371 g_Net_Slist_ServerUpdate();
2373 if NetUseMaster then
2375 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2377 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2379 NetTimeToMaster := gTime + NetMasterRate;
2384 else if (NetMode
= NET_CLIENT
) then
2386 MC_SEND_PlayerPos();
2388 end; // if gameOn ...
2390 // Активно окно интерфейса - передаем клавиши ему:
2391 {$IFDEF ENABLE_MENU}
2392 if g_ActiveWindow
<> nil then
2394 w
:= e_GetFirstKeyPressed();
2396 if (w
<> IK_INVALID
) then
2398 Msg
.Msg
:= MESSAGE_DIKEY
;
2400 g_ActiveWindow
.OnMessage(Msg
);
2403 // Если оно от этого не закрылось, то обновляем:
2404 if g_ActiveWindow
<> nil then
2405 g_ActiveWindow
.Update();
2407 // Нужно сменить разрешение:
2408 if gResolutionChange
then
2410 {$IFDEF ENABLE_RENDER}
2411 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2414 gResolutionChange
:= False;
2415 g_ActiveWindow
:= nil;
2418 // Нужно сменить язык:
2419 if gLanguageChange
then
2421 //e_WriteLog('Read language file', MSG_NOTIFY);
2422 //g_Language_Load(DataDir + gLanguage + '.txt');
2423 g_Language_Set(gLanguage
);
2425 gLanguageChange
:= False;
2429 // Горячая клавиша для вызова меню выхода из игры (F10):
2430 if e_KeyPressed(IK_F10
) and
2432 (not gConsoleShow
) and
2433 (g_ActiveWindow
= nil) then
2439 Time
:= GetTickCount64() {div 1000};
2441 // Обработка отложенных событий:
2442 if gDelayedEvents
<> nil then
2443 for a
:= 0 to High(gDelayedEvents
) do
2444 if gDelayedEvents
[a
].Pending
and
2446 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2447 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2450 case gDelayedEvents
[a
].DEType
of
2452 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2455 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2459 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2460 if g_Game_IsNet
and g_Game_IsServer
then
2461 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2465 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2467 gDelayedEvents
[a
].Pending
:= False;
2470 // Каждую секунду обновляем счетчик обновлений:
2471 UPSCounter
:= UPSCounter
+ 1;
2472 if Time
- UPSTime
>= 1000 then
2481 g_Weapon_AddDynLights();
2482 g_Items_AddDynLights();
2486 procedure g_Game_LoadChatSounds(Resource
: string);
2489 FileName
, Snd
: string;
2491 len
, cnt
, tags
, i
, j
: Integer;
2494 FileName
:= g_ExtractWadName(Resource
);
2496 WAD
:= TWADFile
.Create();
2497 WAD
.ReadFile(FileName
);
2499 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2506 cfg
:= TConfig
.CreateMem(p
, len
);
2507 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2509 SetLength(gChatSounds
, cnt
);
2510 for i
:= 0 to Length(gChatSounds
) - 1 do
2512 gChatSounds
[i
].Sound
:= nil;
2513 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2514 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2515 if (Snd
= '') or (Tags
<= 0) then
2517 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2518 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2519 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2520 SetLength(gChatSounds
[i
].Tags
, tags
);
2521 for j
:= 0 to tags
- 1 do
2522 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2523 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2530 procedure g_Game_FreeChatSounds();
2534 for i
:= 0 to Length(gChatSounds
) - 1 do
2536 gChatSounds
[i
].Sound
.Free();
2537 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2539 SetLength(gChatSounds
, 0);
2543 procedure g_Game_LoadData();
2545 if DataLoaded
then Exit
;
2547 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2548 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
2550 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2551 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2552 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2553 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2554 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2555 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2556 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2557 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2558 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2559 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2560 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2561 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2562 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2563 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2564 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2565 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2566 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2567 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2568 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2569 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2570 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2571 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2572 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2573 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2574 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2575 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2576 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2577 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2578 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2579 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2580 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2581 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2583 goodsnd
[0] := TPlayableSound
.Create();
2584 goodsnd
[1] := TPlayableSound
.Create();
2585 goodsnd
[2] := TPlayableSound
.Create();
2586 goodsnd
[3] := TPlayableSound
.Create();
2588 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2589 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2590 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2591 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2593 killsnd
[0] := TPlayableSound
.Create();
2594 killsnd
[1] := TPlayableSound
.Create();
2595 killsnd
[2] := TPlayableSound
.Create();
2596 killsnd
[3] := TPlayableSound
.Create();
2598 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2599 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2600 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2601 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2603 hahasnd
[0] := TPlayableSound
.Create();
2604 hahasnd
[1] := TPlayableSound
.Create();
2605 hahasnd
[2] := TPlayableSound
.Create();
2607 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2608 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2609 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2611 sound_get_flag
[0] := TPlayableSound
.Create();
2612 sound_get_flag
[1] := TPlayableSound
.Create();
2613 sound_lost_flag
[0] := TPlayableSound
.Create();
2614 sound_lost_flag
[1] := TPlayableSound
.Create();
2615 sound_ret_flag
[0] := TPlayableSound
.Create();
2616 sound_ret_flag
[1] := TPlayableSound
.Create();
2617 sound_cap_flag
[0] := TPlayableSound
.Create();
2618 sound_cap_flag
[1] := TPlayableSound
.Create();
2620 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2621 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2622 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2623 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2624 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2625 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2626 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2627 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2629 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2633 g_Weapon_LoadData();
2635 g_Monsters_LoadData();
2640 procedure g_Game_Quit();
2642 g_Game_StopAllSounds(True);
2645 g_PlayerModel_FreeData();
2646 {$IFDEF ENABLE_MENU}
2647 // g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2650 if NetInitDone
then g_Net_Free
;
2652 // remove map after test
2653 if gMapToDelete
<> '' then
2654 g_Game_DeleteTestMap();
2658 {$IFDEF ENABLE_SYSTEM}
2663 procedure g_Game_FreeData();
2665 if not DataLoaded
then Exit
;
2668 g_Weapon_FreeData();
2669 g_Monsters_FreeData();
2671 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2673 g_Sound_Delete('SOUND_GAME_TELEPORT');
2674 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2675 g_Sound_Delete('SOUND_GAME_SECRET');
2676 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2677 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2678 g_Sound_Delete('SOUND_GAME_BULK1');
2679 g_Sound_Delete('SOUND_GAME_BULK2');
2680 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2681 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2682 g_Sound_Delete('SOUND_GAME_BURNING');
2683 g_Sound_Delete('SOUND_GAME_SWITCH1');
2684 g_Sound_Delete('SOUND_GAME_SWITCH0');
2691 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2692 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2693 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2694 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2701 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2702 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2703 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2704 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2710 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2711 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2712 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2714 sound_get_flag
[0].Free();
2715 sound_get_flag
[1].Free();
2716 sound_lost_flag
[0].Free();
2717 sound_lost_flag
[1].Free();
2718 sound_ret_flag
[0].Free();
2719 sound_ret_flag
[1].Free();
2720 sound_cap_flag
[0].Free();
2721 sound_cap_flag
[1].Free();
2723 g_Sound_Delete('SOUND_CTF_GET1');
2724 g_Sound_Delete('SOUND_CTF_GET2');
2725 g_Sound_Delete('SOUND_CTF_LOST1');
2726 g_Sound_Delete('SOUND_CTF_LOST2');
2727 g_Sound_Delete('SOUND_CTF_RETURN1');
2728 g_Sound_Delete('SOUND_CTF_RETURN2');
2729 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2730 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2732 g_Game_FreeChatSounds();
2734 DataLoaded
:= False;
2737 procedure g_FatalError(Text: String);
2739 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2740 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2742 gExit
:= EXIT_SIMPLE
;
2743 if gGameOn
then EndGame
;
2746 procedure g_SimpleError(Text: String);
2748 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2749 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2752 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2754 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2755 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2758 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2761 if gPlayer1
= nil then
2763 if g_Game_IsClient
then
2765 if NetPlrUID1
> -1 then
2766 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2770 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2771 Team
:= gPlayer1Settings
.Team
;
2773 // Создание первого игрока:
2774 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2775 gPlayer1Settings
.Color
,
2777 if gPlayer1
= nil then
2778 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2781 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2782 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2783 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2784 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2785 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2786 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2787 if g_Game_IsServer
and g_Game_IsNet
then
2788 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2789 gPlayer1
.Respawn(False, True);
2790 g_Net_Slist_ServerPlayerComes();
2795 if gPlayer2
= nil then
2797 if g_Game_IsClient
then
2799 if NetPlrUID2
> -1 then
2800 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2804 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2805 Team
:= gPlayer2Settings
.Team
;
2807 // Создание второго игрока:
2808 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2809 gPlayer2Settings
.Color
,
2811 if gPlayer2
= nil then
2812 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2815 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2816 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2817 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2818 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2819 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2820 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2821 if g_Game_IsServer
and g_Game_IsNet
then
2822 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2823 gPlayer2
.Respawn(False, True);
2824 g_Net_Slist_ServerPlayerComes();
2831 procedure g_Game_RemovePlayer();
2835 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2836 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2841 if g_Game_IsServer
then
2844 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2845 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2846 g_Player_Remove(Pl
.UID
);
2847 g_Net_Slist_ServerPlayerLeaves();
2851 gSpectLatchPID2
:= Pl
.UID
;
2859 if g_Game_IsServer
then
2862 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2863 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2864 g_Player_Remove(Pl
.UID
);
2865 g_Net_Slist_ServerPlayerLeaves();
2868 gSpectLatchPID1
:= Pl
.UID
;
2870 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2874 g_Net_Slist_ServerPlayerLeaves();
2877 procedure g_Game_Spectate();
2879 g_Game_RemovePlayer();
2880 if gPlayer1
<> nil then
2881 g_Game_RemovePlayer();
2884 procedure g_Game_SpectateCenterView();
2886 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2887 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2890 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2897 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2899 g_Game_ClearLoading();
2902 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2905 gGameSettings
.GameType
:= GT_SINGLE
;
2906 gGameSettings
.MaxLives
:= 0;
2907 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2908 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2909 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2910 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2911 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2912 gSwitchGameMode
:= GM_SINGLE
;
2914 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2915 gLMSRespawnTime
:= 0;
2916 gSpectLatchPID1
:= 0;
2917 gSpectLatchPID2
:= 0;
2919 g_Game_ExecuteEvent('ongamestart');
2921 // Создание первого игрока:
2922 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2923 gPlayer1Settings
.Color
,
2924 gPlayer1Settings
.Team
, False));
2925 if gPlayer1
= nil then
2927 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2931 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2932 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2933 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2934 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2935 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2938 // Создание второго игрока, если есть:
2941 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2942 gPlayer2Settings
.Color
,
2943 gPlayer2Settings
.Team
, False));
2944 if gPlayer2
= nil then
2946 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2950 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2951 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2952 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2953 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2954 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2958 // Загрузка и запуск карты:
2959 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2961 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2962 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2966 // Настройки игроков и ботов:
2970 for i
:= nPl
+1 to nPlayers
do
2971 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2974 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2975 TimeLimit
, ScoreLimit
: Word;
2977 Options
: LongWord; nPlayers
: Byte);
2983 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2985 g_Game_ClearLoading();
2988 gGameSettings
.GameType
:= GT_CUSTOM
;
2989 gGameSettings
.GameMode
:= GameMode
;
2990 gSwitchGameMode
:= GameMode
;
2991 gGameSettings
.TimeLimit
:= TimeLimit
;
2992 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2993 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2994 gGameSettings
.Options
:= Options
;
2996 gCoopTotalMonstersKilled
:= 0;
2997 gCoopTotalSecretsFound
:= 0;
2998 gCoopTotalMonsters
:= 0;
2999 gCoopTotalSecrets
:= 0;
3003 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3004 gLMSRespawnTime
:= 0;
3005 gSpectLatchPID1
:= 0;
3006 gSpectLatchPID2
:= 0;
3008 g_Game_ExecuteEvent('ongamestart');
3010 // Режим наблюдателя:
3011 if nPlayers
= 0 then
3018 if nPlayers
>= 1 then
3020 // Создание первого игрока:
3021 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3022 gPlayer1Settings
.Color
,
3023 gPlayer1Settings
.Team
, False));
3024 if gPlayer1
= nil then
3026 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3030 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3031 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3032 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3033 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3034 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3038 if nPlayers
>= 2 then
3040 // Создание второго игрока:
3041 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3042 gPlayer2Settings
.Color
,
3043 gPlayer2Settings
.Team
, False));
3044 if gPlayer2
= nil then
3046 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3050 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3051 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3052 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3053 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3054 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3058 // Загрузка и запуск карты:
3059 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3061 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3065 // Нет точек появления:
3066 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3067 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3068 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3069 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3070 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3072 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3076 // Настройки игроков и ботов:
3080 for i
:= nPl
+1 to nPlayers
do
3081 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3084 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3085 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3086 Options
: LongWord; nPlayers
: Byte;
3087 IPAddr
: LongWord; Port
: Word);
3090 g_Net_Slist_ServerClosed();
3092 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3094 g_Game_ClearLoading();
3099 gGameSettings
.GameType
:= GT_SERVER
;
3100 gGameSettings
.GameMode
:= GameMode
;
3101 gSwitchGameMode
:= GameMode
;
3102 gGameSettings
.TimeLimit
:= TimeLimit
;
3103 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3104 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3105 gGameSettings
.Options
:= Options
;
3107 gCoopTotalMonstersKilled
:= 0;
3108 gCoopTotalSecretsFound
:= 0;
3109 gCoopTotalMonsters
:= 0;
3110 gCoopTotalSecrets
:= 0;
3114 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3115 gLMSRespawnTime
:= 0;
3116 gSpectLatchPID1
:= 0;
3117 gSpectLatchPID2
:= 0;
3119 g_Game_ExecuteEvent('ongamestart');
3121 // Режим наблюдателя:
3122 if nPlayers
= 0 then
3128 if nPlayers
>= 1 then
3130 // Создание первого игрока:
3131 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3132 gPlayer1Settings
.Color
,
3133 gPlayer1Settings
.Team
, False));
3134 if gPlayer1
= nil then
3136 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3140 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3141 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3142 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3143 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3144 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3147 if nPlayers
>= 2 then
3149 // Создание второго игрока:
3150 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3151 gPlayer2Settings
.Color
,
3152 gPlayer2Settings
.Team
, False));
3153 if gPlayer2
= nil then
3155 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3159 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3160 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3161 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3162 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3163 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3166 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3167 if NetForwardPorts
then
3168 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3171 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3173 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3177 g_Net_Slist_Set(NetMasterList
);
3179 g_Net_Slist_ServerStarted();
3181 // Загрузка и запуск карты:
3182 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3184 g_Net_Slist_ServerClosed();
3185 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3189 // Нет точек появления:
3190 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3191 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3192 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3193 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3194 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3196 g_Net_Slist_ServerClosed();
3197 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3201 // Настройки игроков и ботов:
3204 g_Net_Slist_ServerMapStarted();
3205 NetState
:= NET_STATE_GAME
;
3208 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3223 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3224 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3226 g_Game_ClearLoading();
3231 gGameSettings
.GameType
:= GT_CLIENT
;
3233 gCoopTotalMonstersKilled
:= 0;
3234 gCoopTotalSecretsFound
:= 0;
3235 gCoopTotalMonsters
:= 0;
3236 gCoopTotalSecrets
:= 0;
3240 g_Game_ExecuteEvent('ongamestart');
3242 NetState
:= NET_STATE_AUTH
;
3244 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3246 // create (or update) map/resource databases
3247 g_Res_CreateDatabases(true);
3249 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3250 gLMSRespawnTime
:= 0;
3251 gSpectLatchPID1
:= 0;
3252 gSpectLatchPID2
:= 0;
3255 if not g_Net_Connect(Addr
, Port
) then
3257 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3258 NetState
:= NET_STATE_NONE
;
3262 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3264 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3269 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3270 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3271 // thank you, enet. let's ignore failures altogether then.
3272 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3274 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3276 Ptr
:= NetEvent
.packet
^.data
;
3277 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3279 enet_packet_destroy(NetEvent
.packet
);
3283 InMsg
.ReadLongWord(); // skip size
3284 MID
:= InMsg
.ReadByte();
3286 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3288 NetMyID
:= InMsg
.ReadByte();
3289 NetPlrUID1
:= InMsg
.ReadWord();
3291 WadName
:= InMsg
.ReadString();
3292 Map
:= InMsg
.ReadString();
3294 gWADHash
:= InMsg
.ReadMD5();
3296 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3297 gSwitchGameMode
:= gGameSettings
.GameMode
;
3298 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3299 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3300 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3301 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3302 T
:= InMsg
.ReadLongWord();
3304 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3305 //if newResPath = '' then
3307 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3308 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3309 if newResPath
= '' then
3311 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3312 enet_packet_destroy(NetEvent
.packet
);
3313 NetState
:= NET_STATE_NONE
;
3316 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3318 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3321 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3322 gPlayer1Settings
.Color
,
3323 gPlayer1Settings
.Team
, False));
3325 if gPlayer1
= nil then
3327 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3329 enet_packet_destroy(NetEvent
.packet
);
3330 NetState
:= NET_STATE_NONE
;
3334 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3335 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3336 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3337 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3338 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3339 gPlayer1
.UID
:= NetPlrUID1
;
3340 gPlayer1
.Reset(True);
3342 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3344 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3346 enet_packet_destroy(NetEvent
.packet
);
3347 NetState
:= NET_STATE_NONE
;
3355 enet_packet_destroy(NetEvent
.packet
);
3359 enet_packet_destroy(NetEvent
.packet
);
3363 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3366 if (NetEvent
.data
<= NET_DISC_MAX
) then
3367 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3368 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3375 ProcessLoading(True);
3376 if g_Net_UserRequestExit() then
3385 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3386 NetState
:= NET_STATE_NONE
;
3391 NetState
:= NET_STATE_GAME
;
3392 MC_SEND_FullStateRequest
;
3393 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3397 lastAsMegaWad
: Boolean = false;
3399 procedure g_Game_ChangeMap(const MapPath
: String);
3403 g_Game_ClearLoading();
3405 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3406 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3407 if gExitByTrigger
then
3410 gExitByTrigger
:= False;
3412 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3413 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3416 procedure g_Game_Restart();
3420 if g_Game_IsClient
then
3422 map
:= g_ExtractFileName(gMapInfo
.Map
);
3423 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3427 g_Game_ClearLoading();
3428 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3431 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3433 NewWAD
, ResName
: String;
3437 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3439 {$IFDEF ENABLE_GIBS}
3442 {$IFDEF ENALBE_SHELLS}
3445 {$IFDEF ENABLE_CORPSES}
3446 g_Corpses_RemoveAll
;
3449 if (not g_Game_IsClient
) and
3450 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3451 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3453 if gSwitchGameMode
= GM_CTF
then
3454 gGameSettings
.MaxLives
:= 0;
3455 gGameSettings
.GameMode
:= gSwitchGameMode
;
3458 gSwitchGameMode
:= gGameSettings
.GameMode
;
3460 g_Player_ResetTeams();
3462 lastAsMegaWad
:= asMegawad
;
3463 if isWadPath(Map
) then
3465 NewWAD
:= g_ExtractWadName(Map
);
3466 ResName
:= g_ExtractFileName(Map
);
3467 if g_Game_IsServer
then
3469 nws
:= findDiskWad(NewWAD
);
3470 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3473 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3474 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3478 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3479 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3481 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3482 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3484 if (length(nws
) = 0) then
3486 ResName
:= ''; // failed
3491 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3492 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3493 g_Game_LoadWAD(NewWAD
);
3498 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3499 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3504 NewWAD
:= gGameSettings
.WAD
;
3510 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3512 if (ResName
<> '') and (NewWAD
<> '') then
3514 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3515 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3519 {$IFDEF ENABLE_RENDER}
3520 r_Render_LoadTextures
;
3523 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3525 gState
:= STATE_NONE
;
3526 {$IFDEF ENABLE_MENU}
3527 g_ActiveWindow
:= nil;
3532 wNeedTimeReset
:= True;
3534 if gGameSettings
.GameMode
= GM_CTF
then
3536 g_Map_ResetFlag(FLAG_RED
);
3537 g_Map_ResetFlag(FLAG_BLUE
);
3538 // CTF, а флагов нет:
3539 if not g_Map_HaveFlagPoints() then
3540 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3545 gState
:= STATE_MENU
;
3550 gPauseMain
:= false;
3551 gPauseHolmes
:= false;
3552 NetTimeToUpdate
:= 1;
3553 NetTimeToReliable
:= 0;
3554 NetTimeToMaster
:= NetMasterRate
;
3555 gSpectLatchPID1
:= 0;
3556 gSpectLatchPID2
:= 0;
3557 gMissionFailed
:= False;
3560 gCoopMonstersKilled
:= 0;
3561 gCoopSecretsFound
:= 0;
3563 gVoteInProgress
:= False;
3564 gVotePassed
:= False;
3570 if not gGameOn
then Exit
;
3572 g_Game_SpectateCenterView();
3574 if g_Game_IsServer
then
3576 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3578 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3579 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3580 gLMSSoftSpawn
:= True;
3581 if g_Game_IsNet
then
3582 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3586 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3587 gLMSRespawnTime
:= 0;
3591 if NetMode
= NET_SERVER
then
3593 // reset full state flags
3594 if NetClients
<> nil then
3595 for I
:= 0 to High(NetClients
) do
3596 NetClients
[I
].FullUpdateSent
:= False;
3598 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3601 g_Net_Slist_ServerMapStarted();
3603 if NetClients
<> nil then
3604 for I
:= 0 to High(NetClients
) do
3605 if NetClients
[I
].Used
then
3607 NetClients
[I
].Voted
:= False;
3608 if NetClients
[I
].RequestedFullUpdate
then
3610 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3611 NetClients
[I
].RequestedFullUpdate
:= False;
3615 g_Net_UnbanNonPermHosts();
3620 gCoopTotalMonstersKilled
:= 0;
3621 gCoopTotalSecretsFound
:= 0;
3622 gCoopTotalMonsters
:= 0;
3623 gCoopTotalSecrets
:= 0;
3627 g_Game_ExecuteEvent('onmapstart');
3630 procedure SetFirstLevel
;
3634 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3635 if MapList
= nil then
3638 SortSArray(MapList
);
3639 gNextMap
:= MapList
[Low(MapList
)];
3644 procedure g_Game_ExitLevel(const Map
: AnsiString);
3648 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3649 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3650 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3651 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3653 // Вышли в выход в Одиночной игре:
3654 if gGameSettings
.GameType
= GT_SINGLE
then
3655 gExit
:= EXIT_ENDLEVELSINGLE
3656 else // Вышли в выход в Своей игре
3658 gExit
:= EXIT_ENDLEVELCUSTOM
;
3659 if gGameSettings
.GameMode
= GM_COOP
then
3660 g_Player_RememberAll
;
3662 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3665 if gGameSettings
.GameMode
= GM_COOP
then
3668 gStatsPressed
:= True;
3669 gNextMap
:= 'MAP01';
3671 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3674 if g_Game_IsNet
then
3676 MH_SEND_GameStats();
3677 MH_SEND_CoopStats();
3683 procedure g_Game_RestartLevel();
3687 if gGameSettings
.GameMode
= GM_SINGLE
then
3692 gExit
:= EXIT_ENDLEVELCUSTOM
;
3693 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3697 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3699 gWAD
{, xwad}: String;
3702 if not g_Game_IsClient
then Exit
;
3703 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3705 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3710 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3714 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3717 g_Game_LoadWAD(NewWAD
);
3721 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3722 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3725 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3726 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3730 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3734 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3735 g_Game_LoadWAD(NewWAD);
3739 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3741 i
, n
, nb
, nr
: Integer;
3743 if not g_Game_IsServer
then Exit
;
3744 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3745 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3746 gLMSRespawnTime
:= 0;
3749 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3751 gMissionFailed
:= True;
3752 g_Game_RestartLevel
;
3756 n
:= 0; nb
:= 0; nr
:= 0;
3757 for i
:= Low(gPlayers
) to High(gPlayers
) do
3758 if (gPlayers
[i
] <> nil) and
3759 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3760 (gPlayers
[i
] is TBot
)) then
3763 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3764 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3767 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3769 // wait a second until the fuckers finally decide to join
3770 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3771 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3772 gLMSSoftSpawn
:= NoMapRestart
;
3773 if g_Game_IsNet
then
3774 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3778 {$IFDEF ENABLE_GIBS}
3781 {$IFDEF ENALBE_SHELLS}
3784 {$IFDEF ENABLE_CORPSES}
3785 g_Corpses_RemoveAll
;
3788 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3789 if g_Game_IsNet
then
3790 MH_SEND_GameEvent(NET_EV_LMS_START
);
3792 for i
:= Low(gPlayers
) to High(gPlayers
) do
3794 if gPlayers
[i
] = nil then continue
;
3795 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3796 // don't touch normal spectators
3797 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3799 gPlayers
[i
].FNoRespawn
:= True;
3800 gPlayers
[i
].Lives
:= 0;
3801 if g_Game_IsNet
then
3802 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3805 gPlayers
[i
].FNoRespawn
:= False;
3806 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3807 gPlayers
[i
].Respawn(False, True);
3808 if gGameSettings
.GameMode
= GM_COOP
then
3810 gPlayers
[i
].Frags
:= 0;
3811 gPlayers
[i
].RecallState
;
3813 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3814 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3815 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3816 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3819 g_Items_RestartRound();
3821 gLMSSoftSpawn
:= False;
3824 function g_Game_GetFirstMap(WAD
: String): String;
3828 MapList
:= g_Map_GetMapsList(WAD
);
3829 if MapList
= nil then
3832 SortSArray(MapList
);
3833 Result
:= MapList
[Low(MapList
)];
3835 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3841 function g_Game_GetNextMap(): String;
3848 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3849 if MapList
= nil then
3852 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3854 SortSArray(MapList
);
3856 for I
:= Low(MapList
) to High(MapList
) do
3857 if Map
= MapList
[I
] then
3863 if MapIndex
<> -255 then
3865 if MapIndex
= High(MapList
) then
3866 Result
:= MapList
[Low(MapList
)]
3868 Result
:= MapList
[MapIndex
+ 1];
3870 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3876 procedure g_Game_NextLevel();
3878 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3879 gExit
:= EXIT_ENDLEVELCUSTOM
3882 gExit
:= EXIT_ENDLEVELSINGLE
;
3886 if gNextMap
<> '' then Exit
;
3887 gNextMap
:= g_Game_GetNextMap();
3890 function g_Game_IsTestMap(): Boolean;
3892 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3895 procedure g_Game_DeleteTestMap();
3898 //MapName: AnsiString;
3906 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3907 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3908 if (a
= 0) then exit
;
3910 // Выделяем имя wad-файла и имя карты
3911 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3912 Delete(gMapToDelete
, 1, a
+5);
3913 gMapToDelete
:= UpperCase(gMapToDelete
);
3915 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3918 // Имя карты не стандартное тестовое:
3919 if MapName <> TEST_MAP_NAME then
3922 if not gTempDelete then
3924 time := g_GetFileTime(WadName);
3925 WAD := TWADFile.Create();
3928 if not WAD.ReadFile(WadName) then
3929 begin // Нет такого WAD-файла
3934 // Составляем список карт и ищем нужную:
3936 MapList := WAD.GetResourcesList('');
3938 if MapList <> nil then
3939 for a := 0 to High(MapList) do
3940 if MapList[a] = MapName then
3942 // Удаляем и сохраняем:
3943 WAD.RemoveResource('', MapName);
3944 WAD.SaveTo(WadName);
3949 g_SetFileTime(WadName, time);
3952 if gTempDelete
then DeleteFile(WadName
);
3955 procedure GameCVars(P
: SSArray
);
3958 stat
: TPlayerStatArray
;
3961 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3965 if Length(P
) > 1 then
3970 gsGameFlags
:= gsGameFlags
or Flag
3972 gsGameFlags
:= gsGameFlags
and (not Flag
);
3974 if g_Game_IsServer
then
3977 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3979 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3980 if g_Game_IsNet
then MH_SEND_GameSettings
;
3984 if LongBool(gsGameFlags
and Flag
) then
3985 g_Console_Add(_lc
[OnMsg
])
3987 g_Console_Add(_lc
[OffMsg
]);
3989 if OnMapChange
and g_Game_IsServer
then
3990 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3995 cmd
:= LowerCase(P
[0]);
3997 if cmd
= 'g_gamemode' then
3999 if (Length(P
) > 1) then
4001 a
:= g_Game_TextToMode(P
[1]);
4002 if a
= GM_SINGLE
then a
:= GM_COOP
;
4003 gsGameMode
:= g_Game_ModeToText(a
);
4004 if g_Game_IsServer
then
4006 gSwitchGameMode
:= a
;
4007 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4008 (gState
= STATE_INTERSINGLE
) then
4009 gSwitchGameMode
:= GM_SINGLE
;
4011 gGameSettings
.GameMode
:= gSwitchGameMode
;
4015 if gSwitchGameMode
= gGameSettings
.GameMode
then
4016 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4017 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4019 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4020 [g_Game_ModeToText(gGameSettings
.GameMode
),
4021 g_Game_ModeToText(gSwitchGameMode
)]));
4023 else if cmd
= 'g_friendlyfire' then
4025 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4027 else if cmd
= 'g_friendly_absorb_damage' then
4029 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
4031 else if cmd
= 'g_friendly_hit_trace' then
4033 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
4035 else if cmd
= 'g_friendly_hit_projectile' then
4037 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
4039 else if cmd
= 'g_weaponstay' then
4041 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
4043 else if cmd
= 'g_allow_exit' then
4045 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
4047 else if cmd
= 'g_allow_monsters' then
4049 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
4051 else if cmd
= 'g_allow_dropflag' then
4053 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
4055 else if cmd
= 'g_throw_flag' then
4057 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
4059 else if cmd
= 'g_bot_vsplayers' then
4061 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4063 else if cmd
= 'g_bot_vsmonsters' then
4065 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4067 else if cmd
= 'g_dm_keys' then
4069 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4071 else if cmd
= 'g_gameflags' then
4073 if Length(P
) > 1 then
4075 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4076 if g_Game_IsServer
then
4078 gGameSettings
.Options
:= gsGameFlags
;
4079 if g_Game_IsNet
then MH_SEND_GameSettings
;
4083 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4085 else if cmd
= 'g_warmup_time' then
4087 if Length(P
) > 1 then
4089 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4090 if g_Game_IsServer
then
4092 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4093 // extend warmup if it's already going
4094 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4096 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4097 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4099 if g_Game_IsNet
then MH_SEND_GameSettings
;
4103 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4104 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4106 else if cmd
= 'g_spawn_invul' then
4108 if Length(P
) > 1 then
4110 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4111 if g_Game_IsServer
then
4113 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4114 if g_Game_IsNet
then MH_SEND_GameSettings
;
4118 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4120 else if cmd
= 'g_item_respawn_time' then
4122 if Length(P
) > 1 then
4124 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4125 if g_Game_IsServer
then
4127 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4128 if g_Game_IsNet
then MH_SEND_GameSettings
;
4132 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4133 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4135 else if cmd
= 'sv_intertime' then
4137 if (Length(P
) > 1) then
4138 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4140 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4142 else if cmd
= 'g_max_particles' then
4144 if Length(p
) = 2 then
4147 a
:= Max(0, StrToIntDef(p
[1], 0));
4151 else if Length(p
) = 1 then
4154 e_LogWritefln('%s', [g_GFX_GetMax()])
4156 e_LogWritefln('%s', [0])
4161 e_LogWritefln('usage: %s <n>', [cmd
])
4164 else if cmd
= 'g_max_shells' then
4166 if Length(p
) = 2 then
4168 {$IFDEF ENABLE_SHELLS}
4169 a
:= Max(0, StrToIntDef(p
[1], 0));
4173 else if Length(p
) = 1 then
4175 {$IFDEF ENABLE_SHELLS}
4176 e_LogWritefln('%s', [g_Shells_GetMax()])
4178 e_LogWritefln('%s', [0])
4183 e_LogWritefln('usage: %s <n>', [cmd
])
4186 else if cmd
= 'g_max_gibs' then
4188 if Length(p
) = 2 then
4190 {$IFDEF ENABLE_GIBS}
4191 a
:= Max(0, StrToIntDef(p
[1], 0));
4195 else if Length(p
) = 1 then
4197 {$IFDEF ENABLE_GIBS}
4198 e_LogWritefln('%s', [g_Gibs_GetMax()])
4200 e_LogWritefln('%s', [0])
4205 e_LogWritefln('usage: %s <n>', [cmd
])
4208 else if cmd
= 'g_max_corpses' then
4210 if Length(p
) = 2 then
4212 {$IFDEF ENABLE_CORPSES}
4213 a
:= Max(0, StrToIntDef(p
[1], 0));
4217 else if Length(p
) = 1 then
4219 {$IFDEF ENABLE_CORPSES}
4220 e_LogWritefln('%s', [g_Corpses_GetMax()])
4222 e_LogWritefln('%s', [0])
4227 e_LogWritefln('usage: %s <n>', [cmd
])
4230 else if cmd
= 'g_force_model' then
4232 if Length(p
) = 2 then
4234 a
:= StrToIntDef(p
[1], 0);
4235 g_Force_Model_Set(a
);
4236 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4238 for a
:= Low(gPlayers
) to High(gPlayers
) do
4240 if (gPlayers
[a
] <> nil) then
4242 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4244 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4246 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4250 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4252 for a
:= Low(gPlayers
) to High(gPlayers
) do
4254 if (gPlayers
[a
] <> nil) then
4256 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4258 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4260 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4266 else if cmd
= 'g_force_model_name' then
4268 if (Length(P
) > 1) then
4270 cmd
:= b_Text_Unformat(P
[1]);
4271 g_Forced_Model_SetName(cmd
);
4272 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4274 for a
:= Low(gPlayers
) to High(gPlayers
) do
4276 if (gPlayers
[a
] <> nil) then
4278 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4280 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4282 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4288 else if cmd
= 'g_scorelimit' then
4290 if Length(P
) > 1 then
4292 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4294 if g_Game_IsServer
then
4297 if gGameSettings
.GameMode
= GM_DM
then
4299 stat
:= g_Player_GetStats();
4301 for a
:= 0 to High(stat
) do
4302 if stat
[a
].Frags
> b
then
4306 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4308 // if someone has a higher score, set it to that instead
4309 gsScoreLimit
:= max(gsScoreLimit
, b
);
4310 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4312 if g_Game_IsNet
then MH_SEND_GameSettings
;
4316 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4318 else if cmd
= 'g_timelimit' then
4320 if Length(P
) > 1 then
4322 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4323 if g_Game_IsServer
then
4325 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4326 if g_Game_IsNet
then MH_SEND_GameSettings
;
4329 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4330 [gsTimeLimit
div 3600,
4331 (gsTimeLimit
div 60) mod 60,
4332 gsTimeLimit
mod 60]));
4334 else if cmd
= 'g_max_bots' then
4336 if Length(P
) > 1 then
4337 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4338 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4340 else if cmd
= 'g_maxlives' then
4342 if Length(P
) > 1 then
4344 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4345 if g_Game_IsServer
then
4347 gGameSettings
.MaxLives
:= gsMaxLives
;
4348 if g_Game_IsNet
then MH_SEND_GameSettings
;
4352 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4356 procedure PlayerSettingsCVars(P
: SSArray
);
4361 function ParseTeam(s
: string): Byte;
4365 'red', '1': result
:= TEAM_RED
;
4366 'blue', '2': result
:= TEAM_BLUE
;
4367 else result
:= TEAM_NONE
;
4371 cmd
:= LowerCase(P
[0]);
4375 if (Length(P
) > 1) then
4377 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4378 if g_Game_IsClient
then
4379 MC_SEND_PlayerSettings
4380 else if gGameOn
and (gPlayer1
<> nil) then
4382 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4383 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4389 if (Length(P
) > 1) then
4391 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4392 if g_Game_IsClient
then
4393 MC_SEND_PlayerSettings
4394 else if gGameOn
and (gPlayer2
<> nil) then
4396 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4397 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4403 if Length(P
) > 3 then
4405 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4406 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4407 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4408 if g_Game_IsClient
then
4409 MC_SEND_PlayerSettings
4410 else if gGameOn
and (gPlayer1
<> nil) then
4412 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4413 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4419 if Length(P
) > 3 then
4421 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4422 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4423 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4424 if g_Game_IsClient
then
4425 MC_SEND_PlayerSettings
4426 else if gGameOn
and (gPlayer2
<> nil) then
4428 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4429 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4435 if (Length(P
) > 1) then
4437 gPlayer1Settings
.Model
:= P
[1];
4438 if g_Game_IsClient
then
4439 MC_SEND_PlayerSettings
4440 else if gGameOn
and (gPlayer1
<> nil) then
4442 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4443 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4444 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4450 if (Length(P
) > 1) then
4452 gPlayer2Settings
.Model
:= P
[1];
4453 if g_Game_IsClient
then
4454 MC_SEND_PlayerSettings
4455 else if gGameOn
and (gPlayer2
<> nil) then
4457 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4458 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4459 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4465 // TODO: switch teams if in game or store this separately
4466 if (Length(P
) > 1) then
4468 team
:= ParseTeam(P
[1]);
4469 if team
= TEAM_NONE
then
4470 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4471 else if not gGameOn
and not g_Game_IsNet
then
4472 gPlayer1Settings
.Team
:= team
4474 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4479 // TODO: switch teams if in game or store this separately
4480 if (Length(P
) > 1) then
4482 team
:= ParseTeam(P
[1]);
4483 if team
= TEAM_NONE
then
4484 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4485 else if not gGameOn
and not g_Game_IsNet
then
4486 gPlayer2Settings
.Team
:= team
4488 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4493 if (Length(P
) = 2) then
4494 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4498 if (Length(P
) = 2) then
4499 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4503 if (Length(P
) = 2) then
4504 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4508 if (Length(P
) = 2) then
4509 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4513 if (Length(P
) = 2) then
4514 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4518 if (Length(P
) = 2) then
4519 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4521 'p1_priority_kastet':
4523 if (Length(P
) = 2) then
4524 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4526 'p2_priority_kastet':
4528 if (Length(P
) = 2) then
4529 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4533 if (Length(P
) = 2) then
4534 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4538 if (Length(P
) = 2) then
4539 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4541 'p1_priority_pistol':
4543 if (Length(P
) = 2) then
4544 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4546 'p2_priority_pistol':
4548 if (Length(P
) = 2) then
4549 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4551 'p1_priority_shotgun1':
4553 if (Length(P
) = 2) then
4554 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4556 'p2_priority_shotgun1':
4558 if (Length(P
) = 2) then
4559 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4561 'p1_priority_shotgun2':
4563 if (Length(P
) = 2) then
4564 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4566 'p2_priority_shotgun2':
4568 if (Length(P
) = 2) then
4569 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4571 'p1_priority_chaingun':
4573 if (Length(P
) = 2) then
4574 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4576 'p2_priority_chaingun':
4578 if (Length(P
) = 2) then
4579 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4581 'p1_priority_rocketlauncher':
4583 if (Length(P
) = 2) then
4584 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4586 'p2_priority_rocketlauncher':
4588 if (Length(P
) = 2) then
4589 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4591 'p1_priority_plasma':
4593 if (Length(P
) = 2) then
4594 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4596 'p2_priority_plasma':
4598 if (Length(P
) = 2) then
4599 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4603 if (Length(P
) = 2) then
4604 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4608 if (Length(P
) = 2) then
4609 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4611 'p1_priority_super':
4613 if (Length(P
) = 2) then
4614 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4616 'p2_priority_super':
4618 if (Length(P
) = 2) then
4619 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4621 'p1_priority_flamethrower':
4623 if (Length(P
) = 2) then
4624 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4626 'p2_priority_flamethrower':
4628 if (Length(P
) = 2) then
4629 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4631 'p1_priority_berserk':
4633 if (Length(P
) = 2) then
4634 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4636 'p2_priority_berserk':
4638 if (Length(P
) = 2) then
4639 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4644 procedure PrintHeapStats();
4648 hs
:= GetFPCHeapStatus();
4649 e_LogWriteLn ('v===== heap status =====v');
4650 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4651 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4652 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4653 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4654 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4655 e_LogWriteLn ('^=======================^');
4658 procedure DebugCommands(P
: SSArray
);
4665 // Команды отладочного режима:
4666 if {gDebugMode}conIsCheatsEnabled
then
4668 cmd
:= LowerCase(P
[0]);
4669 if cmd
= 'd_window' then
4671 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4672 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4674 else if cmd
= 'd_sounds' then
4676 if (Length(P
) > 1) and
4677 ((P
[1] = '1') or (P
[1] = '0')) then
4678 g_Debug_Sounds
:= (P
[1][1] = '1');
4680 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4682 else if cmd
= 'd_frames' then
4684 if (Length(P
) > 1) and
4685 ((P
[1] = '1') or (P
[1] = '0')) then
4686 g_Debug_Frames
:= (P
[1][1] = '1');
4688 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4690 else if cmd
= 'd_winmsg' then
4692 if (Length(P
) > 1) and
4693 ((P
[1] = '1') or (P
[1] = '0')) then
4694 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4696 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4698 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4700 if (Length(P
) > 1) and
4701 ((P
[1] = '1') or (P
[1] = '0')) then
4702 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4704 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4706 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4708 if Length(P
) > 1 then
4710 '0': g_debug_BotAIOff
:= 0;
4711 '1': g_debug_BotAIOff
:= 1;
4712 '2': g_debug_BotAIOff
:= 2;
4713 '3': g_debug_BotAIOff
:= 3;
4716 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4718 else if cmd
= 'd_monster' then
4720 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4721 if Length(P
) < 2 then
4723 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4724 g_Console_Add('ID | Name');
4725 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4726 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4727 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4730 a
:= StrToIntDef(P
[1], 0);
4731 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4732 a
:= g_Mons_TypeIdByName(P
[1]);
4734 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4735 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4738 with gPlayer1
.Obj
do
4740 mon
:= g_Monsters_Create(a
,
4741 X
+ Rect
.X
+ (Rect
.Width
div 2),
4742 Y
+ Rect
.Y
+ Rect
.Height
,
4743 gPlayer1
.Direction
, True);
4745 if (Length(P
) > 2) and (mon
<> nil) then
4747 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4748 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4749 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4750 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4751 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4752 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4753 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4754 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4755 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4760 else if (cmd
= 'd_health') then
4762 if (Length(P
) > 1) and
4763 ((P
[1] = '1') or (P
[1] = '0')) then
4764 g_debug_HealthBar
:= (P
[1][1] = '1');
4766 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4768 else if (cmd
= 'd_player') then
4770 if (Length(P
) > 1) and
4771 ((P
[1] = '1') or (P
[1] = '0')) then
4772 g_debug_Player
:= (P
[1][1] = '1');
4774 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4776 else if (cmd
= 'd_mem') then
4782 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4786 procedure GameCheats(P
: SSArray
);
4792 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4794 g_Console_Add('not available');
4800 g_Console_Add('where is the player?!');
4803 cmd
:= LowerCase(P
[0]);
4807 plr
.GodMode
:= not plr
.GodMode
;
4808 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4811 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4812 if cmd
= 'give' then
4814 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4815 for f
:= 1 to High(P
) do
4817 cmd
:= LowerCase(P
[f
]);
4818 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4819 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4820 if cmd
= 'exit' then
4822 if gTriggers
<> nil then
4824 for a
:= 0 to High(gTriggers
) do
4826 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4828 g_Console_Add('player left the map');
4829 gExitByTrigger
:= True;
4830 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4831 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4839 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4840 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4841 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4842 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4843 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4845 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4846 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4848 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4849 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;
4851 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4852 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4854 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4855 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4857 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4858 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4860 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4861 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4862 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4864 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4865 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4866 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4867 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;
4868 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4869 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4871 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;
4872 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;
4873 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;
4874 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;
4875 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;
4876 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;
4878 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4879 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;
4881 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;
4882 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;
4884 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4886 if cmd
= 'ammo' then
4888 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4889 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4890 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4891 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4892 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4893 g_Console_Add('player got some ammo');
4897 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4898 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4900 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4901 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4903 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4904 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4906 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4907 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4909 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4911 if cmd
= 'weapons' then
4913 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4914 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4915 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4916 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4917 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4918 plr
.GiveItem(ITEM_WEAPON_BFG
);
4919 g_Console_Add('player got weapons');
4923 if cmd
= 'keys' then
4925 plr
.GiveItem(ITEM_KEY_RED
);
4926 plr
.GiveItem(ITEM_KEY_GREEN
);
4927 plr
.GiveItem(ITEM_KEY_BLUE
);
4928 g_Console_Add('player got all keys');
4932 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4937 if cmd
= 'open' then
4939 g_Console_Add('player activated sesame');
4940 g_Triggers_OpenAll();
4947 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4951 if cmd
= 'noclip' then
4954 g_Console_Add('wall hardeness adjusted');
4958 if cmd
= 'notarget' then
4960 plr
.NoTarget
:= not plr
.NoTarget
;
4961 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4965 if cmd
= 'noreload' then
4967 plr
.NoReload
:= not plr
.NoReload
;
4968 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4972 if cmd
= 'speedy' then
4974 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4975 g_Console_Add('speed adjusted');
4979 if cmd
= 'jumpy' then
4981 VEL_JUMP
:= 30-VEL_JUMP
;
4982 g_Console_Add('jump height adjusted');
4986 if cmd
= 'automap' then
4988 gShowMap
:= not gShowMap
;
4989 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4993 if cmd
= 'aimline' then
4995 gAimLine
:= not gAimLine
;
4996 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
5001 procedure GameCommands(P
: SSArray
);
5007 pl
: pTNetClient
= nil;
5015 cmd
:= LowerCase(P
[0]);
5017 if cmd
= 'pause' then
5019 {$IFDEF ENABLE_MENU}
5020 if (g_ActiveWindow
= nil) then
5021 g_Game_Pause(not gPauseMain
);
5023 g_Game_Pause(not gPauseMain
);
5026 else if cmd
= 'endgame' then
5027 gExit
:= EXIT_SIMPLE
5028 else if cmd
= 'restart' then
5030 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5032 if g_Game_IsClient
then
5034 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5039 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5041 else if cmd
= 'kick' then
5043 if g_Game_IsServer
then
5045 if Length(P
) < 2 then
5047 g_Console_Add('kick <name>');
5052 g_Console_Add('kick <name>');
5056 if g_Game_IsNet
then
5057 pl
:= g_Net_Client_ByName(P
[1]);
5060 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5061 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5062 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5063 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5064 g_Net_Slist_ServerPlayerLeaves();
5065 end else if gPlayers
<> nil then
5066 for a
:= Low(gPlayers
) to High(gPlayers
) do
5067 if gPlayers
[a
] <> nil then
5068 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5070 // Не отключать основных игроков в сингле
5071 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5073 gPlayers
[a
].Lives
:= 0;
5074 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5075 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5076 g_Player_Remove(gPlayers
[a
].UID
);
5077 g_Net_Slist_ServerPlayerLeaves();
5078 // Если не перемешать, при добавлении новых ботов появятся старые
5082 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5084 else if cmd
= 'kick_id' then
5086 if g_Game_IsServer
and g_Game_IsNet
then
5088 if Length(P
) < 2 then
5090 g_Console_Add('kick_id <client ID>');
5095 g_Console_Add('kick_id <client ID>');
5099 a
:= StrToIntDef(P
[1], 0);
5100 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5102 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5104 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5105 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
5106 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5107 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5108 g_Net_Slist_ServerPlayerLeaves();
5112 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5114 else if cmd
= 'kick_pid' then
5116 if g_Game_IsServer
and g_Game_IsNet
then
5118 if Length(P
) < 2 then
5120 g_Console_Add('kick_pid <player ID>');
5125 g_Console_Add('kick_pid <player ID>');
5129 a
:= StrToIntDef(P
[1], 0);
5130 pl
:= g_Net_Client_ByPlayer(a
);
5131 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5133 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5134 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5135 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5136 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5137 g_Net_Slist_ServerPlayerLeaves();
5140 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5142 else if cmd
= 'ban' then
5144 if g_Game_IsServer
and g_Game_IsNet
then
5146 if Length(P
) < 2 then
5148 g_Console_Add('ban <name>');
5153 g_Console_Add('ban <name>');
5157 pl
:= g_Net_Client_ByName(P
[1]);
5160 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5161 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5162 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5163 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5164 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5165 g_Net_Slist_ServerPlayerLeaves();
5167 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5169 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5171 else if cmd
= 'ban_id' then
5173 if g_Game_IsServer
and g_Game_IsNet
then
5175 if Length(P
) < 2 then
5177 g_Console_Add('ban_id <client ID>');
5182 g_Console_Add('ban_id <client ID>');
5186 a
:= StrToIntDef(P
[1], 0);
5187 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5188 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5190 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5191 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5192 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5193 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5194 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5195 g_Net_Slist_ServerPlayerLeaves();
5198 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5200 else if cmd
= 'ban_pid' then
5202 if g_Game_IsServer
and g_Game_IsNet
then
5204 if Length(P
) < 2 then
5206 g_Console_Add('ban_pid <player ID>');
5211 g_Console_Add('ban_pid <player ID>');
5215 a
:= StrToIntDef(P
[1], 0);
5216 pl
:= g_Net_Client_ByPlayer(a
);
5217 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5219 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5220 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5221 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5222 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5223 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5224 g_Net_Slist_ServerPlayerLeaves();
5227 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5229 else if cmd
= 'permban' then
5231 if g_Game_IsServer
and g_Game_IsNet
then
5233 if Length(P
) < 2 then
5235 g_Console_Add('permban <name>');
5240 g_Console_Add('permban <name>');
5244 pl
:= g_Net_Client_ByName(P
[1]);
5247 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5248 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5249 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5250 g_Net_SaveBanList();
5251 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5252 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5253 g_Net_Slist_ServerPlayerLeaves();
5255 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5257 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5259 else if cmd
= 'permban_id' then
5261 if g_Game_IsServer
and g_Game_IsNet
then
5263 if Length(P
) < 2 then
5265 g_Console_Add('permban_id <client ID>');
5270 g_Console_Add('permban_id <client ID>');
5274 a
:= StrToIntDef(P
[1], 0);
5275 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5276 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5278 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5279 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5280 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5281 g_Net_SaveBanList();
5282 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5283 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5284 g_Net_Slist_ServerPlayerLeaves();
5287 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5289 else if cmd
= 'permban_pid' then
5291 if g_Game_IsServer
and g_Game_IsNet
then
5293 if Length(P
) < 2 then
5295 g_Console_Add('permban_pid <player ID>');
5300 g_Console_Add('permban_pid <player ID>');
5304 a
:= StrToIntDef(P
[1], 0);
5305 pl
:= g_Net_Client_ByPlayer(a
);
5306 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5308 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5309 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5310 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5311 g_Net_SaveBanList();
5312 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5313 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5314 g_Net_Slist_ServerPlayerLeaves();
5317 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5319 else if cmd
= 'permban_ip' then
5321 if g_Game_IsServer
and g_Game_IsNet
then
5323 if Length(P
) < 2 then
5325 g_Console_Add('permban_ip <IP address>');
5330 g_Console_Add('permban_ip <IP address>');
5334 g_Net_BanHost(P
[1]);
5335 g_Net_SaveBanList();
5336 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5338 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5340 else if cmd
= 'unban' then
5342 if g_Game_IsServer
and g_Game_IsNet
then
5344 if Length(P
) < 2 then
5346 g_Console_Add('unban <IP Address>');
5351 g_Console_Add('unban <IP Address>');
5355 if g_Net_UnbanHost(P
[1]) then
5357 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5358 g_Net_SaveBanList();
5360 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5362 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5364 else if cmd
= 'clientlist' then
5366 if g_Game_IsServer
and g_Game_IsNet
then
5369 if NetClients
<> nil then
5370 for a
:= Low(NetClients
) to High(NetClients
) do
5371 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5373 plr
:= g_Player_Get(NetClients
[a
].Player
);
5374 if plr
= nil then continue
;
5376 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5377 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5380 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5382 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5384 else if cmd
= 'connect' then
5386 if (NetMode
= NET_NONE
) then
5388 if Length(P
) < 2 then
5390 g_Console_Add('connect <IP> [port] [password]');
5395 g_Console_Add('connect <IP> [port] [password]');
5399 if Length(P
) > 2 then
5400 prt
:= StrToIntDef(P
[2], 25666)
5404 if Length(P
) > 3 then
5409 g_Game_StartClient(P
[1], prt
, pw
);
5412 else if cmd
= 'disconnect' then
5414 if (NetMode
= NET_CLIENT
) then
5417 else if cmd
= 'reconnect' then
5419 if (NetMode
= NET_SERVER
) then
5422 if (NetMode
= NET_CLIENT
) then
5425 gExit
:= EXIT_SIMPLE
;
5429 //TODO: Use last successful password to reconnect, instead of ''
5430 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5432 else if (cmd
= 'addbot') or
5433 (cmd
= 'bot_add') then
5435 if Length(P
) > 2 then
5436 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5437 else if Length(P
) > 1 then
5438 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5440 g_Bot_Add(TEAM_NONE
, 2);
5442 else if cmd
= 'bot_addlist' then
5444 if Length(P
) > 1 then
5446 if Length(P
) = 2 then
5447 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5448 else if Length(P
) = 3 then
5449 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5451 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5454 else if cmd
= 'bot_removeall' then
5456 else if cmd
= 'chat' then
5458 if g_Game_IsNet
then
5460 if Length(P
) > 1 then
5462 for a
:= 1 to High(P
) do
5463 chstr
:= chstr
+ P
[a
] + ' ';
5465 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5467 if Length(chstr
) < 1 then
5469 g_Console_Add('chat <text>');
5473 chstr
:= b_Text_Format(chstr
);
5474 if g_Game_IsClient
then
5475 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5477 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5480 g_Console_Add('chat <text>');
5482 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5484 else if cmd
= 'teamchat' then
5486 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5488 if Length(P
) > 1 then
5490 for a
:= 1 to High(P
) do
5491 chstr
:= chstr
+ P
[a
] + ' ';
5493 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5495 if Length(chstr
) < 1 then
5497 g_Console_Add('teamchat <text>');
5501 chstr
:= b_Text_Format(chstr
);
5502 if g_Game_IsClient
then
5503 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5505 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5506 gPlayer1Settings
.Team
);
5509 g_Console_Add('teamchat <text>');
5511 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5513 else if (cmd
= 'an') or (cmd
= 'announce') then
5515 if g_Game_IsNet
then
5517 if Length(P
) > 1 then
5519 for a
:= 1 to High(P
) do
5520 chstr
:= chstr
+ P
[a
] + ' ';
5522 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5524 if Length(chstr
) < 1 then
5526 g_Console_Add('announce <text>');
5530 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5531 if g_Game_IsClient
then
5532 MC_SEND_RCONCommand(chstr
)
5534 g_Console_Process(chstr
, True);
5537 g_Console_Add('announce <text>');
5539 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5541 else if cmd
= 'game' then
5543 if gGameSettings
.GameType
<> GT_NONE
then
5545 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5548 if Length(P
) = 1 then
5550 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5553 // game not started yet, load fist map from some wad
5555 s
:= addWadExtension(P
[1]);
5556 found
:= e_FindResource(AllMapDirs
, s
);
5560 P
[1] := ExpandFileName(P
[1]);
5561 // if map not choosed then set first map
5562 if Length(P
) < 3 then
5565 P
[2] := g_Game_GetFirstMap(P
[1]);
5568 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5570 if g_Map_Exist(s
) then
5574 with gGameSettings
do
5576 Options
:= gsGameFlags
;
5577 GameMode
:= g_Game_TextToMode(gsGameMode
);
5578 if gSwitchGameMode
<> GM_NONE
then
5579 GameMode
:= gSwitchGameMode
;
5580 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5581 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5583 if Length(P
) >= 4 then
5584 b
:= StrToIntDef(P
[3], 1);
5585 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5586 ScoreLimit
, MaxLives
, Options
, b
);
5591 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5593 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5595 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5597 else if cmd
= 'host' then
5599 if gGameSettings
.GameType
<> GT_NONE
then
5601 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5604 if Length(P
) < 4 then
5606 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5609 if not StrToIp(P
[1], listen
) then
5611 prt
:= StrToIntDef(P
[2], 25666);
5613 s
:= addWadExtension(P
[3]);
5614 found
:= e_FindResource(AllMapDirs
, s
);
5618 // get first map in wad, if not specified
5619 if Length(P
) < 5 then
5622 P
[4] := g_Game_GetFirstMap(P
[1]);
5624 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5625 if g_Map_Exist(s
) then
5629 with gGameSettings
do
5631 Options
:= gsGameFlags
;
5632 GameMode
:= g_Game_TextToMode(gsGameMode
);
5633 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5634 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5635 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5637 if Length(P
) >= 6 then
5638 b
:= StrToIntDef(P
[5], 0);
5639 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5645 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5647 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5652 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5655 else if cmd
= 'map' then
5657 if Length(P
) = 1 then
5659 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5661 g_Console_Add(cmd
+ ' <MAP>');
5662 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5666 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5671 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5673 if Length(P
) < 3 then
5675 // first param is map or wad
5676 s
:= UpperCase(P
[1]);
5677 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5679 gExitByTrigger
:= False;
5682 // already in game, finish current map
5684 gExit
:= EXIT_ENDLEVELCUSTOM
;
5688 // intermission, so change map immediately
5695 found
:= e_FindResource(AllMapDirs
, s
);
5697 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5700 // no such map, found wad
5703 P
[1] := ExpandFileName(pw
);
5704 P
[2] := g_Game_GetFirstMap(P
[1]);
5705 s
:= P
[1] + ':\' + P
[2];
5706 if g_Map_Exist(s
) then
5708 gExitByTrigger
:= False;
5711 // already in game, finish current map
5713 gExit
:= EXIT_ENDLEVELCUSTOM
5717 // intermission, so change map immediately
5724 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5726 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5731 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5737 s
:= addWadExtension(P
[1]);
5738 found
:= e_FindResource(AllMapDirs
, s
);
5742 P
[2] := UpperCase(P
[2]);
5743 s
:= P
[1] + ':\' + P
[2];
5744 if g_Map_Exist(s
) then
5746 gExitByTrigger
:= False;
5750 gExit
:= EXIT_ENDLEVELCUSTOM
5759 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5764 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5770 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5774 else if cmd
= 'nextmap' then
5776 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5778 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5783 if Length(P
) = 1 then
5785 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5787 g_Console_Add(cmd
+ ' <MAP>');
5788 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5793 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5799 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5801 if Length(P
) < 3 then
5803 // first param is map or wad
5804 s
:= UpperCase(P
[1]);
5805 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5808 gExitByTrigger
:= False;
5814 // no such map, found wad
5815 pw
:= addWadExtension(P
[1]);
5816 found
:= e_FindResource(MapDirs
, pw
);
5818 found
:= e_FindResource(WadDirs
, pw
);
5820 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5823 // map not specified, select first map
5825 P
[2] := g_Game_GetFirstMap(P
[1]);
5826 s
:= P
[1] + ':\' + P
[2];
5827 if g_Map_Exist(s
) then
5829 gExitByTrigger
:= False;
5836 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5838 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5843 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5849 // specified two params wad + map
5850 pw
:= addWadExtension(P
[1]);
5851 found
:= e_FindResource(MapDirs
, pw
);
5853 found
:= e_FindResource(MapDirs
, pw
);
5857 P
[2] := UpperCase(P
[2]);
5858 s
:= P
[1] + ':\' + P
[2];
5859 if g_Map_Exist(s
) then
5861 gExitByTrigger
:= False;
5867 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5872 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5878 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5883 if gNextMap
= '' then
5884 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5886 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5890 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5894 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5898 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5900 gExitByTrigger
:= False;
5901 // next map not specified, try to find trigger EXIT
5902 if (gNextMap
= '') and (gTriggers
<> nil) then
5904 for a
:= 0 to High(gTriggers
) do
5906 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5908 gExitByTrigger
:= True;
5909 //gNextMap := gTriggers[a].Data.MapName;
5910 gNextMap
:= gTriggers
[a
].tgcMap
;
5915 if gNextMap
= '' then
5916 gNextMap
:= g_Game_GetNextMap();
5917 if not isWadPath(gNextMap
) then
5918 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5921 if g_Map_Exist(s
) then
5922 gExit
:= EXIT_ENDLEVELCUSTOM
5924 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5928 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5932 else if (cmd
= 'event') then
5934 if (Length(P
) <= 1) then
5936 for a
:= 0 to High(gEvents
) do
5937 if gEvents
[a
].Command
= '' then
5938 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5940 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5943 if (Length(P
) = 2) then
5945 for a
:= 0 to High(gEvents
) do
5946 if gEvents
[a
].Name
= P
[1] then
5947 if gEvents
[a
].Command
= '' then
5948 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5950 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5953 for a
:= 0 to High(gEvents
) do
5954 if gEvents
[a
].Name
= P
[1] then
5956 gEvents
[a
].Command
:= '';
5957 for b
:= 2 to High(P
) do
5958 if Pos(' ', P
[b
]) = 0 then
5959 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5961 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5962 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5966 else if cmd
= 'suicide' then
5970 if g_Game_IsClient
then
5971 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5974 if gPlayer1
<> nil then
5975 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5976 if gPlayer2
<> nil then
5977 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5981 else if cmd
= 'screenshot' then
5983 {$IFDEF ENABLE_RENDER}
5987 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5989 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5991 gWeaponAction
[0, WP_PREV
] := True;
5993 gWeaponAction
[0, WP_NEXT
] := True;
5995 else if cmd
= 'weapon' then
5997 if Length(p
) = 2 then
5999 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
6000 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6001 gSelectWeapon
[0, a
] := True
6004 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
6005 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
6007 a
:= 1 - (ord(cmd
[8]) - ord('n'));
6008 b
:= ord(cmd
[2]) - ord('1');
6010 gWeaponAction
[b
, WP_PREV
] := True;
6012 gWeaponAction
[b
, WP_NEXT
] := True;
6014 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
6016 if Length(p
) = 2 then
6018 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
6019 b
:= ord(cmd
[2]) - ord('1');
6020 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6021 gSelectWeapon
[b
, a
] := True
6024 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
6026 b
:= ord(cmd
[2]) - ord('1');
6028 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
6030 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
6032 else if (cmd
= 'dropflag') then
6034 if g_Game_IsServer
then
6036 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
6037 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
6040 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6042 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
6044 b
:= ord(cmd
[2]) - ord('1');
6045 if g_Game_IsServer
then
6047 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
6048 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
6051 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6053 // Команды Своей игры:
6054 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6056 if cmd
= 'bot_addred' then
6058 if Length(P
) > 1 then
6059 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6061 g_Bot_Add(TEAM_RED
, 2);
6063 else if cmd
= 'bot_addblue' then
6065 if Length(P
) > 1 then
6066 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6068 g_Bot_Add(TEAM_BLUE
, 2);
6070 else if cmd
= 'spectate' then
6076 else if cmd
= 'say' then
6078 if g_Game_IsServer
and g_Game_IsNet
then
6080 if Length(P
) > 1 then
6083 for a
:= 1 to High(P
) do
6084 chstr
:= chstr
+ P
[a
] + ' ';
6086 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6088 if Length(chstr
) < 1 then
6090 g_Console_Add('say <text>');
6094 chstr
:= b_Text_Format(chstr
);
6095 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6097 else g_Console_Add('say <text>');
6099 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6101 else if cmd
= 'tell' then
6103 if g_Game_IsServer
and g_Game_IsNet
then
6105 if (Length(P
) > 2) and (P
[1] <> '') then
6108 for a
:= 2 to High(P
) do
6109 chstr
:= chstr
+ P
[a
] + ' ';
6111 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6113 if Length(chstr
) < 1 then
6115 g_Console_Add('tell <playername> <text>');
6119 pl
:= g_Net_Client_ByName(P
[1]);
6121 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6123 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6125 else g_Console_Add('tell <playername> <text>');
6127 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6129 else if cmd
= 'centerprint' then
6131 if (Length(P
) > 2) and (P
[1] <> '') then
6134 for a
:= 2 to High(P
) do
6135 chstr
:= chstr
+ P
[a
] + ' ';
6137 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6139 if Length(chstr
) < 1 then
6141 g_Console_Add('centerprint <timeout> <text>');
6145 a
:= StrToIntDef(P
[1], 100);
6146 chstr
:= b_Text_Format(chstr
);
6147 g_Game_Message(chstr
, a
);
6148 if g_Game_IsNet
and g_Game_IsServer
then
6149 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6151 else g_Console_Add('centerprint <timeout> <text>');
6153 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6155 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6157 // Дополнительное время:
6158 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6160 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6161 [gGameSettings
.TimeLimit
div 3600,
6162 (gGameSettings
.TimeLimit
div 60) mod 60,
6163 gGameSettings
.TimeLimit
mod 60]));
6164 if g_Game_IsNet
then MH_SEND_GameSettings
;
6166 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6168 if (Length(P
) <= 1) then
6169 g_Console_Add('rcon_password <password>')
6171 MC_SEND_RCONPassword(P
[1]);
6173 else if cmd
= 'rcon' then
6175 if g_Game_IsClient
then
6177 if Length(P
) > 1 then
6180 for a
:= 1 to High(P
) do
6181 chstr
:= chstr
+ P
[a
] + ' ';
6183 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6185 if Length(chstr
) < 1 then
6187 g_Console_Add('rcon <command>');
6191 MC_SEND_RCONCommand(chstr
);
6193 else g_Console_Add('rcon <command>');
6196 else if cmd
= 'ready' then
6198 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6199 gLMSRespawnTime
:= gTime
+ 100;
6201 else if (cmd
= 'callvote') and g_Game_IsNet
then
6203 if Length(P
) > 1 then
6206 for a
:= 1 to High(P
) do begin
6207 if a
> 1 then chstr
:= chstr
+ ' ';
6208 chstr
:= chstr
+ P
[a
];
6211 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6213 if Length(chstr
) < 1 then
6215 g_Console_Add('callvote <command>');
6219 if g_Game_IsClient
then
6220 MC_SEND_Vote(True, chstr
)
6222 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6223 g_Console_Process('vote', True);
6226 g_Console_Add('callvote <command>');
6228 else if (cmd
= 'vote') and g_Game_IsNet
then
6230 if g_Game_IsClient
then
6232 else if gVoteInProgress
then
6234 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6235 a
:= Floor((NetClientCount
+1)/2.0) + 1
6237 a
:= Floor(NetClientCount
/2.0) + 1;
6242 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6243 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6249 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6250 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6258 procedure SystemCommands(P
: SSArray
);
6262 cmd
:= LowerCase(P
[0]);
6269 {$IFDEF ENABLE_RENDER}
6275 if Length(p
) = 2 then
6277 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6279 gFrameTime
:= 1000 div gMaxFPS
6283 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6287 if Length(p
) = 2 then
6289 gAskLanguage
:= true;
6290 gLanguage
:= LANGUAGE_ENGLISH
;
6291 case LowerCase(p
[1]) of
6294 gAskLanguage
:= false;
6295 gLanguage
:= LANGUAGE_ENGLISH
;
6299 gAskLanguage
:= false;
6300 gLanguage
:= LANGUAGE_RUSSIAN
;
6304 gAskLanguage
:= true;
6305 gLanguage
:= LANGUAGE_ENGLISH
;
6308 g_Language_Set(gLanguage
);
6312 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6318 {$IFDEF ENABLE_RENDER}
6319 procedure g_TakeScreenShot(Filename
: string = '');
6320 var t
: TDateTime
; dir
, date
, name
: String;
6322 if e_NoGraphics
then
6325 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6326 if Filename
= '' then
6329 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6330 Filename
:= 'screenshot-' + date
;
6333 name
:= e_CatPath(dir
, Filename
+ '.png');
6334 if r_Render_WriteScreenShot(name
) then
6335 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6337 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6341 {$IFDEF ENABLE_MENU}
6342 procedure g_Game_InGameMenu(Show
: Boolean);
6344 if (g_ActiveWindow
= nil) and Show
then
6346 if gGameSettings
.GameType
= GT_SINGLE
then
6347 g_GUI_ShowWindow('GameSingleMenu')
6350 if g_Game_IsClient
then
6351 g_GUI_ShowWindow('GameClientMenu')
6353 if g_Game_IsNet
then
6354 g_GUI_ShowWindow('GameServerMenu')
6356 g_GUI_ShowWindow('GameCustomMenu');
6358 g_Sound_PlayEx('MENU_OPEN');
6360 // Пауза при меню только в одиночной игре:
6361 if (not g_Game_IsNet
) then
6365 if (g_ActiveWindow
<> nil) and (not Show
) then
6367 // Пауза при меню только в одиночной игре:
6368 if (not g_Game_IsNet
) then
6369 g_Game_Pause(False);
6374 procedure g_Game_Pause (Enable
: Boolean);
6378 if not gGameOn
then exit
;
6380 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6383 gPauseMain
:= Enable
;
6385 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6388 procedure g_Game_HolmesPause (Enable
: Boolean);
6392 if not gGameOn
then exit
;
6393 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6396 gPauseHolmes
:= Enable
;
6398 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6401 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6406 if gTriggers
<> nil then
6407 for i
:= 0 to High(gTriggers
) do
6408 with gTriggers
[i
] do
6409 if (TriggerType
= TRIGGER_SOUND
) and
6411 Sound
.IsPlaying() then
6413 Sound
.Pause(Enable
);
6417 if gPlayers
<> nil then
6418 for i
:= 0 to High(gPlayers
) do
6419 if gPlayers
[i
] <> nil then
6420 gPlayers
[i
].PauseSounds(Enable
);
6423 if gMusic
<> nil then
6424 gMusic
.Pause(Enable
);
6427 procedure g_Game_StopAllSounds(all
: Boolean);
6431 if gTriggers
<> nil then
6432 for i
:= 0 to High(gTriggers
) do
6433 with gTriggers
[i
] do
6434 if (TriggerType
= TRIGGER_SOUND
) and
6438 if gMusic
<> nil then
6445 procedure g_Game_UpdateTriggerSounds
;
6448 if gTriggers
<> nil then
6449 for i
:= 0 to High(gTriggers
) do
6450 with gTriggers
[i
] do
6451 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6452 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6455 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6458 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6463 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6468 if gSpectMode
<> SPECT_PLAYERS
then
6470 if gSpectPID1
= UID
then
6475 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6482 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6487 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6492 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6497 if gSpectMode
<> SPECT_PLAYERS
then
6499 Pl
:= g_Player_Get(gSpectPID1
);
6500 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6505 if gSpectViewTwo
then
6507 Pl
:= g_Player_Get(gSpectPID2
);
6508 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6516 procedure g_Game_Message (Msg
: string; Time
: Word);
6519 MessageTime
:= Time
;
6522 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6524 punct
: Array[0..13] of String =
6525 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6531 function IsPunctuation(S
: String): Boolean;
6536 if Length(S
) <> 1 then
6538 for i
:= Low(punct
) to High(punct
) do
6539 if S
= punct
[i
] then
6545 function FilterPunctuation(S
: String): String;
6549 for i
:= Low(punct
) to High(punct
) do
6550 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6556 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6558 // remove player name
6559 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6560 // for FullWord check
6561 Text := toLowerCase1251(' ' + Text + ' ');
6562 fpText
:= FilterPunctuation(Text);
6564 for i
:= 0 to Length(gChatSounds
) - 1 do
6567 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6569 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6570 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6572 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6578 gChatSounds
[i
].Sound
.Play();
6584 g_Sound_PlayEx('SOUND_GAME_RADIO');
6587 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6596 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6600 if goodsnd
[a
].IsPlaying() then
6603 goodsnd
[Random(4)].Play();
6606 procedure g_Game_Announce_KillCombo(Param
: Integer);
6613 UID
:= Param
and $FFFF;
6618 Pl
:= g_Player_Get(UID
);
6627 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6631 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6635 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6639 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6647 if not g_Game_IsWatchedPlayer(UID
) then
6650 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6654 if killsnd
[n
].IsPlaying() then
6659 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6667 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6671 if hahasnd
[a
].IsPlaying() then
6674 hahasnd
[Random(3)].Play();
6677 procedure g_Game_StartVote(Command
, Initiator
: string);
6681 if not gVotesEnabled
then Exit
;
6682 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6683 if gVoteInProgress
or gVotePassed
then
6685 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6686 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6689 gVoteInProgress
:= True;
6690 gVotePassed
:= False;
6691 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6694 gVoteCommand
:= Command
;
6696 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6697 Need
:= Floor((NetClientCount
+1)/2.0)+1
6699 Need
:= Floor(NetClientCount
/2.0)+1;
6700 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6701 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6704 procedure g_Game_CheckVote
;
6708 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6709 if not gVoteInProgress
then Exit
;
6711 if (gTime
>= gVoteTimer
) then
6713 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6714 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6716 Need
:= Floor(NetClientCount
/2.0) + 1;
6717 if gVoteCount
>= Need
then
6719 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6720 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6721 gVotePassed
:= True;
6722 gVoteCmdTimer
:= gTime
+ 5000;
6726 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6727 MH_SEND_VoteEvent(NET_VE_FAILED
);
6729 if NetClients
<> nil then
6730 for I
:= Low(NetClients
) to High(NetClients
) do
6731 if NetClients
[i
].Used
then
6732 NetClients
[i
].Voted
:= False;
6733 gVoteInProgress
:= False;
6739 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6740 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6742 Need
:= Floor(NetClientCount
/2.0) + 1;
6743 if gVoteCount
>= Need
then
6745 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6746 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6747 gVoteInProgress
:= False;
6748 gVotePassed
:= True;
6749 gVoteCmdTimer
:= gTime
+ 5000;
6752 if NetClients
<> nil then
6753 for I
:= Low(NetClients
) to High(NetClients
) do
6754 if NetClients
[i
].Used
then
6755 NetClients
[i
].Voted
:= False;
6760 procedure g_Game_LoadMapList(FileName
: string);
6768 if not FileExists(FileName
) then Exit
;
6770 AssignFile(ListFile
, FileName
);
6772 while not EOF(ListFile
) do
6774 ReadLn(ListFile
, s
);
6777 if s
= '' then Continue
;
6779 SetLength(MapList
, Length(MapList
)+1);
6780 MapList
[High(MapList
)] := s
;
6782 CloseFile(ListFile
);
6785 procedure g_Game_SetDebugMode();
6788 // Читы (даже в своей игре):
6792 procedure Parse_Params(var pars
: TParamStrValues
);
6799 while i
<= ParamCount
do
6802 if (Length(s
) > 1) and (s
[1] = '-') then
6804 if (Length(s
) > 2) and (s
[2] = '-') then
6805 begin // Одиночный параметр
6806 SetLength(pars
, Length(pars
) + 1);
6807 with pars
[High(pars
)] do
6809 Name
:= LowerCase(s
);
6814 if (i
< ParamCount
) then
6815 begin // Параметр со значением
6817 SetLength(pars
, Length(pars
) + 1);
6818 with pars
[High(pars
)] do
6820 Name
:= LowerCase(s
);
6821 Value
:= LowerCase(ParamStr(i
));
6830 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6835 for i
:= 0 to High(pars
) do
6836 if pars
[i
].Name
= aName
then
6838 Result
:= pars
[i
].Value
;
6843 procedure g_Game_Process_Params();
6845 pars
: TParamStrValues
;
6848 LimT
, LimS
: Integer;
6859 s
:= Find_Param_Value(pars
, '--debug');
6862 g_Game_SetDebugMode();
6863 s
:= Find_Param_Value(pars
, '--netdump');
6868 // Connect when game loads
6869 ip
:= Find_Param_Value(pars
, '-connect');
6873 s
:= Find_Param_Value(pars
, '-port');
6874 if (s
= '') or not TryStrToInt(s
, Port
) then
6877 s
:= Find_Param_Value(pars
, '-pw');
6879 g_Game_StartClient(ip
, Port
, s
);
6883 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6886 gDefaultMegawadStart
:= s
;
6889 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6890 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6892 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6895 // Start map when game loads:
6896 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6897 if isWadPath(map
) then
6900 s
:= Find_Param_Value(pars
, '-gm');
6901 GMode
:= g_Game_TextToMode(s
);
6902 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6903 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6906 s
:= Find_Param_Value(pars
, '-limt');
6907 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6913 s
:= Find_Param_Value(pars
, '-lims');
6914 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6920 s
:= Find_Param_Value(pars
, '-lives');
6921 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6927 s
:= Find_Param_Value(pars
, '-opt');
6931 Opt
:= StrToIntDef(s
, 0);
6934 s
:= Find_Param_Value(pars
, '--close');
6938 // Override map to test:
6939 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6942 if e_IsValidResourceName(s
) then
6943 e_FindResource(AllMapDirs
, s
);
6944 gTestMap
:= ExpandFileName(s
);
6947 // Delete test map after play:
6948 s
:= Find_Param_Value(pars
, '--testdelete');
6951 //gMapToDelete := MapsDir + map;
6952 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6956 // Delete temporary WAD after play:
6957 s
:= Find_Param_Value(pars
, '--tempdelete');
6958 if (s
<> '') and (gTestMap
<> '') then
6960 gMapToDelete
:= gTestMap
;
6961 gTempDelete
:= True;
6964 // Number of players:
6965 s
:= Find_Param_Value(pars
, '-pl');
6967 n
:= DEFAULT_PLAYERS
6969 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6972 s
:= Find_Param_Value(pars
, '-port');
6973 if (s
= '') or not TryStrToInt(s
, Port
) then
6974 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6976 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6979 // Execute script when game loads:
6980 s
:= Find_Param_Value(pars
, '-exec');
6983 // if not isWadPath(s) then
6984 // s := GameDir + '/' + s;
6989 if IOResult
<> 0 then
6991 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6992 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6996 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6997 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7002 if IOResult
<> 0 then
7004 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7005 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7009 if Pos('#', s
) <> 1 then // script comment
7010 g_Console_Process(s
, True);
7021 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7022 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7023 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7024 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7026 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7027 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7028 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7029 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7032 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7033 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7036 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7037 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7039 {$IFDEF ENABLE_HOLMES}
7040 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7043 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7045 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7046 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7048 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7049 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7051 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
7052 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
7053 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
7054 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
7055 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7056 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7057 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7058 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7059 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');