1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 g_base
, g_basic
, g_player
, g_res_downloader
,
24 g_sound
, g_gui
, utils
, md5
, mempool
, xprofiler
,
28 TGameSettings
= record
35 ItemRespawnTime
: Word;
46 TDelayedEvent
= record
55 Sound
: TPlayableSound
;
56 Tags
: Array of String;
60 TPlayerSettings
= record
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 MapList
: SSArray
= nil;
900 MapIndex
: Integer = -1;
901 InterReadyTime
: Integer = -1;
902 StatDate
: string = '';
917 function Compare(a
, b
: TPlayerStat
): Integer;
919 if a
.Spectator
then Result
:= 1
920 else if b
.Spectator
then Result
:= -1
921 else if a
.Frags
< b
.Frags
then Result
:= 1
922 else if a
.Frags
> b
.Frags
then Result
:= -1
923 else if a
.Deaths
< b
.Deaths
then Result
:= -1
924 else if a
.Deaths
> b
.Deaths
then Result
:= 1
925 else if a
.Kills
< b
.Kills
then Result
:= -1
929 procedure SortGameStat(var stat
: TPlayerStatArray
);
934 if stat
= nil then Exit
;
936 for I
:= High(stat
) downto Low(stat
) do
937 for J
:= Low(stat
) to High(stat
) - 1 do
938 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
941 stat
[J
] := stat
[J
+ 1];
946 // saves a shitty CSV containing the game stats passed to it
947 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
950 dir
, fname
, map
, mode
, etime
: String;
954 dir
:= e_GetWriteableDir(StatsDirs
);
955 // stats are placed in stats/yy/mm/dd/*.csv
956 fname
:= e_CatPath(dir
, Path
);
957 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
958 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
959 AssignFile(s
, fname
);
961 SetTextCodePage(s
, CP_UTF8
);
963 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
964 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
965 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
966 mode
:= g_Game_ModeToText(Stat
.GameMode
);
967 etime
:= Format('%d:%.2d:%.2d', [
968 Stat
.GameTime
div 1000 div 3600,
969 (Stat
.GameTime
div 1000 div 60) mod 60,
970 Stat
.GameTime
div 1000 mod 60
972 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
973 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
979 gGameSettings
.TimeLimit
,
980 gGameSettings
.ScoreLimit
,
981 gGameSettings
.Options
,
983 Length(Stat
.PlayerStat
)
985 // line 2: game specific shit
986 // if it's a team game: red score, blue score
987 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
989 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
991 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
992 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
994 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
995 // lines 3-...: team, player name, frags, deaths
996 WriteLn(s
, 'team,name,frags,deaths');
997 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
998 with Stat
.PlayerStat
[I
] do
999 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1001 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1004 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1009 procedure ClearDebugCvars();
1011 g_debug_Sounds
:= False;
1012 g_debug_Frames
:= False;
1013 g_debug_WinMsgs
:= False;
1014 g_debug_MonsterOff
:= False;
1015 g_debug_BotAIOff
:= 0;
1016 g_debug_HealthBar
:= False;
1017 g_Debug_Player
:= False;
1020 function g_Game_ModeToText(Mode
: Byte): string;
1024 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1025 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1026 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1027 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1028 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1032 function g_Game_TextToMode(Mode
: string): Byte;
1035 Mode
:= UpperCase(Mode
);
1036 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1041 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1046 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1051 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1056 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1058 Result
:= GM_SINGLE
;
1063 function g_Game_IsNet(): Boolean;
1065 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1068 function g_Game_IsServer(): Boolean;
1070 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1073 function g_Game_IsClient(): Boolean;
1075 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1078 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1085 Result
.name
:= ExtractFileName(WAD
);
1086 Result
.description
:= '';
1087 Result
.author
:= '';
1089 w
:= TWADFile
.Create();
1092 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1098 cfg
:= TConfig
.CreateMem(p
, len
);
1099 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1100 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1101 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1102 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1108 procedure g_Game_FreeWAD
;
1111 g_Sound_Delete('MUSIC_endmus');
1112 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1113 gGameSettings
.WAD
:= '';
1116 procedure g_Game_LoadWAD(WAD
: string);
1125 gGameSettings
.WAD
:= WAD
;
1126 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1129 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1131 w
:= TWADFile
.Create();
1134 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1140 cfg
:= TConfig
.CreateMem(p
, len
);
1143 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1144 if MegaWAD
.endpic
<> '' then
1145 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1147 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1148 if MegaWAD
.endmus
<> '' then
1150 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1151 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1159 {procedure start_trigger(t: string);
1163 function next_trigger(): Boolean;
1167 procedure DisableCheats();
1173 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1174 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1175 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1176 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1178 {$IF DEFINED(D2F_DEBUG)}
1179 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1180 gAimLine
:= g_dbg_aimline_on
;
1184 procedure g_Game_ExecuteEvent(Name
: String);
1190 if gEvents
= nil then
1192 for a
:= 0 to High(gEvents
) do
1193 if gEvents
[a
].Name
= Name
then
1195 if gEvents
[a
].Command
<> '' then
1196 g_Console_Process(gEvents
[a
].Command
, True);
1201 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1206 if gDelayedEvents
<> nil then
1207 for a
:= 0 to High(gDelayedEvents
) do
1208 if not gDelayedEvents
[a
].Pending
then
1215 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1216 n
:= High(gDelayedEvents
);
1218 gDelayedEvents
[n
].Pending
:= True;
1219 gDelayedEvents
[n
].DEType
:= DEType
;
1220 gDelayedEvents
[n
].DENum
:= Num
;
1221 gDelayedEvents
[n
].DEStr
:= Str
;
1222 if DEType
= DE_GLOBEVENT
then
1223 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1225 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1229 procedure EndGame();
1235 if g_Game_IsNet
and g_Game_IsServer
then
1236 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1239 gPauseMain
:= false;
1240 gPauseHolmes
:= false;
1243 g_Game_StopAllSounds(False);
1248 EndingGameCounter
:= 0;
1249 g_ActiveWindow
:= nil;
1251 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1252 gLMSRespawnTime
:= 0;
1255 EXIT_SIMPLE
: // Выход через меню или конец теста
1260 begin // Это был тест
1264 begin // Выход в главное меню
1265 gMusic
.SetByName('MUSIC_MENU');
1267 if gState
<> STATE_SLIST
then
1269 g_GUI_ShowWindow('MainMenu');
1270 gState
:= STATE_MENU
;
1273 // Обновляем список серверов
1274 slReturnPressed
:= True;
1275 if g_Net_Slist_Fetch(slCurrent
) then
1277 if slCurrent
= nil then
1278 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1281 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1282 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1285 g_Game_ExecuteEvent('ongameend');
1289 EXIT_RESTART
: // Начать уровень сначала
1291 if not g_Game_IsClient
then g_Game_Restart();
1294 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1296 // Статистика Своей игры:
1297 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1299 CustomStat
.GameTime
:= gTime
;
1300 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1301 CustomStat
.MapName
:= gMapInfo
.Name
;
1302 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1303 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1304 CustomStat
.TeamStat
:= gTeamStat
;
1306 CustomStat
.PlayerStat
:= nil;
1308 // Статистика игроков:
1309 if gPlayers
<> nil then
1311 for a
:= 0 to High(gPlayers
) do
1312 if gPlayers
[a
] <> nil then
1314 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1315 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1318 Name
:= gPlayers
[a
].Name
;
1319 Frags
:= gPlayers
[a
].Frags
;
1320 Deaths
:= gPlayers
[a
].Death
;
1321 Kills
:= gPlayers
[a
].Kills
;
1322 Team
:= gPlayers
[a
].Team
;
1323 Color
:= gPlayers
[a
].Model
.Color
;
1324 Spectator
:= gPlayers
[a
].FSpectator
;
1328 SortGameStat(CustomStat
.PlayerStat
);
1330 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1333 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1334 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1335 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1336 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1338 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1341 StatShotDone
:= False;
1344 g_Game_ExecuteEvent('onmapend');
1345 if not g_Game_IsClient
then g_Player_ResetReady
;
1346 gInterReadyCount
:= 0;
1348 // Затухающий экран:
1349 EndingGameCounter
:= 255;
1350 gState
:= STATE_FOLD
;
1352 if gDefInterTime
< 0 then
1353 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1355 gInterEndTime
:= gDefInterTime
* 1000;
1358 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1360 // Статистика Одиночной игры:
1361 SingleStat
.GameTime
:= gTime
;
1362 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1363 SingleStat
.TotalSecrets
:= gSecretsCount
;
1364 // Статистика первого игрока:
1365 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1366 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1367 // Статистика второго игрока (если есть):
1368 if SingleStat
.TwoPlayers
then
1370 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1371 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1374 g_Game_ExecuteEvent('onmapend');
1377 if gNextMap
<> '' then
1379 gMusic
.SetByName('MUSIC_INTERMUS');
1381 gState
:= STATE_INTERSINGLE
;
1384 g_Game_ExecuteEvent('oninter');
1386 else // Больше нет карт
1388 // Затухающий экран:
1389 EndingGameCounter
:= 255;
1390 gState
:= STATE_FOLD
;
1395 // Окончание обработано:
1396 if gExit
<> EXIT_QUIT
then
1400 procedure g_Game_Init();
1404 gTempDelete
:= False;
1406 sfsGCDisable(); // temporary disable removing of temporary volumes
1409 g_Game_ClearLoading();
1410 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1411 g_Game_SetLoadingText('', 0, False);
1413 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1416 gPauseMain
:= false;
1417 gPauseHolmes
:= false;
1420 {e_MouseInfo.Accel := 1.0;}
1422 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1425 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1426 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1427 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1428 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1429 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1431 gMusic
:= TMusic
.Create();
1432 gMusic
.SetByName('MUSIC_MENU');
1435 gGameSettings
.WarmupTime
:= 30;
1437 gState
:= STATE_MENU
;
1439 SetLength(gEvents
, 6);
1440 gEvents
[0].Name
:= 'ongamestart';
1441 gEvents
[1].Name
:= 'ongameend';
1442 gEvents
[2].Name
:= 'onmapstart';
1443 gEvents
[3].Name
:= 'onmapend';
1444 gEvents
[4].Name
:= 'oninter';
1445 gEvents
[5].Name
:= 'onwadend';
1447 sfsGCEnable(); // enable releasing unused volumes
1451 procedure g_Game_Free(freeTextures
: Boolean=true);
1453 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1454 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1456 g_Map_Free(freeTextures
);
1458 g_Player_RemoveAllCorpses();
1460 gGameSettings
.GameType
:= GT_NONE
;
1461 if gGameSettings
.GameMode
= GM_SINGLE
then
1462 gGameSettings
.GameMode
:= GM_DM
;
1463 gSwitchGameMode
:= gGameSettings
.GameMode
;
1466 gExitByTrigger
:= False;
1469 function IsActivePlayer(p
: TPlayer
): Boolean;
1474 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1477 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1483 if gPlayers
= nil then
1487 for a
:= Low(gPlayers
) to High(gPlayers
) do
1488 if IsActivePlayer(gPlayers
[a
]) then
1490 SetLength(ids
, Length(ids
) + 1);
1491 ids
[High(ids
)] := gPlayers
[a
].UID
;
1492 if gPlayers
[a
].UID
= Skip
then
1495 if Length(ids
) = 0 then
1500 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1503 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1509 if gPlayers
= nil then
1513 for a
:= Low(gPlayers
) to High(gPlayers
) do
1514 if IsActivePlayer(gPlayers
[a
]) then
1516 SetLength(ids
, Length(ids
) + 1);
1517 ids
[High(ids
)] := gPlayers
[a
].UID
;
1518 if gPlayers
[a
].UID
= Skip
then
1521 if Length(ids
) = 0 then
1524 Result
:= ids
[Length(ids
) - 1]
1526 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1529 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1535 if gPlayers
= nil then
1539 for a
:= Low(gPlayers
) to High(gPlayers
) do
1540 if IsActivePlayer(gPlayers
[a
]) then
1542 SetLength(ids
, Length(ids
) + 1);
1543 ids
[High(ids
)] := gPlayers
[a
].UID
;
1544 if gPlayers
[a
].UID
= Skip
then
1547 if Length(ids
) = 0 then
1549 if Length(ids
) = 1 then
1554 Result
:= ids
[Random(Length(ids
))];
1556 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1558 Result
:= ids
[Random(Length(ids
))];
1563 function GetRandomSpectMode(Current
: Byte): Byte;
1570 0: Result
:= SPECT_STATS
;
1571 1: Result
:= SPECT_MAPVIEW
;
1572 2: Result
:= SPECT_MAPVIEW
;
1573 3: Result
:= SPECT_PLAYERS
;
1574 4: Result
:= SPECT_PLAYERS
;
1575 5: Result
:= SPECT_PLAYERS
;
1576 6: Result
:= SPECT_PLAYERS
;
1578 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1582 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1588 if (plr
= nil) then exit
;
1589 if (p
= 2) then time
:= 1000 else time
:= 1;
1590 strafeDir
:= MoveButton
shr 4;
1591 MoveButton
:= MoveButton
and $0F;
1593 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1594 MoveButton
:= 1 // Нажата только "Влево"
1595 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1596 MoveButton
:= 2 // Нажата только "Вправо"
1597 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1598 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1600 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1601 if MoveButton
= 1 then
1602 plr
.PressKey(KEY_LEFT
, time
)
1603 else if MoveButton
= 2 then
1604 plr
.PressKey(KEY_RIGHT
, time
);
1606 // if we have "strafe" key, turn off old strafe mechanics
1607 if gPlayerAction
[p
, ACTION_STRAFE
] then
1609 // new strafe mechanics
1610 if (strafeDir
= 0) then
1611 strafeDir
:= MoveButton
; // start strafing
1612 // now set direction according to strafe (reversed)
1613 if (strafeDir
= 2) then
1614 plr
.SetDirection(TDirection
.D_LEFT
)
1615 else if (strafeDir
= 1) then
1616 plr
.SetDirection(TDirection
.D_RIGHT
)
1620 strafeDir
:= 0; // not strafing anymore
1621 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1622 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1623 plr
.SetDirection(TDirection
.D_LEFT
)
1624 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1625 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1626 plr
.SetDirection(TDirection
.D_RIGHT
)
1627 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1628 else if MoveButton
<> 0 then
1629 plr
.SetDirection(TDirection(MoveButton
-1))
1632 // fix movebutton state
1633 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1635 // Остальные клавиши:
1636 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1637 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1638 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1639 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1640 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1642 for i
:= WP_FACT
to WP_LACT
do
1644 if gWeaponAction
[p
, i
] then
1646 plr
.ProcessWeaponAction(i
);
1647 gWeaponAction
[p
, i
] := False
1651 for i
:= WP_FIRST
to WP_LAST
do
1653 if gSelectWeapon
[p
, i
] then
1655 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1656 gSelectWeapon
[p
, i
] := False
1660 // HACK: add dynlight here
1661 if gwin_k8_enable_light_experiments
then
1663 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1665 g_playerLight
:= true;
1667 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1669 g_playerLight
:= false;
1673 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1676 // HACK: don't have a "key was pressed" function
1677 procedure InterReady();
1679 if InterReadyTime
> gTime
then Exit
;
1680 InterReadyTime
:= gTime
+ 3000;
1681 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1684 procedure g_Game_PreUpdate();
1686 // these are in separate PreUpdate functions because they can interact during Update()
1687 // and are synced over the net
1688 // we don't care that much about corpses and gibs
1689 g_Player_PreUpdate();
1690 g_Monsters_PreUpdate();
1691 g_Items_PreUpdate();
1692 g_Weapon_PreUpdate();
1695 procedure g_Game_Update();
1697 Msg
: g_gui
.TMessage
;
1703 function sendMonsPos (mon
: TMonster
): Boolean;
1705 result
:= false; // don't stop
1706 // this will also reset "need-send" flag
1707 if mon
.gncNeedSend
then
1709 MH_SEND_MonsterPos(mon
.UID
);
1711 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1713 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1715 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1717 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1721 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1723 result
:= false; // don't stop
1724 // this will also reset "need-send" flag
1725 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1728 function sendItemPos (it
: PItem
): Boolean;
1730 result
:= false; // don't stop
1733 MH_SEND_ItemPos(it
.myId
);
1734 it
.needSend
:= False;
1739 reliableUpdate
: Boolean;
1744 // Пора выключать игру:
1745 if gExit
= EXIT_QUIT
then
1747 // Игра закончилась - обрабатываем:
1751 if gExit
= EXIT_QUIT
then
1755 // Читаем клавиатуру и джойстик, если окно активно
1756 // no need to, as we'll do it in event handler
1758 // Обновляем консоль (движение и сообщения):
1762 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1764 gExit
:= EXIT_SIMPLE
;
1769 // process master server communications
1770 g_Net_Slist_Pulse();
1773 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1774 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1775 STATE_INTERTEXT
, // Текст между уровнями
1776 STATE_INTERPIC
: // Картинка между уровнями
1778 if g_Game_IsNet
and g_Game_IsServer
then
1780 gInterTime
:= gInterTime
+ GAME_TICK
;
1781 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1782 if a
<> gServInterTime
then
1784 gServInterTime
:= a
;
1785 MH_SEND_TimeSync(gServInterTime
);
1789 if (not g_Game_IsClient
) and
1793 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1794 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1795 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1796 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1798 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1799 and (g_ActiveWindow
= nil)
1801 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1804 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1805 g_Game_StopAllSounds(True);
1807 if gMapOnce
then // Это был тест
1808 gExit
:= EXIT_SIMPLE
1810 if gNextMap
<> '' then // Переходим на следующую карту
1811 g_Game_ChangeMap(gNextMap
)
1812 else // Следующей карты нет
1814 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1816 // Выход в главное меню:
1818 g_GUI_ShowWindow('MainMenu');
1819 gMusic
.SetByName('MUSIC_MENU');
1821 gState
:= STATE_MENU
;
1824 // Финальная картинка:
1825 g_Game_ExecuteEvent('onwadend');
1827 if not gMusic
.SetByName('MUSIC_endmus') then
1828 gMusic
.SetByName('MUSIC_STDENDMUS');
1830 gState
:= STATE_ENDPIC
;
1832 g_Game_ExecuteEvent('ongameend');
1837 else if g_Game_IsClient
and
1840 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1841 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1842 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1843 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1845 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1846 and (g_ActiveWindow
= nil)
1854 if gState
= STATE_INTERTEXT
then
1855 if InterText
.counter
> 0 then
1856 InterText
.counter
:= InterText
.counter
- 1;
1859 STATE_FOLD
: // Затухание экрана
1861 if EndingGameCounter
= 0 then
1863 // Закончился уровень в Своей игре:
1864 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1866 gState
:= STATE_INTERCUSTOM
;
1867 InterReadyTime
:= -1;
1868 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1870 g_Game_ExecuteEvent('onwadend');
1871 if not gMusic
.SetByName('MUSIC_endmus') then
1872 gMusic
.SetByName('MUSIC_STDENDMUS');
1875 gMusic
.SetByName('MUSIC_ROUNDMUS');
1879 else // Закончилась последняя карта в Одиночной игре
1881 gMusic
.SetByName('MUSIC_INTERMUS');
1883 gState
:= STATE_INTERSINGLE
;
1886 g_Game_ExecuteEvent('oninter');
1889 DecMin(EndingGameCounter
, 6, 0);
1892 STATE_ENDPIC
: // Картинка окончания мегаВада
1894 if gMapOnce
then // Это был тест
1896 gExit
:= EXIT_SIMPLE
;
1902 g_Serverlist_Control(slCurrent
, slTable
);
1905 // Статистика по Tab:
1907 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1910 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1912 // Время += 28 миллисекунд:
1913 gTime
:= gTime
+ GAME_TICK
;
1915 // Сообщение посередине экрана:
1916 if MessageTime
= 0 then
1918 if MessageTime
> 0 then
1919 MessageTime
:= MessageTime
- 1;
1921 if (g_Game_IsServer
) then
1923 // Был задан лимит времени:
1924 if (gGameSettings
.TimeLimit
> 0) then
1925 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1926 begin // Он прошел => конец уровня
1931 // Надо респавнить игроков в LMS:
1932 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1933 g_Game_RestartRound(gLMSSoftSpawn
);
1935 // Проверим результат голосования, если время прошло
1936 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1938 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1940 g_Console_Process(gVoteCommand
);
1942 gVotePassed
:= False;
1945 // Замеряем время захвата флагов
1946 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1947 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1948 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1949 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1951 // Был задан лимит побед:
1952 if (gGameSettings
.ScoreLimit
> 0) then
1956 if gGameSettings
.GameMode
= GM_DM
then
1957 begin // В DM ищем игрока с max фрагами
1958 for i
:= 0 to High(gPlayers
) do
1959 if gPlayers
[i
] <> nil then
1960 if gPlayers
[i
].Frags
> b
then
1961 b
:= gPlayers
[i
].Frags
;
1964 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1965 begin // В CTF/TDM выбираем команду с наибольшим счетом
1966 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
1969 // Лимит побед набран => конец уровня:
1970 if b
>= gGameSettings
.ScoreLimit
then
1977 // Обрабатываем клавиши игроков:
1978 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1979 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1980 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1982 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1983 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1984 end // if not console
1987 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1989 // process weapon switch queue
1993 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1994 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1996 if not gSpectKeyPress
then
1998 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2000 // switch spect mode
2002 SPECT_NONE
: ; // not spectator
2004 SPECT_MAPVIEW
: Inc(gSpectMode
);
2005 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2007 gSpectKeyPress
:= True;
2009 if (gSpectMode
= SPECT_MAPVIEW
)
2010 and (not gSpectAuto
) then
2012 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2013 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2014 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2015 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2016 if gPlayerAction
[0, ACTION_LOOKUP
] then
2017 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2018 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2019 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2020 if gWeaponAction
[0, WP_PREV
] then
2023 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2024 gWeaponAction
[0, WP_PREV
] := False;
2026 if gWeaponAction
[0, WP_NEXT
] then
2029 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2030 gWeaponAction
[0, WP_NEXT
] := False;
2033 if (gSpectMode
= SPECT_PLAYERS
)
2034 and (not gSpectAuto
) then
2036 if gPlayerAction
[0, ACTION_LOOKUP
] then
2039 gSpectViewTwo
:= True;
2040 gSpectKeyPress
:= True;
2042 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2044 // remove second view
2045 gSpectViewTwo
:= False;
2046 gSpectKeyPress
:= True;
2048 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2050 // prev player (view 1)
2051 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2052 gSpectKeyPress
:= True;
2054 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2056 // next player (view 1)
2057 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2058 gSpectKeyPress
:= True;
2060 if gWeaponAction
[0, WP_PREV
] then
2062 // prev player (view 2)
2063 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2064 gWeaponAction
[0, WP_PREV
] := False;
2066 if gWeaponAction
[0, WP_NEXT
] then
2068 // next player (view 2)
2069 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2070 gWeaponAction
[0, WP_NEXT
] := False;
2073 if gPlayerAction
[0, ACTION_ATTACK
] then
2075 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2078 gSpectAutoNext
:= 0;
2079 gSpectViewTwo
:= False;
2080 gSpectKeyPress
:= True;
2085 gSpectMode
:= SPECT_STATS
;
2086 gSpectAuto
:= False;
2087 gSpectKeyPress
:= True;
2092 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2093 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2094 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2095 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2096 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2097 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2098 gSpectKeyPress
:= False;
2102 if gSpectMode
= SPECT_MAPVIEW
then
2104 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2106 gSpectAutoNext
:= gTime
2109 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2111 gSpectAutoNext
:= gTime
2115 if gSpectAutoNext
<= gTime
then
2117 if gSpectAutoNext
> 0 then
2119 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2123 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2124 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2125 gSpectAutoStepX
:= Random(9) - 4;
2126 gSpectAutoStepY
:= Random(9) - 4;
2127 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2128 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2129 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2130 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2131 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2132 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2136 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2141 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2142 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2143 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2149 // Обновляем все остальное:
2152 g_Triggers_Update();
2154 g_Monsters_Update();
2157 g_Player_UpdateAll();
2158 g_Player_UpdatePhysicalObjects();
2160 // server: send newly spawned monsters unconditionally
2161 if (gGameSettings
.GameType
= GT_SERVER
) then
2163 if (Length(gMonstersSpawned
) > 0) then
2165 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2166 SetLength(gMonstersSpawned
, 0);
2170 if (gSoundTriggerTime
> 8) then
2172 g_Game_UpdateTriggerSounds();
2173 gSoundTriggerTime
:= 0;
2177 Inc(gSoundTriggerTime
);
2180 if (NetMode
= NET_SERVER
) then
2182 Inc(NetTimeToUpdate
);
2183 Inc(NetTimeToReliable
);
2185 // send monster updates
2186 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2188 // send all monsters (periodic sync)
2189 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2191 for I
:= 0 to High(gPlayers
) do
2193 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2196 g_Mons_ForEach(sendMonsPos
);
2198 // update flags that aren't stationary
2199 if gGameSettings
.GameMode
= GM_CTF
then
2200 for I
:= FLAG_RED
to FLAG_BLUE
do
2201 if gFlags
[I
].NeedSend
then
2203 gFlags
[I
].NeedSend
:= False;
2207 // update items that aren't stationary
2208 g_Items_ForEachAlive(sendItemPos
);
2210 if reliableUpdate
then
2212 NetTimeToReliable
:= 0;
2213 NetTimeToUpdate
:= NetUpdateRate
;
2217 NetTimeToUpdate
:= 0;
2222 // send only mosters with some unexpected changes
2223 g_Mons_ForEach(sendMonsPosUnexpected
);
2226 // send unexpected platform changes
2227 g_Map_NetSendInterestingPanels();
2229 g_Net_Slist_ServerUpdate();
2231 if NetUseMaster then
2233 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2235 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2237 NetTimeToMaster := gTime + NetMasterRate;
2242 else if (NetMode
= NET_CLIENT
) then
2244 MC_SEND_PlayerPos();
2246 end; // if gameOn ...
2248 // Активно окно интерфейса - передаем клавиши ему:
2249 if g_ActiveWindow
<> nil then
2251 w
:= e_GetFirstKeyPressed();
2253 if (w
<> IK_INVALID
) then
2255 Msg
.Msg
:= MESSAGE_DIKEY
;
2257 g_ActiveWindow
.OnMessage(Msg
);
2260 // Если оно от этого не закрылось, то обновляем:
2261 if g_ActiveWindow
<> nil then
2262 g_ActiveWindow
.Update();
2264 // Нужно сменить разрешение:
2265 if gResolutionChange
then
2267 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2269 gResolutionChange
:= False;
2270 g_ActiveWindow
:= nil;
2273 // Нужно сменить язык:
2274 if gLanguageChange
then
2276 //e_WriteLog('Read language file', MSG_NOTIFY);
2277 //g_Language_Load(DataDir + gLanguage + '.txt');
2278 g_Language_Set(gLanguage
);
2282 gLanguageChange
:= False;
2286 // Горячая клавиша для вызова меню выхода из игры (F10):
2287 if e_KeyPressed(IK_F10
) and
2289 (not gConsoleShow
) and
2290 (g_ActiveWindow
= nil) then
2295 Time
:= GetTickCount64() {div 1000};
2297 // Обработка отложенных событий:
2298 if gDelayedEvents
<> nil then
2299 for a
:= 0 to High(gDelayedEvents
) do
2300 if gDelayedEvents
[a
].Pending
and
2302 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2303 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2306 case gDelayedEvents
[a
].DEType
of
2308 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2311 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2315 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2316 if g_Game_IsNet
and g_Game_IsServer
then
2317 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2321 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2323 gDelayedEvents
[a
].Pending
:= False;
2326 // Каждую секунду обновляем счетчик обновлений:
2327 UPSCounter
:= UPSCounter
+ 1;
2328 if Time
- UPSTime
>= 1000 then
2337 g_Weapon_AddDynLights();
2338 g_Items_AddDynLights();
2342 procedure g_Game_LoadChatSounds(Resource
: string);
2345 FileName
, Snd
: string;
2347 len
, cnt
, tags
, i
, j
: Integer;
2350 FileName
:= g_ExtractWadName(Resource
);
2352 WAD
:= TWADFile
.Create();
2353 WAD
.ReadFile(FileName
);
2355 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2362 cfg
:= TConfig
.CreateMem(p
, len
);
2363 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2365 SetLength(gChatSounds
, cnt
);
2366 for i
:= 0 to Length(gChatSounds
) - 1 do
2368 gChatSounds
[i
].Sound
:= nil;
2369 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2370 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2371 if (Snd
= '') or (Tags
<= 0) then
2373 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2374 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2375 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2376 SetLength(gChatSounds
[i
].Tags
, tags
);
2377 for j
:= 0 to tags
- 1 do
2378 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2379 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2386 procedure g_Game_FreeChatSounds();
2390 for i
:= 0 to Length(gChatSounds
) - 1 do
2392 gChatSounds
[i
].Sound
.Free();
2393 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2395 SetLength(gChatSounds
, 0);
2399 procedure g_Game_LoadData();
2401 if DataLoaded
then Exit
;
2403 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2405 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2406 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2407 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2408 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2409 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2410 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2411 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2412 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2413 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2414 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2415 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2416 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2417 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2418 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2419 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2420 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2421 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2422 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2423 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2424 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2425 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2426 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2427 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2428 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2429 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2430 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2431 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2432 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2433 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2434 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2435 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2436 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2438 goodsnd
[0] := TPlayableSound
.Create();
2439 goodsnd
[1] := TPlayableSound
.Create();
2440 goodsnd
[2] := TPlayableSound
.Create();
2441 goodsnd
[3] := TPlayableSound
.Create();
2443 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2444 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2445 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2446 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2448 killsnd
[0] := TPlayableSound
.Create();
2449 killsnd
[1] := TPlayableSound
.Create();
2450 killsnd
[2] := TPlayableSound
.Create();
2451 killsnd
[3] := TPlayableSound
.Create();
2453 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2454 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2455 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2456 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2458 hahasnd
[0] := TPlayableSound
.Create();
2459 hahasnd
[1] := TPlayableSound
.Create();
2460 hahasnd
[2] := TPlayableSound
.Create();
2462 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2463 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2464 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2466 sound_get_flag
[0] := TPlayableSound
.Create();
2467 sound_get_flag
[1] := TPlayableSound
.Create();
2468 sound_lost_flag
[0] := TPlayableSound
.Create();
2469 sound_lost_flag
[1] := TPlayableSound
.Create();
2470 sound_ret_flag
[0] := TPlayableSound
.Create();
2471 sound_ret_flag
[1] := TPlayableSound
.Create();
2472 sound_cap_flag
[0] := TPlayableSound
.Create();
2473 sound_cap_flag
[1] := TPlayableSound
.Create();
2475 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2476 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2477 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2478 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2479 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2480 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2481 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2482 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2484 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2486 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2489 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2490 g_Weapon_LoadData();
2492 g_Monsters_LoadData();
2497 procedure g_Game_Quit();
2499 g_Game_StopAllSounds(True);
2502 g_PlayerModel_FreeData();
2504 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2507 if NetInitDone
then g_Net_Free
;
2509 // remove map after test
2510 if gMapToDelete
<> '' then
2511 g_Game_DeleteTestMap();
2517 procedure g_Game_FreeData();
2519 if not DataLoaded
then Exit
;
2522 g_Weapon_FreeData();
2523 g_Monsters_FreeData();
2525 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2527 g_Sound_Delete('SOUND_GAME_TELEPORT');
2528 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2529 g_Sound_Delete('SOUND_GAME_SECRET');
2530 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2531 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2532 g_Sound_Delete('SOUND_GAME_BULK1');
2533 g_Sound_Delete('SOUND_GAME_BULK2');
2534 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2535 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2536 g_Sound_Delete('SOUND_GAME_BURNING');
2537 g_Sound_Delete('SOUND_GAME_SWITCH1');
2538 g_Sound_Delete('SOUND_GAME_SWITCH0');
2545 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2546 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2547 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2548 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2555 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2556 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2557 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2558 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2564 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2565 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2566 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2568 sound_get_flag
[0].Free();
2569 sound_get_flag
[1].Free();
2570 sound_lost_flag
[0].Free();
2571 sound_lost_flag
[1].Free();
2572 sound_ret_flag
[0].Free();
2573 sound_ret_flag
[1].Free();
2574 sound_cap_flag
[0].Free();
2575 sound_cap_flag
[1].Free();
2577 g_Sound_Delete('SOUND_CTF_GET1');
2578 g_Sound_Delete('SOUND_CTF_GET2');
2579 g_Sound_Delete('SOUND_CTF_LOST1');
2580 g_Sound_Delete('SOUND_CTF_LOST2');
2581 g_Sound_Delete('SOUND_CTF_RETURN1');
2582 g_Sound_Delete('SOUND_CTF_RETURN2');
2583 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2584 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2586 g_Game_FreeChatSounds();
2588 DataLoaded
:= False;
2591 procedure g_FatalError(Text: String);
2593 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2594 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2596 gExit
:= EXIT_SIMPLE
;
2597 if gGameOn
then EndGame
;
2600 procedure g_SimpleError(Text: String);
2602 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2603 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2606 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2608 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2609 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2612 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2615 if gPlayer1
= nil then
2617 if g_Game_IsClient
then
2619 if NetPlrUID1
> -1 then
2620 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2624 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2625 Team
:= gPlayer1Settings
.Team
;
2627 // Создание первого игрока:
2628 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2629 gPlayer1Settings
.Color
,
2631 if gPlayer1
= nil then
2632 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2635 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2636 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2637 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2638 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2639 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2640 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2641 if g_Game_IsServer
and g_Game_IsNet
then
2642 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2643 gPlayer1
.Respawn(False, True);
2644 g_Net_Slist_ServerPlayerComes();
2649 if gPlayer2
= nil then
2651 if g_Game_IsClient
then
2653 if NetPlrUID2
> -1 then
2654 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2658 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2659 Team
:= gPlayer2Settings
.Team
;
2661 // Создание второго игрока:
2662 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2663 gPlayer2Settings
.Color
,
2665 if gPlayer2
= nil then
2666 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2669 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2670 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2671 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2672 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2673 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2674 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2675 if g_Game_IsServer
and g_Game_IsNet
then
2676 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2677 gPlayer2
.Respawn(False, True);
2678 g_Net_Slist_ServerPlayerComes();
2685 procedure g_Game_RemovePlayer();
2689 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2690 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2695 if g_Game_IsServer
then
2698 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2699 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2700 g_Player_Remove(Pl
.UID
);
2701 g_Net_Slist_ServerPlayerLeaves();
2705 gSpectLatchPID2
:= Pl
.UID
;
2713 if g_Game_IsServer
then
2716 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2717 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2718 g_Player_Remove(Pl
.UID
);
2719 g_Net_Slist_ServerPlayerLeaves();
2722 gSpectLatchPID1
:= Pl
.UID
;
2724 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2728 g_Net_Slist_ServerPlayerLeaves();
2731 procedure g_Game_Spectate();
2733 g_Game_RemovePlayer();
2734 if gPlayer1
<> nil then
2735 g_Game_RemovePlayer();
2738 procedure g_Game_SpectateCenterView();
2740 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2741 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2744 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2751 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2753 g_Game_ClearLoading();
2756 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2759 gGameSettings
.GameType
:= GT_SINGLE
;
2760 gGameSettings
.MaxLives
:= 0;
2761 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2762 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2763 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2764 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2765 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2766 gSwitchGameMode
:= GM_SINGLE
;
2768 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2769 gLMSRespawnTime
:= 0;
2770 gSpectLatchPID1
:= 0;
2771 gSpectLatchPID2
:= 0;
2773 g_Game_ExecuteEvent('ongamestart');
2775 // Создание первого игрока:
2776 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2777 gPlayer1Settings
.Color
,
2778 gPlayer1Settings
.Team
, False));
2779 if gPlayer1
= nil then
2781 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2785 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2786 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2787 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2788 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2789 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2792 // Создание второго игрока, если есть:
2795 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2796 gPlayer2Settings
.Color
,
2797 gPlayer2Settings
.Team
, False));
2798 if gPlayer2
= nil then
2800 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2804 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2805 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2806 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2807 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2808 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2812 // Загрузка и запуск карты:
2813 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2815 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2816 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2820 // Настройки игроков и ботов:
2824 for i
:= nPl
+1 to nPlayers
do
2825 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2828 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2829 TimeLimit
, ScoreLimit
: Word;
2831 Options
: LongWord; nPlayers
: Byte);
2837 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2839 g_Game_ClearLoading();
2842 gGameSettings
.GameType
:= GT_CUSTOM
;
2843 gGameSettings
.GameMode
:= GameMode
;
2844 gSwitchGameMode
:= GameMode
;
2845 gGameSettings
.TimeLimit
:= TimeLimit
;
2846 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2847 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2848 gGameSettings
.Options
:= Options
;
2850 gCoopTotalMonstersKilled
:= 0;
2851 gCoopTotalSecretsFound
:= 0;
2852 gCoopTotalMonsters
:= 0;
2853 gCoopTotalSecrets
:= 0;
2857 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2858 gLMSRespawnTime
:= 0;
2859 gSpectLatchPID1
:= 0;
2860 gSpectLatchPID2
:= 0;
2862 g_Game_ExecuteEvent('ongamestart');
2864 // Режим наблюдателя:
2865 if nPlayers
= 0 then
2872 if nPlayers
>= 1 then
2874 // Создание первого игрока:
2875 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2876 gPlayer1Settings
.Color
,
2877 gPlayer1Settings
.Team
, False));
2878 if gPlayer1
= nil then
2880 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2884 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2885 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2886 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2887 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2888 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2892 if nPlayers
>= 2 then
2894 // Создание второго игрока:
2895 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2896 gPlayer2Settings
.Color
,
2897 gPlayer2Settings
.Team
, False));
2898 if gPlayer2
= nil then
2900 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2904 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2905 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2906 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2907 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2908 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2912 // Загрузка и запуск карты:
2913 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
2915 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2919 // Нет точек появления:
2920 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2921 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2922 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2923 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2924 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2926 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2930 // Настройки игроков и ботов:
2934 for i
:= nPl
+1 to nPlayers
do
2935 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2938 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
2939 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
2940 Options
: LongWord; nPlayers
: Byte;
2941 IPAddr
: LongWord; Port
: Word);
2944 g_Net_Slist_ServerClosed();
2946 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
2948 g_Game_ClearLoading();
2953 gGameSettings
.GameType
:= GT_SERVER
;
2954 gGameSettings
.GameMode
:= GameMode
;
2955 gSwitchGameMode
:= GameMode
;
2956 gGameSettings
.TimeLimit
:= TimeLimit
;
2957 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2958 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2959 gGameSettings
.Options
:= Options
;
2961 gCoopTotalMonstersKilled
:= 0;
2962 gCoopTotalSecretsFound
:= 0;
2963 gCoopTotalMonsters
:= 0;
2964 gCoopTotalSecrets
:= 0;
2968 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2969 gLMSRespawnTime
:= 0;
2970 gSpectLatchPID1
:= 0;
2971 gSpectLatchPID2
:= 0;
2973 g_Game_ExecuteEvent('ongamestart');
2975 // Режим наблюдателя:
2976 if nPlayers
= 0 then
2982 if nPlayers
>= 1 then
2984 // Создание первого игрока:
2985 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2986 gPlayer1Settings
.Color
,
2987 gPlayer1Settings
.Team
, False));
2988 if gPlayer1
= nil then
2990 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2994 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2995 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2996 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2997 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2998 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3001 if nPlayers
>= 2 then
3003 // Создание второго игрока:
3004 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3005 gPlayer2Settings
.Color
,
3006 gPlayer2Settings
.Team
, False));
3007 if gPlayer2
= nil then
3009 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3013 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3014 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3015 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3016 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3017 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3020 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3021 if NetForwardPorts
then
3022 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3025 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3027 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3031 g_Net_Slist_Set(NetMasterList
);
3033 g_Net_Slist_ServerStarted();
3035 // Загрузка и запуск карты:
3036 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3038 g_Net_Slist_ServerClosed();
3039 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3043 // Нет точек появления:
3044 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3045 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3046 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3047 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3048 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3050 g_Net_Slist_ServerClosed();
3051 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3055 // Настройки игроков и ботов:
3058 g_Net_Slist_ServerMapStarted();
3059 NetState
:= NET_STATE_GAME
;
3062 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3077 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3078 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3080 g_Game_ClearLoading();
3085 gGameSettings
.GameType
:= GT_CLIENT
;
3087 gCoopTotalMonstersKilled
:= 0;
3088 gCoopTotalSecretsFound
:= 0;
3089 gCoopTotalMonsters
:= 0;
3090 gCoopTotalSecrets
:= 0;
3094 g_Game_ExecuteEvent('ongamestart');
3096 NetState
:= NET_STATE_AUTH
;
3098 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3100 // create (or update) map/resource databases
3101 g_Res_CreateDatabases(true);
3103 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3104 gLMSRespawnTime
:= 0;
3105 gSpectLatchPID1
:= 0;
3106 gSpectLatchPID2
:= 0;
3109 if not g_Net_Connect(Addr
, Port
) then
3111 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3112 NetState
:= NET_STATE_NONE
;
3116 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3118 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3123 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3124 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3125 // thank you, enet. let's ignore failures altogether then.
3126 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3128 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3130 Ptr
:= NetEvent
.packet
^.data
;
3131 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3133 enet_packet_destroy(NetEvent
.packet
);
3137 InMsg
.ReadLongWord(); // skip size
3138 MID
:= InMsg
.ReadByte();
3140 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3142 NetMyID
:= InMsg
.ReadByte();
3143 NetPlrUID1
:= InMsg
.ReadWord();
3145 WadName
:= InMsg
.ReadString();
3146 Map
:= InMsg
.ReadString();
3148 gWADHash
:= InMsg
.ReadMD5();
3150 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3151 gSwitchGameMode
:= gGameSettings
.GameMode
;
3152 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3153 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3154 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3155 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3156 T
:= InMsg
.ReadLongWord();
3158 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3159 //if newResPath = '' then
3161 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3162 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3163 if newResPath
= '' then
3165 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3166 enet_packet_destroy(NetEvent
.packet
);
3167 NetState
:= NET_STATE_NONE
;
3170 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3172 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3175 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3176 gPlayer1Settings
.Color
,
3177 gPlayer1Settings
.Team
, False));
3179 if gPlayer1
= nil then
3181 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3183 enet_packet_destroy(NetEvent
.packet
);
3184 NetState
:= NET_STATE_NONE
;
3188 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3189 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3190 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3191 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3192 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3193 gPlayer1
.UID
:= NetPlrUID1
;
3194 gPlayer1
.Reset(True);
3196 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3198 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3200 enet_packet_destroy(NetEvent
.packet
);
3201 NetState
:= NET_STATE_NONE
;
3209 enet_packet_destroy(NetEvent
.packet
);
3213 enet_packet_destroy(NetEvent
.packet
);
3217 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3220 if (NetEvent
.data
<= NET_DISC_MAX
) then
3221 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3222 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3229 ProcessLoading(True);
3230 if g_Net_UserRequestExit() then
3239 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3240 NetState
:= NET_STATE_NONE
;
3245 NetState
:= NET_STATE_GAME
;
3246 MC_SEND_FullStateRequest
;
3247 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3251 lastAsMegaWad
: Boolean = false;
3253 procedure g_Game_ChangeMap(const MapPath
: String);
3257 g_Game_ClearLoading();
3259 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3260 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3261 if gExitByTrigger
then
3264 gExitByTrigger
:= False;
3266 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3267 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3270 procedure g_Game_Restart();
3274 if g_Game_IsClient
then
3276 map
:= g_ExtractFileName(gMapInfo
.Map
);
3277 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3281 g_Game_ClearLoading();
3282 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3285 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3287 NewWAD
, ResName
: String;
3291 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3292 g_Player_RemoveAllCorpses();
3294 if (not g_Game_IsClient
) and
3295 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3296 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3298 if gSwitchGameMode
= GM_CTF
then
3299 gGameSettings
.MaxLives
:= 0;
3300 gGameSettings
.GameMode
:= gSwitchGameMode
;
3303 gSwitchGameMode
:= gGameSettings
.GameMode
;
3305 g_Player_ResetTeams();
3307 lastAsMegaWad
:= asMegawad
;
3308 if isWadPath(Map
) then
3310 NewWAD
:= g_ExtractWadName(Map
);
3311 ResName
:= g_ExtractFileName(Map
);
3312 if g_Game_IsServer
then
3314 nws
:= findDiskWad(NewWAD
);
3315 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3318 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3319 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3323 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3324 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3326 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3327 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3329 if (length(nws
) = 0) then
3331 ResName
:= ''; // failed
3336 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3337 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3338 g_Game_LoadWAD(NewWAD
);
3343 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3344 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3349 NewWAD
:= gGameSettings
.WAD
;
3355 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3357 if (ResName
<> '') and (NewWAD
<> '') then
3359 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3360 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3361 r_Render_LoadTextures
;
3365 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3367 gState
:= STATE_NONE
;
3368 g_ActiveWindow
:= nil;
3372 wNeedTimeReset
:= True;
3374 if gGameSettings
.GameMode
= GM_CTF
then
3376 g_Map_ResetFlag(FLAG_RED
);
3377 g_Map_ResetFlag(FLAG_BLUE
);
3378 // CTF, а флагов нет:
3379 if not g_Map_HaveFlagPoints() then
3380 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3385 gState
:= STATE_MENU
;
3390 gPauseMain
:= false;
3391 gPauseHolmes
:= false;
3392 NetTimeToUpdate
:= 1;
3393 NetTimeToReliable
:= 0;
3394 NetTimeToMaster
:= NetMasterRate
;
3395 gSpectLatchPID1
:= 0;
3396 gSpectLatchPID2
:= 0;
3397 gMissionFailed
:= False;
3400 gCoopMonstersKilled
:= 0;
3401 gCoopSecretsFound
:= 0;
3403 gVoteInProgress
:= False;
3404 gVotePassed
:= False;
3410 if not gGameOn
then Exit
;
3412 g_Game_SpectateCenterView();
3414 if g_Game_IsServer
then
3416 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3418 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3419 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3420 gLMSSoftSpawn
:= True;
3421 if g_Game_IsNet
then
3422 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3426 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3427 gLMSRespawnTime
:= 0;
3431 if NetMode
= NET_SERVER
then
3433 // reset full state flags
3434 if NetClients
<> nil then
3435 for I
:= 0 to High(NetClients
) do
3436 NetClients
[I
].FullUpdateSent
:= False;
3438 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3441 g_Net_Slist_ServerMapStarted();
3443 if NetClients
<> nil then
3444 for I
:= 0 to High(NetClients
) do
3445 if NetClients
[I
].Used
then
3447 NetClients
[I
].Voted
:= False;
3448 if NetClients
[I
].RequestedFullUpdate
then
3450 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3451 NetClients
[I
].RequestedFullUpdate
:= False;
3455 g_Net_UnbanNonPermHosts();
3460 gCoopTotalMonstersKilled
:= 0;
3461 gCoopTotalSecretsFound
:= 0;
3462 gCoopTotalMonsters
:= 0;
3463 gCoopTotalSecrets
:= 0;
3467 g_Game_ExecuteEvent('onmapstart');
3470 procedure SetFirstLevel
;
3474 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3475 if MapList
= nil then
3478 SortSArray(MapList
);
3479 gNextMap
:= MapList
[Low(MapList
)];
3484 procedure g_Game_ExitLevel(const Map
: AnsiString);
3488 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3489 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3490 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3491 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3493 // Вышли в выход в Одиночной игре:
3494 if gGameSettings
.GameType
= GT_SINGLE
then
3495 gExit
:= EXIT_ENDLEVELSINGLE
3496 else // Вышли в выход в Своей игре
3498 gExit
:= EXIT_ENDLEVELCUSTOM
;
3499 if gGameSettings
.GameMode
= GM_COOP
then
3500 g_Player_RememberAll
;
3502 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3505 if gGameSettings
.GameMode
= GM_COOP
then
3508 gStatsPressed
:= True;
3509 gNextMap
:= 'MAP01';
3511 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3514 if g_Game_IsNet
then
3516 MH_SEND_GameStats();
3517 MH_SEND_CoopStats();
3523 procedure g_Game_RestartLevel();
3527 if gGameSettings
.GameMode
= GM_SINGLE
then
3532 gExit
:= EXIT_ENDLEVELCUSTOM
;
3533 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3537 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3539 gWAD
{, xwad}: String;
3542 if not g_Game_IsClient
then Exit
;
3543 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3545 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3550 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3554 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3557 g_Game_LoadWAD(NewWAD
);
3561 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3562 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3565 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3566 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3570 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3574 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3575 g_Game_LoadWAD(NewWAD);
3579 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3581 i
, n
, nb
, nr
: Integer;
3583 if not g_Game_IsServer
then Exit
;
3584 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3585 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3586 gLMSRespawnTime
:= 0;
3589 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3591 gMissionFailed
:= True;
3592 g_Game_RestartLevel
;
3596 n
:= 0; nb
:= 0; nr
:= 0;
3597 for i
:= Low(gPlayers
) to High(gPlayers
) do
3598 if (gPlayers
[i
] <> nil) and
3599 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3600 (gPlayers
[i
] is TBot
)) then
3603 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3604 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3607 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3609 // wait a second until the fuckers finally decide to join
3610 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3611 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3612 gLMSSoftSpawn
:= NoMapRestart
;
3613 if g_Game_IsNet
then
3614 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3618 g_Player_RemoveAllCorpses
;
3619 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3620 if g_Game_IsNet
then
3621 MH_SEND_GameEvent(NET_EV_LMS_START
);
3623 for i
:= Low(gPlayers
) to High(gPlayers
) do
3625 if gPlayers
[i
] = nil then continue
;
3626 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3627 // don't touch normal spectators
3628 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3630 gPlayers
[i
].FNoRespawn
:= True;
3631 gPlayers
[i
].Lives
:= 0;
3632 if g_Game_IsNet
then
3633 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3636 gPlayers
[i
].FNoRespawn
:= False;
3637 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3638 gPlayers
[i
].Respawn(False, True);
3639 if gGameSettings
.GameMode
= GM_COOP
then
3641 gPlayers
[i
].Frags
:= 0;
3642 gPlayers
[i
].RecallState
;
3644 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3645 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3646 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3647 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3650 g_Items_RestartRound();
3652 gLMSSoftSpawn
:= False;
3655 function g_Game_GetFirstMap(WAD
: String): String;
3659 MapList
:= g_Map_GetMapsList(WAD
);
3660 if MapList
= nil then
3663 SortSArray(MapList
);
3664 Result
:= MapList
[Low(MapList
)];
3666 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3672 function g_Game_GetNextMap(): String;
3679 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3680 if MapList
= nil then
3683 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3685 SortSArray(MapList
);
3687 for I
:= Low(MapList
) to High(MapList
) do
3688 if Map
= MapList
[I
] then
3694 if MapIndex
<> -255 then
3696 if MapIndex
= High(MapList
) then
3697 Result
:= MapList
[Low(MapList
)]
3699 Result
:= MapList
[MapIndex
+ 1];
3701 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3707 procedure g_Game_NextLevel();
3709 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3710 gExit
:= EXIT_ENDLEVELCUSTOM
3713 gExit
:= EXIT_ENDLEVELSINGLE
;
3717 if gNextMap
<> '' then Exit
;
3718 gNextMap
:= g_Game_GetNextMap();
3721 function g_Game_IsTestMap(): Boolean;
3723 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3726 procedure g_Game_DeleteTestMap();
3729 //MapName: AnsiString;
3737 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3738 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3739 if (a
= 0) then exit
;
3741 // Выделяем имя wad-файла и имя карты
3742 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3743 Delete(gMapToDelete
, 1, a
+5);
3744 gMapToDelete
:= UpperCase(gMapToDelete
);
3746 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3749 // Имя карты не стандартное тестовое:
3750 if MapName <> TEST_MAP_NAME then
3753 if not gTempDelete then
3755 time := g_GetFileTime(WadName);
3756 WAD := TWADFile.Create();
3759 if not WAD.ReadFile(WadName) then
3760 begin // Нет такого WAD-файла
3765 // Составляем список карт и ищем нужную:
3767 MapList := WAD.GetResourcesList('');
3769 if MapList <> nil then
3770 for a := 0 to High(MapList) do
3771 if MapList[a] = MapName then
3773 // Удаляем и сохраняем:
3774 WAD.RemoveResource('', MapName);
3775 WAD.SaveTo(WadName);
3780 g_SetFileTime(WadName, time);
3783 if gTempDelete
then DeleteFile(WadName
);
3786 procedure GameCVars(P
: SSArray
);
3789 stat
: TPlayerStatArray
;
3792 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3796 if Length(P
) > 1 then
3801 gsGameFlags
:= gsGameFlags
or Flag
3803 gsGameFlags
:= gsGameFlags
and (not Flag
);
3805 if g_Game_IsServer
then
3808 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3810 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3811 if g_Game_IsNet
then MH_SEND_GameSettings
;
3815 if LongBool(gsGameFlags
and Flag
) then
3816 g_Console_Add(_lc
[OnMsg
])
3818 g_Console_Add(_lc
[OffMsg
]);
3820 if OnMapChange
and g_Game_IsServer
then
3821 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3826 cmd
:= LowerCase(P
[0]);
3828 if cmd
= 'g_gamemode' then
3830 if (Length(P
) > 1) then
3832 a
:= g_Game_TextToMode(P
[1]);
3833 if a
= GM_SINGLE
then a
:= GM_COOP
;
3834 gsGameMode
:= g_Game_ModeToText(a
);
3835 if g_Game_IsServer
then
3837 gSwitchGameMode
:= a
;
3838 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3839 (gState
= STATE_INTERSINGLE
) then
3840 gSwitchGameMode
:= GM_SINGLE
;
3842 gGameSettings
.GameMode
:= gSwitchGameMode
;
3846 if gSwitchGameMode
= gGameSettings
.GameMode
then
3847 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3848 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3850 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3851 [g_Game_ModeToText(gGameSettings
.GameMode
),
3852 g_Game_ModeToText(gSwitchGameMode
)]));
3854 else if cmd
= 'g_friendlyfire' then
3856 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3858 else if cmd
= 'g_friendly_absorb_damage' then
3860 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
3862 else if cmd
= 'g_friendly_hit_trace' then
3864 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
3866 else if cmd
= 'g_friendly_hit_projectile' then
3868 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
3870 else if cmd
= 'g_weaponstay' then
3872 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3874 else if cmd
= 'g_allow_exit' then
3876 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3878 else if cmd
= 'g_allow_monsters' then
3880 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3882 else if cmd
= 'g_allow_dropflag' then
3884 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
3886 else if cmd
= 'g_throw_flag' then
3888 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
3890 else if cmd
= 'g_bot_vsplayers' then
3892 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3894 else if cmd
= 'g_bot_vsmonsters' then
3896 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3898 else if cmd
= 'g_dm_keys' then
3900 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
3902 else if cmd
= 'g_gameflags' then
3904 if Length(P
) > 1 then
3906 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
3907 if g_Game_IsServer
then
3909 gGameSettings
.Options
:= gsGameFlags
;
3910 if g_Game_IsNet
then MH_SEND_GameSettings
;
3914 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
3916 else if cmd
= 'g_warmup_time' then
3918 if Length(P
) > 1 then
3920 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
3921 if g_Game_IsServer
then
3923 gGameSettings
.WarmupTime
:= gsWarmupTime
;
3924 // extend warmup if it's already going
3925 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
3927 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
3928 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3930 if g_Game_IsNet
then MH_SEND_GameSettings
;
3934 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
3935 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3937 else if cmd
= 'g_spawn_invul' then
3939 if Length(P
) > 1 then
3941 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
3942 if g_Game_IsServer
then
3944 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
3945 if g_Game_IsNet
then MH_SEND_GameSettings
;
3949 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
3951 else if cmd
= 'g_item_respawn_time' then
3953 if Length(P
) > 1 then
3955 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
3956 if g_Game_IsServer
then
3958 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
3959 if g_Game_IsNet
then MH_SEND_GameSettings
;
3963 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
3964 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3966 else if cmd
= 'sv_intertime' then
3968 if (Length(P
) > 1) then
3969 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
3971 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
3973 else if cmd
= 'g_max_particles' then
3975 if Length(p
) = 2 then
3977 a
:= Max(0, StrToIntDef(p
[1], 0));
3980 else if Length(p
) = 1 then
3982 e_LogWritefln('%s', [g_GFX_GetMax()])
3986 e_LogWritefln('usage: %s <n>', [cmd
])
3989 else if cmd
= 'g_max_shells' then
3991 if Length(p
) = 2 then
3993 a
:= Max(0, StrToIntDef(p
[1], 0));
3996 else if Length(p
) = 1 then
3998 e_LogWritefln('%s', [g_Shells_GetMax()])
4002 e_LogWritefln('usage: %s <n>', [cmd
])
4005 else if cmd
= 'g_max_gibs' then
4007 if Length(p
) = 2 then
4009 a
:= Max(0, StrToIntDef(p
[1], 0));
4012 else if Length(p
) = 1 then
4014 e_LogWritefln('%s', [g_Gibs_GetMax()])
4018 e_LogWritefln('usage: %s <n>', [cmd
])
4021 else if cmd
= 'g_max_corpses' then
4023 if Length(p
) = 2 then
4025 a
:= Max(0, StrToIntDef(p
[1], 0));
4028 else if Length(p
) = 1 then
4030 e_LogWritefln('%s', [g_Corpses_GetMax()])
4034 e_LogWritefln('usage: %s <n>', [cmd
])
4037 else if cmd
= 'g_force_model' then
4039 if Length(p
) = 2 then
4041 a
:= StrToIntDef(p
[1], 0);
4042 g_Force_Model_Set(a
);
4043 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4045 for a
:= Low(gPlayers
) to High(gPlayers
) do
4047 if (gPlayers
[a
] <> nil) then
4049 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4051 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4053 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4057 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4059 for a
:= Low(gPlayers
) to High(gPlayers
) do
4061 if (gPlayers
[a
] <> nil) then
4063 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4065 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4067 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4073 else if cmd
= 'g_force_model_name' then
4075 if (Length(P
) > 1) then
4077 cmd
:= b_Text_Unformat(P
[1]);
4078 g_Forced_Model_SetName(cmd
);
4079 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4081 for a
:= Low(gPlayers
) to High(gPlayers
) do
4083 if (gPlayers
[a
] <> nil) then
4085 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4087 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4089 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4095 else if cmd
= 'g_scorelimit' then
4097 if Length(P
) > 1 then
4099 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4101 if g_Game_IsServer
then
4104 if gGameSettings
.GameMode
= GM_DM
then
4106 stat
:= g_Player_GetStats();
4108 for a
:= 0 to High(stat
) do
4109 if stat
[a
].Frags
> b
then
4113 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4115 // if someone has a higher score, set it to that instead
4116 gsScoreLimit
:= max(gsScoreLimit
, b
);
4117 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4119 if g_Game_IsNet
then MH_SEND_GameSettings
;
4123 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4125 else if cmd
= 'g_timelimit' then
4127 if Length(P
) > 1 then
4129 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4130 if g_Game_IsServer
then
4132 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4133 if g_Game_IsNet
then MH_SEND_GameSettings
;
4136 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4137 [gsTimeLimit
div 3600,
4138 (gsTimeLimit
div 60) mod 60,
4139 gsTimeLimit
mod 60]));
4141 else if cmd
= 'g_max_bots' then
4143 if Length(P
) > 1 then
4144 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4145 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4147 else if cmd
= 'g_maxlives' then
4149 if Length(P
) > 1 then
4151 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4152 if g_Game_IsServer
then
4154 gGameSettings
.MaxLives
:= gsMaxLives
;
4155 if g_Game_IsNet
then MH_SEND_GameSettings
;
4159 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4163 procedure PlayerSettingsCVars(P
: SSArray
);
4168 function ParseTeam(s
: string): Byte;
4172 'red', '1': result
:= TEAM_RED
;
4173 'blue', '2': result
:= TEAM_BLUE
;
4174 else result
:= TEAM_NONE
;
4178 cmd
:= LowerCase(P
[0]);
4182 if (Length(P
) > 1) then
4184 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4185 if g_Game_IsClient
then
4186 MC_SEND_PlayerSettings
4187 else if gGameOn
and (gPlayer1
<> nil) then
4189 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4190 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4196 if (Length(P
) > 1) then
4198 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4199 if g_Game_IsClient
then
4200 MC_SEND_PlayerSettings
4201 else if gGameOn
and (gPlayer2
<> nil) then
4203 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4204 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4210 if Length(P
) > 3 then
4212 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4213 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4214 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4215 if g_Game_IsClient
then
4216 MC_SEND_PlayerSettings
4217 else if gGameOn
and (gPlayer1
<> nil) then
4219 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4220 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4226 if Length(P
) > 3 then
4228 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4229 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4230 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4231 if g_Game_IsClient
then
4232 MC_SEND_PlayerSettings
4233 else if gGameOn
and (gPlayer2
<> nil) then
4235 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4236 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4242 if (Length(P
) > 1) then
4244 gPlayer1Settings
.Model
:= P
[1];
4245 if g_Game_IsClient
then
4246 MC_SEND_PlayerSettings
4247 else if gGameOn
and (gPlayer1
<> nil) then
4249 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4250 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4251 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4257 if (Length(P
) > 1) then
4259 gPlayer2Settings
.Model
:= P
[1];
4260 if g_Game_IsClient
then
4261 MC_SEND_PlayerSettings
4262 else if gGameOn
and (gPlayer2
<> nil) then
4264 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4265 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4266 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4272 // TODO: switch teams if in game or store this separately
4273 if (Length(P
) > 1) then
4275 team
:= ParseTeam(P
[1]);
4276 if team
= TEAM_NONE
then
4277 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4278 else if not gGameOn
and not g_Game_IsNet
then
4279 gPlayer1Settings
.Team
:= team
4281 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4286 // TODO: switch teams if in game or store this separately
4287 if (Length(P
) > 1) then
4289 team
:= ParseTeam(P
[1]);
4290 if team
= TEAM_NONE
then
4291 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4292 else if not gGameOn
and not g_Game_IsNet
then
4293 gPlayer2Settings
.Team
:= team
4295 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4300 if (Length(P
) = 2) then
4301 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4305 if (Length(P
) = 2) then
4306 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4310 if (Length(P
) = 2) then
4311 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4315 if (Length(P
) = 2) then
4316 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4320 if (Length(P
) = 2) then
4321 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4325 if (Length(P
) = 2) then
4326 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4328 'p1_priority_kastet':
4330 if (Length(P
) = 2) then
4331 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4333 'p2_priority_kastet':
4335 if (Length(P
) = 2) then
4336 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4340 if (Length(P
) = 2) then
4341 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4345 if (Length(P
) = 2) then
4346 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4348 'p1_priority_pistol':
4350 if (Length(P
) = 2) then
4351 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4353 'p2_priority_pistol':
4355 if (Length(P
) = 2) then
4356 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4358 'p1_priority_shotgun1':
4360 if (Length(P
) = 2) then
4361 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4363 'p2_priority_shotgun1':
4365 if (Length(P
) = 2) then
4366 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4368 'p1_priority_shotgun2':
4370 if (Length(P
) = 2) then
4371 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4373 'p2_priority_shotgun2':
4375 if (Length(P
) = 2) then
4376 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4378 'p1_priority_chaingun':
4380 if (Length(P
) = 2) then
4381 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4383 'p2_priority_chaingun':
4385 if (Length(P
) = 2) then
4386 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4388 'p1_priority_rocketlauncher':
4390 if (Length(P
) = 2) then
4391 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4393 'p2_priority_rocketlauncher':
4395 if (Length(P
) = 2) then
4396 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4398 'p1_priority_plasma':
4400 if (Length(P
) = 2) then
4401 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4403 'p2_priority_plasma':
4405 if (Length(P
) = 2) then
4406 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4410 if (Length(P
) = 2) then
4411 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4415 if (Length(P
) = 2) then
4416 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4418 'p1_priority_super':
4420 if (Length(P
) = 2) then
4421 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4423 'p2_priority_super':
4425 if (Length(P
) = 2) then
4426 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4428 'p1_priority_flamethrower':
4430 if (Length(P
) = 2) then
4431 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4433 'p2_priority_flamethrower':
4435 if (Length(P
) = 2) then
4436 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4438 'p1_priority_berserk':
4440 if (Length(P
) = 2) then
4441 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4443 'p2_priority_berserk':
4445 if (Length(P
) = 2) then
4446 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4451 procedure PrintHeapStats();
4455 hs
:= GetFPCHeapStatus();
4456 e_LogWriteLn ('v===== heap status =====v');
4457 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4458 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4459 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4460 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4461 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4462 e_LogWriteLn ('^=======================^');
4465 procedure DebugCommands(P
: SSArray
);
4472 // Команды отладочного режима:
4473 if {gDebugMode}conIsCheatsEnabled
then
4475 cmd
:= LowerCase(P
[0]);
4476 if cmd
= 'd_window' then
4478 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4479 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4481 else if cmd
= 'd_sounds' then
4483 if (Length(P
) > 1) and
4484 ((P
[1] = '1') or (P
[1] = '0')) then
4485 g_Debug_Sounds
:= (P
[1][1] = '1');
4487 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4489 else if cmd
= 'd_frames' then
4491 if (Length(P
) > 1) and
4492 ((P
[1] = '1') or (P
[1] = '0')) then
4493 g_Debug_Frames
:= (P
[1][1] = '1');
4495 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4497 else if cmd
= 'd_winmsg' then
4499 if (Length(P
) > 1) and
4500 ((P
[1] = '1') or (P
[1] = '0')) then
4501 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4503 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4505 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4507 if (Length(P
) > 1) and
4508 ((P
[1] = '1') or (P
[1] = '0')) then
4509 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4511 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4513 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4515 if Length(P
) > 1 then
4517 '0': g_debug_BotAIOff
:= 0;
4518 '1': g_debug_BotAIOff
:= 1;
4519 '2': g_debug_BotAIOff
:= 2;
4520 '3': g_debug_BotAIOff
:= 3;
4523 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4525 else if cmd
= 'd_monster' then
4527 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4528 if Length(P
) < 2 then
4530 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4531 g_Console_Add('ID | Name');
4532 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4533 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4534 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4537 a
:= StrToIntDef(P
[1], 0);
4538 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4539 a
:= g_Mons_TypeIdByName(P
[1]);
4541 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4542 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4545 with gPlayer1
.Obj
do
4547 mon
:= g_Monsters_Create(a
,
4548 X
+ Rect
.X
+ (Rect
.Width
div 2),
4549 Y
+ Rect
.Y
+ Rect
.Height
,
4550 gPlayer1
.Direction
, True);
4552 if (Length(P
) > 2) and (mon
<> nil) then
4554 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4555 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4556 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4557 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4558 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4559 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4560 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4561 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4562 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4567 else if (cmd
= 'd_health') then
4569 if (Length(P
) > 1) and
4570 ((P
[1] = '1') or (P
[1] = '0')) then
4571 g_debug_HealthBar
:= (P
[1][1] = '1');
4573 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4575 else if (cmd
= 'd_player') then
4577 if (Length(P
) > 1) and
4578 ((P
[1] = '1') or (P
[1] = '0')) then
4579 g_debug_Player
:= (P
[1][1] = '1');
4581 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4583 else if (cmd
= 'd_mem') then
4589 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4593 procedure GameCheats(P
: SSArray
);
4599 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4601 g_Console_Add('not available');
4607 g_Console_Add('where is the player?!');
4610 cmd
:= LowerCase(P
[0]);
4614 plr
.GodMode
:= not plr
.GodMode
;
4615 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4618 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4619 if cmd
= 'give' then
4621 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4622 for f
:= 1 to High(P
) do
4624 cmd
:= LowerCase(P
[f
]);
4625 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4626 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4627 if cmd
= 'exit' then
4629 if gTriggers
<> nil then
4631 for a
:= 0 to High(gTriggers
) do
4633 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4635 g_Console_Add('player left the map');
4636 gExitByTrigger
:= True;
4637 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4638 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4646 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4647 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4648 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4649 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4650 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4652 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4653 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4655 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4656 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;
4658 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4659 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4661 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4662 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4664 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4665 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4667 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4668 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4669 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4671 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4672 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4673 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4674 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;
4675 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4676 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4678 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;
4679 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;
4680 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;
4681 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;
4682 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;
4683 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;
4685 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4686 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;
4688 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;
4689 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;
4691 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4693 if cmd
= 'ammo' then
4695 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4696 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4697 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4698 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4699 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4700 g_Console_Add('player got some ammo');
4704 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4705 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4707 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4708 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4710 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4711 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4713 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4714 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4716 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4718 if cmd
= 'weapons' then
4720 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4721 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4722 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4723 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4724 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4725 plr
.GiveItem(ITEM_WEAPON_BFG
);
4726 g_Console_Add('player got weapons');
4730 if cmd
= 'keys' then
4732 plr
.GiveItem(ITEM_KEY_RED
);
4733 plr
.GiveItem(ITEM_KEY_GREEN
);
4734 plr
.GiveItem(ITEM_KEY_BLUE
);
4735 g_Console_Add('player got all keys');
4739 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4744 if cmd
= 'open' then
4746 g_Console_Add('player activated sesame');
4747 g_Triggers_OpenAll();
4754 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4758 if cmd
= 'noclip' then
4761 g_Console_Add('wall hardeness adjusted');
4765 if cmd
= 'notarget' then
4767 plr
.NoTarget
:= not plr
.NoTarget
;
4768 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4772 if cmd
= 'noreload' then
4774 plr
.NoReload
:= not plr
.NoReload
;
4775 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4779 if cmd
= 'speedy' then
4781 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4782 g_Console_Add('speed adjusted');
4786 if cmd
= 'jumpy' then
4788 VEL_JUMP
:= 30-VEL_JUMP
;
4789 g_Console_Add('jump height adjusted');
4793 if cmd
= 'automap' then
4795 gShowMap
:= not gShowMap
;
4796 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4800 if cmd
= 'aimline' then
4802 gAimLine
:= not gAimLine
;
4803 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4808 procedure GameCommands(P
: SSArray
);
4814 pl
: pTNetClient
= nil;
4822 cmd
:= LowerCase(P
[0]);
4824 if cmd
= 'pause' then
4826 if (g_ActiveWindow
= nil) then
4827 g_Game_Pause(not gPauseMain
);
4829 else if cmd
= 'endgame' then
4830 gExit
:= EXIT_SIMPLE
4831 else if cmd
= 'restart' then
4833 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4835 if g_Game_IsClient
then
4837 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4842 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4844 else if cmd
= 'kick' then
4846 if g_Game_IsServer
then
4848 if Length(P
) < 2 then
4850 g_Console_Add('kick <name>');
4855 g_Console_Add('kick <name>');
4859 if g_Game_IsNet
then
4860 pl
:= g_Net_Client_ByName(P
[1]);
4863 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4864 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4865 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4866 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4867 g_Net_Slist_ServerPlayerLeaves();
4868 end else if gPlayers
<> nil then
4869 for a
:= Low(gPlayers
) to High(gPlayers
) do
4870 if gPlayers
[a
] <> nil then
4871 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4873 // Не отключать основных игроков в сингле
4874 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4876 gPlayers
[a
].Lives
:= 0;
4877 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4878 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4879 g_Player_Remove(gPlayers
[a
].UID
);
4880 g_Net_Slist_ServerPlayerLeaves();
4881 // Если не перемешать, при добавлении новых ботов появятся старые
4885 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4887 else if cmd
= 'kick_id' then
4889 if g_Game_IsServer
and g_Game_IsNet
then
4891 if Length(P
) < 2 then
4893 g_Console_Add('kick_id <client ID>');
4898 g_Console_Add('kick_id <client ID>');
4902 a
:= StrToIntDef(P
[1], 0);
4903 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4905 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4907 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4908 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
4909 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4910 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4911 g_Net_Slist_ServerPlayerLeaves();
4915 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4917 else if cmd
= 'kick_pid' then
4919 if g_Game_IsServer
and g_Game_IsNet
then
4921 if Length(P
) < 2 then
4923 g_Console_Add('kick_pid <player ID>');
4928 g_Console_Add('kick_pid <player ID>');
4932 a
:= StrToIntDef(P
[1], 0);
4933 pl
:= g_Net_Client_ByPlayer(a
);
4934 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4936 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4937 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4938 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4939 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4940 g_Net_Slist_ServerPlayerLeaves();
4943 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4945 else if cmd
= 'ban' then
4947 if g_Game_IsServer
and g_Game_IsNet
then
4949 if Length(P
) < 2 then
4951 g_Console_Add('ban <name>');
4956 g_Console_Add('ban <name>');
4960 pl
:= g_Net_Client_ByName(P
[1]);
4963 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4964 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4965 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
4966 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4967 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4968 g_Net_Slist_ServerPlayerLeaves();
4970 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4972 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4974 else if cmd
= 'ban_id' then
4976 if g_Game_IsServer
and g_Game_IsNet
then
4978 if Length(P
) < 2 then
4980 g_Console_Add('ban_id <client ID>');
4985 g_Console_Add('ban_id <client ID>');
4989 a
:= StrToIntDef(P
[1], 0);
4990 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4991 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4993 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4994 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
4995 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
4996 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4997 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4998 g_Net_Slist_ServerPlayerLeaves();
5001 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5003 else if cmd
= 'ban_pid' then
5005 if g_Game_IsServer
and g_Game_IsNet
then
5007 if Length(P
) < 2 then
5009 g_Console_Add('ban_pid <player ID>');
5014 g_Console_Add('ban_pid <player ID>');
5018 a
:= StrToIntDef(P
[1], 0);
5019 pl
:= g_Net_Client_ByPlayer(a
);
5020 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5022 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5023 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5024 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5025 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5026 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5027 g_Net_Slist_ServerPlayerLeaves();
5030 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5032 else if cmd
= 'permban' then
5034 if g_Game_IsServer
and g_Game_IsNet
then
5036 if Length(P
) < 2 then
5038 g_Console_Add('permban <name>');
5043 g_Console_Add('permban <name>');
5047 pl
:= g_Net_Client_ByName(P
[1]);
5050 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5051 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5052 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5053 g_Net_SaveBanList();
5054 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5055 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5056 g_Net_Slist_ServerPlayerLeaves();
5058 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5060 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5062 else if cmd
= 'permban_id' then
5064 if g_Game_IsServer
and g_Game_IsNet
then
5066 if Length(P
) < 2 then
5068 g_Console_Add('permban_id <client ID>');
5073 g_Console_Add('permban_id <client ID>');
5077 a
:= StrToIntDef(P
[1], 0);
5078 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5079 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5081 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5082 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5083 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5084 g_Net_SaveBanList();
5085 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5086 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5087 g_Net_Slist_ServerPlayerLeaves();
5090 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5092 else if cmd
= 'permban_pid' then
5094 if g_Game_IsServer
and g_Game_IsNet
then
5096 if Length(P
) < 2 then
5098 g_Console_Add('permban_pid <player ID>');
5103 g_Console_Add('permban_pid <player ID>');
5107 a
:= StrToIntDef(P
[1], 0);
5108 pl
:= g_Net_Client_ByPlayer(a
);
5109 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5111 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5112 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5113 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5114 g_Net_SaveBanList();
5115 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5116 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5117 g_Net_Slist_ServerPlayerLeaves();
5120 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5122 else if cmd
= 'permban_ip' then
5124 if g_Game_IsServer
and g_Game_IsNet
then
5126 if Length(P
) < 2 then
5128 g_Console_Add('permban_ip <IP address>');
5133 g_Console_Add('permban_ip <IP address>');
5137 g_Net_BanHost(P
[1]);
5138 g_Net_SaveBanList();
5139 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5141 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5143 else if cmd
= 'unban' then
5145 if g_Game_IsServer
and g_Game_IsNet
then
5147 if Length(P
) < 2 then
5149 g_Console_Add('unban <IP Address>');
5154 g_Console_Add('unban <IP Address>');
5158 if g_Net_UnbanHost(P
[1]) then
5160 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5161 g_Net_SaveBanList();
5163 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5165 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5167 else if cmd
= 'clientlist' then
5169 if g_Game_IsServer
and g_Game_IsNet
then
5172 if NetClients
<> nil then
5173 for a
:= Low(NetClients
) to High(NetClients
) do
5174 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5176 plr
:= g_Player_Get(NetClients
[a
].Player
);
5177 if plr
= nil then continue
;
5179 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5180 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5183 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5185 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5187 else if cmd
= 'connect' then
5189 if (NetMode
= NET_NONE
) then
5191 if Length(P
) < 2 then
5193 g_Console_Add('connect <IP> [port] [password]');
5198 g_Console_Add('connect <IP> [port] [password]');
5202 if Length(P
) > 2 then
5203 prt
:= StrToIntDef(P
[2], 25666)
5207 if Length(P
) > 3 then
5212 g_Game_StartClient(P
[1], prt
, pw
);
5215 else if cmd
= 'disconnect' then
5217 if (NetMode
= NET_CLIENT
) then
5220 else if cmd
= 'reconnect' then
5222 if (NetMode
= NET_SERVER
) then
5225 if (NetMode
= NET_CLIENT
) then
5228 gExit
:= EXIT_SIMPLE
;
5232 //TODO: Use last successful password to reconnect, instead of ''
5233 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5235 else if (cmd
= 'addbot') or
5236 (cmd
= 'bot_add') then
5238 if Length(P
) > 2 then
5239 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5240 else if Length(P
) > 1 then
5241 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5243 g_Bot_Add(TEAM_NONE
, 2);
5245 else if cmd
= 'bot_addlist' then
5247 if Length(P
) > 1 then
5249 if Length(P
) = 2 then
5250 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5251 else if Length(P
) = 3 then
5252 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5254 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5257 else if cmd
= 'bot_removeall' then
5259 else if cmd
= 'chat' then
5261 if g_Game_IsNet
then
5263 if Length(P
) > 1 then
5265 for a
:= 1 to High(P
) do
5266 chstr
:= chstr
+ P
[a
] + ' ';
5268 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5270 if Length(chstr
) < 1 then
5272 g_Console_Add('chat <text>');
5276 chstr
:= b_Text_Format(chstr
);
5277 if g_Game_IsClient
then
5278 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5280 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5283 g_Console_Add('chat <text>');
5285 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5287 else if cmd
= 'teamchat' then
5289 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5291 if Length(P
) > 1 then
5293 for a
:= 1 to High(P
) do
5294 chstr
:= chstr
+ P
[a
] + ' ';
5296 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5298 if Length(chstr
) < 1 then
5300 g_Console_Add('teamchat <text>');
5304 chstr
:= b_Text_Format(chstr
);
5305 if g_Game_IsClient
then
5306 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5308 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5309 gPlayer1Settings
.Team
);
5312 g_Console_Add('teamchat <text>');
5314 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5316 else if (cmd
= 'an') or (cmd
= 'announce') then
5318 if g_Game_IsNet
then
5320 if Length(P
) > 1 then
5322 for a
:= 1 to High(P
) do
5323 chstr
:= chstr
+ P
[a
] + ' ';
5325 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5327 if Length(chstr
) < 1 then
5329 g_Console_Add('announce <text>');
5333 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5334 if g_Game_IsClient
then
5335 MC_SEND_RCONCommand(chstr
)
5337 g_Console_Process(chstr
, True);
5340 g_Console_Add('announce <text>');
5342 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5344 else if cmd
= 'game' then
5346 if gGameSettings
.GameType
<> GT_NONE
then
5348 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5351 if Length(P
) = 1 then
5353 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5356 // game not started yet, load fist map from some wad
5358 s
:= addWadExtension(P
[1]);
5359 found
:= e_FindResource(AllMapDirs
, s
);
5363 P
[1] := ExpandFileName(P
[1]);
5364 // if map not choosed then set first map
5365 if Length(P
) < 3 then
5368 P
[2] := g_Game_GetFirstMap(P
[1]);
5371 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5373 if g_Map_Exist(s
) then
5377 with gGameSettings
do
5379 Options
:= gsGameFlags
;
5380 GameMode
:= g_Game_TextToMode(gsGameMode
);
5381 if gSwitchGameMode
<> GM_NONE
then
5382 GameMode
:= gSwitchGameMode
;
5383 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5384 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5386 if Length(P
) >= 4 then
5387 b
:= StrToIntDef(P
[3], 1);
5388 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5389 ScoreLimit
, MaxLives
, Options
, b
);
5394 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5396 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5398 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5400 else if cmd
= 'host' then
5402 if gGameSettings
.GameType
<> GT_NONE
then
5404 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5407 if Length(P
) < 4 then
5409 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5412 if not StrToIp(P
[1], listen
) then
5414 prt
:= StrToIntDef(P
[2], 25666);
5416 s
:= addWadExtension(P
[3]);
5417 found
:= e_FindResource(AllMapDirs
, s
);
5421 // get first map in wad, if not specified
5422 if Length(P
) < 5 then
5425 P
[4] := g_Game_GetFirstMap(P
[1]);
5427 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5428 if g_Map_Exist(s
) then
5432 with gGameSettings
do
5434 Options
:= gsGameFlags
;
5435 GameMode
:= g_Game_TextToMode(gsGameMode
);
5436 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5437 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5438 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5440 if Length(P
) >= 6 then
5441 b
:= StrToIntDef(P
[5], 0);
5442 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5448 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5450 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5455 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5458 else if cmd
= 'map' then
5460 if Length(P
) = 1 then
5462 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5464 g_Console_Add(cmd
+ ' <MAP>');
5465 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5469 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5474 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5476 if Length(P
) < 3 then
5478 // first param is map or wad
5479 s
:= UpperCase(P
[1]);
5480 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5482 gExitByTrigger
:= False;
5485 // already in game, finish current map
5487 gExit
:= EXIT_ENDLEVELCUSTOM
;
5491 // intermission, so change map immediately
5498 found
:= e_FindResource(AllMapDirs
, s
);
5500 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5503 // no such map, found wad
5506 P
[1] := ExpandFileName(pw
);
5507 P
[2] := g_Game_GetFirstMap(P
[1]);
5508 s
:= P
[1] + ':\' + P
[2];
5509 if g_Map_Exist(s
) then
5511 gExitByTrigger
:= False;
5514 // already in game, finish current map
5516 gExit
:= EXIT_ENDLEVELCUSTOM
5520 // intermission, so change map immediately
5527 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5529 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5534 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5540 s
:= addWadExtension(P
[1]);
5541 found
:= e_FindResource(AllMapDirs
, s
);
5545 P
[2] := UpperCase(P
[2]);
5546 s
:= P
[1] + ':\' + P
[2];
5547 if g_Map_Exist(s
) then
5549 gExitByTrigger
:= False;
5553 gExit
:= EXIT_ENDLEVELCUSTOM
5562 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5567 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5573 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5577 else if cmd
= 'nextmap' then
5579 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5581 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5586 if Length(P
) = 1 then
5588 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5590 g_Console_Add(cmd
+ ' <MAP>');
5591 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5596 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5602 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5604 if Length(P
) < 3 then
5606 // first param is map or wad
5607 s
:= UpperCase(P
[1]);
5608 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5611 gExitByTrigger
:= False;
5617 // no such map, found wad
5618 pw
:= addWadExtension(P
[1]);
5619 found
:= e_FindResource(MapDirs
, pw
);
5621 found
:= e_FindResource(WadDirs
, pw
);
5623 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5626 // map not specified, select first map
5628 P
[2] := g_Game_GetFirstMap(P
[1]);
5629 s
:= P
[1] + ':\' + P
[2];
5630 if g_Map_Exist(s
) then
5632 gExitByTrigger
:= False;
5639 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5641 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5646 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5652 // specified two params wad + map
5653 pw
:= addWadExtension(P
[1]);
5654 found
:= e_FindResource(MapDirs
, pw
);
5656 found
:= e_FindResource(MapDirs
, pw
);
5660 P
[2] := UpperCase(P
[2]);
5661 s
:= P
[1] + ':\' + P
[2];
5662 if g_Map_Exist(s
) then
5664 gExitByTrigger
:= False;
5670 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5675 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5681 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5686 if gNextMap
= '' then
5687 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5689 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5693 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5697 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5701 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5703 gExitByTrigger
:= False;
5704 // next map not specified, try to find trigger EXIT
5705 if (gNextMap
= '') and (gTriggers
<> nil) then
5707 for a
:= 0 to High(gTriggers
) do
5709 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5711 gExitByTrigger
:= True;
5712 //gNextMap := gTriggers[a].Data.MapName;
5713 gNextMap
:= gTriggers
[a
].tgcMap
;
5718 if gNextMap
= '' then
5719 gNextMap
:= g_Game_GetNextMap();
5720 if not isWadPath(gNextMap
) then
5721 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5724 if g_Map_Exist(s
) then
5725 gExit
:= EXIT_ENDLEVELCUSTOM
5727 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5731 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5735 else if (cmd
= 'event') then
5737 if (Length(P
) <= 1) then
5739 for a
:= 0 to High(gEvents
) do
5740 if gEvents
[a
].Command
= '' then
5741 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5743 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5746 if (Length(P
) = 2) then
5748 for a
:= 0 to High(gEvents
) do
5749 if gEvents
[a
].Name
= P
[1] then
5750 if gEvents
[a
].Command
= '' then
5751 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5753 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5756 for a
:= 0 to High(gEvents
) do
5757 if gEvents
[a
].Name
= P
[1] then
5759 gEvents
[a
].Command
:= '';
5760 for b
:= 2 to High(P
) do
5761 if Pos(' ', P
[b
]) = 0 then
5762 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5764 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5765 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5769 else if cmd
= 'suicide' then
5773 if g_Game_IsClient
then
5774 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5777 if gPlayer1
<> nil then
5778 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5779 if gPlayer2
<> nil then
5780 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5784 else if cmd
= 'screenshot' then
5788 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5790 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5792 gWeaponAction
[0, WP_PREV
] := True;
5794 gWeaponAction
[0, WP_NEXT
] := True;
5796 else if cmd
= 'weapon' then
5798 if Length(p
) = 2 then
5800 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5801 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5802 gSelectWeapon
[0, a
] := True
5805 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5806 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5808 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5809 b
:= ord(cmd
[2]) - ord('1');
5811 gWeaponAction
[b
, WP_PREV
] := True;
5813 gWeaponAction
[b
, WP_NEXT
] := True;
5815 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5817 if Length(p
) = 2 then
5819 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5820 b
:= ord(cmd
[2]) - ord('1');
5821 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5822 gSelectWeapon
[b
, a
] := True
5825 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
5827 b
:= ord(cmd
[2]) - ord('1');
5829 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
5831 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
5833 else if (cmd
= 'dropflag') then
5835 if g_Game_IsServer
then
5837 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
5838 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
5841 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5843 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
5845 b
:= ord(cmd
[2]) - ord('1');
5846 if g_Game_IsServer
then
5848 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
5849 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
5852 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5854 // Команды Своей игры:
5855 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5857 if cmd
= 'bot_addred' then
5859 if Length(P
) > 1 then
5860 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5862 g_Bot_Add(TEAM_RED
, 2);
5864 else if cmd
= 'bot_addblue' then
5866 if Length(P
) > 1 then
5867 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5869 g_Bot_Add(TEAM_BLUE
, 2);
5871 else if cmd
= 'spectate' then
5877 else if cmd
= 'say' then
5879 if g_Game_IsServer
and g_Game_IsNet
then
5881 if Length(P
) > 1 then
5884 for a
:= 1 to High(P
) do
5885 chstr
:= chstr
+ P
[a
] + ' ';
5887 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5889 if Length(chstr
) < 1 then
5891 g_Console_Add('say <text>');
5895 chstr
:= b_Text_Format(chstr
);
5896 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5898 else g_Console_Add('say <text>');
5900 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5902 else if cmd
= 'tell' then
5904 if g_Game_IsServer
and g_Game_IsNet
then
5906 if (Length(P
) > 2) and (P
[1] <> '') then
5909 for a
:= 2 to High(P
) do
5910 chstr
:= chstr
+ P
[a
] + ' ';
5912 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5914 if Length(chstr
) < 1 then
5916 g_Console_Add('tell <playername> <text>');
5920 pl
:= g_Net_Client_ByName(P
[1]);
5922 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5924 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5926 else g_Console_Add('tell <playername> <text>');
5928 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5930 else if cmd
= 'centerprint' then
5932 if (Length(P
) > 2) and (P
[1] <> '') then
5935 for a
:= 2 to High(P
) do
5936 chstr
:= chstr
+ P
[a
] + ' ';
5938 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5940 if Length(chstr
) < 1 then
5942 g_Console_Add('centerprint <timeout> <text>');
5946 a
:= StrToIntDef(P
[1], 100);
5947 chstr
:= b_Text_Format(chstr
);
5948 g_Game_Message(chstr
, a
);
5949 if g_Game_IsNet
and g_Game_IsServer
then
5950 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
5952 else g_Console_Add('centerprint <timeout> <text>');
5954 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5956 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5958 // Дополнительное время:
5959 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5961 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5962 [gGameSettings
.TimeLimit
div 3600,
5963 (gGameSettings
.TimeLimit
div 60) mod 60,
5964 gGameSettings
.TimeLimit
mod 60]));
5965 if g_Game_IsNet
then MH_SEND_GameSettings
;
5967 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5969 if (Length(P
) <= 1) then
5970 g_Console_Add('rcon_password <password>')
5972 MC_SEND_RCONPassword(P
[1]);
5974 else if cmd
= 'rcon' then
5976 if g_Game_IsClient
then
5978 if Length(P
) > 1 then
5981 for a
:= 1 to High(P
) do
5982 chstr
:= chstr
+ P
[a
] + ' ';
5984 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5986 if Length(chstr
) < 1 then
5988 g_Console_Add('rcon <command>');
5992 MC_SEND_RCONCommand(chstr
);
5994 else g_Console_Add('rcon <command>');
5997 else if cmd
= 'ready' then
5999 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6000 gLMSRespawnTime
:= gTime
+ 100;
6002 else if (cmd
= 'callvote') and g_Game_IsNet
then
6004 if Length(P
) > 1 then
6007 for a
:= 1 to High(P
) do begin
6008 if a
> 1 then chstr
:= chstr
+ ' ';
6009 chstr
:= chstr
+ P
[a
];
6012 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6014 if Length(chstr
) < 1 then
6016 g_Console_Add('callvote <command>');
6020 if g_Game_IsClient
then
6021 MC_SEND_Vote(True, chstr
)
6023 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6024 g_Console_Process('vote', True);
6027 g_Console_Add('callvote <command>');
6029 else if (cmd
= 'vote') and g_Game_IsNet
then
6031 if g_Game_IsClient
then
6033 else if gVoteInProgress
then
6035 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6036 a
:= Floor((NetClientCount
+1)/2.0) + 1
6038 a
:= Floor(NetClientCount
/2.0) + 1;
6043 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6044 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6050 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6051 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6059 procedure SystemCommands(P
: SSArray
);
6063 cmd
:= LowerCase(P
[0]);
6074 if Length(p
) = 2 then
6076 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6078 gFrameTime
:= 1000 div gMaxFPS
6082 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6086 if Length(p
) = 2 then
6088 gAskLanguage
:= true;
6089 gLanguage
:= LANGUAGE_ENGLISH
;
6090 case LowerCase(p
[1]) of
6093 gAskLanguage
:= false;
6094 gLanguage
:= LANGUAGE_ENGLISH
;
6098 gAskLanguage
:= false;
6099 gLanguage
:= LANGUAGE_RUSSIAN
;
6103 gAskLanguage
:= true;
6104 gLanguage
:= LANGUAGE_ENGLISH
;
6107 g_Language_Set(gLanguage
);
6111 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6117 procedure g_TakeScreenShot(Filename
: string = '');
6118 var t
: TDateTime
; dir
, date
, name
: String;
6120 if e_NoGraphics
then
6123 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6124 if Filename
= '' then
6127 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6128 Filename
:= 'screenshot-' + date
;
6131 name
:= e_CatPath(dir
, Filename
+ '.png');
6132 if r_Render_WriteScreenShot(name
) then
6133 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6135 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6138 procedure g_Game_InGameMenu(Show
: Boolean);
6140 if (g_ActiveWindow
= nil) and Show
then
6142 if gGameSettings
.GameType
= GT_SINGLE
then
6143 g_GUI_ShowWindow('GameSingleMenu')
6146 if g_Game_IsClient
then
6147 g_GUI_ShowWindow('GameClientMenu')
6149 if g_Game_IsNet
then
6150 g_GUI_ShowWindow('GameServerMenu')
6152 g_GUI_ShowWindow('GameCustomMenu');
6154 g_Sound_PlayEx('MENU_OPEN');
6156 // Пауза при меню только в одиночной игре:
6157 if (not g_Game_IsNet
) then
6161 if (g_ActiveWindow
<> nil) and (not Show
) then
6163 // Пауза при меню только в одиночной игре:
6164 if (not g_Game_IsNet
) then
6165 g_Game_Pause(False);
6169 procedure g_Game_Pause (Enable
: Boolean);
6173 if not gGameOn
then exit
;
6175 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6178 gPauseMain
:= Enable
;
6180 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6183 procedure g_Game_HolmesPause (Enable
: Boolean);
6187 if not gGameOn
then exit
;
6188 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6191 gPauseHolmes
:= Enable
;
6193 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6196 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6201 if gTriggers
<> nil then
6202 for i
:= 0 to High(gTriggers
) do
6203 with gTriggers
[i
] do
6204 if (TriggerType
= TRIGGER_SOUND
) and
6206 Sound
.IsPlaying() then
6208 Sound
.Pause(Enable
);
6212 if gPlayers
<> nil then
6213 for i
:= 0 to High(gPlayers
) do
6214 if gPlayers
[i
] <> nil then
6215 gPlayers
[i
].PauseSounds(Enable
);
6218 if gMusic
<> nil then
6219 gMusic
.Pause(Enable
);
6222 procedure g_Game_StopAllSounds(all
: Boolean);
6226 if gTriggers
<> nil then
6227 for i
:= 0 to High(gTriggers
) do
6228 with gTriggers
[i
] do
6229 if (TriggerType
= TRIGGER_SOUND
) and
6233 if gMusic
<> nil then
6240 procedure g_Game_UpdateTriggerSounds
;
6243 if gTriggers
<> nil then
6244 for i
:= 0 to High(gTriggers
) do
6245 with gTriggers
[i
] do
6246 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6247 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6250 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6253 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6258 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6263 if gSpectMode
<> SPECT_PLAYERS
then
6265 if gSpectPID1
= UID
then
6270 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6277 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6282 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6287 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6292 if gSpectMode
<> SPECT_PLAYERS
then
6294 Pl
:= g_Player_Get(gSpectPID1
);
6295 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6300 if gSpectViewTwo
then
6302 Pl
:= g_Player_Get(gSpectPID2
);
6303 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6311 procedure g_Game_Message (Msg
: string; Time
: Word);
6314 MessageTime
:= Time
;
6317 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6319 punct
: Array[0..13] of String =
6320 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6326 function IsPunctuation(S
: String): Boolean;
6331 if Length(S
) <> 1 then
6333 for i
:= Low(punct
) to High(punct
) do
6334 if S
= punct
[i
] then
6340 function FilterPunctuation(S
: String): String;
6344 for i
:= Low(punct
) to High(punct
) do
6345 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6351 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6353 // remove player name
6354 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6355 // for FullWord check
6356 Text := toLowerCase1251(' ' + Text + ' ');
6357 fpText
:= FilterPunctuation(Text);
6359 for i
:= 0 to Length(gChatSounds
) - 1 do
6362 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6364 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6365 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6367 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6373 gChatSounds
[i
].Sound
.Play();
6379 g_Sound_PlayEx('SOUND_GAME_RADIO');
6382 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6391 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6395 if goodsnd
[a
].IsPlaying() then
6398 goodsnd
[Random(4)].Play();
6401 procedure g_Game_Announce_KillCombo(Param
: Integer);
6408 UID
:= Param
and $FFFF;
6413 Pl
:= g_Player_Get(UID
);
6422 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6426 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6430 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6434 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6442 if not g_Game_IsWatchedPlayer(UID
) then
6445 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6449 if killsnd
[n
].IsPlaying() then
6454 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6462 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6466 if hahasnd
[a
].IsPlaying() then
6469 hahasnd
[Random(3)].Play();
6472 procedure g_Game_StartVote(Command
, Initiator
: string);
6476 if not gVotesEnabled
then Exit
;
6477 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6478 if gVoteInProgress
or gVotePassed
then
6480 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6481 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6484 gVoteInProgress
:= True;
6485 gVotePassed
:= False;
6486 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6489 gVoteCommand
:= Command
;
6491 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6492 Need
:= Floor((NetClientCount
+1)/2.0)+1
6494 Need
:= Floor(NetClientCount
/2.0)+1;
6495 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6496 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6499 procedure g_Game_CheckVote
;
6503 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6504 if not gVoteInProgress
then Exit
;
6506 if (gTime
>= gVoteTimer
) then
6508 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6509 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6511 Need
:= Floor(NetClientCount
/2.0) + 1;
6512 if gVoteCount
>= Need
then
6514 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6515 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6516 gVotePassed
:= True;
6517 gVoteCmdTimer
:= gTime
+ 5000;
6521 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6522 MH_SEND_VoteEvent(NET_VE_FAILED
);
6524 if NetClients
<> nil then
6525 for I
:= Low(NetClients
) to High(NetClients
) do
6526 if NetClients
[i
].Used
then
6527 NetClients
[i
].Voted
:= False;
6528 gVoteInProgress
:= False;
6534 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6535 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6537 Need
:= Floor(NetClientCount
/2.0) + 1;
6538 if gVoteCount
>= Need
then
6540 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6541 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6542 gVoteInProgress
:= False;
6543 gVotePassed
:= True;
6544 gVoteCmdTimer
:= gTime
+ 5000;
6547 if NetClients
<> nil then
6548 for I
:= Low(NetClients
) to High(NetClients
) do
6549 if NetClients
[i
].Used
then
6550 NetClients
[i
].Voted
:= False;
6555 procedure g_Game_LoadMapList(FileName
: string);
6563 if not FileExists(FileName
) then Exit
;
6565 AssignFile(ListFile
, FileName
);
6567 while not EOF(ListFile
) do
6569 ReadLn(ListFile
, s
);
6572 if s
= '' then Continue
;
6574 SetLength(MapList
, Length(MapList
)+1);
6575 MapList
[High(MapList
)] := s
;
6577 CloseFile(ListFile
);
6580 procedure g_Game_SetDebugMode();
6583 // Читы (даже в своей игре):
6587 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6591 if Length(LoadingStat
.Msgs
) = 0 then
6597 begin // Переходим на следующую строку или скроллируем:
6598 if NextMsg
= Length(Msgs
) then
6600 for i
:= 0 to High(Msgs
)-1 do
6601 Msgs
[i
] := Msgs
[i
+1];
6609 Msgs
[NextMsg
-1] := Text;
6613 PBarWasHere
:= false;
6616 g_ActiveWindow
:= nil;
6617 ProcessLoading(True);
6620 procedure g_Game_StepLoading(Value
: Integer = -1);
6632 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6635 ProcessLoading(False);
6640 procedure g_Game_ClearLoading();
6649 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6650 if len
< 1 then len
:= 1;
6651 SetLength(Msgs
, len
);
6652 for len
:= Low(Msgs
) to High(Msgs
) do
6655 PBarWasHere
:= false;
6659 procedure Parse_Params(var pars
: TParamStrValues
);
6666 while i
<= ParamCount
do
6669 if (Length(s
) > 1) and (s
[1] = '-') then
6671 if (Length(s
) > 2) and (s
[2] = '-') then
6672 begin // Одиночный параметр
6673 SetLength(pars
, Length(pars
) + 1);
6674 with pars
[High(pars
)] do
6676 Name
:= LowerCase(s
);
6681 if (i
< ParamCount
) then
6682 begin // Параметр со значением
6684 SetLength(pars
, Length(pars
) + 1);
6685 with pars
[High(pars
)] do
6687 Name
:= LowerCase(s
);
6688 Value
:= LowerCase(ParamStr(i
));
6697 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6702 for i
:= 0 to High(pars
) do
6703 if pars
[i
].Name
= aName
then
6705 Result
:= pars
[i
].Value
;
6710 procedure g_Game_Process_Params();
6712 pars
: TParamStrValues
;
6715 LimT
, LimS
: Integer;
6726 s
:= Find_Param_Value(pars
, '--debug');
6729 g_Game_SetDebugMode();
6730 s
:= Find_Param_Value(pars
, '--netdump');
6735 // Connect when game loads
6736 ip
:= Find_Param_Value(pars
, '-connect');
6740 s
:= Find_Param_Value(pars
, '-port');
6741 if (s
= '') or not TryStrToInt(s
, Port
) then
6744 s
:= Find_Param_Value(pars
, '-pw');
6746 g_Game_StartClient(ip
, Port
, s
);
6750 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6753 gDefaultMegawadStart
:= s
;
6756 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6757 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6759 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6762 // Start map when game loads:
6763 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6764 if isWadPath(map
) then
6767 s
:= Find_Param_Value(pars
, '-gm');
6768 GMode
:= g_Game_TextToMode(s
);
6769 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6770 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6773 s
:= Find_Param_Value(pars
, '-limt');
6774 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6780 s
:= Find_Param_Value(pars
, '-lims');
6781 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6787 s
:= Find_Param_Value(pars
, '-lives');
6788 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6794 s
:= Find_Param_Value(pars
, '-opt');
6798 Opt
:= StrToIntDef(s
, 0);
6801 s
:= Find_Param_Value(pars
, '--close');
6805 // Override map to test:
6806 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6809 if e_IsValidResourceName(s
) then
6810 e_FindResource(AllMapDirs
, s
);
6811 gTestMap
:= ExpandFileName(s
);
6814 // Delete test map after play:
6815 s
:= Find_Param_Value(pars
, '--testdelete');
6818 //gMapToDelete := MapsDir + map;
6819 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6823 // Delete temporary WAD after play:
6824 s
:= Find_Param_Value(pars
, '--tempdelete');
6825 if (s
<> '') and (gTestMap
<> '') then
6827 gMapToDelete
:= gTestMap
;
6828 gTempDelete
:= True;
6831 // Number of players:
6832 s
:= Find_Param_Value(pars
, '-pl');
6834 n
:= DEFAULT_PLAYERS
6836 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6839 s
:= Find_Param_Value(pars
, '-port');
6840 if (s
= '') or not TryStrToInt(s
, Port
) then
6841 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6843 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6846 // Execute script when game loads:
6847 s
:= Find_Param_Value(pars
, '-exec');
6850 // if not isWadPath(s) then
6851 // s := GameDir + '/' + s;
6856 if IOResult
<> 0 then
6858 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6859 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6863 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6864 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6869 if IOResult
<> 0 then
6871 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6872 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6876 if Pos('#', s
) <> 1 then // script comment
6877 g_Console_Process(s
, True);
6888 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6889 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6890 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6891 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6893 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6894 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6895 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6896 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6898 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6899 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6901 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6902 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6904 {$IFDEF ENABLE_HOLMES}
6905 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6908 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6910 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6911 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6913 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6914 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6916 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6917 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6918 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6919 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
6920 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6921 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6922 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6923 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6924 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');