1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 g_base
, g_basic
, g_player
, r_graphics
, g_res_downloader
,
24 g_sound
, g_gui
, utils
, md5
, mempool
, xprofiler
,
28 TGameSettings
= record
35 ItemRespawnTime
: Word;
46 TDelayedEvent
= record
55 Sound
: TPlayableSound
;
56 Tags
: Array of String;
60 TPlayerSettings
= record
65 // ones below are sent only to the server
67 WeaponPreferences
: Array[WP_FIRST
..WP_LAST
+1] of Byte;
84 function g_Game_IsNet(): Boolean;
85 function g_Game_IsServer(): Boolean;
86 function g_Game_IsClient(): Boolean;
87 procedure g_Game_Init();
88 procedure g_Game_Free (freeTextures
: Boolean=true);
89 procedure g_Game_LoadData();
90 procedure g_Game_FreeData();
91 procedure g_Game_Update();
92 procedure g_Game_PreUpdate();
93 procedure g_Game_Quit();
94 function g_Game_ModeToText(Mode
: Byte): string;
95 function g_Game_TextToMode(Mode
: string): Byte;
96 procedure g_Game_ExecuteEvent(Name
: String);
97 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
98 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
99 procedure g_Game_RemovePlayer();
100 procedure g_Game_Spectate();
101 procedure g_Game_SpectateCenterView();
102 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
103 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
104 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
105 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
106 procedure g_Game_Restart();
107 procedure g_Game_RestartLevel();
108 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
109 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
110 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
111 procedure g_Game_ChangeMap(const MapPath
: String);
112 procedure g_Game_ExitLevel(const Map
: AnsiString);
113 function g_Game_GetFirstMap(WAD
: String): String;
114 function g_Game_GetNextMap(): String;
115 procedure g_Game_NextLevel();
116 procedure g_Game_Pause(Enable
: Boolean);
117 procedure g_Game_HolmesPause(Enable
: Boolean);
118 procedure g_Game_InGameMenu(Show
: Boolean);
119 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
120 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
121 procedure g_Game_Message(Msg
: String; Time
: Word);
122 procedure g_Game_LoadMapList(FileName
: String);
123 procedure g_Game_PauseAllSounds(Enable
: Boolean);
124 procedure g_Game_StopAllSounds(all
: Boolean);
125 procedure g_Game_UpdateTriggerSounds();
126 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
127 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
128 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
129 procedure g_Game_Announce_KillCombo(Param
: Integer);
130 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
131 procedure g_Game_StartVote(Command
, Initiator
: string);
132 procedure g_Game_CheckVote
;
133 procedure g_TakeScreenShot(Filename
: string = '');
134 procedure g_FatalError(Text: String);
135 procedure g_SimpleError(Text: String);
136 function g_Game_IsTestMap(): Boolean;
137 procedure g_Game_DeleteTestMap();
138 procedure GameCVars(P
: SSArray
);
139 procedure PlayerSettingsCVars(P
: SSArray
);
140 procedure SystemCommands(P
: SSArray
);
141 procedure GameCommands(P
: SSArray
);
142 procedure GameCheats(P
: SSArray
);
143 procedure DebugCommands(P
: SSArray
);
144 procedure g_Game_Process_Params
;
145 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
146 procedure g_Game_StepLoading(Value
: Integer = -1);
147 procedure g_Game_ClearLoading();
148 procedure g_Game_SetDebugMode();
150 function IsActivePlayer(p
: TPlayer
): Boolean;
151 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
152 procedure SortGameStat(var stat
: TPlayerStatArray
);
154 procedure KeyPress (K
: Word);
155 procedure CharPress (C
: AnsiChar);
157 { procedure SetWinPause(Enable: Boolean); }
162 LOADING_SHOW_STEP
= 100;
163 LOADING_INTERLINE
= 20;
178 MESSAGE_DIKEY
= WM_USER
+ 1;
183 EXIT_ENDLEVELSINGLE
= 4;
184 EXIT_ENDLEVELCUSTOM
= 5;
186 GAME_OPTION_RESERVED
= 1;
187 GAME_OPTION_TEAMDAMAGE
= 2;
188 GAME_OPTION_ALLOWEXIT
= 4;
189 GAME_OPTION_WEAPONSTAY
= 8;
190 GAME_OPTION_MONSTERS
= 16;
191 GAME_OPTION_BOTVSPLAYER
= 32;
192 GAME_OPTION_BOTVSMONSTER
= 64;
193 GAME_OPTION_DMKEYS
= 128;
194 GAME_OPTION_TEAMHITTRACE
= 256;
195 GAME_OPTION_TEAMHITPROJECTILE
= 512;
196 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
197 GAME_OPTION_ALLOWDROPFLAG
= 2048;
198 GAME_OPTION_THROWFLAG
= 4096;
203 STATE_INTERCUSTOM
= 3;
204 STATE_INTERSINGLE
= 4;
210 LMS_RESPAWN_NONE
= 0;
211 LMS_RESPAWN_WARMUP
= 1;
212 LMS_RESPAWN_FINAL
= 2;
229 CONFIG_FILENAME
= 'Doom2DF.cfg';
231 TEST_MAP_NAME
= '$$$_TEST_$$$';
233 STD_PLAYER_MODEL
= 'Doomer';
241 STATFILE_VERSION
= $03;
244 gGameSettings
: TGameSettings
;
245 gPlayer1Settings
: TPlayerSettings
;
246 gPlayer2Settings
: TPlayerSettings
;
248 gPlayerScreenSize
: TDFPoint
;
249 gPlayer1ScreenCoord
: TDFPoint
;
250 gPlayer2ScreenCoord
: TDFPoint
;
251 gPlayer1
: TPlayer
= nil;
252 gPlayer2
: TPlayer
= nil;
253 gPlayerDrawn
: TPlayer
= nil;
255 gLerpFactor
: Single = 1.0;
256 gSwitchGameMode
: Byte = GM_DM
;
257 gHearPoint1
, gHearPoint2
: THearPoint
;
258 gSoundEffectsDF
: Boolean = False;
259 gSoundTriggerTime
: Word = 0;
260 gAnnouncer
: Integer = ANNOUNCE_NONE
;
261 goodsnd
: array[0..3] of TPlayableSound
;
262 killsnd
: array[0..3] of TPlayableSound
;
263 hahasnd
: array[0..2] of TPlayableSound
;
264 sound_get_flag
: array[0..1] of TPlayableSound
;
265 sound_lost_flag
: array[0..1] of TPlayableSound
;
266 sound_ret_flag
: array[0..1] of TPlayableSound
;
267 sound_cap_flag
: array[0..1] of TPlayableSound
;
268 gBodyKillEvent
: Integer = -1;
269 gDefInterTime
: ShortInt = -1;
270 gInterEndTime
: LongWord = 0;
271 gInterTime
: LongWord = 0;
272 gServInterTime
: Byte = 0;
273 gGameStartTime
: LongWord = 0;
274 gTotalMonsters
: Integer = 0;
275 gPauseMain
: Boolean = false;
276 gPauseHolmes
: Boolean = false;
277 gShowTime
: Boolean = False;
278 gShowFPS
: Boolean = False;
279 gShowScore
: Boolean = True;
280 gShowStat
: Boolean = True;
281 gShowPIDs
: Boolean = False;
282 gShowKillMsg
: Boolean = True;
283 gShowLives
: Boolean = True;
284 gShowPing
: Boolean = False;
285 gShowMap
: Boolean = False;
287 gState
: Byte = STATE_NONE
;
289 sWidth
, sHeight
: Word;
290 gSpectMode
: Byte = SPECT_NONE
;
291 gSpectHUD
: Boolean = True;
292 gSpectKeyPress
: Boolean = False;
293 gSpectX
: Integer = 0;
294 gSpectY
: Integer = 0;
295 gSpectStep
: Byte = 8;
296 gSpectViewTwo
: Boolean = False;
297 gSpectPID1
: Integer = -1;
298 gSpectPID2
: Integer = -1;
299 gSpectAuto
: Boolean = False;
300 gSpectAutoNext
: LongWord;
301 gSpectAutoStepX
: Integer;
302 gSpectAutoStepY
: Integer;
303 gMusic
: TMusic
= nil;
304 gLoadGameMode
: Boolean;
305 gCheats
: Boolean = False;
306 gMapOnce
: Boolean = False;
307 gMapToDelete
: String;
308 gTempDelete
: Boolean = False;
309 gLastMap
: Boolean = False;
312 gResolutionChange
: Boolean = False;
313 gRC_Width
, gRC_Height
: Integer;
314 gRC_FullScreen
, gRC_Maximized
: Boolean;
315 gLanguageChange
: Boolean = False;
316 gDebugMode
: Boolean = False;
317 g_debug_Sounds
: Boolean = False;
318 g_debug_Frames
: Boolean = False;
319 g_debug_WinMsgs
: Boolean = False;
320 g_debug_MonsterOff
: Boolean = False;
321 g_debug_BotAIOff
: Byte = 0;
322 g_debug_HealthBar
: Boolean = False;
323 g_Debug_Player
: Boolean = False;
324 gCoopMonstersKilled
: Word = 0;
325 gCoopSecretsFound
: Word = 0;
326 gCoopTotalMonstersKilled
: Word = 0;
327 gCoopTotalSecretsFound
: Word = 0;
328 gCoopTotalMonsters
: Word = 0;
329 gCoopTotalSecrets
: Word = 0;
330 gStatsOff
: Boolean = False;
331 gStatsPressed
: Boolean = False;
332 gExitByTrigger
: Boolean = False;
333 gNextMap
: String = '';
334 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
335 gLMSRespawnTime
: Cardinal = 0;
336 gLMSSoftSpawn
: Boolean = False;
337 gMissionFailed
: Boolean = False;
338 gVoteInProgress
: Boolean = False;
339 gVotePassed
: Boolean = False;
340 gVoteCommand
: string = '';
341 gVoteTimer
: Cardinal = 0;
342 gVoteCmdTimer
: Cardinal = 0;
343 gVoteCount
: Integer = 0;
344 gVoteTimeout
: Cardinal = 30;
345 gVoted
: Boolean = False;
346 gVotesEnabled
: Boolean = True;
347 gEvents
: Array of TGameEvent
;
348 gDelayedEvents
: Array of TDelayedEvent
;
349 gUseChatSounds
: Boolean = True;
350 gChatSounds
: Array of TChatSound
;
351 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
352 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
353 gInterReadyCount
: Integer = 0;
354 gMaxBots
: Integer = 127;
356 g_dbg_ignore_bounds
: Boolean = false;
357 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
358 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
360 // move button values:
361 // bits 0-1: l/r state:
362 // 0: neither left, nor right pressed
365 // bits 4-5: l/r state when strafe was pressed
366 P1MoveButton
: Byte = 0;
367 P2MoveButton
: Byte = 0;
369 g_profile_frame_update
: Boolean = false;
370 g_profile_frame_draw
: Boolean = false;
371 g_profile_collision
: Boolean = false;
372 g_profile_los
: Boolean = false;
373 g_profile_history_size
: Integer = 1000;
375 g_rlayer_back
: Boolean = true;
376 g_rlayer_step
: Boolean = true;
377 g_rlayer_wall
: Boolean = true;
378 g_rlayer_door
: Boolean = true;
379 g_rlayer_acid1
: Boolean = true;
380 g_rlayer_acid2
: Boolean = true;
381 g_rlayer_water
: Boolean = true;
382 g_rlayer_fore
: Boolean = true;
384 wNeedTimeReset
: Boolean = false;
386 procedure g_ResetDynlights ();
387 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
388 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
390 function conIsCheatsEnabled (): Boolean; inline;
391 function gPause (): Boolean; inline;
393 type (* private state *)
394 TEndCustomGameStat
= record
395 PlayerStat
: TPlayerStatArray
;
399 Map
, MapName
: String;
402 TEndSingleGameStat
= record
403 PlayerStat
: Array [0..1] of record
409 TotalSecrets
: Integer;
412 TLoadingStat
= record
416 Msgs
: Array of String;
418 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
422 x
, y
, radius
: Integer;
425 exploRadius
: Integer;
428 var (* private state *)
429 CustomStat
: TEndCustomGameStat
;
430 StatShotDone
: Boolean;
431 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
432 SingleStat
: TEndSingleGameStat
;
433 LoadingStat
: TLoadingStat
;
436 EndingGameCounter
: Byte;
438 g_playerLight
: Boolean;
439 g_dynLights
: array of TDynLight
= nil;
440 g_dynLightCount
: Integer = 0;
441 EndPicPath
: AnsiString; // full path, used by render
446 {$IFDEF ENABLE_HOLMES}
449 e_res
, g_window
, g_menu
, r_render
, r_gfx
,
450 e_input
, e_log
, g_console
, r_console
, g_items
, g_map
, g_panel
,
451 g_playermodel
, g_gfx
, g_options
, Math
,
452 g_triggers
, g_monsters
, e_sound
, CONFIG
,
453 g_language
, g_net
, g_phys
,
454 ENet
, e_msg
, g_netmsg
, g_netmaster
,
455 sfs
, wadreader
, g_system
, r_playermodel
;
458 charbuff
: packed array [0..15] of AnsiChar = (
459 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
462 function Translit (const S
: AnsiString): AnsiString;
467 for i
:= 1 to Length(Result
) do
470 #
$C9: Result
[i
] := 'Q';
471 #
$D6: Result
[i
] := 'W';
472 #
$D3: Result
[i
] := 'E';
473 #
$CA: Result
[i
] := 'R';
474 #
$C5: Result
[i
] := 'T';
475 #
$CD: Result
[i
] := 'Y';
476 #
$C3: Result
[i
] := 'U';
477 #
$D8: Result
[i
] := 'I';
478 #
$D9: Result
[i
] := 'O';
479 #
$C7: Result
[i
] := 'P';
480 #
$D5: Result
[i
] := '['; //Chr(219);
481 #
$DA: Result
[i
] := ']'; //Chr(221);
482 #
$D4: Result
[i
] := 'A';
483 #
$DB: Result
[i
] := 'S';
484 #
$C2: Result
[i
] := 'D';
485 #
$C0: Result
[i
] := 'F';
486 #
$CF: Result
[i
] := 'G';
487 #
$D0: Result
[i
] := 'H';
488 #
$CE: Result
[i
] := 'J';
489 #
$CB: Result
[i
] := 'K';
490 #
$C4: Result
[i
] := 'L';
491 #
$C6: Result
[i
] := ';'; //Chr(186);
492 #
$DD: Result
[i
] := #39; //Chr(222);
493 #
$DF: Result
[i
] := 'Z';
494 #
$D7: Result
[i
] := 'X';
495 #
$D1: Result
[i
] := 'C';
496 #
$CC: Result
[i
] := 'V';
497 #
$C8: Result
[i
] := 'B';
498 #
$D2: Result
[i
] := 'N';
499 #
$DC: Result
[i
] := 'M';
500 #
$C1: Result
[i
] := ','; //Chr(188);
501 #
$DE: Result
[i
] := '.'; //Chr(190);
507 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
512 ls2
:= Translit(CheatRus
[ct
]);
513 if length(ls1
) = 0 then ls1
:= '~';
514 if length(ls2
) = 0 then ls2
:= '~';
516 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
517 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
518 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
519 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
521 if ct = I_GAME_CHEAT_JETPACK then
523 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
524 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
525 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
526 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
527 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
528 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
544 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
545 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
546 or g_Game_IsNet then Exit;
548 if not gGameOn
then exit
;
549 if not conIsCheatsEnabled
then exit
;
551 s
:= 'SOUND_GAME_RADIO';
554 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
556 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
557 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
561 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
563 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
564 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
568 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
570 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
571 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
575 if CheckCheat(I_GAME_CHEAT_DEATH
) then
577 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
578 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
579 s
:= 'SOUND_MONSTER_HAHA';
583 if CheckCheat(I_GAME_CHEAT_DOORS
) then
585 g_Triggers_OpenAll();
589 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
591 if gTriggers
<> nil then
592 for a
:= 0 to High(gTriggers
) do
593 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
595 gExitByTrigger
:= True;
596 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
597 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
603 s2
:= Copy(charbuff
, 15, 2);
604 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
606 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
614 if CheckCheat(I_GAME_CHEAT_FLY
) then
620 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
622 VEL_JUMP
:= 30-VEL_JUMP
;
626 if CheckCheat(I_GAME_CHEAT_SPEED
) then
628 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
632 if CheckCheat(I_GAME_CHEAT_SUIT
) then
634 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
635 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
639 if CheckCheat(I_GAME_CHEAT_AIR
) then
641 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
642 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
646 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
648 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
649 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
653 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
655 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
656 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
660 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
662 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
663 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
667 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
669 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
670 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
674 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
676 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
677 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
680 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
682 gAimLine
:= not gAimLine
;
685 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
687 gShowMap
:= not gShowMap
;
697 procedure KeyPress (K
: Word);
707 if (g_ActiveWindow
<> nil) then
709 Msg
.Msg
:= WM_KEYDOWN
;
710 Msg
.WParam
:= VK_ESCAPE
;
711 g_ActiveWindow
.OnMessage(Msg
);
712 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
714 else if (gState
<> STATE_FOLD
) then
716 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
718 g_Game_InGameMenu(True);
720 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
722 if (gState
<> STATE_MENU
) then
724 if (NetMode
<> NET_NONE
) then
726 g_Game_StopAllSounds(True);
728 gState
:= STATE_MENU
;
732 g_GUI_ShowWindow('MainMenu');
733 g_Sound_PlayEx('MENU_OPEN');
738 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
739 begin // <F2> .. <F6> � <F12>
740 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
742 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
743 if (not g_Game_IsNet
) then g_Game_Pause(True);
745 IK_F2
: g_Menu_Show_SaveMenu();
746 IK_F3
: g_Menu_Show_LoadMenu();
747 IK_F4
: g_Menu_Show_GameSetGame();
748 IK_F5
: g_Menu_Show_OptionsVideo();
749 IK_F6
: g_Menu_Show_OptionsSound();
750 IK_F7
: g_Menu_Show_EndGameMenu();
751 IK_F10
: g_Menu_Show_QuitGameMenu();
758 gJustChatted
:= False;
759 if gConsoleShow
or gChatShow
then
761 g_Console_Control(K
);
763 else if (g_ActiveWindow
<> nil) then
765 Msg
.Msg
:= WM_KEYDOWN
;
767 g_ActiveWindow
.OnMessage(Msg
);
769 else if (gState
= STATE_MENU
) then
771 g_GUI_ShowWindow('MainMenu');
772 g_Sound_PlayEx('MENU_OPEN');
779 procedure CharPress (C
: AnsiChar);
784 if gConsoleShow
or gChatShow
then
788 else if (g_ActiveWindow
<> nil) then
791 Msg
.WParam
:= Ord(C
);
792 g_ActiveWindow
.OnMessage(Msg
);
796 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
797 charbuff
[15] := upcase1251(C
);
803 // ////////////////////////////////////////////////////////////////////////// //
804 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
806 procedure g_ResetDynlights ();
810 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
812 for idx
:= 0 to g_dynLightCount
-1 do
814 if g_dynLights
[idx
].exploCount
= -666 then
821 Inc(g_dynLights
[idx
].exploCount
);
822 if (g_dynLights
[idx
].exploCount
< 10) then
824 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
825 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
826 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
827 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
832 g_dynLightCount
:= lnum
;
835 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
837 if not gwin_has_stencil
then exit
;
838 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
839 g_dynLights
[g_dynLightCount
].x
:= x
;
840 g_dynLights
[g_dynLightCount
].y
:= y
;
841 g_dynLights
[g_dynLightCount
].radius
:= radius
;
842 g_dynLights
[g_dynLightCount
].r
:= r
;
843 g_dynLights
[g_dynLightCount
].g
:= g
;
844 g_dynLights
[g_dynLightCount
].b
:= b
;
845 g_dynLights
[g_dynLightCount
].a
:= a
;
846 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
847 Inc(g_dynLightCount
);
850 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
852 if not gwin_has_stencil
then exit
;
853 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
854 g_dynLights
[g_dynLightCount
].x
:= x
;
855 g_dynLights
[g_dynLightCount
].y
:= y
;
856 g_dynLights
[g_dynLightCount
].radius
:= 0;
857 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
858 g_dynLights
[g_dynLightCount
].r
:= r
;
859 g_dynLights
[g_dynLightCount
].g
:= g
;
860 g_dynLights
[g_dynLightCount
].b
:= b
;
861 g_dynLights
[g_dynLightCount
].a
:= 0;
862 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
863 Inc(g_dynLightCount
);
866 // ////////////////////////////////////////////////////////////////////////// //
867 function conIsCheatsEnabled (): Boolean; inline;
870 if g_Game_IsNet
then exit
;
871 if not gDebugMode
then
873 //if not gCheats then exit;
874 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
875 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
880 // ////////////////////////////////////////////////////////////////////////// //
882 TParamStrValue
= record
887 TParamStrValues
= Array of TParamStrValue
;
890 INTER_ACTION_TEXT
= 1;
891 INTER_ACTION_PIC
= 2;
892 INTER_ACTION_MUSIC
= 3;
897 DataLoaded
: Boolean = False;
899 MessageLineLength
: Integer = 80;
900 MapList
: SSArray
= nil;
901 MapIndex
: Integer = -1;
902 InterReadyTime
: Integer = -1;
903 StatDate
: string = '';
918 function Compare(a
, b
: TPlayerStat
): Integer;
920 if a
.Spectator
then Result
:= 1
921 else if b
.Spectator
then Result
:= -1
922 else if a
.Frags
< b
.Frags
then Result
:= 1
923 else if a
.Frags
> b
.Frags
then Result
:= -1
924 else if a
.Deaths
< b
.Deaths
then Result
:= -1
925 else if a
.Deaths
> b
.Deaths
then Result
:= 1
926 else if a
.Kills
< b
.Kills
then Result
:= -1
930 procedure SortGameStat(var stat
: TPlayerStatArray
);
935 if stat
= nil then Exit
;
937 for I
:= High(stat
) downto Low(stat
) do
938 for J
:= Low(stat
) to High(stat
) - 1 do
939 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
942 stat
[J
] := stat
[J
+ 1];
947 // saves a shitty CSV containing the game stats passed to it
948 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
951 dir
, fname
, map
, mode
, etime
: String;
955 dir
:= e_GetWriteableDir(StatsDirs
);
956 // stats are placed in stats/yy/mm/dd/*.csv
957 fname
:= e_CatPath(dir
, Path
);
958 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
959 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
960 AssignFile(s
, fname
);
962 SetTextCodePage(s
, CP_UTF8
);
964 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
965 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
966 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
967 mode
:= g_Game_ModeToText(Stat
.GameMode
);
968 etime
:= Format('%d:%.2d:%.2d', [
969 Stat
.GameTime
div 1000 div 3600,
970 (Stat
.GameTime
div 1000 div 60) mod 60,
971 Stat
.GameTime
div 1000 mod 60
973 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
974 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
980 gGameSettings
.TimeLimit
,
981 gGameSettings
.ScoreLimit
,
982 gGameSettings
.Options
,
984 Length(Stat
.PlayerStat
)
986 // line 2: game specific shit
987 // if it's a team game: red score, blue score
988 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
990 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
992 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
993 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
995 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
996 // lines 3-...: team, player name, frags, deaths
997 WriteLn(s
, 'team,name,frags,deaths');
998 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
999 with Stat
.PlayerStat
[I
] do
1000 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1002 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1005 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1010 procedure ClearDebugCvars();
1012 g_debug_Sounds
:= False;
1013 g_debug_Frames
:= False;
1014 g_debug_WinMsgs
:= False;
1015 g_debug_MonsterOff
:= False;
1016 g_debug_BotAIOff
:= 0;
1017 g_debug_HealthBar
:= False;
1018 g_Debug_Player
:= False;
1021 function g_Game_ModeToText(Mode
: Byte): string;
1025 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1026 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1027 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1028 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1029 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1033 function g_Game_TextToMode(Mode
: string): Byte;
1036 Mode
:= UpperCase(Mode
);
1037 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1042 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1047 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1052 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1057 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1059 Result
:= GM_SINGLE
;
1064 function g_Game_IsNet(): Boolean;
1066 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1069 function g_Game_IsServer(): Boolean;
1071 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1074 function g_Game_IsClient(): Boolean;
1076 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1079 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1086 Result
.name
:= ExtractFileName(WAD
);
1087 Result
.description
:= '';
1088 Result
.author
:= '';
1090 w
:= TWADFile
.Create();
1093 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1099 cfg
:= TConfig
.CreateMem(p
, len
);
1100 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1101 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1102 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1103 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1109 procedure g_Game_FreeWAD
;
1112 g_Sound_Delete('MUSIC_endmus');
1113 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1114 gGameSettings
.WAD
:= '';
1117 procedure g_Game_LoadWAD(WAD
: string);
1126 gGameSettings
.WAD
:= WAD
;
1127 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1130 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1132 w
:= TWADFile
.Create();
1135 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1141 cfg
:= TConfig
.CreateMem(p
, len
);
1144 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1145 if MegaWAD
.endpic
<> '' then
1146 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1148 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1149 if MegaWAD
.endmus
<> '' then
1151 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1152 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1160 {procedure start_trigger(t: string);
1164 function next_trigger(): Boolean;
1168 procedure DisableCheats();
1174 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1175 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1176 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1177 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1179 {$IF DEFINED(D2F_DEBUG)}
1180 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1181 gAimLine
:= g_dbg_aimline_on
;
1185 procedure g_Game_ExecuteEvent(Name
: String);
1191 if gEvents
= nil then
1193 for a
:= 0 to High(gEvents
) do
1194 if gEvents
[a
].Name
= Name
then
1196 if gEvents
[a
].Command
<> '' then
1197 g_Console_Process(gEvents
[a
].Command
, True);
1202 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1207 if gDelayedEvents
<> nil then
1208 for a
:= 0 to High(gDelayedEvents
) do
1209 if not gDelayedEvents
[a
].Pending
then
1216 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1217 n
:= High(gDelayedEvents
);
1219 gDelayedEvents
[n
].Pending
:= True;
1220 gDelayedEvents
[n
].DEType
:= DEType
;
1221 gDelayedEvents
[n
].DENum
:= Num
;
1222 gDelayedEvents
[n
].DEStr
:= Str
;
1223 if DEType
= DE_GLOBEVENT
then
1224 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1226 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1230 procedure EndGame();
1236 if g_Game_IsNet
and g_Game_IsServer
then
1237 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1240 gPauseMain
:= false;
1241 gPauseHolmes
:= false;
1244 g_Game_StopAllSounds(False);
1249 EndingGameCounter
:= 0;
1250 g_ActiveWindow
:= nil;
1252 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1253 gLMSRespawnTime
:= 0;
1256 EXIT_SIMPLE
: // Выход через меню или конец теста
1261 begin // Это был тест
1265 begin // Выход в главное меню
1266 gMusic
.SetByName('MUSIC_MENU');
1268 if gState
<> STATE_SLIST
then
1270 g_GUI_ShowWindow('MainMenu');
1271 gState
:= STATE_MENU
;
1274 // Обновляем список серверов
1275 slReturnPressed
:= True;
1276 if g_Net_Slist_Fetch(slCurrent
) then
1278 if slCurrent
= nil then
1279 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1282 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1283 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1286 g_Game_ExecuteEvent('ongameend');
1290 EXIT_RESTART
: // Начать уровень сначала
1292 if not g_Game_IsClient
then g_Game_Restart();
1295 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1297 // Статистика Своей игры:
1298 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1300 CustomStat
.GameTime
:= gTime
;
1301 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1302 CustomStat
.MapName
:= gMapInfo
.Name
;
1303 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1304 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1305 CustomStat
.TeamStat
:= gTeamStat
;
1307 CustomStat
.PlayerStat
:= nil;
1309 // Статистика игроков:
1310 if gPlayers
<> nil then
1312 for a
:= 0 to High(gPlayers
) do
1313 if gPlayers
[a
] <> nil then
1315 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1316 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1319 Name
:= gPlayers
[a
].Name
;
1320 Frags
:= gPlayers
[a
].Frags
;
1321 Deaths
:= gPlayers
[a
].Death
;
1322 Kills
:= gPlayers
[a
].Kills
;
1323 Team
:= gPlayers
[a
].Team
;
1324 Color
:= gPlayers
[a
].Model
.Color
;
1325 Spectator
:= gPlayers
[a
].FSpectator
;
1329 SortGameStat(CustomStat
.PlayerStat
);
1331 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1334 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1335 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1336 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1337 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1339 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1342 StatShotDone
:= False;
1345 g_Game_ExecuteEvent('onmapend');
1346 if not g_Game_IsClient
then g_Player_ResetReady
;
1347 gInterReadyCount
:= 0;
1349 // Затухающий экран:
1350 EndingGameCounter
:= 255;
1351 gState
:= STATE_FOLD
;
1353 if gDefInterTime
< 0 then
1354 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1356 gInterEndTime
:= gDefInterTime
* 1000;
1359 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1361 // Статистика Одиночной игры:
1362 SingleStat
.GameTime
:= gTime
;
1363 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1364 SingleStat
.TotalSecrets
:= gSecretsCount
;
1365 // Статистика первого игрока:
1366 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1367 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1368 // Статистика второго игрока (если есть):
1369 if SingleStat
.TwoPlayers
then
1371 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1372 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1375 g_Game_ExecuteEvent('onmapend');
1378 if gNextMap
<> '' then
1380 gMusic
.SetByName('MUSIC_INTERMUS');
1382 gState
:= STATE_INTERSINGLE
;
1385 g_Game_ExecuteEvent('oninter');
1387 else // Больше нет карт
1389 // Затухающий экран:
1390 EndingGameCounter
:= 255;
1391 gState
:= STATE_FOLD
;
1396 // Окончание обработано:
1397 if gExit
<> EXIT_QUIT
then
1401 procedure g_Game_Init();
1405 gTempDelete
:= False;
1407 sfsGCDisable(); // temporary disable removing of temporary volumes
1410 g_Game_ClearLoading();
1411 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1412 g_Game_SetLoadingText('', 0, False);
1414 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1417 gPauseMain
:= false;
1418 gPauseHolmes
:= false;
1421 {e_MouseInfo.Accel := 1.0;}
1423 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1426 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1427 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1428 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1429 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1430 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1432 gMusic
:= TMusic
.Create();
1433 gMusic
.SetByName('MUSIC_MENU');
1436 gGameSettings
.WarmupTime
:= 30;
1438 gState
:= STATE_MENU
;
1440 SetLength(gEvents
, 6);
1441 gEvents
[0].Name
:= 'ongamestart';
1442 gEvents
[1].Name
:= 'ongameend';
1443 gEvents
[2].Name
:= 'onmapstart';
1444 gEvents
[3].Name
:= 'onmapend';
1445 gEvents
[4].Name
:= 'oninter';
1446 gEvents
[5].Name
:= 'onwadend';
1448 sfsGCEnable(); // enable releasing unused volumes
1452 procedure g_Game_Free(freeTextures
: Boolean=true);
1454 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1455 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1457 g_Map_Free(freeTextures
);
1459 g_Player_RemoveAllCorpses();
1461 gGameSettings
.GameType
:= GT_NONE
;
1462 if gGameSettings
.GameMode
= GM_SINGLE
then
1463 gGameSettings
.GameMode
:= GM_DM
;
1464 gSwitchGameMode
:= gGameSettings
.GameMode
;
1467 gExitByTrigger
:= False;
1470 function IsActivePlayer(p
: TPlayer
): Boolean;
1475 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1478 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1484 if gPlayers
= nil then
1488 for a
:= Low(gPlayers
) to High(gPlayers
) do
1489 if IsActivePlayer(gPlayers
[a
]) then
1491 SetLength(ids
, Length(ids
) + 1);
1492 ids
[High(ids
)] := gPlayers
[a
].UID
;
1493 if gPlayers
[a
].UID
= Skip
then
1496 if Length(ids
) = 0 then
1501 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1504 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1510 if gPlayers
= nil then
1514 for a
:= Low(gPlayers
) to High(gPlayers
) do
1515 if IsActivePlayer(gPlayers
[a
]) then
1517 SetLength(ids
, Length(ids
) + 1);
1518 ids
[High(ids
)] := gPlayers
[a
].UID
;
1519 if gPlayers
[a
].UID
= Skip
then
1522 if Length(ids
) = 0 then
1525 Result
:= ids
[Length(ids
) - 1]
1527 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1530 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1536 if gPlayers
= nil then
1540 for a
:= Low(gPlayers
) to High(gPlayers
) do
1541 if IsActivePlayer(gPlayers
[a
]) then
1543 SetLength(ids
, Length(ids
) + 1);
1544 ids
[High(ids
)] := gPlayers
[a
].UID
;
1545 if gPlayers
[a
].UID
= Skip
then
1548 if Length(ids
) = 0 then
1550 if Length(ids
) = 1 then
1555 Result
:= ids
[Random(Length(ids
))];
1557 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1559 Result
:= ids
[Random(Length(ids
))];
1564 function GetRandomSpectMode(Current
: Byte): Byte;
1571 0: Result
:= SPECT_STATS
;
1572 1: Result
:= SPECT_MAPVIEW
;
1573 2: Result
:= SPECT_MAPVIEW
;
1574 3: Result
:= SPECT_PLAYERS
;
1575 4: Result
:= SPECT_PLAYERS
;
1576 5: Result
:= SPECT_PLAYERS
;
1577 6: Result
:= SPECT_PLAYERS
;
1579 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1583 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1589 if (plr
= nil) then exit
;
1590 if (p
= 2) then time
:= 1000 else time
:= 1;
1591 strafeDir
:= MoveButton
shr 4;
1592 MoveButton
:= MoveButton
and $0F;
1594 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1595 MoveButton
:= 1 // Нажата только "Влево"
1596 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1597 MoveButton
:= 2 // Нажата только "Вправо"
1598 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1599 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1601 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1602 if MoveButton
= 1 then
1603 plr
.PressKey(KEY_LEFT
, time
)
1604 else if MoveButton
= 2 then
1605 plr
.PressKey(KEY_RIGHT
, time
);
1607 // if we have "strafe" key, turn off old strafe mechanics
1608 if gPlayerAction
[p
, ACTION_STRAFE
] then
1610 // new strafe mechanics
1611 if (strafeDir
= 0) then
1612 strafeDir
:= MoveButton
; // start strafing
1613 // now set direction according to strafe (reversed)
1614 if (strafeDir
= 2) then
1615 plr
.SetDirection(TDirection
.D_LEFT
)
1616 else if (strafeDir
= 1) then
1617 plr
.SetDirection(TDirection
.D_RIGHT
)
1621 strafeDir
:= 0; // not strafing anymore
1622 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1623 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1624 plr
.SetDirection(TDirection
.D_LEFT
)
1625 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1626 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1627 plr
.SetDirection(TDirection
.D_RIGHT
)
1628 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1629 else if MoveButton
<> 0 then
1630 plr
.SetDirection(TDirection(MoveButton
-1))
1633 // fix movebutton state
1634 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1636 // Остальные клавиши:
1637 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1638 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1639 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1640 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1641 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1643 for i
:= WP_FACT
to WP_LACT
do
1645 if gWeaponAction
[p
, i
] then
1647 plr
.ProcessWeaponAction(i
);
1648 gWeaponAction
[p
, i
] := False
1652 for i
:= WP_FIRST
to WP_LAST
do
1654 if gSelectWeapon
[p
, i
] then
1656 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1657 gSelectWeapon
[p
, i
] := False
1661 // HACK: add dynlight here
1662 if gwin_k8_enable_light_experiments
then
1664 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1666 g_playerLight
:= true;
1668 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1670 g_playerLight
:= false;
1674 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1677 // HACK: don't have a "key was pressed" function
1678 procedure InterReady();
1680 if InterReadyTime
> gTime
then Exit
;
1681 InterReadyTime
:= gTime
+ 3000;
1682 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1685 procedure g_Game_PreUpdate();
1687 // these are in separate PreUpdate functions because they can interact during Update()
1688 // and are synced over the net
1689 // we don't care that much about corpses and gibs
1690 g_Player_PreUpdate();
1691 g_Monsters_PreUpdate();
1692 g_Items_PreUpdate();
1693 g_Weapon_PreUpdate();
1696 procedure g_Game_Update();
1698 Msg
: g_gui
.TMessage
;
1704 function sendMonsPos (mon
: TMonster
): Boolean;
1706 result
:= false; // don't stop
1707 // this will also reset "need-send" flag
1708 if mon
.gncNeedSend
then
1710 MH_SEND_MonsterPos(mon
.UID
);
1712 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1714 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1716 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1718 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1722 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1724 result
:= false; // don't stop
1725 // this will also reset "need-send" flag
1726 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1729 function sendItemPos (it
: PItem
): Boolean;
1731 result
:= false; // don't stop
1734 MH_SEND_ItemPos(it
.myId
);
1735 it
.needSend
:= False;
1740 reliableUpdate
: Boolean;
1745 // Пора выключать игру:
1746 if gExit
= EXIT_QUIT
then
1748 // Игра закончилась - обрабатываем:
1752 if gExit
= EXIT_QUIT
then
1756 // Читаем клавиатуру и джойстик, если окно активно
1757 // no need to, as we'll do it in event handler
1759 // Обновляем консоль (движение и сообщения):
1763 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1765 gExit
:= EXIT_SIMPLE
;
1770 // process master server communications
1771 g_Net_Slist_Pulse();
1774 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1775 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1776 STATE_INTERTEXT
, // Текст между уровнями
1777 STATE_INTERPIC
: // Картинка между уровнями
1779 if g_Game_IsNet
and g_Game_IsServer
then
1781 gInterTime
:= gInterTime
+ GAME_TICK
;
1782 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1783 if a
<> gServInterTime
then
1785 gServInterTime
:= a
;
1786 MH_SEND_TimeSync(gServInterTime
);
1790 if (not g_Game_IsClient
) and
1794 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1795 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1796 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1797 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1799 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1800 and (g_ActiveWindow
= nil)
1802 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1805 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1806 g_Game_StopAllSounds(True);
1808 if gMapOnce
then // Это был тест
1809 gExit
:= EXIT_SIMPLE
1811 if gNextMap
<> '' then // Переходим на следующую карту
1812 g_Game_ChangeMap(gNextMap
)
1813 else // Следующей карты нет
1815 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1817 // Выход в главное меню:
1819 g_GUI_ShowWindow('MainMenu');
1820 gMusic
.SetByName('MUSIC_MENU');
1822 gState
:= STATE_MENU
;
1825 // Финальная картинка:
1826 g_Game_ExecuteEvent('onwadend');
1828 if not gMusic
.SetByName('MUSIC_endmus') then
1829 gMusic
.SetByName('MUSIC_STDENDMUS');
1831 gState
:= STATE_ENDPIC
;
1833 g_Game_ExecuteEvent('ongameend');
1838 else if g_Game_IsClient
and
1841 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1842 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1843 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1844 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1846 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1847 and (g_ActiveWindow
= nil)
1855 if gState
= STATE_INTERTEXT
then
1856 if InterText
.counter
> 0 then
1857 InterText
.counter
:= InterText
.counter
- 1;
1860 STATE_FOLD
: // Затухание экрана
1862 if EndingGameCounter
= 0 then
1864 // Закончился уровень в Своей игре:
1865 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1867 gState
:= STATE_INTERCUSTOM
;
1868 InterReadyTime
:= -1;
1869 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1871 g_Game_ExecuteEvent('onwadend');
1872 if not gMusic
.SetByName('MUSIC_endmus') then
1873 gMusic
.SetByName('MUSIC_STDENDMUS');
1876 gMusic
.SetByName('MUSIC_ROUNDMUS');
1880 else // Закончилась последняя карта в Одиночной игре
1882 gMusic
.SetByName('MUSIC_INTERMUS');
1884 gState
:= STATE_INTERSINGLE
;
1887 g_Game_ExecuteEvent('oninter');
1890 DecMin(EndingGameCounter
, 6, 0);
1893 STATE_ENDPIC
: // Картинка окончания мегаВада
1895 if gMapOnce
then // Это был тест
1897 gExit
:= EXIT_SIMPLE
;
1903 g_Serverlist_Control(slCurrent
, slTable
);
1906 // Статистика по Tab:
1908 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1911 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1913 // Время += 28 миллисекунд:
1914 gTime
:= gTime
+ GAME_TICK
;
1916 // Сообщение посередине экрана:
1917 if MessageTime
= 0 then
1919 if MessageTime
> 0 then
1920 MessageTime
:= MessageTime
- 1;
1922 if (g_Game_IsServer
) then
1924 // Был задан лимит времени:
1925 if (gGameSettings
.TimeLimit
> 0) then
1926 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1927 begin // Он прошел => конец уровня
1932 // Надо респавнить игроков в LMS:
1933 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1934 g_Game_RestartRound(gLMSSoftSpawn
);
1936 // Проверим результат голосования, если время прошло
1937 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1939 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1941 g_Console_Process(gVoteCommand
);
1943 gVotePassed
:= False;
1946 // Замеряем время захвата флагов
1947 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1948 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1949 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1950 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1952 // Был задан лимит побед:
1953 if (gGameSettings
.ScoreLimit
> 0) then
1957 if gGameSettings
.GameMode
= GM_DM
then
1958 begin // В DM ищем игрока с max фрагами
1959 for i
:= 0 to High(gPlayers
) do
1960 if gPlayers
[i
] <> nil then
1961 if gPlayers
[i
].Frags
> b
then
1962 b
:= gPlayers
[i
].Frags
;
1965 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1966 begin // В CTF/TDM выбираем команду с наибольшим счетом
1967 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
1970 // Лимит побед набран => конец уровня:
1971 if b
>= gGameSettings
.ScoreLimit
then
1978 // Обрабатываем клавиши игроков:
1979 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1980 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1981 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1983 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1984 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1985 end // if not console
1988 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1990 // process weapon switch queue
1994 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1995 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1997 if not gSpectKeyPress
then
1999 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2001 // switch spect mode
2003 SPECT_NONE
: ; // not spectator
2005 SPECT_MAPVIEW
: Inc(gSpectMode
);
2006 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2008 gSpectKeyPress
:= True;
2010 if (gSpectMode
= SPECT_MAPVIEW
)
2011 and (not gSpectAuto
) then
2013 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2014 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2015 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2016 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2017 if gPlayerAction
[0, ACTION_LOOKUP
] then
2018 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2019 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2020 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2021 if gWeaponAction
[0, WP_PREV
] then
2024 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2025 gWeaponAction
[0, WP_PREV
] := False;
2027 if gWeaponAction
[0, WP_NEXT
] then
2030 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2031 gWeaponAction
[0, WP_NEXT
] := False;
2034 if (gSpectMode
= SPECT_PLAYERS
)
2035 and (not gSpectAuto
) then
2037 if gPlayerAction
[0, ACTION_LOOKUP
] then
2040 gSpectViewTwo
:= True;
2041 gSpectKeyPress
:= True;
2043 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2045 // remove second view
2046 gSpectViewTwo
:= False;
2047 gSpectKeyPress
:= True;
2049 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2051 // prev player (view 1)
2052 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2053 gSpectKeyPress
:= True;
2055 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2057 // next player (view 1)
2058 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2059 gSpectKeyPress
:= True;
2061 if gWeaponAction
[0, WP_PREV
] then
2063 // prev player (view 2)
2064 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2065 gWeaponAction
[0, WP_PREV
] := False;
2067 if gWeaponAction
[0, WP_NEXT
] then
2069 // next player (view 2)
2070 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2071 gWeaponAction
[0, WP_NEXT
] := False;
2074 if gPlayerAction
[0, ACTION_ATTACK
] then
2076 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2079 gSpectAutoNext
:= 0;
2080 gSpectViewTwo
:= False;
2081 gSpectKeyPress
:= True;
2086 gSpectMode
:= SPECT_STATS
;
2087 gSpectAuto
:= False;
2088 gSpectKeyPress
:= True;
2093 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2094 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2095 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2096 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2097 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2098 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2099 gSpectKeyPress
:= False;
2103 if gSpectMode
= SPECT_MAPVIEW
then
2105 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2107 gSpectAutoNext
:= gTime
2110 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2112 gSpectAutoNext
:= gTime
2116 if gSpectAutoNext
<= gTime
then
2118 if gSpectAutoNext
> 0 then
2120 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2124 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2125 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2126 gSpectAutoStepX
:= Random(9) - 4;
2127 gSpectAutoStepY
:= Random(9) - 4;
2128 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2129 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2130 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2131 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2132 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2133 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2137 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2142 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2143 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2144 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2150 // Обновляем все остальное:
2153 g_Triggers_Update();
2155 g_Monsters_Update();
2158 g_Player_UpdateAll();
2159 g_Player_UpdatePhysicalObjects();
2161 // server: send newly spawned monsters unconditionally
2162 if (gGameSettings
.GameType
= GT_SERVER
) then
2164 if (Length(gMonstersSpawned
) > 0) then
2166 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2167 SetLength(gMonstersSpawned
, 0);
2171 if (gSoundTriggerTime
> 8) then
2173 g_Game_UpdateTriggerSounds();
2174 gSoundTriggerTime
:= 0;
2178 Inc(gSoundTriggerTime
);
2181 if (NetMode
= NET_SERVER
) then
2183 Inc(NetTimeToUpdate
);
2184 Inc(NetTimeToReliable
);
2186 // send monster updates
2187 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2189 // send all monsters (periodic sync)
2190 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2192 for I
:= 0 to High(gPlayers
) do
2194 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2197 g_Mons_ForEach(sendMonsPos
);
2199 // update flags that aren't stationary
2200 if gGameSettings
.GameMode
= GM_CTF
then
2201 for I
:= FLAG_RED
to FLAG_BLUE
do
2202 if gFlags
[I
].NeedSend
then
2204 gFlags
[I
].NeedSend
:= False;
2208 // update items that aren't stationary
2209 g_Items_ForEachAlive(sendItemPos
);
2211 if reliableUpdate
then
2213 NetTimeToReliable
:= 0;
2214 NetTimeToUpdate
:= NetUpdateRate
;
2218 NetTimeToUpdate
:= 0;
2223 // send only mosters with some unexpected changes
2224 g_Mons_ForEach(sendMonsPosUnexpected
);
2227 // send unexpected platform changes
2228 g_Map_NetSendInterestingPanels();
2230 g_Net_Slist_ServerUpdate();
2232 if NetUseMaster then
2234 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2236 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2238 NetTimeToMaster := gTime + NetMasterRate;
2243 else if (NetMode
= NET_CLIENT
) then
2245 MC_SEND_PlayerPos();
2247 end; // if gameOn ...
2249 // Активно окно интерфейса - передаем клавиши ему:
2250 if g_ActiveWindow
<> nil then
2252 w
:= e_GetFirstKeyPressed();
2254 if (w
<> IK_INVALID
) then
2256 Msg
.Msg
:= MESSAGE_DIKEY
;
2258 g_ActiveWindow
.OnMessage(Msg
);
2261 // Если оно от этого не закрылось, то обновляем:
2262 if g_ActiveWindow
<> nil then
2263 g_ActiveWindow
.Update();
2265 // Нужно сменить разрешение:
2266 if gResolutionChange
then
2268 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2270 gResolutionChange
:= False;
2271 g_ActiveWindow
:= nil;
2274 // Нужно сменить язык:
2275 if gLanguageChange
then
2277 //e_WriteLog('Read language file', MSG_NOTIFY);
2278 //g_Language_Load(DataDir + gLanguage + '.txt');
2279 g_Language_Set(gLanguage
);
2283 gLanguageChange
:= False;
2287 // Горячая клавиша для вызова меню выхода из игры (F10):
2288 if e_KeyPressed(IK_F10
) and
2290 (not gConsoleShow
) and
2291 (g_ActiveWindow
= nil) then
2296 Time
:= GetTickCount64() {div 1000};
2298 // Обработка отложенных событий:
2299 if gDelayedEvents
<> nil then
2300 for a
:= 0 to High(gDelayedEvents
) do
2301 if gDelayedEvents
[a
].Pending
and
2303 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2304 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2307 case gDelayedEvents
[a
].DEType
of
2309 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2312 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2316 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2317 if g_Game_IsNet
and g_Game_IsServer
then
2318 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2322 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2324 gDelayedEvents
[a
].Pending
:= False;
2327 // Каждую секунду обновляем счетчик обновлений:
2328 UPSCounter
:= UPSCounter
+ 1;
2329 if Time
- UPSTime
>= 1000 then
2338 g_Weapon_AddDynLights();
2339 g_Items_AddDynLights();
2343 procedure g_Game_LoadChatSounds(Resource
: string);
2346 FileName
, Snd
: string;
2348 len
, cnt
, tags
, i
, j
: Integer;
2351 FileName
:= g_ExtractWadName(Resource
);
2353 WAD
:= TWADFile
.Create();
2354 WAD
.ReadFile(FileName
);
2356 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2363 cfg
:= TConfig
.CreateMem(p
, len
);
2364 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2366 SetLength(gChatSounds
, cnt
);
2367 for i
:= 0 to Length(gChatSounds
) - 1 do
2369 gChatSounds
[i
].Sound
:= nil;
2370 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2371 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2372 if (Snd
= '') or (Tags
<= 0) then
2374 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2375 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2376 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2377 SetLength(gChatSounds
[i
].Tags
, tags
);
2378 for j
:= 0 to tags
- 1 do
2379 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2380 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2387 procedure g_Game_FreeChatSounds();
2391 for i
:= 0 to Length(gChatSounds
) - 1 do
2393 gChatSounds
[i
].Sound
.Free();
2394 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2396 SetLength(gChatSounds
, 0);
2400 procedure g_Game_LoadData();
2402 if DataLoaded
then Exit
;
2404 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2406 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2407 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2408 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2409 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2410 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2411 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2412 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2413 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2414 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2415 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2416 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2417 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2418 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2419 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2420 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2421 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2422 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2423 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2424 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2425 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2426 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2427 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2428 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2429 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2430 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2431 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2432 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2433 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2434 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2435 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2436 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2437 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2439 goodsnd
[0] := TPlayableSound
.Create();
2440 goodsnd
[1] := TPlayableSound
.Create();
2441 goodsnd
[2] := TPlayableSound
.Create();
2442 goodsnd
[3] := TPlayableSound
.Create();
2444 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2445 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2446 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2447 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2449 killsnd
[0] := TPlayableSound
.Create();
2450 killsnd
[1] := TPlayableSound
.Create();
2451 killsnd
[2] := TPlayableSound
.Create();
2452 killsnd
[3] := TPlayableSound
.Create();
2454 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2455 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2456 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2457 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2459 hahasnd
[0] := TPlayableSound
.Create();
2460 hahasnd
[1] := TPlayableSound
.Create();
2461 hahasnd
[2] := TPlayableSound
.Create();
2463 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2464 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2465 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2467 sound_get_flag
[0] := TPlayableSound
.Create();
2468 sound_get_flag
[1] := TPlayableSound
.Create();
2469 sound_lost_flag
[0] := TPlayableSound
.Create();
2470 sound_lost_flag
[1] := TPlayableSound
.Create();
2471 sound_ret_flag
[0] := TPlayableSound
.Create();
2472 sound_ret_flag
[1] := TPlayableSound
.Create();
2473 sound_cap_flag
[0] := TPlayableSound
.Create();
2474 sound_cap_flag
[1] := TPlayableSound
.Create();
2476 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2477 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2478 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2479 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2480 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2481 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2482 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2483 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2485 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2487 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2490 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2491 g_Weapon_LoadData();
2493 g_Monsters_LoadData();
2498 procedure g_Game_Quit();
2500 g_Game_StopAllSounds(True);
2503 g_PlayerModel_FreeData();
2505 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2508 if NetInitDone
then g_Net_Free
;
2510 // remove map after test
2511 if gMapToDelete
<> '' then
2512 g_Game_DeleteTestMap();
2518 procedure g_Game_FreeData();
2520 if not DataLoaded
then Exit
;
2523 g_Weapon_FreeData();
2524 g_Monsters_FreeData();
2526 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2528 g_Sound_Delete('SOUND_GAME_TELEPORT');
2529 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2530 g_Sound_Delete('SOUND_GAME_SECRET');
2531 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2532 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2533 g_Sound_Delete('SOUND_GAME_BULK1');
2534 g_Sound_Delete('SOUND_GAME_BULK2');
2535 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2536 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2537 g_Sound_Delete('SOUND_GAME_BURNING');
2538 g_Sound_Delete('SOUND_GAME_SWITCH1');
2539 g_Sound_Delete('SOUND_GAME_SWITCH0');
2546 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2547 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2548 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2549 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2556 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2557 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2558 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2559 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2565 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2566 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2567 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2569 sound_get_flag
[0].Free();
2570 sound_get_flag
[1].Free();
2571 sound_lost_flag
[0].Free();
2572 sound_lost_flag
[1].Free();
2573 sound_ret_flag
[0].Free();
2574 sound_ret_flag
[1].Free();
2575 sound_cap_flag
[0].Free();
2576 sound_cap_flag
[1].Free();
2578 g_Sound_Delete('SOUND_CTF_GET1');
2579 g_Sound_Delete('SOUND_CTF_GET2');
2580 g_Sound_Delete('SOUND_CTF_LOST1');
2581 g_Sound_Delete('SOUND_CTF_LOST2');
2582 g_Sound_Delete('SOUND_CTF_RETURN1');
2583 g_Sound_Delete('SOUND_CTF_RETURN2');
2584 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2585 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2587 g_Game_FreeChatSounds();
2589 DataLoaded
:= False;
2592 procedure g_FatalError(Text: String);
2594 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2595 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2597 gExit
:= EXIT_SIMPLE
;
2598 if gGameOn
then EndGame
;
2601 procedure g_SimpleError(Text: String);
2603 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2604 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2607 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2609 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2610 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2613 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2616 if gPlayer1
= nil then
2618 if g_Game_IsClient
then
2620 if NetPlrUID1
> -1 then
2621 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2625 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2626 Team
:= gPlayer1Settings
.Team
;
2628 // Создание первого игрока:
2629 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2630 gPlayer1Settings
.Color
,
2632 if gPlayer1
= nil then
2633 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2636 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2637 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2638 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2639 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2640 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2641 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2642 if g_Game_IsServer
and g_Game_IsNet
then
2643 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2644 gPlayer1
.Respawn(False, True);
2645 g_Net_Slist_ServerPlayerComes();
2650 if gPlayer2
= nil then
2652 if g_Game_IsClient
then
2654 if NetPlrUID2
> -1 then
2655 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2659 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2660 Team
:= gPlayer2Settings
.Team
;
2662 // Создание второго игрока:
2663 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2664 gPlayer2Settings
.Color
,
2666 if gPlayer2
= nil then
2667 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2670 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2671 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2672 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2673 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2674 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2675 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2676 if g_Game_IsServer
and g_Game_IsNet
then
2677 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2678 gPlayer2
.Respawn(False, True);
2679 g_Net_Slist_ServerPlayerComes();
2686 procedure g_Game_RemovePlayer();
2690 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2691 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2696 if g_Game_IsServer
then
2699 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2700 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2701 g_Player_Remove(Pl
.UID
);
2702 g_Net_Slist_ServerPlayerLeaves();
2706 gSpectLatchPID2
:= Pl
.UID
;
2714 if g_Game_IsServer
then
2717 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2718 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2719 g_Player_Remove(Pl
.UID
);
2720 g_Net_Slist_ServerPlayerLeaves();
2723 gSpectLatchPID1
:= Pl
.UID
;
2725 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2729 g_Net_Slist_ServerPlayerLeaves();
2732 procedure g_Game_Spectate();
2734 g_Game_RemovePlayer();
2735 if gPlayer1
<> nil then
2736 g_Game_RemovePlayer();
2739 procedure g_Game_SpectateCenterView();
2741 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2742 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2745 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2752 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2754 g_Game_ClearLoading();
2757 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2760 gGameSettings
.GameType
:= GT_SINGLE
;
2761 gGameSettings
.MaxLives
:= 0;
2762 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2763 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2764 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2765 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2766 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2767 gSwitchGameMode
:= GM_SINGLE
;
2769 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2770 gLMSRespawnTime
:= 0;
2771 gSpectLatchPID1
:= 0;
2772 gSpectLatchPID2
:= 0;
2774 g_Game_ExecuteEvent('ongamestart');
2776 // Создание первого игрока:
2777 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2778 gPlayer1Settings
.Color
,
2779 gPlayer1Settings
.Team
, False));
2780 if gPlayer1
= nil then
2782 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2786 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2787 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2788 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2789 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2790 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2793 // Создание второго игрока, если есть:
2796 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2797 gPlayer2Settings
.Color
,
2798 gPlayer2Settings
.Team
, False));
2799 if gPlayer2
= nil then
2801 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2805 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2806 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2807 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2808 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2809 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2813 // Загрузка и запуск карты:
2814 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2816 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2817 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2821 // Настройки игроков и ботов:
2825 for i
:= nPl
+1 to nPlayers
do
2826 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2829 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2830 TimeLimit
, ScoreLimit
: Word;
2832 Options
: LongWord; nPlayers
: Byte);
2838 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2840 g_Game_ClearLoading();
2843 gGameSettings
.GameType
:= GT_CUSTOM
;
2844 gGameSettings
.GameMode
:= GameMode
;
2845 gSwitchGameMode
:= GameMode
;
2846 gGameSettings
.TimeLimit
:= TimeLimit
;
2847 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2848 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2849 gGameSettings
.Options
:= Options
;
2851 gCoopTotalMonstersKilled
:= 0;
2852 gCoopTotalSecretsFound
:= 0;
2853 gCoopTotalMonsters
:= 0;
2854 gCoopTotalSecrets
:= 0;
2858 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2859 gLMSRespawnTime
:= 0;
2860 gSpectLatchPID1
:= 0;
2861 gSpectLatchPID2
:= 0;
2863 g_Game_ExecuteEvent('ongamestart');
2865 // Режим наблюдателя:
2866 if nPlayers
= 0 then
2873 if nPlayers
>= 1 then
2875 // Создание первого игрока:
2876 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2877 gPlayer1Settings
.Color
,
2878 gPlayer1Settings
.Team
, False));
2879 if gPlayer1
= nil then
2881 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2885 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2886 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2887 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2888 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2889 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2893 if nPlayers
>= 2 then
2895 // Создание второго игрока:
2896 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2897 gPlayer2Settings
.Color
,
2898 gPlayer2Settings
.Team
, False));
2899 if gPlayer2
= nil then
2901 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2905 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2906 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2907 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2908 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2909 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2913 // Загрузка и запуск карты:
2914 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
2916 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2920 // Нет точек появления:
2921 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2922 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2923 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2924 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2925 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2927 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2931 // Настройки игроков и ботов:
2935 for i
:= nPl
+1 to nPlayers
do
2936 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2939 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
2940 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
2941 Options
: LongWord; nPlayers
: Byte;
2942 IPAddr
: LongWord; Port
: Word);
2945 g_Net_Slist_ServerClosed();
2947 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
2949 g_Game_ClearLoading();
2954 gGameSettings
.GameType
:= GT_SERVER
;
2955 gGameSettings
.GameMode
:= GameMode
;
2956 gSwitchGameMode
:= GameMode
;
2957 gGameSettings
.TimeLimit
:= TimeLimit
;
2958 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2959 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2960 gGameSettings
.Options
:= Options
;
2962 gCoopTotalMonstersKilled
:= 0;
2963 gCoopTotalSecretsFound
:= 0;
2964 gCoopTotalMonsters
:= 0;
2965 gCoopTotalSecrets
:= 0;
2969 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2970 gLMSRespawnTime
:= 0;
2971 gSpectLatchPID1
:= 0;
2972 gSpectLatchPID2
:= 0;
2974 g_Game_ExecuteEvent('ongamestart');
2976 // Режим наблюдателя:
2977 if nPlayers
= 0 then
2983 if nPlayers
>= 1 then
2985 // Создание первого игрока:
2986 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2987 gPlayer1Settings
.Color
,
2988 gPlayer1Settings
.Team
, False));
2989 if gPlayer1
= nil then
2991 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2995 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2996 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2997 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2998 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2999 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3002 if nPlayers
>= 2 then
3004 // Создание второго игрока:
3005 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3006 gPlayer2Settings
.Color
,
3007 gPlayer2Settings
.Team
, False));
3008 if gPlayer2
= nil then
3010 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3014 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3015 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3016 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3017 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3018 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3021 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3022 if NetForwardPorts
then
3023 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3026 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3028 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3032 g_Net_Slist_Set(NetMasterList
);
3034 g_Net_Slist_ServerStarted();
3036 // Загрузка и запуск карты:
3037 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3039 g_Net_Slist_ServerClosed();
3040 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3044 // Нет точек появления:
3045 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3046 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3047 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3048 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3049 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3051 g_Net_Slist_ServerClosed();
3052 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3056 // Настройки игроков и ботов:
3059 g_Net_Slist_ServerMapStarted();
3060 NetState
:= NET_STATE_GAME
;
3063 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3078 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3079 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3081 g_Game_ClearLoading();
3086 gGameSettings
.GameType
:= GT_CLIENT
;
3088 gCoopTotalMonstersKilled
:= 0;
3089 gCoopTotalSecretsFound
:= 0;
3090 gCoopTotalMonsters
:= 0;
3091 gCoopTotalSecrets
:= 0;
3095 g_Game_ExecuteEvent('ongamestart');
3097 NetState
:= NET_STATE_AUTH
;
3099 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3101 // create (or update) map/resource databases
3102 g_Res_CreateDatabases(true);
3104 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3105 gLMSRespawnTime
:= 0;
3106 gSpectLatchPID1
:= 0;
3107 gSpectLatchPID2
:= 0;
3110 if not g_Net_Connect(Addr
, Port
) then
3112 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3113 NetState
:= NET_STATE_NONE
;
3117 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3119 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3124 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3125 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3126 // thank you, enet. let's ignore failures altogether then.
3127 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3129 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3131 Ptr
:= NetEvent
.packet
^.data
;
3132 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3134 enet_packet_destroy(NetEvent
.packet
);
3138 InMsg
.ReadLongWord(); // skip size
3139 MID
:= InMsg
.ReadByte();
3141 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3143 NetMyID
:= InMsg
.ReadByte();
3144 NetPlrUID1
:= InMsg
.ReadWord();
3146 WadName
:= InMsg
.ReadString();
3147 Map
:= InMsg
.ReadString();
3149 gWADHash
:= InMsg
.ReadMD5();
3151 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3152 gSwitchGameMode
:= gGameSettings
.GameMode
;
3153 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3154 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3155 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3156 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3157 T
:= InMsg
.ReadLongWord();
3159 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3160 //if newResPath = '' then
3162 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3163 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3164 if newResPath
= '' then
3166 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3167 enet_packet_destroy(NetEvent
.packet
);
3168 NetState
:= NET_STATE_NONE
;
3171 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3173 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3176 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3177 gPlayer1Settings
.Color
,
3178 gPlayer1Settings
.Team
, False));
3180 if gPlayer1
= nil then
3182 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3184 enet_packet_destroy(NetEvent
.packet
);
3185 NetState
:= NET_STATE_NONE
;
3189 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3190 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3191 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3192 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3193 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3194 gPlayer1
.UID
:= NetPlrUID1
;
3195 gPlayer1
.Reset(True);
3197 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3199 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3201 enet_packet_destroy(NetEvent
.packet
);
3202 NetState
:= NET_STATE_NONE
;
3210 enet_packet_destroy(NetEvent
.packet
);
3214 enet_packet_destroy(NetEvent
.packet
);
3218 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3221 if (NetEvent
.data
<= NET_DISC_MAX
) then
3222 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3223 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3230 ProcessLoading(True);
3231 if g_Net_UserRequestExit() then
3240 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3241 NetState
:= NET_STATE_NONE
;
3246 NetState
:= NET_STATE_GAME
;
3247 MC_SEND_FullStateRequest
;
3248 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3252 lastAsMegaWad
: Boolean = false;
3254 procedure g_Game_ChangeMap(const MapPath
: String);
3258 g_Game_ClearLoading();
3260 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3261 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3262 if gExitByTrigger
then
3265 gExitByTrigger
:= False;
3267 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3268 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3271 procedure g_Game_Restart();
3275 if g_Game_IsClient
then
3277 map
:= g_ExtractFileName(gMapInfo
.Map
);
3278 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3282 g_Game_ClearLoading();
3283 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3286 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3288 NewWAD
, ResName
: String;
3292 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3293 g_Player_RemoveAllCorpses();
3295 if (not g_Game_IsClient
) and
3296 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3297 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3299 if gSwitchGameMode
= GM_CTF
then
3300 gGameSettings
.MaxLives
:= 0;
3301 gGameSettings
.GameMode
:= gSwitchGameMode
;
3304 gSwitchGameMode
:= gGameSettings
.GameMode
;
3306 g_Player_ResetTeams();
3308 lastAsMegaWad
:= asMegawad
;
3309 if isWadPath(Map
) then
3311 NewWAD
:= g_ExtractWadName(Map
);
3312 ResName
:= g_ExtractFileName(Map
);
3313 if g_Game_IsServer
then
3315 nws
:= findDiskWad(NewWAD
);
3316 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3319 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3320 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3324 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3325 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3327 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3328 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3330 if (length(nws
) = 0) then
3332 ResName
:= ''; // failed
3337 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3338 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3339 g_Game_LoadWAD(NewWAD
);
3344 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3345 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3350 NewWAD
:= gGameSettings
.WAD
;
3356 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3358 if (ResName
<> '') and (NewWAD
<> '') then
3360 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3361 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3362 r_Render_LoadTextures
;
3366 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3368 gState
:= STATE_NONE
;
3369 g_ActiveWindow
:= nil;
3373 wNeedTimeReset
:= True;
3375 if gGameSettings
.GameMode
= GM_CTF
then
3377 g_Map_ResetFlag(FLAG_RED
);
3378 g_Map_ResetFlag(FLAG_BLUE
);
3379 // CTF, а флагов нет:
3380 if not g_Map_HaveFlagPoints() then
3381 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3386 gState
:= STATE_MENU
;
3391 gPauseMain
:= false;
3392 gPauseHolmes
:= false;
3393 NetTimeToUpdate
:= 1;
3394 NetTimeToReliable
:= 0;
3395 NetTimeToMaster
:= NetMasterRate
;
3396 gSpectLatchPID1
:= 0;
3397 gSpectLatchPID2
:= 0;
3398 gMissionFailed
:= False;
3401 gCoopMonstersKilled
:= 0;
3402 gCoopSecretsFound
:= 0;
3404 gVoteInProgress
:= False;
3405 gVotePassed
:= False;
3411 if not gGameOn
then Exit
;
3413 g_Game_SpectateCenterView();
3415 if g_Game_IsServer
then
3417 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3419 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3420 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3421 gLMSSoftSpawn
:= True;
3422 if g_Game_IsNet
then
3423 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3427 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3428 gLMSRespawnTime
:= 0;
3432 if NetMode
= NET_SERVER
then
3434 // reset full state flags
3435 if NetClients
<> nil then
3436 for I
:= 0 to High(NetClients
) do
3437 NetClients
[I
].FullUpdateSent
:= False;
3439 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3442 g_Net_Slist_ServerMapStarted();
3444 if NetClients
<> nil then
3445 for I
:= 0 to High(NetClients
) do
3446 if NetClients
[I
].Used
then
3448 NetClients
[I
].Voted
:= False;
3449 if NetClients
[I
].RequestedFullUpdate
then
3451 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3452 NetClients
[I
].RequestedFullUpdate
:= False;
3456 g_Net_UnbanNonPermHosts();
3461 gCoopTotalMonstersKilled
:= 0;
3462 gCoopTotalSecretsFound
:= 0;
3463 gCoopTotalMonsters
:= 0;
3464 gCoopTotalSecrets
:= 0;
3468 g_Game_ExecuteEvent('onmapstart');
3471 procedure SetFirstLevel
;
3475 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3476 if MapList
= nil then
3479 SortSArray(MapList
);
3480 gNextMap
:= MapList
[Low(MapList
)];
3485 procedure g_Game_ExitLevel(const Map
: AnsiString);
3489 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3490 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3491 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3492 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3494 // Вышли в выход в Одиночной игре:
3495 if gGameSettings
.GameType
= GT_SINGLE
then
3496 gExit
:= EXIT_ENDLEVELSINGLE
3497 else // Вышли в выход в Своей игре
3499 gExit
:= EXIT_ENDLEVELCUSTOM
;
3500 if gGameSettings
.GameMode
= GM_COOP
then
3501 g_Player_RememberAll
;
3503 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3506 if gGameSettings
.GameMode
= GM_COOP
then
3509 gStatsPressed
:= True;
3510 gNextMap
:= 'MAP01';
3512 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3515 if g_Game_IsNet
then
3517 MH_SEND_GameStats();
3518 MH_SEND_CoopStats();
3524 procedure g_Game_RestartLevel();
3528 if gGameSettings
.GameMode
= GM_SINGLE
then
3533 gExit
:= EXIT_ENDLEVELCUSTOM
;
3534 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3538 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3540 gWAD
{, xwad}: String;
3543 if not g_Game_IsClient
then Exit
;
3544 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3546 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3551 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3555 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3558 g_Game_LoadWAD(NewWAD
);
3562 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3563 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3566 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3567 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3571 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3575 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3576 g_Game_LoadWAD(NewWAD);
3580 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3582 i
, n
, nb
, nr
: Integer;
3584 if not g_Game_IsServer
then Exit
;
3585 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3586 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3587 gLMSRespawnTime
:= 0;
3590 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3592 gMissionFailed
:= True;
3593 g_Game_RestartLevel
;
3597 n
:= 0; nb
:= 0; nr
:= 0;
3598 for i
:= Low(gPlayers
) to High(gPlayers
) do
3599 if (gPlayers
[i
] <> nil) and
3600 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3601 (gPlayers
[i
] is TBot
)) then
3604 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3605 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3608 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3610 // wait a second until the fuckers finally decide to join
3611 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3612 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3613 gLMSSoftSpawn
:= NoMapRestart
;
3614 if g_Game_IsNet
then
3615 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3619 g_Player_RemoveAllCorpses
;
3620 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3621 if g_Game_IsNet
then
3622 MH_SEND_GameEvent(NET_EV_LMS_START
);
3624 for i
:= Low(gPlayers
) to High(gPlayers
) do
3626 if gPlayers
[i
] = nil then continue
;
3627 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3628 // don't touch normal spectators
3629 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3631 gPlayers
[i
].FNoRespawn
:= True;
3632 gPlayers
[i
].Lives
:= 0;
3633 if g_Game_IsNet
then
3634 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3637 gPlayers
[i
].FNoRespawn
:= False;
3638 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3639 gPlayers
[i
].Respawn(False, True);
3640 if gGameSettings
.GameMode
= GM_COOP
then
3642 gPlayers
[i
].Frags
:= 0;
3643 gPlayers
[i
].RecallState
;
3645 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3646 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3647 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3648 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3651 g_Items_RestartRound();
3653 gLMSSoftSpawn
:= False;
3656 function g_Game_GetFirstMap(WAD
: String): String;
3660 MapList
:= g_Map_GetMapsList(WAD
);
3661 if MapList
= nil then
3664 SortSArray(MapList
);
3665 Result
:= MapList
[Low(MapList
)];
3667 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3673 function g_Game_GetNextMap(): String;
3680 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3681 if MapList
= nil then
3684 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3686 SortSArray(MapList
);
3688 for I
:= Low(MapList
) to High(MapList
) do
3689 if Map
= MapList
[I
] then
3695 if MapIndex
<> -255 then
3697 if MapIndex
= High(MapList
) then
3698 Result
:= MapList
[Low(MapList
)]
3700 Result
:= MapList
[MapIndex
+ 1];
3702 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3708 procedure g_Game_NextLevel();
3710 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3711 gExit
:= EXIT_ENDLEVELCUSTOM
3714 gExit
:= EXIT_ENDLEVELSINGLE
;
3718 if gNextMap
<> '' then Exit
;
3719 gNextMap
:= g_Game_GetNextMap();
3722 function g_Game_IsTestMap(): Boolean;
3724 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3727 procedure g_Game_DeleteTestMap();
3730 //MapName: AnsiString;
3738 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3739 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3740 if (a
= 0) then exit
;
3742 // Выделяем имя wad-файла и имя карты
3743 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3744 Delete(gMapToDelete
, 1, a
+5);
3745 gMapToDelete
:= UpperCase(gMapToDelete
);
3747 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3750 // Имя карты не стандартное тестовое:
3751 if MapName <> TEST_MAP_NAME then
3754 if not gTempDelete then
3756 time := g_GetFileTime(WadName);
3757 WAD := TWADFile.Create();
3760 if not WAD.ReadFile(WadName) then
3761 begin // Нет такого WAD-файла
3766 // Составляем список карт и ищем нужную:
3768 MapList := WAD.GetResourcesList('');
3770 if MapList <> nil then
3771 for a := 0 to High(MapList) do
3772 if MapList[a] = MapName then
3774 // Удаляем и сохраняем:
3775 WAD.RemoveResource('', MapName);
3776 WAD.SaveTo(WadName);
3781 g_SetFileTime(WadName, time);
3784 if gTempDelete
then DeleteFile(WadName
);
3787 procedure GameCVars(P
: SSArray
);
3790 stat
: TPlayerStatArray
;
3793 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3797 if Length(P
) > 1 then
3802 gsGameFlags
:= gsGameFlags
or Flag
3804 gsGameFlags
:= gsGameFlags
and (not Flag
);
3806 if g_Game_IsServer
then
3809 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3811 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3812 if g_Game_IsNet
then MH_SEND_GameSettings
;
3816 if LongBool(gsGameFlags
and Flag
) then
3817 g_Console_Add(_lc
[OnMsg
])
3819 g_Console_Add(_lc
[OffMsg
]);
3821 if OnMapChange
and g_Game_IsServer
then
3822 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3827 cmd
:= LowerCase(P
[0]);
3829 if cmd
= 'g_gamemode' then
3831 if (Length(P
) > 1) then
3833 a
:= g_Game_TextToMode(P
[1]);
3834 if a
= GM_SINGLE
then a
:= GM_COOP
;
3835 gsGameMode
:= g_Game_ModeToText(a
);
3836 if g_Game_IsServer
then
3838 gSwitchGameMode
:= a
;
3839 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3840 (gState
= STATE_INTERSINGLE
) then
3841 gSwitchGameMode
:= GM_SINGLE
;
3843 gGameSettings
.GameMode
:= gSwitchGameMode
;
3847 if gSwitchGameMode
= gGameSettings
.GameMode
then
3848 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3849 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3851 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3852 [g_Game_ModeToText(gGameSettings
.GameMode
),
3853 g_Game_ModeToText(gSwitchGameMode
)]));
3855 else if cmd
= 'g_friendlyfire' then
3857 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3859 else if cmd
= 'g_friendly_absorb_damage' then
3861 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
3863 else if cmd
= 'g_friendly_hit_trace' then
3865 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
3867 else if cmd
= 'g_friendly_hit_projectile' then
3869 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
3871 else if cmd
= 'g_weaponstay' then
3873 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3875 else if cmd
= 'g_allow_exit' then
3877 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3879 else if cmd
= 'g_allow_monsters' then
3881 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3883 else if cmd
= 'g_allow_dropflag' then
3885 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
3887 else if cmd
= 'g_throw_flag' then
3889 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
3891 else if cmd
= 'g_bot_vsplayers' then
3893 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3895 else if cmd
= 'g_bot_vsmonsters' then
3897 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3899 else if cmd
= 'g_dm_keys' then
3901 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
3903 else if cmd
= 'g_gameflags' then
3905 if Length(P
) > 1 then
3907 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
3908 if g_Game_IsServer
then
3910 gGameSettings
.Options
:= gsGameFlags
;
3911 if g_Game_IsNet
then MH_SEND_GameSettings
;
3915 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
3917 else if cmd
= 'g_warmup_time' then
3919 if Length(P
) > 1 then
3921 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
3922 if g_Game_IsServer
then
3924 gGameSettings
.WarmupTime
:= gsWarmupTime
;
3925 // extend warmup if it's already going
3926 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
3928 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
3929 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3931 if g_Game_IsNet
then MH_SEND_GameSettings
;
3935 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
3936 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3938 else if cmd
= 'g_spawn_invul' then
3940 if Length(P
) > 1 then
3942 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
3943 if g_Game_IsServer
then
3945 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
3946 if g_Game_IsNet
then MH_SEND_GameSettings
;
3950 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
3952 else if cmd
= 'g_item_respawn_time' then
3954 if Length(P
) > 1 then
3956 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
3957 if g_Game_IsServer
then
3959 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
3960 if g_Game_IsNet
then MH_SEND_GameSettings
;
3964 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
3965 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3967 else if cmd
= 'sv_intertime' then
3969 if (Length(P
) > 1) then
3970 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
3972 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
3974 else if cmd
= 'g_max_particles' then
3976 if Length(p
) = 2 then
3978 a
:= Max(0, StrToIntDef(p
[1], 0));
3981 else if Length(p
) = 1 then
3983 e_LogWritefln('%s', [g_GFX_GetMax()])
3987 e_LogWritefln('usage: %s <n>', [cmd
])
3990 else if cmd
= 'g_max_shells' then
3992 if Length(p
) = 2 then
3994 a
:= Max(0, StrToIntDef(p
[1], 0));
3997 else if Length(p
) = 1 then
3999 e_LogWritefln('%s', [g_Shells_GetMax()])
4003 e_LogWritefln('usage: %s <n>', [cmd
])
4006 else if cmd
= 'g_max_gibs' then
4008 if Length(p
) = 2 then
4010 a
:= Max(0, StrToIntDef(p
[1], 0));
4013 else if Length(p
) = 1 then
4015 e_LogWritefln('%s', [g_Gibs_GetMax()])
4019 e_LogWritefln('usage: %s <n>', [cmd
])
4022 else if cmd
= 'g_max_corpses' then
4024 if Length(p
) = 2 then
4026 a
:= Max(0, StrToIntDef(p
[1], 0));
4029 else if Length(p
) = 1 then
4031 e_LogWritefln('%s', [g_Corpses_GetMax()])
4035 e_LogWritefln('usage: %s <n>', [cmd
])
4038 else if cmd
= 'g_force_model' then
4040 if Length(p
) = 2 then
4042 a
:= StrToIntDef(p
[1], 0);
4043 g_Force_Model_Set(a
);
4044 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4046 for a
:= Low(gPlayers
) to High(gPlayers
) do
4048 if (gPlayers
[a
] <> nil) then
4050 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4052 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4054 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4058 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4060 for a
:= Low(gPlayers
) to High(gPlayers
) do
4062 if (gPlayers
[a
] <> nil) then
4064 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4066 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4068 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4074 else if cmd
= 'g_force_model_name' then
4076 if (Length(P
) > 1) then
4078 cmd
:= b_Text_Unformat(P
[1]);
4079 g_Forced_Model_SetName(cmd
);
4080 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4082 for a
:= Low(gPlayers
) to High(gPlayers
) do
4084 if (gPlayers
[a
] <> nil) then
4086 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4088 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4090 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4096 else if cmd
= 'g_scorelimit' then
4098 if Length(P
) > 1 then
4100 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4102 if g_Game_IsServer
then
4105 if gGameSettings
.GameMode
= GM_DM
then
4107 stat
:= g_Player_GetStats();
4109 for a
:= 0 to High(stat
) do
4110 if stat
[a
].Frags
> b
then
4114 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4116 // if someone has a higher score, set it to that instead
4117 gsScoreLimit
:= max(gsScoreLimit
, b
);
4118 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4120 if g_Game_IsNet
then MH_SEND_GameSettings
;
4124 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4126 else if cmd
= 'g_timelimit' then
4128 if Length(P
) > 1 then
4130 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4131 if g_Game_IsServer
then
4133 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4134 if g_Game_IsNet
then MH_SEND_GameSettings
;
4137 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4138 [gsTimeLimit
div 3600,
4139 (gsTimeLimit
div 60) mod 60,
4140 gsTimeLimit
mod 60]));
4142 else if cmd
= 'g_max_bots' then
4144 if Length(P
) > 1 then
4145 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4146 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4148 else if cmd
= 'g_maxlives' then
4150 if Length(P
) > 1 then
4152 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4153 if g_Game_IsServer
then
4155 gGameSettings
.MaxLives
:= gsMaxLives
;
4156 if g_Game_IsNet
then MH_SEND_GameSettings
;
4160 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4164 procedure PlayerSettingsCVars(P
: SSArray
);
4169 function ParseTeam(s
: string): Byte;
4173 'red', '1': result
:= TEAM_RED
;
4174 'blue', '2': result
:= TEAM_BLUE
;
4175 else result
:= TEAM_NONE
;
4179 cmd
:= LowerCase(P
[0]);
4183 if (Length(P
) > 1) then
4185 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4186 if g_Game_IsClient
then
4187 MC_SEND_PlayerSettings
4188 else if gGameOn
and (gPlayer1
<> nil) then
4190 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4191 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4197 if (Length(P
) > 1) then
4199 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4200 if g_Game_IsClient
then
4201 MC_SEND_PlayerSettings
4202 else if gGameOn
and (gPlayer2
<> nil) then
4204 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4205 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4211 if Length(P
) > 3 then
4213 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4214 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4215 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4216 if g_Game_IsClient
then
4217 MC_SEND_PlayerSettings
4218 else if gGameOn
and (gPlayer1
<> nil) then
4220 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4221 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4227 if Length(P
) > 3 then
4229 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4230 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4231 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4232 if g_Game_IsClient
then
4233 MC_SEND_PlayerSettings
4234 else if gGameOn
and (gPlayer2
<> nil) then
4236 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4237 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4243 if (Length(P
) > 1) then
4245 gPlayer1Settings
.Model
:= P
[1];
4246 if g_Game_IsClient
then
4247 MC_SEND_PlayerSettings
4248 else if gGameOn
and (gPlayer1
<> nil) then
4250 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4251 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4252 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4258 if (Length(P
) > 1) then
4260 gPlayer2Settings
.Model
:= P
[1];
4261 if g_Game_IsClient
then
4262 MC_SEND_PlayerSettings
4263 else if gGameOn
and (gPlayer2
<> nil) then
4265 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4266 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4267 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4273 // TODO: switch teams if in game or store this separately
4274 if (Length(P
) > 1) then
4276 team
:= ParseTeam(P
[1]);
4277 if team
= TEAM_NONE
then
4278 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4279 else if not gGameOn
and not g_Game_IsNet
then
4280 gPlayer1Settings
.Team
:= team
4282 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4287 // TODO: switch teams if in game or store this separately
4288 if (Length(P
) > 1) then
4290 team
:= ParseTeam(P
[1]);
4291 if team
= TEAM_NONE
then
4292 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4293 else if not gGameOn
and not g_Game_IsNet
then
4294 gPlayer2Settings
.Team
:= team
4296 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4301 if (Length(P
) = 2) then
4302 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4306 if (Length(P
) = 2) then
4307 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4311 if (Length(P
) = 2) then
4312 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4316 if (Length(P
) = 2) then
4317 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4321 if (Length(P
) = 2) then
4322 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4326 if (Length(P
) = 2) then
4327 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4329 'p1_priority_kastet':
4331 if (Length(P
) = 2) then
4332 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4334 'p2_priority_kastet':
4336 if (Length(P
) = 2) then
4337 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4341 if (Length(P
) = 2) then
4342 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4346 if (Length(P
) = 2) then
4347 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4349 'p1_priority_pistol':
4351 if (Length(P
) = 2) then
4352 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4354 'p2_priority_pistol':
4356 if (Length(P
) = 2) then
4357 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4359 'p1_priority_shotgun1':
4361 if (Length(P
) = 2) then
4362 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4364 'p2_priority_shotgun1':
4366 if (Length(P
) = 2) then
4367 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4369 'p1_priority_shotgun2':
4371 if (Length(P
) = 2) then
4372 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4374 'p2_priority_shotgun2':
4376 if (Length(P
) = 2) then
4377 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4379 'p1_priority_chaingun':
4381 if (Length(P
) = 2) then
4382 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4384 'p2_priority_chaingun':
4386 if (Length(P
) = 2) then
4387 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4389 'p1_priority_rocketlauncher':
4391 if (Length(P
) = 2) then
4392 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4394 'p2_priority_rocketlauncher':
4396 if (Length(P
) = 2) then
4397 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4399 'p1_priority_plasma':
4401 if (Length(P
) = 2) then
4402 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4404 'p2_priority_plasma':
4406 if (Length(P
) = 2) then
4407 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4411 if (Length(P
) = 2) then
4412 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4416 if (Length(P
) = 2) then
4417 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4419 'p1_priority_super':
4421 if (Length(P
) = 2) then
4422 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4424 'p2_priority_super':
4426 if (Length(P
) = 2) then
4427 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4429 'p1_priority_flamethrower':
4431 if (Length(P
) = 2) then
4432 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4434 'p2_priority_flamethrower':
4436 if (Length(P
) = 2) then
4437 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4439 'p1_priority_berserk':
4441 if (Length(P
) = 2) then
4442 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4444 'p2_priority_berserk':
4446 if (Length(P
) = 2) then
4447 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4452 procedure PrintHeapStats();
4456 hs
:= GetFPCHeapStatus();
4457 e_LogWriteLn ('v===== heap status =====v');
4458 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4459 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4460 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4461 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4462 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4463 e_LogWriteLn ('^=======================^');
4466 procedure DebugCommands(P
: SSArray
);
4473 // Команды отладочного режима:
4474 if {gDebugMode}conIsCheatsEnabled
then
4476 cmd
:= LowerCase(P
[0]);
4477 if cmd
= 'd_window' then
4479 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4480 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4482 else if cmd
= 'd_sounds' then
4484 if (Length(P
) > 1) and
4485 ((P
[1] = '1') or (P
[1] = '0')) then
4486 g_Debug_Sounds
:= (P
[1][1] = '1');
4488 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4490 else if cmd
= 'd_frames' then
4492 if (Length(P
) > 1) and
4493 ((P
[1] = '1') or (P
[1] = '0')) then
4494 g_Debug_Frames
:= (P
[1][1] = '1');
4496 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4498 else if cmd
= 'd_winmsg' then
4500 if (Length(P
) > 1) and
4501 ((P
[1] = '1') or (P
[1] = '0')) then
4502 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4504 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4506 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4508 if (Length(P
) > 1) and
4509 ((P
[1] = '1') or (P
[1] = '0')) then
4510 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4512 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4514 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4516 if Length(P
) > 1 then
4518 '0': g_debug_BotAIOff
:= 0;
4519 '1': g_debug_BotAIOff
:= 1;
4520 '2': g_debug_BotAIOff
:= 2;
4521 '3': g_debug_BotAIOff
:= 3;
4524 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4526 else if cmd
= 'd_monster' then
4528 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4529 if Length(P
) < 2 then
4531 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4532 g_Console_Add('ID | Name');
4533 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4534 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4535 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4538 a
:= StrToIntDef(P
[1], 0);
4539 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4540 a
:= g_Mons_TypeIdByName(P
[1]);
4542 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4543 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4546 with gPlayer1
.Obj
do
4548 mon
:= g_Monsters_Create(a
,
4549 X
+ Rect
.X
+ (Rect
.Width
div 2),
4550 Y
+ Rect
.Y
+ Rect
.Height
,
4551 gPlayer1
.Direction
, True);
4553 if (Length(P
) > 2) and (mon
<> nil) then
4555 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4556 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4557 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4558 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4559 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4560 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4561 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4562 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4563 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4568 else if (cmd
= 'd_health') then
4570 if (Length(P
) > 1) and
4571 ((P
[1] = '1') or (P
[1] = '0')) then
4572 g_debug_HealthBar
:= (P
[1][1] = '1');
4574 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4576 else if (cmd
= 'd_player') then
4578 if (Length(P
) > 1) and
4579 ((P
[1] = '1') or (P
[1] = '0')) then
4580 g_debug_Player
:= (P
[1][1] = '1');
4582 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4584 else if (cmd
= 'd_mem') then
4590 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4594 procedure GameCheats(P
: SSArray
);
4600 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4602 g_Console_Add('not available');
4608 g_Console_Add('where is the player?!');
4611 cmd
:= LowerCase(P
[0]);
4615 plr
.GodMode
:= not plr
.GodMode
;
4616 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4619 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4620 if cmd
= 'give' then
4622 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4623 for f
:= 1 to High(P
) do
4625 cmd
:= LowerCase(P
[f
]);
4626 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4627 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4628 if cmd
= 'exit' then
4630 if gTriggers
<> nil then
4632 for a
:= 0 to High(gTriggers
) do
4634 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4636 g_Console_Add('player left the map');
4637 gExitByTrigger
:= True;
4638 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4639 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4647 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4648 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4649 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4650 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4651 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4653 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4654 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4656 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4657 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;
4659 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4660 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4662 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4663 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4665 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4666 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4668 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4669 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4670 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4672 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4673 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4674 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4675 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;
4676 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4677 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4679 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;
4680 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;
4681 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;
4682 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;
4683 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;
4684 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;
4686 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4687 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;
4689 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;
4690 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;
4692 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4694 if cmd
= 'ammo' then
4696 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4697 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4698 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4699 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4700 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4701 g_Console_Add('player got some ammo');
4705 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4706 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4708 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4709 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4711 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4712 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4714 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4715 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4717 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4719 if cmd
= 'weapons' then
4721 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4722 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4723 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4724 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4725 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4726 plr
.GiveItem(ITEM_WEAPON_BFG
);
4727 g_Console_Add('player got weapons');
4731 if cmd
= 'keys' then
4733 plr
.GiveItem(ITEM_KEY_RED
);
4734 plr
.GiveItem(ITEM_KEY_GREEN
);
4735 plr
.GiveItem(ITEM_KEY_BLUE
);
4736 g_Console_Add('player got all keys');
4740 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4745 if cmd
= 'open' then
4747 g_Console_Add('player activated sesame');
4748 g_Triggers_OpenAll();
4755 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4759 if cmd
= 'noclip' then
4762 g_Console_Add('wall hardeness adjusted');
4766 if cmd
= 'notarget' then
4768 plr
.NoTarget
:= not plr
.NoTarget
;
4769 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4773 if cmd
= 'noreload' then
4775 plr
.NoReload
:= not plr
.NoReload
;
4776 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4780 if cmd
= 'speedy' then
4782 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4783 g_Console_Add('speed adjusted');
4787 if cmd
= 'jumpy' then
4789 VEL_JUMP
:= 30-VEL_JUMP
;
4790 g_Console_Add('jump height adjusted');
4794 if cmd
= 'automap' then
4796 gShowMap
:= not gShowMap
;
4797 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4801 if cmd
= 'aimline' then
4803 gAimLine
:= not gAimLine
;
4804 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4809 procedure GameCommands(P
: SSArray
);
4815 pl
: pTNetClient
= nil;
4823 cmd
:= LowerCase(P
[0]);
4825 if cmd
= 'pause' then
4827 if (g_ActiveWindow
= nil) then
4828 g_Game_Pause(not gPauseMain
);
4830 else if cmd
= 'endgame' then
4831 gExit
:= EXIT_SIMPLE
4832 else if cmd
= 'restart' then
4834 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4836 if g_Game_IsClient
then
4838 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4843 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4845 else if cmd
= 'kick' then
4847 if g_Game_IsServer
then
4849 if Length(P
) < 2 then
4851 g_Console_Add('kick <name>');
4856 g_Console_Add('kick <name>');
4860 if g_Game_IsNet
then
4861 pl
:= g_Net_Client_ByName(P
[1]);
4864 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4865 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4866 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4867 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4868 g_Net_Slist_ServerPlayerLeaves();
4869 end else if gPlayers
<> nil then
4870 for a
:= Low(gPlayers
) to High(gPlayers
) do
4871 if gPlayers
[a
] <> nil then
4872 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4874 // Не отключать основных игроков в сингле
4875 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4877 gPlayers
[a
].Lives
:= 0;
4878 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4879 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4880 g_Player_Remove(gPlayers
[a
].UID
);
4881 g_Net_Slist_ServerPlayerLeaves();
4882 // Если не перемешать, при добавлении новых ботов появятся старые
4886 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4888 else if cmd
= 'kick_id' then
4890 if g_Game_IsServer
and g_Game_IsNet
then
4892 if Length(P
) < 2 then
4894 g_Console_Add('kick_id <client ID>');
4899 g_Console_Add('kick_id <client ID>');
4903 a
:= StrToIntDef(P
[1], 0);
4904 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4906 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4908 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4909 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
4910 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4911 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4912 g_Net_Slist_ServerPlayerLeaves();
4916 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4918 else if cmd
= 'kick_pid' then
4920 if g_Game_IsServer
and g_Game_IsNet
then
4922 if Length(P
) < 2 then
4924 g_Console_Add('kick_pid <player ID>');
4929 g_Console_Add('kick_pid <player ID>');
4933 a
:= StrToIntDef(P
[1], 0);
4934 pl
:= g_Net_Client_ByPlayer(a
);
4935 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4937 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4938 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4939 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4940 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4941 g_Net_Slist_ServerPlayerLeaves();
4944 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4946 else if cmd
= 'ban' then
4948 if g_Game_IsServer
and g_Game_IsNet
then
4950 if Length(P
) < 2 then
4952 g_Console_Add('ban <name>');
4957 g_Console_Add('ban <name>');
4961 pl
:= g_Net_Client_ByName(P
[1]);
4964 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4965 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4966 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
4967 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4968 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4969 g_Net_Slist_ServerPlayerLeaves();
4971 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4973 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4975 else if cmd
= 'ban_id' then
4977 if g_Game_IsServer
and g_Game_IsNet
then
4979 if Length(P
) < 2 then
4981 g_Console_Add('ban_id <client ID>');
4986 g_Console_Add('ban_id <client ID>');
4990 a
:= StrToIntDef(P
[1], 0);
4991 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4992 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4994 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4995 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
4996 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
4997 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4998 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4999 g_Net_Slist_ServerPlayerLeaves();
5002 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5004 else if cmd
= 'ban_pid' then
5006 if g_Game_IsServer
and g_Game_IsNet
then
5008 if Length(P
) < 2 then
5010 g_Console_Add('ban_pid <player ID>');
5015 g_Console_Add('ban_pid <player ID>');
5019 a
:= StrToIntDef(P
[1], 0);
5020 pl
:= g_Net_Client_ByPlayer(a
);
5021 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5023 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5024 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5025 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5026 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5027 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5028 g_Net_Slist_ServerPlayerLeaves();
5031 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5033 else if cmd
= 'permban' then
5035 if g_Game_IsServer
and g_Game_IsNet
then
5037 if Length(P
) < 2 then
5039 g_Console_Add('permban <name>');
5044 g_Console_Add('permban <name>');
5048 pl
:= g_Net_Client_ByName(P
[1]);
5051 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5052 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5053 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5054 g_Net_SaveBanList();
5055 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5056 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5057 g_Net_Slist_ServerPlayerLeaves();
5059 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5061 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5063 else if cmd
= 'permban_id' then
5065 if g_Game_IsServer
and g_Game_IsNet
then
5067 if Length(P
) < 2 then
5069 g_Console_Add('permban_id <client ID>');
5074 g_Console_Add('permban_id <client ID>');
5078 a
:= StrToIntDef(P
[1], 0);
5079 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5080 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5082 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5083 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5084 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5085 g_Net_SaveBanList();
5086 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5087 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5088 g_Net_Slist_ServerPlayerLeaves();
5091 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5093 else if cmd
= 'permban_pid' then
5095 if g_Game_IsServer
and g_Game_IsNet
then
5097 if Length(P
) < 2 then
5099 g_Console_Add('permban_pid <player ID>');
5104 g_Console_Add('permban_pid <player ID>');
5108 a
:= StrToIntDef(P
[1], 0);
5109 pl
:= g_Net_Client_ByPlayer(a
);
5110 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5112 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5113 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5114 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5115 g_Net_SaveBanList();
5116 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5117 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5118 g_Net_Slist_ServerPlayerLeaves();
5121 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5123 else if cmd
= 'permban_ip' then
5125 if g_Game_IsServer
and g_Game_IsNet
then
5127 if Length(P
) < 2 then
5129 g_Console_Add('permban_ip <IP address>');
5134 g_Console_Add('permban_ip <IP address>');
5138 g_Net_BanHost(P
[1]);
5139 g_Net_SaveBanList();
5140 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5142 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5144 else if cmd
= 'unban' then
5146 if g_Game_IsServer
and g_Game_IsNet
then
5148 if Length(P
) < 2 then
5150 g_Console_Add('unban <IP Address>');
5155 g_Console_Add('unban <IP Address>');
5159 if g_Net_UnbanHost(P
[1]) then
5161 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5162 g_Net_SaveBanList();
5164 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5166 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5168 else if cmd
= 'clientlist' then
5170 if g_Game_IsServer
and g_Game_IsNet
then
5173 if NetClients
<> nil then
5174 for a
:= Low(NetClients
) to High(NetClients
) do
5175 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5177 plr
:= g_Player_Get(NetClients
[a
].Player
);
5178 if plr
= nil then continue
;
5180 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5181 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5184 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5186 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5188 else if cmd
= 'connect' then
5190 if (NetMode
= NET_NONE
) then
5192 if Length(P
) < 2 then
5194 g_Console_Add('connect <IP> [port] [password]');
5199 g_Console_Add('connect <IP> [port] [password]');
5203 if Length(P
) > 2 then
5204 prt
:= StrToIntDef(P
[2], 25666)
5208 if Length(P
) > 3 then
5213 g_Game_StartClient(P
[1], prt
, pw
);
5216 else if cmd
= 'disconnect' then
5218 if (NetMode
= NET_CLIENT
) then
5221 else if cmd
= 'reconnect' then
5223 if (NetMode
= NET_SERVER
) then
5226 if (NetMode
= NET_CLIENT
) then
5229 gExit
:= EXIT_SIMPLE
;
5233 //TODO: Use last successful password to reconnect, instead of ''
5234 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5236 else if (cmd
= 'addbot') or
5237 (cmd
= 'bot_add') then
5239 if Length(P
) > 2 then
5240 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5241 else if Length(P
) > 1 then
5242 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5244 g_Bot_Add(TEAM_NONE
, 2);
5246 else if cmd
= 'bot_addlist' then
5248 if Length(P
) > 1 then
5250 if Length(P
) = 2 then
5251 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5252 else if Length(P
) = 3 then
5253 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5255 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5258 else if cmd
= 'bot_removeall' then
5260 else if cmd
= 'chat' then
5262 if g_Game_IsNet
then
5264 if Length(P
) > 1 then
5266 for a
:= 1 to High(P
) do
5267 chstr
:= chstr
+ P
[a
] + ' ';
5269 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5271 if Length(chstr
) < 1 then
5273 g_Console_Add('chat <text>');
5277 chstr
:= b_Text_Format(chstr
);
5278 if g_Game_IsClient
then
5279 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5281 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5284 g_Console_Add('chat <text>');
5286 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5288 else if cmd
= 'teamchat' then
5290 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5292 if Length(P
) > 1 then
5294 for a
:= 1 to High(P
) do
5295 chstr
:= chstr
+ P
[a
] + ' ';
5297 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5299 if Length(chstr
) < 1 then
5301 g_Console_Add('teamchat <text>');
5305 chstr
:= b_Text_Format(chstr
);
5306 if g_Game_IsClient
then
5307 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5309 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5310 gPlayer1Settings
.Team
);
5313 g_Console_Add('teamchat <text>');
5315 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5317 else if (cmd
= 'an') or (cmd
= 'announce') then
5319 if g_Game_IsNet
then
5321 if Length(P
) > 1 then
5323 for a
:= 1 to High(P
) do
5324 chstr
:= chstr
+ P
[a
] + ' ';
5326 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5328 if Length(chstr
) < 1 then
5330 g_Console_Add('announce <text>');
5334 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5335 if g_Game_IsClient
then
5336 MC_SEND_RCONCommand(chstr
)
5338 g_Console_Process(chstr
, True);
5341 g_Console_Add('announce <text>');
5343 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5345 else if cmd
= 'game' then
5347 if gGameSettings
.GameType
<> GT_NONE
then
5349 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5352 if Length(P
) = 1 then
5354 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5357 // game not started yet, load fist map from some wad
5359 s
:= addWadExtension(P
[1]);
5360 found
:= e_FindResource(AllMapDirs
, s
);
5364 P
[1] := ExpandFileName(P
[1]);
5365 // if map not choosed then set first map
5366 if Length(P
) < 3 then
5369 P
[2] := g_Game_GetFirstMap(P
[1]);
5372 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5374 if g_Map_Exist(s
) then
5378 with gGameSettings
do
5380 Options
:= gsGameFlags
;
5381 GameMode
:= g_Game_TextToMode(gsGameMode
);
5382 if gSwitchGameMode
<> GM_NONE
then
5383 GameMode
:= gSwitchGameMode
;
5384 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5385 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5387 if Length(P
) >= 4 then
5388 b
:= StrToIntDef(P
[3], 1);
5389 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5390 ScoreLimit
, MaxLives
, Options
, b
);
5395 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5397 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5399 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5401 else if cmd
= 'host' then
5403 if gGameSettings
.GameType
<> GT_NONE
then
5405 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5408 if Length(P
) < 4 then
5410 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5413 if not StrToIp(P
[1], listen
) then
5415 prt
:= StrToIntDef(P
[2], 25666);
5417 s
:= addWadExtension(P
[3]);
5418 found
:= e_FindResource(AllMapDirs
, s
);
5422 // get first map in wad, if not specified
5423 if Length(P
) < 5 then
5426 P
[4] := g_Game_GetFirstMap(P
[1]);
5428 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5429 if g_Map_Exist(s
) then
5433 with gGameSettings
do
5435 Options
:= gsGameFlags
;
5436 GameMode
:= g_Game_TextToMode(gsGameMode
);
5437 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5438 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5439 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5441 if Length(P
) >= 6 then
5442 b
:= StrToIntDef(P
[5], 0);
5443 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5449 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5451 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5456 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5459 else if cmd
= 'map' then
5461 if Length(P
) = 1 then
5463 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5465 g_Console_Add(cmd
+ ' <MAP>');
5466 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5470 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5475 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5477 if Length(P
) < 3 then
5479 // first param is map or wad
5480 s
:= UpperCase(P
[1]);
5481 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5483 gExitByTrigger
:= False;
5486 // already in game, finish current map
5488 gExit
:= EXIT_ENDLEVELCUSTOM
;
5492 // intermission, so change map immediately
5499 found
:= e_FindResource(AllMapDirs
, s
);
5501 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5504 // no such map, found wad
5507 P
[1] := ExpandFileName(pw
);
5508 P
[2] := g_Game_GetFirstMap(P
[1]);
5509 s
:= P
[1] + ':\' + P
[2];
5510 if g_Map_Exist(s
) then
5512 gExitByTrigger
:= False;
5515 // already in game, finish current map
5517 gExit
:= EXIT_ENDLEVELCUSTOM
5521 // intermission, so change map immediately
5528 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5530 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5535 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5541 s
:= addWadExtension(P
[1]);
5542 found
:= e_FindResource(AllMapDirs
, s
);
5546 P
[2] := UpperCase(P
[2]);
5547 s
:= P
[1] + ':\' + P
[2];
5548 if g_Map_Exist(s
) then
5550 gExitByTrigger
:= False;
5554 gExit
:= EXIT_ENDLEVELCUSTOM
5563 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5568 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5574 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5578 else if cmd
= 'nextmap' then
5580 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5582 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5587 if Length(P
) = 1 then
5589 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5591 g_Console_Add(cmd
+ ' <MAP>');
5592 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5597 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5603 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5605 if Length(P
) < 3 then
5607 // first param is map or wad
5608 s
:= UpperCase(P
[1]);
5609 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5612 gExitByTrigger
:= False;
5618 // no such map, found wad
5619 pw
:= addWadExtension(P
[1]);
5620 found
:= e_FindResource(MapDirs
, pw
);
5622 found
:= e_FindResource(WadDirs
, pw
);
5624 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5627 // map not specified, select first map
5629 P
[2] := g_Game_GetFirstMap(P
[1]);
5630 s
:= P
[1] + ':\' + P
[2];
5631 if g_Map_Exist(s
) then
5633 gExitByTrigger
:= False;
5640 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5642 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5647 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5653 // specified two params wad + map
5654 pw
:= addWadExtension(P
[1]);
5655 found
:= e_FindResource(MapDirs
, pw
);
5657 found
:= e_FindResource(MapDirs
, pw
);
5661 P
[2] := UpperCase(P
[2]);
5662 s
:= P
[1] + ':\' + P
[2];
5663 if g_Map_Exist(s
) then
5665 gExitByTrigger
:= False;
5671 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5676 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5682 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5687 if gNextMap
= '' then
5688 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5690 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5694 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5698 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5702 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5704 gExitByTrigger
:= False;
5705 // next map not specified, try to find trigger EXIT
5706 if (gNextMap
= '') and (gTriggers
<> nil) then
5708 for a
:= 0 to High(gTriggers
) do
5710 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5712 gExitByTrigger
:= True;
5713 //gNextMap := gTriggers[a].Data.MapName;
5714 gNextMap
:= gTriggers
[a
].tgcMap
;
5719 if gNextMap
= '' then
5720 gNextMap
:= g_Game_GetNextMap();
5721 if not isWadPath(gNextMap
) then
5722 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5725 if g_Map_Exist(s
) then
5726 gExit
:= EXIT_ENDLEVELCUSTOM
5728 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5732 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5736 else if (cmd
= 'event') then
5738 if (Length(P
) <= 1) then
5740 for a
:= 0 to High(gEvents
) do
5741 if gEvents
[a
].Command
= '' then
5742 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5744 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5747 if (Length(P
) = 2) then
5749 for a
:= 0 to High(gEvents
) do
5750 if gEvents
[a
].Name
= P
[1] then
5751 if gEvents
[a
].Command
= '' then
5752 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5754 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5757 for a
:= 0 to High(gEvents
) do
5758 if gEvents
[a
].Name
= P
[1] then
5760 gEvents
[a
].Command
:= '';
5761 for b
:= 2 to High(P
) do
5762 if Pos(' ', P
[b
]) = 0 then
5763 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5765 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5766 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5770 else if cmd
= 'suicide' then
5774 if g_Game_IsClient
then
5775 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5778 if gPlayer1
<> nil then
5779 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5780 if gPlayer2
<> nil then
5781 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5785 else if cmd
= 'screenshot' then
5789 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5791 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5793 gWeaponAction
[0, WP_PREV
] := True;
5795 gWeaponAction
[0, WP_NEXT
] := True;
5797 else if cmd
= 'weapon' then
5799 if Length(p
) = 2 then
5801 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5802 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5803 gSelectWeapon
[0, a
] := True
5806 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5807 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5809 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5810 b
:= ord(cmd
[2]) - ord('1');
5812 gWeaponAction
[b
, WP_PREV
] := True;
5814 gWeaponAction
[b
, WP_NEXT
] := True;
5816 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5818 if Length(p
) = 2 then
5820 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5821 b
:= ord(cmd
[2]) - ord('1');
5822 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5823 gSelectWeapon
[b
, a
] := True
5826 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
5828 b
:= ord(cmd
[2]) - ord('1');
5830 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
5832 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
5834 else if (cmd
= 'dropflag') then
5836 if g_Game_IsServer
then
5838 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
5839 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
5842 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5844 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
5846 b
:= ord(cmd
[2]) - ord('1');
5847 if g_Game_IsServer
then
5849 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
5850 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
5853 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5855 // Команды Своей игры:
5856 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5858 if cmd
= 'bot_addred' then
5860 if Length(P
) > 1 then
5861 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5863 g_Bot_Add(TEAM_RED
, 2);
5865 else if cmd
= 'bot_addblue' then
5867 if Length(P
) > 1 then
5868 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5870 g_Bot_Add(TEAM_BLUE
, 2);
5872 else if cmd
= 'spectate' then
5878 else if cmd
= 'say' then
5880 if g_Game_IsServer
and g_Game_IsNet
then
5882 if Length(P
) > 1 then
5885 for a
:= 1 to High(P
) do
5886 chstr
:= chstr
+ P
[a
] + ' ';
5888 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5890 if Length(chstr
) < 1 then
5892 g_Console_Add('say <text>');
5896 chstr
:= b_Text_Format(chstr
);
5897 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5899 else g_Console_Add('say <text>');
5901 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5903 else if cmd
= 'tell' then
5905 if g_Game_IsServer
and g_Game_IsNet
then
5907 if (Length(P
) > 2) and (P
[1] <> '') then
5910 for a
:= 2 to High(P
) do
5911 chstr
:= chstr
+ P
[a
] + ' ';
5913 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5915 if Length(chstr
) < 1 then
5917 g_Console_Add('tell <playername> <text>');
5921 pl
:= g_Net_Client_ByName(P
[1]);
5923 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5925 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5927 else g_Console_Add('tell <playername> <text>');
5929 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5931 else if cmd
= 'centerprint' then
5933 if (Length(P
) > 2) and (P
[1] <> '') then
5936 for a
:= 2 to High(P
) do
5937 chstr
:= chstr
+ P
[a
] + ' ';
5939 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5941 if Length(chstr
) < 1 then
5943 g_Console_Add('centerprint <timeout> <text>');
5947 a
:= StrToIntDef(P
[1], 100);
5948 chstr
:= b_Text_Format(chstr
);
5949 g_Game_Message(chstr
, a
);
5950 if g_Game_IsNet
and g_Game_IsServer
then
5951 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
5953 else g_Console_Add('centerprint <timeout> <text>');
5955 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5957 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5959 // Дополнительное время:
5960 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5962 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5963 [gGameSettings
.TimeLimit
div 3600,
5964 (gGameSettings
.TimeLimit
div 60) mod 60,
5965 gGameSettings
.TimeLimit
mod 60]));
5966 if g_Game_IsNet
then MH_SEND_GameSettings
;
5968 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5970 if (Length(P
) <= 1) then
5971 g_Console_Add('rcon_password <password>')
5973 MC_SEND_RCONPassword(P
[1]);
5975 else if cmd
= 'rcon' then
5977 if g_Game_IsClient
then
5979 if Length(P
) > 1 then
5982 for a
:= 1 to High(P
) do
5983 chstr
:= chstr
+ P
[a
] + ' ';
5985 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5987 if Length(chstr
) < 1 then
5989 g_Console_Add('rcon <command>');
5993 MC_SEND_RCONCommand(chstr
);
5995 else g_Console_Add('rcon <command>');
5998 else if cmd
= 'ready' then
6000 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6001 gLMSRespawnTime
:= gTime
+ 100;
6003 else if (cmd
= 'callvote') and g_Game_IsNet
then
6005 if Length(P
) > 1 then
6008 for a
:= 1 to High(P
) do begin
6009 if a
> 1 then chstr
:= chstr
+ ' ';
6010 chstr
:= chstr
+ P
[a
];
6013 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6015 if Length(chstr
) < 1 then
6017 g_Console_Add('callvote <command>');
6021 if g_Game_IsClient
then
6022 MC_SEND_Vote(True, chstr
)
6024 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6025 g_Console_Process('vote', True);
6028 g_Console_Add('callvote <command>');
6030 else if (cmd
= 'vote') and g_Game_IsNet
then
6032 if g_Game_IsClient
then
6034 else if gVoteInProgress
then
6036 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6037 a
:= Floor((NetClientCount
+1)/2.0) + 1
6039 a
:= Floor(NetClientCount
/2.0) + 1;
6044 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6045 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6051 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6052 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6060 procedure SystemCommands(P
: SSArray
);
6064 cmd
:= LowerCase(P
[0]);
6075 if Length(p
) = 2 then
6077 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6079 gFrameTime
:= 1000 div gMaxFPS
6083 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6087 if Length(p
) = 2 then
6089 gAskLanguage
:= true;
6090 gLanguage
:= LANGUAGE_ENGLISH
;
6091 case LowerCase(p
[1]) of
6094 gAskLanguage
:= false;
6095 gLanguage
:= LANGUAGE_ENGLISH
;
6099 gAskLanguage
:= false;
6100 gLanguage
:= LANGUAGE_RUSSIAN
;
6104 gAskLanguage
:= true;
6105 gLanguage
:= LANGUAGE_ENGLISH
;
6108 g_Language_Set(gLanguage
);
6112 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6118 procedure g_TakeScreenShot(Filename
: string = '');
6119 var t
: TDateTime
; dir
, date
, name
: String;
6121 if e_NoGraphics
then
6124 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6125 if Filename
= '' then
6128 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6129 Filename
:= 'screenshot-' + date
;
6132 name
:= e_CatPath(dir
, Filename
+ '.png');
6133 if r_Render_WriteScreenShot(name
) then
6134 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6136 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6139 procedure g_Game_InGameMenu(Show
: Boolean);
6141 if (g_ActiveWindow
= nil) and Show
then
6143 if gGameSettings
.GameType
= GT_SINGLE
then
6144 g_GUI_ShowWindow('GameSingleMenu')
6147 if g_Game_IsClient
then
6148 g_GUI_ShowWindow('GameClientMenu')
6150 if g_Game_IsNet
then
6151 g_GUI_ShowWindow('GameServerMenu')
6153 g_GUI_ShowWindow('GameCustomMenu');
6155 g_Sound_PlayEx('MENU_OPEN');
6157 // Пауза при меню только в одиночной игре:
6158 if (not g_Game_IsNet
) then
6162 if (g_ActiveWindow
<> nil) and (not Show
) then
6164 // Пауза при меню только в одиночной игре:
6165 if (not g_Game_IsNet
) then
6166 g_Game_Pause(False);
6170 procedure g_Game_Pause (Enable
: Boolean);
6174 if not gGameOn
then exit
;
6176 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6179 gPauseMain
:= Enable
;
6181 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6184 procedure g_Game_HolmesPause (Enable
: Boolean);
6188 if not gGameOn
then exit
;
6189 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6192 gPauseHolmes
:= Enable
;
6194 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6197 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6202 if gTriggers
<> nil then
6203 for i
:= 0 to High(gTriggers
) do
6204 with gTriggers
[i
] do
6205 if (TriggerType
= TRIGGER_SOUND
) and
6207 Sound
.IsPlaying() then
6209 Sound
.Pause(Enable
);
6213 if gPlayers
<> nil then
6214 for i
:= 0 to High(gPlayers
) do
6215 if gPlayers
[i
] <> nil then
6216 gPlayers
[i
].PauseSounds(Enable
);
6219 if gMusic
<> nil then
6220 gMusic
.Pause(Enable
);
6223 procedure g_Game_StopAllSounds(all
: Boolean);
6227 if gTriggers
<> nil then
6228 for i
:= 0 to High(gTriggers
) do
6229 with gTriggers
[i
] do
6230 if (TriggerType
= TRIGGER_SOUND
) and
6234 if gMusic
<> nil then
6241 procedure g_Game_UpdateTriggerSounds
;
6244 if gTriggers
<> nil then
6245 for i
:= 0 to High(gTriggers
) do
6246 with gTriggers
[i
] do
6247 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6248 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6251 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6254 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6259 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6264 if gSpectMode
<> SPECT_PLAYERS
then
6266 if gSpectPID1
= UID
then
6271 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6278 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6283 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6288 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6293 if gSpectMode
<> SPECT_PLAYERS
then
6295 Pl
:= g_Player_Get(gSpectPID1
);
6296 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6301 if gSpectViewTwo
then
6303 Pl
:= g_Player_Get(gSpectPID2
);
6304 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6312 procedure g_Game_Message(Msg
: string; Time
: Word);
6314 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
6315 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
6316 MessageTime
:= Time
;
6319 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6321 punct
: Array[0..13] of String =
6322 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6328 function IsPunctuation(S
: String): Boolean;
6333 if Length(S
) <> 1 then
6335 for i
:= Low(punct
) to High(punct
) do
6336 if S
= punct
[i
] then
6342 function FilterPunctuation(S
: String): String;
6346 for i
:= Low(punct
) to High(punct
) do
6347 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6353 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6355 // remove player name
6356 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6357 // for FullWord check
6358 Text := toLowerCase1251(' ' + Text + ' ');
6359 fpText
:= FilterPunctuation(Text);
6361 for i
:= 0 to Length(gChatSounds
) - 1 do
6364 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6366 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6367 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6369 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6375 gChatSounds
[i
].Sound
.Play();
6381 g_Sound_PlayEx('SOUND_GAME_RADIO');
6384 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6393 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6397 if goodsnd
[a
].IsPlaying() then
6400 goodsnd
[Random(4)].Play();
6403 procedure g_Game_Announce_KillCombo(Param
: Integer);
6410 UID
:= Param
and $FFFF;
6415 Pl
:= g_Player_Get(UID
);
6424 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6428 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6432 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6436 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6444 if not g_Game_IsWatchedPlayer(UID
) then
6447 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6451 if killsnd
[n
].IsPlaying() then
6456 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6464 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6468 if hahasnd
[a
].IsPlaying() then
6471 hahasnd
[Random(3)].Play();
6474 procedure g_Game_StartVote(Command
, Initiator
: string);
6478 if not gVotesEnabled
then Exit
;
6479 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6480 if gVoteInProgress
or gVotePassed
then
6482 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6483 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6486 gVoteInProgress
:= True;
6487 gVotePassed
:= False;
6488 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6491 gVoteCommand
:= Command
;
6493 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6494 Need
:= Floor((NetClientCount
+1)/2.0)+1
6496 Need
:= Floor(NetClientCount
/2.0)+1;
6497 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6498 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6501 procedure g_Game_CheckVote
;
6505 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6506 if not gVoteInProgress
then Exit
;
6508 if (gTime
>= gVoteTimer
) then
6510 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6511 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6513 Need
:= Floor(NetClientCount
/2.0) + 1;
6514 if gVoteCount
>= Need
then
6516 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6517 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6518 gVotePassed
:= True;
6519 gVoteCmdTimer
:= gTime
+ 5000;
6523 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6524 MH_SEND_VoteEvent(NET_VE_FAILED
);
6526 if NetClients
<> nil then
6527 for I
:= Low(NetClients
) to High(NetClients
) do
6528 if NetClients
[i
].Used
then
6529 NetClients
[i
].Voted
:= False;
6530 gVoteInProgress
:= False;
6536 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6537 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6539 Need
:= Floor(NetClientCount
/2.0) + 1;
6540 if gVoteCount
>= Need
then
6542 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6543 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6544 gVoteInProgress
:= False;
6545 gVotePassed
:= True;
6546 gVoteCmdTimer
:= gTime
+ 5000;
6549 if NetClients
<> nil then
6550 for I
:= Low(NetClients
) to High(NetClients
) do
6551 if NetClients
[i
].Used
then
6552 NetClients
[i
].Voted
:= False;
6557 procedure g_Game_LoadMapList(FileName
: string);
6565 if not FileExists(FileName
) then Exit
;
6567 AssignFile(ListFile
, FileName
);
6569 while not EOF(ListFile
) do
6571 ReadLn(ListFile
, s
);
6574 if s
= '' then Continue
;
6576 SetLength(MapList
, Length(MapList
)+1);
6577 MapList
[High(MapList
)] := s
;
6579 CloseFile(ListFile
);
6582 procedure g_Game_SetDebugMode();
6585 // Читы (даже в своей игре):
6589 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6593 if Length(LoadingStat
.Msgs
) = 0 then
6599 begin // Переходим на следующую строку или скроллируем:
6600 if NextMsg
= Length(Msgs
) then
6602 for i
:= 0 to High(Msgs
)-1 do
6603 Msgs
[i
] := Msgs
[i
+1];
6611 Msgs
[NextMsg
-1] := Text;
6615 PBarWasHere
:= false;
6618 g_ActiveWindow
:= nil;
6619 ProcessLoading(True);
6622 procedure g_Game_StepLoading(Value
: Integer = -1);
6634 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6637 ProcessLoading(False);
6642 procedure g_Game_ClearLoading();
6651 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6652 if len
< 1 then len
:= 1;
6653 SetLength(Msgs
, len
);
6654 for len
:= Low(Msgs
) to High(Msgs
) do
6657 PBarWasHere
:= false;
6661 procedure Parse_Params(var pars
: TParamStrValues
);
6668 while i
<= ParamCount
do
6671 if (Length(s
) > 1) and (s
[1] = '-') then
6673 if (Length(s
) > 2) and (s
[2] = '-') then
6674 begin // Одиночный параметр
6675 SetLength(pars
, Length(pars
) + 1);
6676 with pars
[High(pars
)] do
6678 Name
:= LowerCase(s
);
6683 if (i
< ParamCount
) then
6684 begin // Параметр со значением
6686 SetLength(pars
, Length(pars
) + 1);
6687 with pars
[High(pars
)] do
6689 Name
:= LowerCase(s
);
6690 Value
:= LowerCase(ParamStr(i
));
6699 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6704 for i
:= 0 to High(pars
) do
6705 if pars
[i
].Name
= aName
then
6707 Result
:= pars
[i
].Value
;
6712 procedure g_Game_Process_Params();
6714 pars
: TParamStrValues
;
6717 LimT
, LimS
: Integer;
6728 s
:= Find_Param_Value(pars
, '--debug');
6731 g_Game_SetDebugMode();
6732 s
:= Find_Param_Value(pars
, '--netdump');
6737 // Connect when game loads
6738 ip
:= Find_Param_Value(pars
, '-connect');
6742 s
:= Find_Param_Value(pars
, '-port');
6743 if (s
= '') or not TryStrToInt(s
, Port
) then
6746 s
:= Find_Param_Value(pars
, '-pw');
6748 g_Game_StartClient(ip
, Port
, s
);
6752 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6755 gDefaultMegawadStart
:= s
;
6758 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6759 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6761 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6764 // Start map when game loads:
6765 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6766 if isWadPath(map
) then
6769 s
:= Find_Param_Value(pars
, '-gm');
6770 GMode
:= g_Game_TextToMode(s
);
6771 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6772 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6775 s
:= Find_Param_Value(pars
, '-limt');
6776 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6782 s
:= Find_Param_Value(pars
, '-lims');
6783 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6789 s
:= Find_Param_Value(pars
, '-lives');
6790 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6796 s
:= Find_Param_Value(pars
, '-opt');
6800 Opt
:= StrToIntDef(s
, 0);
6803 s
:= Find_Param_Value(pars
, '--close');
6807 // Override map to test:
6808 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6811 if e_IsValidResourceName(s
) then
6812 e_FindResource(AllMapDirs
, s
);
6813 gTestMap
:= ExpandFileName(s
);
6816 // Delete test map after play:
6817 s
:= Find_Param_Value(pars
, '--testdelete');
6820 //gMapToDelete := MapsDir + map;
6821 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6825 // Delete temporary WAD after play:
6826 s
:= Find_Param_Value(pars
, '--tempdelete');
6827 if (s
<> '') and (gTestMap
<> '') then
6829 gMapToDelete
:= gTestMap
;
6830 gTempDelete
:= True;
6833 // Number of players:
6834 s
:= Find_Param_Value(pars
, '-pl');
6836 n
:= DEFAULT_PLAYERS
6838 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6841 s
:= Find_Param_Value(pars
, '-port');
6842 if (s
= '') or not TryStrToInt(s
, Port
) then
6843 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6845 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6848 // Execute script when game loads:
6849 s
:= Find_Param_Value(pars
, '-exec');
6852 // if not isWadPath(s) then
6853 // s := GameDir + '/' + s;
6858 if IOResult
<> 0 then
6860 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6861 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6865 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6866 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6871 if IOResult
<> 0 then
6873 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6874 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6878 if Pos('#', s
) <> 1 then // script comment
6879 g_Console_Process(s
, True);
6890 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6891 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6892 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6893 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6895 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6896 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6897 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6898 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6900 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6901 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6903 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6904 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6906 {$IFDEF ENABLE_HOLMES}
6907 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6910 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6912 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6913 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6915 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6916 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6918 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6919 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6920 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6921 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
6922 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6923 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6924 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6925 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6926 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');