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
;
134 procedure g_TakeScreenShot(Filename
: string = '');
136 procedure g_FatalError(Text: String);
137 procedure g_SimpleError(Text: String);
138 function g_Game_IsTestMap(): Boolean;
139 procedure g_Game_DeleteTestMap();
140 procedure GameCVars(P
: SSArray
);
141 procedure PlayerSettingsCVars(P
: SSArray
);
142 procedure SystemCommands(P
: SSArray
);
143 procedure GameCommands(P
: SSArray
);
144 procedure GameCheats(P
: SSArray
);
145 procedure DebugCommands(P
: SSArray
);
146 procedure g_Game_Process_Params
;
147 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
148 procedure g_Game_StepLoading(Value
: Integer = -1);
149 procedure g_Game_ClearLoading();
150 procedure g_Game_SetDebugMode();
152 function IsActivePlayer(p
: TPlayer
): Boolean;
153 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
154 procedure SortGameStat(var stat
: TPlayerStatArray
);
156 procedure KeyPress (K
: Word);
157 procedure CharPress (C
: AnsiChar);
159 { procedure SetWinPause(Enable: Boolean); }
164 LOADING_SHOW_STEP
= 100;
165 LOADING_INTERLINE
= 20;
180 MESSAGE_DIKEY
= WM_USER
+ 1;
185 EXIT_ENDLEVELSINGLE
= 4;
186 EXIT_ENDLEVELCUSTOM
= 5;
188 GAME_OPTION_RESERVED
= 1;
189 GAME_OPTION_TEAMDAMAGE
= 2;
190 GAME_OPTION_ALLOWEXIT
= 4;
191 GAME_OPTION_WEAPONSTAY
= 8;
192 GAME_OPTION_MONSTERS
= 16;
193 GAME_OPTION_BOTVSPLAYER
= 32;
194 GAME_OPTION_BOTVSMONSTER
= 64;
195 GAME_OPTION_DMKEYS
= 128;
196 GAME_OPTION_TEAMHITTRACE
= 256;
197 GAME_OPTION_TEAMHITPROJECTILE
= 512;
198 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
199 GAME_OPTION_ALLOWDROPFLAG
= 2048;
200 GAME_OPTION_THROWFLAG
= 4096;
205 STATE_INTERCUSTOM
= 3;
206 STATE_INTERSINGLE
= 4;
212 LMS_RESPAWN_NONE
= 0;
213 LMS_RESPAWN_WARMUP
= 1;
214 LMS_RESPAWN_FINAL
= 2;
231 CONFIG_FILENAME
= 'Doom2DF.cfg';
233 TEST_MAP_NAME
= '$$$_TEST_$$$';
235 STD_PLAYER_MODEL
= 'Doomer';
243 STATFILE_VERSION
= $03;
246 gGameSettings
: TGameSettings
;
247 gPlayer1Settings
: TPlayerSettings
;
248 gPlayer2Settings
: TPlayerSettings
;
250 gPlayerScreenSize
: TDFPoint
;
251 gPlayer1ScreenCoord
: TDFPoint
;
252 gPlayer2ScreenCoord
: TDFPoint
;
253 gPlayer1
: TPlayer
= nil;
254 gPlayer2
: TPlayer
= nil;
255 gPlayerDrawn
: TPlayer
= nil;
257 gLerpFactor
: Single = 1.0;
258 gSwitchGameMode
: Byte = GM_DM
;
259 gHearPoint1
, gHearPoint2
: THearPoint
;
260 gSoundEffectsDF
: Boolean = False;
261 gSoundTriggerTime
: Word = 0;
262 gAnnouncer
: Integer = ANNOUNCE_NONE
;
263 goodsnd
: array[0..3] of TPlayableSound
;
264 killsnd
: array[0..3] of TPlayableSound
;
265 hahasnd
: array[0..2] of TPlayableSound
;
266 sound_get_flag
: array[0..1] of TPlayableSound
;
267 sound_lost_flag
: array[0..1] of TPlayableSound
;
268 sound_ret_flag
: array[0..1] of TPlayableSound
;
269 sound_cap_flag
: array[0..1] of TPlayableSound
;
270 gBodyKillEvent
: Integer = -1;
271 gDefInterTime
: ShortInt = -1;
272 gInterEndTime
: LongWord = 0;
273 gInterTime
: LongWord = 0;
274 gServInterTime
: Byte = 0;
275 gGameStartTime
: LongWord = 0;
276 gTotalMonsters
: Integer = 0;
277 gPauseMain
: Boolean = false;
278 gPauseHolmes
: Boolean = false;
279 gShowTime
: Boolean = False;
280 gShowFPS
: Boolean = False;
281 gShowScore
: Boolean = True;
282 gShowStat
: Boolean = True;
283 gShowPIDs
: Boolean = False;
284 gShowKillMsg
: Boolean = True;
285 gShowLives
: Boolean = True;
286 gShowPing
: Boolean = False;
287 gShowMap
: Boolean = False;
289 gState
: Byte = STATE_NONE
;
291 sWidth
, sHeight
: Word;
292 gSpectMode
: Byte = SPECT_NONE
;
293 gSpectHUD
: Boolean = True;
294 gSpectKeyPress
: Boolean = False;
295 gSpectX
: Integer = 0;
296 gSpectY
: Integer = 0;
297 gSpectStep
: Byte = 8;
298 gSpectViewTwo
: Boolean = False;
299 gSpectPID1
: Integer = -1;
300 gSpectPID2
: Integer = -1;
301 gSpectAuto
: Boolean = False;
302 gSpectAutoNext
: LongWord;
303 gSpectAutoStepX
: Integer;
304 gSpectAutoStepY
: Integer;
305 gMusic
: TMusic
= nil;
306 gLoadGameMode
: Boolean;
307 gCheats
: Boolean = False;
308 gMapOnce
: Boolean = False;
309 gMapToDelete
: String;
310 gTempDelete
: Boolean = False;
311 gLastMap
: Boolean = False;
314 gResolutionChange
: Boolean = False;
315 gRC_Width
, gRC_Height
: Integer;
316 gRC_FullScreen
, gRC_Maximized
: Boolean;
317 gLanguageChange
: Boolean = False;
318 gDebugMode
: Boolean = False;
319 g_debug_Sounds
: Boolean = False;
320 g_debug_Frames
: Boolean = False;
321 g_debug_WinMsgs
: Boolean = False;
322 g_debug_MonsterOff
: Boolean = False;
323 g_debug_BotAIOff
: Byte = 0;
324 g_debug_HealthBar
: Boolean = False;
325 g_Debug_Player
: Boolean = False;
326 gCoopMonstersKilled
: Word = 0;
327 gCoopSecretsFound
: Word = 0;
328 gCoopTotalMonstersKilled
: Word = 0;
329 gCoopTotalSecretsFound
: Word = 0;
330 gCoopTotalMonsters
: Word = 0;
331 gCoopTotalSecrets
: Word = 0;
332 gStatsOff
: Boolean = False;
333 gStatsPressed
: Boolean = False;
334 gExitByTrigger
: Boolean = False;
335 gNextMap
: String = '';
336 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
337 gLMSRespawnTime
: Cardinal = 0;
338 gLMSSoftSpawn
: Boolean = False;
339 gMissionFailed
: Boolean = False;
340 gVoteInProgress
: Boolean = False;
341 gVotePassed
: Boolean = False;
342 gVoteCommand
: string = '';
343 gVoteTimer
: Cardinal = 0;
344 gVoteCmdTimer
: Cardinal = 0;
345 gVoteCount
: Integer = 0;
346 gVoteTimeout
: Cardinal = 30;
347 gVoted
: Boolean = False;
348 gVotesEnabled
: Boolean = True;
349 gEvents
: Array of TGameEvent
;
350 gDelayedEvents
: Array of TDelayedEvent
;
351 gUseChatSounds
: Boolean = True;
352 gChatSounds
: Array of TChatSound
;
353 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
354 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
355 gInterReadyCount
: Integer = 0;
356 gMaxBots
: Integer = 127;
358 g_dbg_ignore_bounds
: Boolean = false;
359 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
360 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
362 // move button values:
363 // bits 0-1: l/r state:
364 // 0: neither left, nor right pressed
367 // bits 4-5: l/r state when strafe was pressed
368 P1MoveButton
: Byte = 0;
369 P2MoveButton
: Byte = 0;
371 g_profile_frame_update
: Boolean = false;
372 g_profile_frame_draw
: Boolean = false;
373 g_profile_collision
: Boolean = false;
374 g_profile_los
: Boolean = false;
375 g_profile_history_size
: Integer = 1000;
377 g_rlayer_back
: Boolean = true;
378 g_rlayer_step
: Boolean = true;
379 g_rlayer_wall
: Boolean = true;
380 g_rlayer_door
: Boolean = true;
381 g_rlayer_acid1
: Boolean = true;
382 g_rlayer_acid2
: Boolean = true;
383 g_rlayer_water
: Boolean = true;
384 g_rlayer_fore
: Boolean = true;
386 wNeedTimeReset
: Boolean = false;
388 procedure g_ResetDynlights ();
389 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
390 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
392 function conIsCheatsEnabled (): Boolean; inline;
393 function gPause (): Boolean; inline;
395 type (* private state *)
396 TEndCustomGameStat
= record
397 PlayerStat
: TPlayerStatArray
;
401 Map
, MapName
: String;
404 TEndSingleGameStat
= record
405 PlayerStat
: Array [0..1] of record
411 TotalSecrets
: Integer;
414 TLoadingStat
= record
418 Msgs
: Array of String;
420 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
424 x
, y
, radius
: Integer;
427 exploRadius
: Integer;
430 var (* private state *)
431 CustomStat
: TEndCustomGameStat
;
432 StatShotDone
: Boolean;
433 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
434 SingleStat
: TEndSingleGameStat
;
435 LoadingStat
: TLoadingStat
;
438 EndingGameCounter
: Byte;
440 g_playerLight
: Boolean;
441 g_dynLights
: array of TDynLight
= nil;
442 g_dynLightCount
: Integer = 0;
443 EndPicPath
: AnsiString; // full path, used by render
448 {$IFDEF ENABLE_HOLMES}
454 e_res
, g_window
, g_menu
,
455 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
456 g_playermodel
, g_gfx
, g_options
, Math
,
457 g_triggers
, g_monsters
, e_sound
, CONFIG
,
458 g_language
, g_net
, g_phys
,
459 ENet
, e_msg
, g_netmsg
, g_netmaster
,
460 sfs
, wadreader
, g_system
, r_playermodel
;
463 charbuff
: packed array [0..15] of AnsiChar = (
464 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
467 function Translit (const S
: AnsiString): AnsiString;
472 for i
:= 1 to Length(Result
) do
475 #
$C9: Result
[i
] := 'Q';
476 #
$D6: Result
[i
] := 'W';
477 #
$D3: Result
[i
] := 'E';
478 #
$CA: Result
[i
] := 'R';
479 #
$C5: Result
[i
] := 'T';
480 #
$CD: Result
[i
] := 'Y';
481 #
$C3: Result
[i
] := 'U';
482 #
$D8: Result
[i
] := 'I';
483 #
$D9: Result
[i
] := 'O';
484 #
$C7: Result
[i
] := 'P';
485 #
$D5: Result
[i
] := '['; //Chr(219);
486 #
$DA: Result
[i
] := ']'; //Chr(221);
487 #
$D4: Result
[i
] := 'A';
488 #
$DB: Result
[i
] := 'S';
489 #
$C2: Result
[i
] := 'D';
490 #
$C0: Result
[i
] := 'F';
491 #
$CF: Result
[i
] := 'G';
492 #
$D0: Result
[i
] := 'H';
493 #
$CE: Result
[i
] := 'J';
494 #
$CB: Result
[i
] := 'K';
495 #
$C4: Result
[i
] := 'L';
496 #
$C6: Result
[i
] := ';'; //Chr(186);
497 #
$DD: Result
[i
] := #39; //Chr(222);
498 #
$DF: Result
[i
] := 'Z';
499 #
$D7: Result
[i
] := 'X';
500 #
$D1: Result
[i
] := 'C';
501 #
$CC: Result
[i
] := 'V';
502 #
$C8: Result
[i
] := 'B';
503 #
$D2: Result
[i
] := 'N';
504 #
$DC: Result
[i
] := 'M';
505 #
$C1: Result
[i
] := ','; //Chr(188);
506 #
$DE: Result
[i
] := '.'; //Chr(190);
512 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
517 ls2
:= Translit(CheatRus
[ct
]);
518 if length(ls1
) = 0 then ls1
:= '~';
519 if length(ls2
) = 0 then ls2
:= '~';
521 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
522 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
523 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
524 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
526 if ct = I_GAME_CHEAT_JETPACK then
528 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
529 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
530 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
531 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
532 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
533 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
549 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
550 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
551 or g_Game_IsNet then Exit;
553 if not gGameOn
then exit
;
554 if not conIsCheatsEnabled
then exit
;
556 s
:= 'SOUND_GAME_RADIO';
559 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
561 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
562 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
566 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
568 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
569 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
573 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
575 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
576 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
580 if CheckCheat(I_GAME_CHEAT_DEATH
) then
582 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
583 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
584 s
:= 'SOUND_MONSTER_HAHA';
588 if CheckCheat(I_GAME_CHEAT_DOORS
) then
590 g_Triggers_OpenAll();
594 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
596 if gTriggers
<> nil then
597 for a
:= 0 to High(gTriggers
) do
598 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
600 gExitByTrigger
:= True;
601 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
602 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
608 s2
:= Copy(charbuff
, 15, 2);
609 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
611 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
619 if CheckCheat(I_GAME_CHEAT_FLY
) then
625 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
627 VEL_JUMP
:= 30-VEL_JUMP
;
631 if CheckCheat(I_GAME_CHEAT_SPEED
) then
633 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
637 if CheckCheat(I_GAME_CHEAT_SUIT
) then
639 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
640 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
644 if CheckCheat(I_GAME_CHEAT_AIR
) then
646 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
647 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
651 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
653 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
654 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
658 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
660 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
661 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
665 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
667 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
668 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
672 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
674 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
675 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
679 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
681 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
682 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
685 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
687 gAimLine
:= not gAimLine
;
690 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
692 gShowMap
:= not gShowMap
;
702 procedure KeyPress (K
: Word);
712 if (g_ActiveWindow
<> nil) then
714 Msg
.Msg
:= WM_KEYDOWN
;
715 Msg
.WParam
:= VK_ESCAPE
;
716 g_ActiveWindow
.OnMessage(Msg
);
717 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
719 else if (gState
<> STATE_FOLD
) then
721 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
723 g_Game_InGameMenu(True);
725 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
727 if (gState
<> STATE_MENU
) then
729 if (NetMode
<> NET_NONE
) then
731 g_Game_StopAllSounds(True);
733 gState
:= STATE_MENU
;
737 g_GUI_ShowWindow('MainMenu');
738 g_Sound_PlayEx('MENU_OPEN');
743 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
744 begin // <F2> .. <F6> � <F12>
745 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
747 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
748 if (not g_Game_IsNet
) then g_Game_Pause(True);
750 IK_F2
: g_Menu_Show_SaveMenu();
751 IK_F3
: g_Menu_Show_LoadMenu();
752 IK_F4
: g_Menu_Show_GameSetGame();
753 IK_F5
: g_Menu_Show_OptionsVideo();
754 IK_F6
: g_Menu_Show_OptionsSound();
755 IK_F7
: g_Menu_Show_EndGameMenu();
756 IK_F10
: g_Menu_Show_QuitGameMenu();
763 gJustChatted
:= False;
764 if gConsoleShow
or gChatShow
then
766 g_Console_Control(K
);
768 else if (g_ActiveWindow
<> nil) then
770 Msg
.Msg
:= WM_KEYDOWN
;
772 g_ActiveWindow
.OnMessage(Msg
);
774 else if (gState
= STATE_MENU
) then
776 g_GUI_ShowWindow('MainMenu');
777 g_Sound_PlayEx('MENU_OPEN');
784 procedure CharPress (C
: AnsiChar);
789 if gConsoleShow
or gChatShow
then
793 else if (g_ActiveWindow
<> nil) then
796 Msg
.WParam
:= Ord(C
);
797 g_ActiveWindow
.OnMessage(Msg
);
801 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
802 charbuff
[15] := upcase1251(C
);
808 // ////////////////////////////////////////////////////////////////////////// //
809 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
811 procedure g_ResetDynlights ();
815 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
817 for idx
:= 0 to g_dynLightCount
-1 do
819 if g_dynLights
[idx
].exploCount
= -666 then
826 Inc(g_dynLights
[idx
].exploCount
);
827 if (g_dynLights
[idx
].exploCount
< 10) then
829 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
830 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
831 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
832 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
837 g_dynLightCount
:= lnum
;
840 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
842 if not gwin_has_stencil
then exit
;
843 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
844 g_dynLights
[g_dynLightCount
].x
:= x
;
845 g_dynLights
[g_dynLightCount
].y
:= y
;
846 g_dynLights
[g_dynLightCount
].radius
:= radius
;
847 g_dynLights
[g_dynLightCount
].r
:= r
;
848 g_dynLights
[g_dynLightCount
].g
:= g
;
849 g_dynLights
[g_dynLightCount
].b
:= b
;
850 g_dynLights
[g_dynLightCount
].a
:= a
;
851 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
852 Inc(g_dynLightCount
);
855 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
857 if not gwin_has_stencil
then exit
;
858 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
859 g_dynLights
[g_dynLightCount
].x
:= x
;
860 g_dynLights
[g_dynLightCount
].y
:= y
;
861 g_dynLights
[g_dynLightCount
].radius
:= 0;
862 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
863 g_dynLights
[g_dynLightCount
].r
:= r
;
864 g_dynLights
[g_dynLightCount
].g
:= g
;
865 g_dynLights
[g_dynLightCount
].b
:= b
;
866 g_dynLights
[g_dynLightCount
].a
:= 0;
867 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
868 Inc(g_dynLightCount
);
871 // ////////////////////////////////////////////////////////////////////////// //
872 function conIsCheatsEnabled (): Boolean; inline;
875 if g_Game_IsNet
then exit
;
876 if not gDebugMode
then
878 //if not gCheats then exit;
879 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
880 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
885 // ////////////////////////////////////////////////////////////////////////// //
887 TParamStrValue
= record
892 TParamStrValues
= Array of TParamStrValue
;
895 INTER_ACTION_TEXT
= 1;
896 INTER_ACTION_PIC
= 2;
897 INTER_ACTION_MUSIC
= 3;
902 DataLoaded
: Boolean = False;
904 MapList
: SSArray
= nil;
905 MapIndex
: Integer = -1;
906 InterReadyTime
: Integer = -1;
907 StatDate
: string = '';
922 function Compare(a
, b
: TPlayerStat
): Integer;
924 if a
.Spectator
then Result
:= 1
925 else if b
.Spectator
then Result
:= -1
926 else if a
.Frags
< b
.Frags
then Result
:= 1
927 else if a
.Frags
> b
.Frags
then Result
:= -1
928 else if a
.Deaths
< b
.Deaths
then Result
:= -1
929 else if a
.Deaths
> b
.Deaths
then Result
:= 1
930 else if a
.Kills
< b
.Kills
then Result
:= -1
934 procedure SortGameStat(var stat
: TPlayerStatArray
);
939 if stat
= nil then Exit
;
941 for I
:= High(stat
) downto Low(stat
) do
942 for J
:= Low(stat
) to High(stat
) - 1 do
943 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
946 stat
[J
] := stat
[J
+ 1];
951 // saves a shitty CSV containing the game stats passed to it
952 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
955 dir
, fname
, map
, mode
, etime
: String;
959 dir
:= e_GetWriteableDir(StatsDirs
);
960 // stats are placed in stats/yy/mm/dd/*.csv
961 fname
:= e_CatPath(dir
, Path
);
962 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
963 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
964 AssignFile(s
, fname
);
966 SetTextCodePage(s
, CP_UTF8
);
968 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
969 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
970 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
971 mode
:= g_Game_ModeToText(Stat
.GameMode
);
972 etime
:= Format('%d:%.2d:%.2d', [
973 Stat
.GameTime
div 1000 div 3600,
974 (Stat
.GameTime
div 1000 div 60) mod 60,
975 Stat
.GameTime
div 1000 mod 60
977 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
978 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
984 gGameSettings
.TimeLimit
,
985 gGameSettings
.ScoreLimit
,
986 gGameSettings
.Options
,
988 Length(Stat
.PlayerStat
)
990 // line 2: game specific shit
991 // if it's a team game: red score, blue score
992 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
994 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
996 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
997 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
999 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1000 // lines 3-...: team, player name, frags, deaths
1001 WriteLn(s
, 'team,name,frags,deaths');
1002 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1003 with Stat
.PlayerStat
[I
] do
1004 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1006 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1009 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1014 procedure ClearDebugCvars();
1016 g_debug_Sounds
:= False;
1017 g_debug_Frames
:= False;
1018 g_debug_WinMsgs
:= False;
1019 g_debug_MonsterOff
:= False;
1020 g_debug_BotAIOff
:= 0;
1021 g_debug_HealthBar
:= False;
1022 g_Debug_Player
:= False;
1025 function g_Game_ModeToText(Mode
: Byte): string;
1029 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1030 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1031 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1032 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1033 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1037 function g_Game_TextToMode(Mode
: string): Byte;
1040 Mode
:= UpperCase(Mode
);
1041 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1046 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1051 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1056 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1061 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1063 Result
:= GM_SINGLE
;
1068 function g_Game_IsNet(): Boolean;
1070 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1073 function g_Game_IsServer(): Boolean;
1075 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1078 function g_Game_IsClient(): Boolean;
1080 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1083 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1090 Result
.name
:= ExtractFileName(WAD
);
1091 Result
.description
:= '';
1092 Result
.author
:= '';
1094 w
:= TWADFile
.Create();
1097 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1103 cfg
:= TConfig
.CreateMem(p
, len
);
1104 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1105 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1106 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1107 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1113 procedure g_Game_FreeWAD
;
1116 g_Sound_Delete('MUSIC_endmus');
1117 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1118 gGameSettings
.WAD
:= '';
1121 procedure g_Game_LoadWAD(WAD
: string);
1130 gGameSettings
.WAD
:= WAD
;
1131 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1134 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1136 w
:= TWADFile
.Create();
1139 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1145 cfg
:= TConfig
.CreateMem(p
, len
);
1148 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1149 if MegaWAD
.endpic
<> '' then
1150 EndPicPath
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1152 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1153 if MegaWAD
.endmus
<> '' then
1155 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1156 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1164 {procedure start_trigger(t: string);
1168 function next_trigger(): Boolean;
1172 procedure DisableCheats();
1178 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1179 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1180 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1181 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1183 {$IF DEFINED(D2F_DEBUG)}
1184 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1185 gAimLine
:= g_dbg_aimline_on
;
1189 procedure g_Game_ExecuteEvent(Name
: String);
1195 if gEvents
= nil then
1197 for a
:= 0 to High(gEvents
) do
1198 if gEvents
[a
].Name
= Name
then
1200 if gEvents
[a
].Command
<> '' then
1201 g_Console_Process(gEvents
[a
].Command
, True);
1206 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1211 if gDelayedEvents
<> nil then
1212 for a
:= 0 to High(gDelayedEvents
) do
1213 if not gDelayedEvents
[a
].Pending
then
1220 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1221 n
:= High(gDelayedEvents
);
1223 gDelayedEvents
[n
].Pending
:= True;
1224 gDelayedEvents
[n
].DEType
:= DEType
;
1225 gDelayedEvents
[n
].DENum
:= Num
;
1226 gDelayedEvents
[n
].DEStr
:= Str
;
1227 if DEType
= DE_GLOBEVENT
then
1228 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1230 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1234 procedure EndGame();
1240 if g_Game_IsNet
and g_Game_IsServer
then
1241 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1244 gPauseMain
:= false;
1245 gPauseHolmes
:= false;
1248 g_Game_StopAllSounds(False);
1253 EndingGameCounter
:= 0;
1254 g_ActiveWindow
:= nil;
1256 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1257 gLMSRespawnTime
:= 0;
1260 EXIT_SIMPLE
: // Выход через меню или конец теста
1265 begin // Это был тест
1269 begin // Выход в главное меню
1270 gMusic
.SetByName('MUSIC_MENU');
1272 if gState
<> STATE_SLIST
then
1274 g_GUI_ShowWindow('MainMenu');
1275 gState
:= STATE_MENU
;
1278 // Обновляем список серверов
1279 slReturnPressed
:= True;
1280 if g_Net_Slist_Fetch(slCurrent
) then
1282 if slCurrent
= nil then
1283 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1286 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1287 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1290 g_Game_ExecuteEvent('ongameend');
1294 EXIT_RESTART
: // Начать уровень сначала
1296 if not g_Game_IsClient
then g_Game_Restart();
1299 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1301 // Статистика Своей игры:
1302 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1304 CustomStat
.GameTime
:= gTime
;
1305 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1306 CustomStat
.MapName
:= gMapInfo
.Name
;
1307 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1308 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1309 CustomStat
.TeamStat
:= gTeamStat
;
1311 CustomStat
.PlayerStat
:= nil;
1313 // Статистика игроков:
1314 if gPlayers
<> nil then
1316 for a
:= 0 to High(gPlayers
) do
1317 if gPlayers
[a
] <> nil then
1319 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1320 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1323 Name
:= gPlayers
[a
].Name
;
1324 Frags
:= gPlayers
[a
].Frags
;
1325 Deaths
:= gPlayers
[a
].Death
;
1326 Kills
:= gPlayers
[a
].Kills
;
1327 Team
:= gPlayers
[a
].Team
;
1328 Color
:= gPlayers
[a
].Model
.Color
;
1329 Spectator
:= gPlayers
[a
].FSpectator
;
1333 SortGameStat(CustomStat
.PlayerStat
);
1335 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1338 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1339 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1340 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1341 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1343 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1346 StatShotDone
:= False;
1349 g_Game_ExecuteEvent('onmapend');
1350 if not g_Game_IsClient
then g_Player_ResetReady
;
1351 gInterReadyCount
:= 0;
1353 // Затухающий экран:
1354 EndingGameCounter
:= 255;
1355 gState
:= STATE_FOLD
;
1357 if gDefInterTime
< 0 then
1358 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1360 gInterEndTime
:= gDefInterTime
* 1000;
1363 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1365 // Статистика Одиночной игры:
1366 SingleStat
.GameTime
:= gTime
;
1367 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1368 SingleStat
.TotalSecrets
:= gSecretsCount
;
1369 // Статистика первого игрока:
1370 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1371 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1372 // Статистика второго игрока (если есть):
1373 if SingleStat
.TwoPlayers
then
1375 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1376 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1379 g_Game_ExecuteEvent('onmapend');
1382 if gNextMap
<> '' then
1384 gMusic
.SetByName('MUSIC_INTERMUS');
1386 gState
:= STATE_INTERSINGLE
;
1389 g_Game_ExecuteEvent('oninter');
1391 else // Больше нет карт
1393 // Затухающий экран:
1394 EndingGameCounter
:= 255;
1395 gState
:= STATE_FOLD
;
1400 // Окончание обработано:
1401 if gExit
<> EXIT_QUIT
then
1405 procedure g_Game_Init();
1409 gTempDelete
:= False;
1411 sfsGCDisable(); // temporary disable removing of temporary volumes
1414 g_Game_ClearLoading();
1415 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1416 g_Game_SetLoadingText('', 0, False);
1418 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1421 gPauseMain
:= false;
1422 gPauseHolmes
:= false;
1425 {e_MouseInfo.Accel := 1.0;}
1427 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1430 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1431 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1432 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1433 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1434 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1436 gMusic
:= TMusic
.Create();
1437 gMusic
.SetByName('MUSIC_MENU');
1440 gGameSettings
.WarmupTime
:= 30;
1442 gState
:= STATE_MENU
;
1444 SetLength(gEvents
, 6);
1445 gEvents
[0].Name
:= 'ongamestart';
1446 gEvents
[1].Name
:= 'ongameend';
1447 gEvents
[2].Name
:= 'onmapstart';
1448 gEvents
[3].Name
:= 'onmapend';
1449 gEvents
[4].Name
:= 'oninter';
1450 gEvents
[5].Name
:= 'onwadend';
1452 sfsGCEnable(); // enable releasing unused volumes
1456 procedure g_Game_Free(freeTextures
: Boolean=true);
1458 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1459 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1461 g_Map_Free(freeTextures
);
1463 g_Player_RemoveAllCorpses();
1465 gGameSettings
.GameType
:= GT_NONE
;
1466 if gGameSettings
.GameMode
= GM_SINGLE
then
1467 gGameSettings
.GameMode
:= GM_DM
;
1468 gSwitchGameMode
:= gGameSettings
.GameMode
;
1471 gExitByTrigger
:= False;
1474 function IsActivePlayer(p
: TPlayer
): Boolean;
1479 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1482 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1488 if gPlayers
= nil then
1492 for a
:= Low(gPlayers
) to High(gPlayers
) do
1493 if IsActivePlayer(gPlayers
[a
]) then
1495 SetLength(ids
, Length(ids
) + 1);
1496 ids
[High(ids
)] := gPlayers
[a
].UID
;
1497 if gPlayers
[a
].UID
= Skip
then
1500 if Length(ids
) = 0 then
1505 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1508 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1514 if gPlayers
= nil then
1518 for a
:= Low(gPlayers
) to High(gPlayers
) do
1519 if IsActivePlayer(gPlayers
[a
]) then
1521 SetLength(ids
, Length(ids
) + 1);
1522 ids
[High(ids
)] := gPlayers
[a
].UID
;
1523 if gPlayers
[a
].UID
= Skip
then
1526 if Length(ids
) = 0 then
1529 Result
:= ids
[Length(ids
) - 1]
1531 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1534 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1540 if gPlayers
= nil then
1544 for a
:= Low(gPlayers
) to High(gPlayers
) do
1545 if IsActivePlayer(gPlayers
[a
]) then
1547 SetLength(ids
, Length(ids
) + 1);
1548 ids
[High(ids
)] := gPlayers
[a
].UID
;
1549 if gPlayers
[a
].UID
= Skip
then
1552 if Length(ids
) = 0 then
1554 if Length(ids
) = 1 then
1559 Result
:= ids
[Random(Length(ids
))];
1561 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1563 Result
:= ids
[Random(Length(ids
))];
1568 function GetRandomSpectMode(Current
: Byte): Byte;
1575 0: Result
:= SPECT_STATS
;
1576 1: Result
:= SPECT_MAPVIEW
;
1577 2: Result
:= SPECT_MAPVIEW
;
1578 3: Result
:= SPECT_PLAYERS
;
1579 4: Result
:= SPECT_PLAYERS
;
1580 5: Result
:= SPECT_PLAYERS
;
1581 6: Result
:= SPECT_PLAYERS
;
1583 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1587 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1593 if (plr
= nil) then exit
;
1594 if (p
= 2) then time
:= 1000 else time
:= 1;
1595 strafeDir
:= MoveButton
shr 4;
1596 MoveButton
:= MoveButton
and $0F;
1598 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1599 MoveButton
:= 1 // Нажата только "Влево"
1600 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1601 MoveButton
:= 2 // Нажата только "Вправо"
1602 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1603 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1605 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1606 if MoveButton
= 1 then
1607 plr
.PressKey(KEY_LEFT
, time
)
1608 else if MoveButton
= 2 then
1609 plr
.PressKey(KEY_RIGHT
, time
);
1611 // if we have "strafe" key, turn off old strafe mechanics
1612 if gPlayerAction
[p
, ACTION_STRAFE
] then
1614 // new strafe mechanics
1615 if (strafeDir
= 0) then
1616 strafeDir
:= MoveButton
; // start strafing
1617 // now set direction according to strafe (reversed)
1618 if (strafeDir
= 2) then
1619 plr
.SetDirection(TDirection
.D_LEFT
)
1620 else if (strafeDir
= 1) then
1621 plr
.SetDirection(TDirection
.D_RIGHT
)
1625 strafeDir
:= 0; // not strafing anymore
1626 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1627 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1628 plr
.SetDirection(TDirection
.D_LEFT
)
1629 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1630 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1631 plr
.SetDirection(TDirection
.D_RIGHT
)
1632 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1633 else if MoveButton
<> 0 then
1634 plr
.SetDirection(TDirection(MoveButton
-1))
1637 // fix movebutton state
1638 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1640 // Остальные клавиши:
1641 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1642 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1643 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1644 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1645 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1647 for i
:= WP_FACT
to WP_LACT
do
1649 if gWeaponAction
[p
, i
] then
1651 plr
.ProcessWeaponAction(i
);
1652 gWeaponAction
[p
, i
] := False
1656 for i
:= WP_FIRST
to WP_LAST
do
1658 if gSelectWeapon
[p
, i
] then
1660 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1661 gSelectWeapon
[p
, i
] := False
1665 // HACK: add dynlight here
1666 if gwin_k8_enable_light_experiments
then
1668 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1670 g_playerLight
:= true;
1672 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1674 g_playerLight
:= false;
1678 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1681 // HACK: don't have a "key was pressed" function
1682 procedure InterReady();
1684 if InterReadyTime
> gTime
then Exit
;
1685 InterReadyTime
:= gTime
+ 3000;
1686 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1689 procedure g_Game_PreUpdate();
1691 // these are in separate PreUpdate functions because they can interact during Update()
1692 // and are synced over the net
1693 // we don't care that much about corpses and gibs
1694 g_Player_PreUpdate();
1695 g_Monsters_PreUpdate();
1696 g_Items_PreUpdate();
1697 g_Weapon_PreUpdate();
1700 procedure g_Game_Update();
1702 Msg
: g_gui
.TMessage
;
1708 function sendMonsPos (mon
: TMonster
): Boolean;
1710 result
:= false; // don't stop
1711 // this will also reset "need-send" flag
1712 if mon
.gncNeedSend
then
1714 MH_SEND_MonsterPos(mon
.UID
);
1716 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1718 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1720 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1722 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1726 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1728 result
:= false; // don't stop
1729 // this will also reset "need-send" flag
1730 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1733 function sendItemPos (it
: PItem
): Boolean;
1735 result
:= false; // don't stop
1738 MH_SEND_ItemPos(it
.myId
);
1739 it
.needSend
:= False;
1744 reliableUpdate
: Boolean;
1749 // Пора выключать игру:
1750 if gExit
= EXIT_QUIT
then
1752 // Игра закончилась - обрабатываем:
1756 if gExit
= EXIT_QUIT
then
1760 // Читаем клавиатуру и джойстик, если окно активно
1761 // no need to, as we'll do it in event handler
1763 // Обновляем консоль (движение и сообщения):
1766 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1768 gExit
:= EXIT_SIMPLE
;
1773 // process master server communications
1774 g_Net_Slist_Pulse();
1777 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1778 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1779 STATE_INTERTEXT
, // Текст между уровнями
1780 STATE_INTERPIC
: // Картинка между уровнями
1782 if g_Game_IsNet
and g_Game_IsServer
then
1784 gInterTime
:= gInterTime
+ GAME_TICK
;
1785 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1786 if a
<> gServInterTime
then
1788 gServInterTime
:= a
;
1789 MH_SEND_TimeSync(gServInterTime
);
1793 if (not g_Game_IsClient
) and
1797 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1798 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1799 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1800 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1802 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1803 and (g_ActiveWindow
= nil)
1805 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1808 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1809 g_Game_StopAllSounds(True);
1811 if gMapOnce
then // Это был тест
1812 gExit
:= EXIT_SIMPLE
1814 if gNextMap
<> '' then // Переходим на следующую карту
1815 g_Game_ChangeMap(gNextMap
)
1816 else // Следующей карты нет
1818 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1820 // Выход в главное меню:
1822 g_GUI_ShowWindow('MainMenu');
1823 gMusic
.SetByName('MUSIC_MENU');
1825 gState
:= STATE_MENU
;
1828 // Финальная картинка:
1829 g_Game_ExecuteEvent('onwadend');
1831 if not gMusic
.SetByName('MUSIC_endmus') then
1832 gMusic
.SetByName('MUSIC_STDENDMUS');
1834 gState
:= STATE_ENDPIC
;
1836 g_Game_ExecuteEvent('ongameend');
1841 else if g_Game_IsClient
and
1844 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1845 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1846 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1847 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1849 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1850 and (g_ActiveWindow
= nil)
1858 if gState
= STATE_INTERTEXT
then
1859 if InterText
.counter
> 0 then
1860 InterText
.counter
:= InterText
.counter
- 1;
1863 STATE_FOLD
: // Затухание экрана
1865 if EndingGameCounter
= 0 then
1867 // Закончился уровень в Своей игре:
1868 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1870 gState
:= STATE_INTERCUSTOM
;
1871 InterReadyTime
:= -1;
1872 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1874 g_Game_ExecuteEvent('onwadend');
1875 if not gMusic
.SetByName('MUSIC_endmus') then
1876 gMusic
.SetByName('MUSIC_STDENDMUS');
1879 gMusic
.SetByName('MUSIC_ROUNDMUS');
1883 else // Закончилась последняя карта в Одиночной игре
1885 gMusic
.SetByName('MUSIC_INTERMUS');
1887 gState
:= STATE_INTERSINGLE
;
1890 g_Game_ExecuteEvent('oninter');
1893 DecMin(EndingGameCounter
, 6, 0);
1896 STATE_ENDPIC
: // Картинка окончания мегаВада
1898 if gMapOnce
then // Это был тест
1900 gExit
:= EXIT_SIMPLE
;
1906 g_Serverlist_Control(slCurrent
, slTable
);
1909 // Статистика по Tab:
1911 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1914 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1916 // Время += 28 миллисекунд:
1917 gTime
:= gTime
+ GAME_TICK
;
1919 // Сообщение посередине экрана:
1920 if MessageTime
= 0 then
1922 if MessageTime
> 0 then
1923 MessageTime
:= MessageTime
- 1;
1925 if (g_Game_IsServer
) then
1927 // Был задан лимит времени:
1928 if (gGameSettings
.TimeLimit
> 0) then
1929 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1930 begin // Он прошел => конец уровня
1935 // Надо респавнить игроков в LMS:
1936 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1937 g_Game_RestartRound(gLMSSoftSpawn
);
1939 // Проверим результат голосования, если время прошло
1940 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1942 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1944 g_Console_Process(gVoteCommand
);
1946 gVotePassed
:= False;
1949 // Замеряем время захвата флагов
1950 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1951 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1952 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1953 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1955 // Был задан лимит побед:
1956 if (gGameSettings
.ScoreLimit
> 0) then
1960 if gGameSettings
.GameMode
= GM_DM
then
1961 begin // В DM ищем игрока с max фрагами
1962 for i
:= 0 to High(gPlayers
) do
1963 if gPlayers
[i
] <> nil then
1964 if gPlayers
[i
].Frags
> b
then
1965 b
:= gPlayers
[i
].Frags
;
1968 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1969 begin // В CTF/TDM выбираем команду с наибольшим счетом
1970 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
1973 // Лимит побед набран => конец уровня:
1974 if b
>= gGameSettings
.ScoreLimit
then
1981 // Обрабатываем клавиши игроков:
1982 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1983 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1984 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1986 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1987 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1988 end // if not console
1991 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1993 // process weapon switch queue
1997 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1998 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2000 if not gSpectKeyPress
then
2002 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2004 // switch spect mode
2006 SPECT_NONE
: ; // not spectator
2008 SPECT_MAPVIEW
: Inc(gSpectMode
);
2009 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2011 gSpectKeyPress
:= True;
2013 if (gSpectMode
= SPECT_MAPVIEW
)
2014 and (not gSpectAuto
) then
2016 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2017 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2018 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2019 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2020 if gPlayerAction
[0, ACTION_LOOKUP
] then
2021 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2022 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2023 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2024 if gWeaponAction
[0, WP_PREV
] then
2027 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2028 gWeaponAction
[0, WP_PREV
] := False;
2030 if gWeaponAction
[0, WP_NEXT
] then
2033 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2034 gWeaponAction
[0, WP_NEXT
] := False;
2037 if (gSpectMode
= SPECT_PLAYERS
)
2038 and (not gSpectAuto
) then
2040 if gPlayerAction
[0, ACTION_LOOKUP
] then
2043 gSpectViewTwo
:= True;
2044 gSpectKeyPress
:= True;
2046 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2048 // remove second view
2049 gSpectViewTwo
:= False;
2050 gSpectKeyPress
:= True;
2052 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2054 // prev player (view 1)
2055 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2056 gSpectKeyPress
:= True;
2058 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2060 // next player (view 1)
2061 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2062 gSpectKeyPress
:= True;
2064 if gWeaponAction
[0, WP_PREV
] then
2066 // prev player (view 2)
2067 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2068 gWeaponAction
[0, WP_PREV
] := False;
2070 if gWeaponAction
[0, WP_NEXT
] then
2072 // next player (view 2)
2073 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2074 gWeaponAction
[0, WP_NEXT
] := False;
2077 if gPlayerAction
[0, ACTION_ATTACK
] then
2079 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2082 gSpectAutoNext
:= 0;
2083 gSpectViewTwo
:= False;
2084 gSpectKeyPress
:= True;
2089 gSpectMode
:= SPECT_STATS
;
2090 gSpectAuto
:= False;
2091 gSpectKeyPress
:= True;
2096 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2097 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2098 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2099 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2100 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2101 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2102 gSpectKeyPress
:= False;
2106 if gSpectMode
= SPECT_MAPVIEW
then
2108 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2110 gSpectAutoNext
:= gTime
2113 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2115 gSpectAutoNext
:= gTime
2119 if gSpectAutoNext
<= gTime
then
2121 if gSpectAutoNext
> 0 then
2123 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2127 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2128 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2129 gSpectAutoStepX
:= Random(9) - 4;
2130 gSpectAutoStepY
:= Random(9) - 4;
2131 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2132 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2133 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2134 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2135 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2136 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2140 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2145 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2146 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2147 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2153 // Обновляем все остальное:
2156 g_Triggers_Update();
2158 g_Monsters_Update();
2160 g_Player_UpdateAll();
2161 g_Player_UpdatePhysicalObjects();
2163 // server: send newly spawned monsters unconditionally
2164 if (gGameSettings
.GameType
= GT_SERVER
) then
2166 if (Length(gMonstersSpawned
) > 0) then
2168 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2169 SetLength(gMonstersSpawned
, 0);
2173 if (gSoundTriggerTime
> 8) then
2175 g_Game_UpdateTriggerSounds();
2176 gSoundTriggerTime
:= 0;
2180 Inc(gSoundTriggerTime
);
2183 if (NetMode
= NET_SERVER
) then
2185 Inc(NetTimeToUpdate
);
2186 Inc(NetTimeToReliable
);
2188 // send monster updates
2189 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2191 // send all monsters (periodic sync)
2192 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2194 for I
:= 0 to High(gPlayers
) do
2196 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2199 g_Mons_ForEach(sendMonsPos
);
2201 // update flags that aren't stationary
2202 if gGameSettings
.GameMode
= GM_CTF
then
2203 for I
:= FLAG_RED
to FLAG_BLUE
do
2204 if gFlags
[I
].NeedSend
then
2206 gFlags
[I
].NeedSend
:= False;
2210 // update items that aren't stationary
2211 g_Items_ForEachAlive(sendItemPos
);
2213 if reliableUpdate
then
2215 NetTimeToReliable
:= 0;
2216 NetTimeToUpdate
:= NetUpdateRate
;
2220 NetTimeToUpdate
:= 0;
2225 // send only mosters with some unexpected changes
2226 g_Mons_ForEach(sendMonsPosUnexpected
);
2229 // send unexpected platform changes
2230 g_Map_NetSendInterestingPanels();
2232 g_Net_Slist_ServerUpdate();
2234 if NetUseMaster then
2236 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2238 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2240 NetTimeToMaster := gTime + NetMasterRate;
2245 else if (NetMode
= NET_CLIENT
) then
2247 MC_SEND_PlayerPos();
2249 end; // if gameOn ...
2251 // Активно окно интерфейса - передаем клавиши ему:
2252 if g_ActiveWindow
<> nil then
2254 w
:= e_GetFirstKeyPressed();
2256 if (w
<> IK_INVALID
) then
2258 Msg
.Msg
:= MESSAGE_DIKEY
;
2260 g_ActiveWindow
.OnMessage(Msg
);
2263 // Если оно от этого не закрылось, то обновляем:
2264 if g_ActiveWindow
<> nil then
2265 g_ActiveWindow
.Update();
2267 // Нужно сменить разрешение:
2268 if gResolutionChange
then
2271 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2274 gResolutionChange
:= False;
2275 g_ActiveWindow
:= nil;
2278 // Нужно сменить язык:
2279 if gLanguageChange
then
2281 //e_WriteLog('Read language file', MSG_NOTIFY);
2282 //g_Language_Load(DataDir + gLanguage + '.txt');
2283 g_Language_Set(gLanguage
);
2287 gLanguageChange
:= False;
2291 // Горячая клавиша для вызова меню выхода из игры (F10):
2292 if e_KeyPressed(IK_F10
) and
2294 (not gConsoleShow
) and
2295 (g_ActiveWindow
= nil) then
2300 Time
:= GetTickCount64() {div 1000};
2302 // Обработка отложенных событий:
2303 if gDelayedEvents
<> nil then
2304 for a
:= 0 to High(gDelayedEvents
) do
2305 if gDelayedEvents
[a
].Pending
and
2307 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2308 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2311 case gDelayedEvents
[a
].DEType
of
2313 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2316 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2320 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2321 if g_Game_IsNet
and g_Game_IsServer
then
2322 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2326 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2328 gDelayedEvents
[a
].Pending
:= False;
2331 // Каждую секунду обновляем счетчик обновлений:
2332 UPSCounter
:= UPSCounter
+ 1;
2333 if Time
- UPSTime
>= 1000 then
2342 g_Weapon_AddDynLights();
2343 g_Items_AddDynLights();
2347 procedure g_Game_LoadChatSounds(Resource
: string);
2350 FileName
, Snd
: string;
2352 len
, cnt
, tags
, i
, j
: Integer;
2355 FileName
:= g_ExtractWadName(Resource
);
2357 WAD
:= TWADFile
.Create();
2358 WAD
.ReadFile(FileName
);
2360 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2367 cfg
:= TConfig
.CreateMem(p
, len
);
2368 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2370 SetLength(gChatSounds
, cnt
);
2371 for i
:= 0 to Length(gChatSounds
) - 1 do
2373 gChatSounds
[i
].Sound
:= nil;
2374 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2375 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2376 if (Snd
= '') or (Tags
<= 0) then
2378 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2379 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2380 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2381 SetLength(gChatSounds
[i
].Tags
, tags
);
2382 for j
:= 0 to tags
- 1 do
2383 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2384 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2391 procedure g_Game_FreeChatSounds();
2395 for i
:= 0 to Length(gChatSounds
) - 1 do
2397 gChatSounds
[i
].Sound
.Free();
2398 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2400 SetLength(gChatSounds
, 0);
2404 procedure g_Game_LoadData();
2406 if DataLoaded
then Exit
;
2408 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2410 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2411 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2412 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2413 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2414 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2415 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2416 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2417 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2418 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2419 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2420 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2421 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2422 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2423 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2424 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2425 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2426 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2427 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2428 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2429 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2430 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2431 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2432 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2433 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2434 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2435 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2436 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2437 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2438 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2439 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2440 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2441 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2443 goodsnd
[0] := TPlayableSound
.Create();
2444 goodsnd
[1] := TPlayableSound
.Create();
2445 goodsnd
[2] := TPlayableSound
.Create();
2446 goodsnd
[3] := TPlayableSound
.Create();
2448 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2449 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2450 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2451 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2453 killsnd
[0] := TPlayableSound
.Create();
2454 killsnd
[1] := TPlayableSound
.Create();
2455 killsnd
[2] := TPlayableSound
.Create();
2456 killsnd
[3] := TPlayableSound
.Create();
2458 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2459 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2460 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2461 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2463 hahasnd
[0] := TPlayableSound
.Create();
2464 hahasnd
[1] := TPlayableSound
.Create();
2465 hahasnd
[2] := TPlayableSound
.Create();
2467 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2468 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2469 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2471 sound_get_flag
[0] := TPlayableSound
.Create();
2472 sound_get_flag
[1] := TPlayableSound
.Create();
2473 sound_lost_flag
[0] := TPlayableSound
.Create();
2474 sound_lost_flag
[1] := TPlayableSound
.Create();
2475 sound_ret_flag
[0] := TPlayableSound
.Create();
2476 sound_ret_flag
[1] := TPlayableSound
.Create();
2477 sound_cap_flag
[0] := TPlayableSound
.Create();
2478 sound_cap_flag
[1] := TPlayableSound
.Create();
2480 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2481 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2482 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2483 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2484 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2485 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2486 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2487 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2489 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2491 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2494 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2495 g_Weapon_LoadData();
2497 g_Monsters_LoadData();
2502 procedure g_Game_Quit();
2504 g_Game_StopAllSounds(True);
2507 g_PlayerModel_FreeData();
2509 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2512 if NetInitDone
then g_Net_Free
;
2514 // remove map after test
2515 if gMapToDelete
<> '' then
2516 g_Game_DeleteTestMap();
2522 procedure g_Game_FreeData();
2524 if not DataLoaded
then Exit
;
2527 g_Weapon_FreeData();
2528 g_Monsters_FreeData();
2530 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2532 g_Sound_Delete('SOUND_GAME_TELEPORT');
2533 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2534 g_Sound_Delete('SOUND_GAME_SECRET');
2535 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2536 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2537 g_Sound_Delete('SOUND_GAME_BULK1');
2538 g_Sound_Delete('SOUND_GAME_BULK2');
2539 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2540 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2541 g_Sound_Delete('SOUND_GAME_BURNING');
2542 g_Sound_Delete('SOUND_GAME_SWITCH1');
2543 g_Sound_Delete('SOUND_GAME_SWITCH0');
2550 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2551 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2552 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2553 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2560 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2561 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2562 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2563 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2569 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2570 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2571 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2573 sound_get_flag
[0].Free();
2574 sound_get_flag
[1].Free();
2575 sound_lost_flag
[0].Free();
2576 sound_lost_flag
[1].Free();
2577 sound_ret_flag
[0].Free();
2578 sound_ret_flag
[1].Free();
2579 sound_cap_flag
[0].Free();
2580 sound_cap_flag
[1].Free();
2582 g_Sound_Delete('SOUND_CTF_GET1');
2583 g_Sound_Delete('SOUND_CTF_GET2');
2584 g_Sound_Delete('SOUND_CTF_LOST1');
2585 g_Sound_Delete('SOUND_CTF_LOST2');
2586 g_Sound_Delete('SOUND_CTF_RETURN1');
2587 g_Sound_Delete('SOUND_CTF_RETURN2');
2588 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2589 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2591 g_Game_FreeChatSounds();
2593 DataLoaded
:= False;
2596 procedure g_FatalError(Text: String);
2598 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2599 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2601 gExit
:= EXIT_SIMPLE
;
2602 if gGameOn
then EndGame
;
2605 procedure g_SimpleError(Text: String);
2607 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2608 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2611 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2613 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2614 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2617 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2620 if gPlayer1
= nil then
2622 if g_Game_IsClient
then
2624 if NetPlrUID1
> -1 then
2625 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2629 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2630 Team
:= gPlayer1Settings
.Team
;
2632 // Создание первого игрока:
2633 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2634 gPlayer1Settings
.Color
,
2636 if gPlayer1
= nil then
2637 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2640 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2641 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2642 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2643 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2644 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2645 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2646 if g_Game_IsServer
and g_Game_IsNet
then
2647 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2648 gPlayer1
.Respawn(False, True);
2649 g_Net_Slist_ServerPlayerComes();
2654 if gPlayer2
= nil then
2656 if g_Game_IsClient
then
2658 if NetPlrUID2
> -1 then
2659 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2663 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2664 Team
:= gPlayer2Settings
.Team
;
2666 // Создание второго игрока:
2667 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2668 gPlayer2Settings
.Color
,
2670 if gPlayer2
= nil then
2671 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2674 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2675 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2676 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2677 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2678 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2679 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2680 if g_Game_IsServer
and g_Game_IsNet
then
2681 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2682 gPlayer2
.Respawn(False, True);
2683 g_Net_Slist_ServerPlayerComes();
2690 procedure g_Game_RemovePlayer();
2694 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2695 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2700 if g_Game_IsServer
then
2703 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2704 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2705 g_Player_Remove(Pl
.UID
);
2706 g_Net_Slist_ServerPlayerLeaves();
2710 gSpectLatchPID2
:= Pl
.UID
;
2718 if g_Game_IsServer
then
2721 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2722 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2723 g_Player_Remove(Pl
.UID
);
2724 g_Net_Slist_ServerPlayerLeaves();
2727 gSpectLatchPID1
:= Pl
.UID
;
2729 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2733 g_Net_Slist_ServerPlayerLeaves();
2736 procedure g_Game_Spectate();
2738 g_Game_RemovePlayer();
2739 if gPlayer1
<> nil then
2740 g_Game_RemovePlayer();
2743 procedure g_Game_SpectateCenterView();
2745 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2746 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2749 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2756 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2758 g_Game_ClearLoading();
2761 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2764 gGameSettings
.GameType
:= GT_SINGLE
;
2765 gGameSettings
.MaxLives
:= 0;
2766 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2767 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2768 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2769 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2770 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2771 gSwitchGameMode
:= GM_SINGLE
;
2773 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2774 gLMSRespawnTime
:= 0;
2775 gSpectLatchPID1
:= 0;
2776 gSpectLatchPID2
:= 0;
2778 g_Game_ExecuteEvent('ongamestart');
2780 // Создание первого игрока:
2781 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2782 gPlayer1Settings
.Color
,
2783 gPlayer1Settings
.Team
, False));
2784 if gPlayer1
= nil then
2786 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2790 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2791 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2792 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2793 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2794 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2797 // Создание второго игрока, если есть:
2800 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2801 gPlayer2Settings
.Color
,
2802 gPlayer2Settings
.Team
, False));
2803 if gPlayer2
= nil then
2805 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2809 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2810 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2811 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2812 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2813 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2817 // Загрузка и запуск карты:
2818 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2820 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2821 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2825 // Настройки игроков и ботов:
2829 for i
:= nPl
+1 to nPlayers
do
2830 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2833 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2834 TimeLimit
, ScoreLimit
: Word;
2836 Options
: LongWord; nPlayers
: Byte);
2842 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2844 g_Game_ClearLoading();
2847 gGameSettings
.GameType
:= GT_CUSTOM
;
2848 gGameSettings
.GameMode
:= GameMode
;
2849 gSwitchGameMode
:= GameMode
;
2850 gGameSettings
.TimeLimit
:= TimeLimit
;
2851 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2852 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2853 gGameSettings
.Options
:= Options
;
2855 gCoopTotalMonstersKilled
:= 0;
2856 gCoopTotalSecretsFound
:= 0;
2857 gCoopTotalMonsters
:= 0;
2858 gCoopTotalSecrets
:= 0;
2862 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2863 gLMSRespawnTime
:= 0;
2864 gSpectLatchPID1
:= 0;
2865 gSpectLatchPID2
:= 0;
2867 g_Game_ExecuteEvent('ongamestart');
2869 // Режим наблюдателя:
2870 if nPlayers
= 0 then
2877 if nPlayers
>= 1 then
2879 // Создание первого игрока:
2880 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2881 gPlayer1Settings
.Color
,
2882 gPlayer1Settings
.Team
, False));
2883 if gPlayer1
= nil then
2885 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2889 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2890 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2891 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2892 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2893 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2897 if nPlayers
>= 2 then
2899 // Создание второго игрока:
2900 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2901 gPlayer2Settings
.Color
,
2902 gPlayer2Settings
.Team
, False));
2903 if gPlayer2
= nil then
2905 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2909 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2910 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2911 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2912 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2913 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2917 // Загрузка и запуск карты:
2918 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
2920 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2924 // Нет точек появления:
2925 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2926 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2927 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2928 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2929 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2931 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2935 // Настройки игроков и ботов:
2939 for i
:= nPl
+1 to nPlayers
do
2940 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2943 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
2944 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
2945 Options
: LongWord; nPlayers
: Byte;
2946 IPAddr
: LongWord; Port
: Word);
2949 g_Net_Slist_ServerClosed();
2951 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
2953 g_Game_ClearLoading();
2958 gGameSettings
.GameType
:= GT_SERVER
;
2959 gGameSettings
.GameMode
:= GameMode
;
2960 gSwitchGameMode
:= GameMode
;
2961 gGameSettings
.TimeLimit
:= TimeLimit
;
2962 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2963 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2964 gGameSettings
.Options
:= Options
;
2966 gCoopTotalMonstersKilled
:= 0;
2967 gCoopTotalSecretsFound
:= 0;
2968 gCoopTotalMonsters
:= 0;
2969 gCoopTotalSecrets
:= 0;
2973 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2974 gLMSRespawnTime
:= 0;
2975 gSpectLatchPID1
:= 0;
2976 gSpectLatchPID2
:= 0;
2978 g_Game_ExecuteEvent('ongamestart');
2980 // Режим наблюдателя:
2981 if nPlayers
= 0 then
2987 if nPlayers
>= 1 then
2989 // Создание первого игрока:
2990 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2991 gPlayer1Settings
.Color
,
2992 gPlayer1Settings
.Team
, False));
2993 if gPlayer1
= nil then
2995 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2999 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3000 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3001 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3002 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3003 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3006 if nPlayers
>= 2 then
3008 // Создание второго игрока:
3009 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3010 gPlayer2Settings
.Color
,
3011 gPlayer2Settings
.Team
, False));
3012 if gPlayer2
= nil then
3014 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3018 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3019 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3020 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3021 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3022 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3025 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3026 if NetForwardPorts
then
3027 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3030 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3032 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3036 g_Net_Slist_Set(NetMasterList
);
3038 g_Net_Slist_ServerStarted();
3040 // Загрузка и запуск карты:
3041 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3043 g_Net_Slist_ServerClosed();
3044 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3048 // Нет точек появления:
3049 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3050 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3051 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3052 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3053 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3055 g_Net_Slist_ServerClosed();
3056 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3060 // Настройки игроков и ботов:
3063 g_Net_Slist_ServerMapStarted();
3064 NetState
:= NET_STATE_GAME
;
3067 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3082 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3083 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3085 g_Game_ClearLoading();
3090 gGameSettings
.GameType
:= GT_CLIENT
;
3092 gCoopTotalMonstersKilled
:= 0;
3093 gCoopTotalSecretsFound
:= 0;
3094 gCoopTotalMonsters
:= 0;
3095 gCoopTotalSecrets
:= 0;
3099 g_Game_ExecuteEvent('ongamestart');
3101 NetState
:= NET_STATE_AUTH
;
3103 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3105 // create (or update) map/resource databases
3106 g_Res_CreateDatabases(true);
3108 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3109 gLMSRespawnTime
:= 0;
3110 gSpectLatchPID1
:= 0;
3111 gSpectLatchPID2
:= 0;
3114 if not g_Net_Connect(Addr
, Port
) then
3116 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3117 NetState
:= NET_STATE_NONE
;
3121 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3123 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3128 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3129 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3130 // thank you, enet. let's ignore failures altogether then.
3131 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3133 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3135 Ptr
:= NetEvent
.packet
^.data
;
3136 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3138 enet_packet_destroy(NetEvent
.packet
);
3142 InMsg
.ReadLongWord(); // skip size
3143 MID
:= InMsg
.ReadByte();
3145 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3147 NetMyID
:= InMsg
.ReadByte();
3148 NetPlrUID1
:= InMsg
.ReadWord();
3150 WadName
:= InMsg
.ReadString();
3151 Map
:= InMsg
.ReadString();
3153 gWADHash
:= InMsg
.ReadMD5();
3155 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3156 gSwitchGameMode
:= gGameSettings
.GameMode
;
3157 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3158 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3159 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3160 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3161 T
:= InMsg
.ReadLongWord();
3163 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3164 //if newResPath = '' then
3166 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3167 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3168 if newResPath
= '' then
3170 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3171 enet_packet_destroy(NetEvent
.packet
);
3172 NetState
:= NET_STATE_NONE
;
3175 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3177 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3180 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3181 gPlayer1Settings
.Color
,
3182 gPlayer1Settings
.Team
, False));
3184 if gPlayer1
= nil then
3186 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3188 enet_packet_destroy(NetEvent
.packet
);
3189 NetState
:= NET_STATE_NONE
;
3193 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3194 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3195 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3196 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3197 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3198 gPlayer1
.UID
:= NetPlrUID1
;
3199 gPlayer1
.Reset(True);
3201 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3203 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3205 enet_packet_destroy(NetEvent
.packet
);
3206 NetState
:= NET_STATE_NONE
;
3214 enet_packet_destroy(NetEvent
.packet
);
3218 enet_packet_destroy(NetEvent
.packet
);
3222 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3225 if (NetEvent
.data
<= NET_DISC_MAX
) then
3226 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3227 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3234 ProcessLoading(True);
3235 if g_Net_UserRequestExit() then
3244 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3245 NetState
:= NET_STATE_NONE
;
3250 NetState
:= NET_STATE_GAME
;
3251 MC_SEND_FullStateRequest
;
3252 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3256 lastAsMegaWad
: Boolean = false;
3258 procedure g_Game_ChangeMap(const MapPath
: String);
3262 g_Game_ClearLoading();
3264 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3265 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3266 if gExitByTrigger
then
3269 gExitByTrigger
:= False;
3271 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3272 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3275 procedure g_Game_Restart();
3279 if g_Game_IsClient
then
3281 map
:= g_ExtractFileName(gMapInfo
.Map
);
3282 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3286 g_Game_ClearLoading();
3287 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3290 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3292 NewWAD
, ResName
: String;
3296 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3297 g_Player_RemoveAllCorpses();
3299 if (not g_Game_IsClient
) and
3300 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3301 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3303 if gSwitchGameMode
= GM_CTF
then
3304 gGameSettings
.MaxLives
:= 0;
3305 gGameSettings
.GameMode
:= gSwitchGameMode
;
3308 gSwitchGameMode
:= gGameSettings
.GameMode
;
3310 g_Player_ResetTeams();
3312 lastAsMegaWad
:= asMegawad
;
3313 if isWadPath(Map
) then
3315 NewWAD
:= g_ExtractWadName(Map
);
3316 ResName
:= g_ExtractFileName(Map
);
3317 if g_Game_IsServer
then
3319 nws
:= findDiskWad(NewWAD
);
3320 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3323 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3324 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3328 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3329 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3331 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3332 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3334 if (length(nws
) = 0) then
3336 ResName
:= ''; // failed
3341 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3342 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3343 g_Game_LoadWAD(NewWAD
);
3348 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3349 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3354 NewWAD
:= gGameSettings
.WAD
;
3360 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3362 if (ResName
<> '') and (NewWAD
<> '') then
3364 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3365 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3367 r_Render_LoadTextures
;
3372 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3374 gState
:= STATE_NONE
;
3375 g_ActiveWindow
:= nil;
3379 wNeedTimeReset
:= True;
3381 if gGameSettings
.GameMode
= GM_CTF
then
3383 g_Map_ResetFlag(FLAG_RED
);
3384 g_Map_ResetFlag(FLAG_BLUE
);
3385 // CTF, а флагов нет:
3386 if not g_Map_HaveFlagPoints() then
3387 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3392 gState
:= STATE_MENU
;
3397 gPauseMain
:= false;
3398 gPauseHolmes
:= false;
3399 NetTimeToUpdate
:= 1;
3400 NetTimeToReliable
:= 0;
3401 NetTimeToMaster
:= NetMasterRate
;
3402 gSpectLatchPID1
:= 0;
3403 gSpectLatchPID2
:= 0;
3404 gMissionFailed
:= False;
3407 gCoopMonstersKilled
:= 0;
3408 gCoopSecretsFound
:= 0;
3410 gVoteInProgress
:= False;
3411 gVotePassed
:= False;
3417 if not gGameOn
then Exit
;
3419 g_Game_SpectateCenterView();
3421 if g_Game_IsServer
then
3423 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3425 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3426 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3427 gLMSSoftSpawn
:= True;
3428 if g_Game_IsNet
then
3429 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3433 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3434 gLMSRespawnTime
:= 0;
3438 if NetMode
= NET_SERVER
then
3440 // reset full state flags
3441 if NetClients
<> nil then
3442 for I
:= 0 to High(NetClients
) do
3443 NetClients
[I
].FullUpdateSent
:= False;
3445 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3448 g_Net_Slist_ServerMapStarted();
3450 if NetClients
<> nil then
3451 for I
:= 0 to High(NetClients
) do
3452 if NetClients
[I
].Used
then
3454 NetClients
[I
].Voted
:= False;
3455 if NetClients
[I
].RequestedFullUpdate
then
3457 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3458 NetClients
[I
].RequestedFullUpdate
:= False;
3462 g_Net_UnbanNonPermHosts();
3467 gCoopTotalMonstersKilled
:= 0;
3468 gCoopTotalSecretsFound
:= 0;
3469 gCoopTotalMonsters
:= 0;
3470 gCoopTotalSecrets
:= 0;
3474 g_Game_ExecuteEvent('onmapstart');
3477 procedure SetFirstLevel
;
3481 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3482 if MapList
= nil then
3485 SortSArray(MapList
);
3486 gNextMap
:= MapList
[Low(MapList
)];
3491 procedure g_Game_ExitLevel(const Map
: AnsiString);
3495 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3496 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3497 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3498 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3500 // Вышли в выход в Одиночной игре:
3501 if gGameSettings
.GameType
= GT_SINGLE
then
3502 gExit
:= EXIT_ENDLEVELSINGLE
3503 else // Вышли в выход в Своей игре
3505 gExit
:= EXIT_ENDLEVELCUSTOM
;
3506 if gGameSettings
.GameMode
= GM_COOP
then
3507 g_Player_RememberAll
;
3509 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3512 if gGameSettings
.GameMode
= GM_COOP
then
3515 gStatsPressed
:= True;
3516 gNextMap
:= 'MAP01';
3518 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3521 if g_Game_IsNet
then
3523 MH_SEND_GameStats();
3524 MH_SEND_CoopStats();
3530 procedure g_Game_RestartLevel();
3534 if gGameSettings
.GameMode
= GM_SINGLE
then
3539 gExit
:= EXIT_ENDLEVELCUSTOM
;
3540 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3544 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3546 gWAD
{, xwad}: String;
3549 if not g_Game_IsClient
then Exit
;
3550 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3552 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3557 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3561 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3564 g_Game_LoadWAD(NewWAD
);
3568 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3569 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3572 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3573 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3577 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3581 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3582 g_Game_LoadWAD(NewWAD);
3586 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3588 i
, n
, nb
, nr
: Integer;
3590 if not g_Game_IsServer
then Exit
;
3591 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3592 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3593 gLMSRespawnTime
:= 0;
3596 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3598 gMissionFailed
:= True;
3599 g_Game_RestartLevel
;
3603 n
:= 0; nb
:= 0; nr
:= 0;
3604 for i
:= Low(gPlayers
) to High(gPlayers
) do
3605 if (gPlayers
[i
] <> nil) and
3606 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3607 (gPlayers
[i
] is TBot
)) then
3610 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3611 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3614 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3616 // wait a second until the fuckers finally decide to join
3617 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3618 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3619 gLMSSoftSpawn
:= NoMapRestart
;
3620 if g_Game_IsNet
then
3621 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3625 g_Player_RemoveAllCorpses
;
3626 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3627 if g_Game_IsNet
then
3628 MH_SEND_GameEvent(NET_EV_LMS_START
);
3630 for i
:= Low(gPlayers
) to High(gPlayers
) do
3632 if gPlayers
[i
] = nil then continue
;
3633 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3634 // don't touch normal spectators
3635 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3637 gPlayers
[i
].FNoRespawn
:= True;
3638 gPlayers
[i
].Lives
:= 0;
3639 if g_Game_IsNet
then
3640 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3643 gPlayers
[i
].FNoRespawn
:= False;
3644 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3645 gPlayers
[i
].Respawn(False, True);
3646 if gGameSettings
.GameMode
= GM_COOP
then
3648 gPlayers
[i
].Frags
:= 0;
3649 gPlayers
[i
].RecallState
;
3651 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3652 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3653 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3654 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3657 g_Items_RestartRound();
3659 gLMSSoftSpawn
:= False;
3662 function g_Game_GetFirstMap(WAD
: String): String;
3666 MapList
:= g_Map_GetMapsList(WAD
);
3667 if MapList
= nil then
3670 SortSArray(MapList
);
3671 Result
:= MapList
[Low(MapList
)];
3673 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3679 function g_Game_GetNextMap(): String;
3686 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3687 if MapList
= nil then
3690 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3692 SortSArray(MapList
);
3694 for I
:= Low(MapList
) to High(MapList
) do
3695 if Map
= MapList
[I
] then
3701 if MapIndex
<> -255 then
3703 if MapIndex
= High(MapList
) then
3704 Result
:= MapList
[Low(MapList
)]
3706 Result
:= MapList
[MapIndex
+ 1];
3708 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3714 procedure g_Game_NextLevel();
3716 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3717 gExit
:= EXIT_ENDLEVELCUSTOM
3720 gExit
:= EXIT_ENDLEVELSINGLE
;
3724 if gNextMap
<> '' then Exit
;
3725 gNextMap
:= g_Game_GetNextMap();
3728 function g_Game_IsTestMap(): Boolean;
3730 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3733 procedure g_Game_DeleteTestMap();
3736 //MapName: AnsiString;
3744 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3745 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3746 if (a
= 0) then exit
;
3748 // Выделяем имя wad-файла и имя карты
3749 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3750 Delete(gMapToDelete
, 1, a
+5);
3751 gMapToDelete
:= UpperCase(gMapToDelete
);
3753 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3756 // Имя карты не стандартное тестовое:
3757 if MapName <> TEST_MAP_NAME then
3760 if not gTempDelete then
3762 time := g_GetFileTime(WadName);
3763 WAD := TWADFile.Create();
3766 if not WAD.ReadFile(WadName) then
3767 begin // Нет такого WAD-файла
3772 // Составляем список карт и ищем нужную:
3774 MapList := WAD.GetResourcesList('');
3776 if MapList <> nil then
3777 for a := 0 to High(MapList) do
3778 if MapList[a] = MapName then
3780 // Удаляем и сохраняем:
3781 WAD.RemoveResource('', MapName);
3782 WAD.SaveTo(WadName);
3787 g_SetFileTime(WadName, time);
3790 if gTempDelete
then DeleteFile(WadName
);
3793 procedure GameCVars(P
: SSArray
);
3796 stat
: TPlayerStatArray
;
3799 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3803 if Length(P
) > 1 then
3808 gsGameFlags
:= gsGameFlags
or Flag
3810 gsGameFlags
:= gsGameFlags
and (not Flag
);
3812 if g_Game_IsServer
then
3815 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3817 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3818 if g_Game_IsNet
then MH_SEND_GameSettings
;
3822 if LongBool(gsGameFlags
and Flag
) then
3823 g_Console_Add(_lc
[OnMsg
])
3825 g_Console_Add(_lc
[OffMsg
]);
3827 if OnMapChange
and g_Game_IsServer
then
3828 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3833 cmd
:= LowerCase(P
[0]);
3835 if cmd
= 'g_gamemode' then
3837 if (Length(P
) > 1) then
3839 a
:= g_Game_TextToMode(P
[1]);
3840 if a
= GM_SINGLE
then a
:= GM_COOP
;
3841 gsGameMode
:= g_Game_ModeToText(a
);
3842 if g_Game_IsServer
then
3844 gSwitchGameMode
:= a
;
3845 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3846 (gState
= STATE_INTERSINGLE
) then
3847 gSwitchGameMode
:= GM_SINGLE
;
3849 gGameSettings
.GameMode
:= gSwitchGameMode
;
3853 if gSwitchGameMode
= gGameSettings
.GameMode
then
3854 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3855 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3857 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3858 [g_Game_ModeToText(gGameSettings
.GameMode
),
3859 g_Game_ModeToText(gSwitchGameMode
)]));
3861 else if cmd
= 'g_friendlyfire' then
3863 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3865 else if cmd
= 'g_friendly_absorb_damage' then
3867 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
3869 else if cmd
= 'g_friendly_hit_trace' then
3871 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
3873 else if cmd
= 'g_friendly_hit_projectile' then
3875 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
3877 else if cmd
= 'g_weaponstay' then
3879 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3881 else if cmd
= 'g_allow_exit' then
3883 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3885 else if cmd
= 'g_allow_monsters' then
3887 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3889 else if cmd
= 'g_allow_dropflag' then
3891 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
3893 else if cmd
= 'g_throw_flag' then
3895 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
3897 else if cmd
= 'g_bot_vsplayers' then
3899 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3901 else if cmd
= 'g_bot_vsmonsters' then
3903 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3905 else if cmd
= 'g_dm_keys' then
3907 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
3909 else if cmd
= 'g_gameflags' then
3911 if Length(P
) > 1 then
3913 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
3914 if g_Game_IsServer
then
3916 gGameSettings
.Options
:= gsGameFlags
;
3917 if g_Game_IsNet
then MH_SEND_GameSettings
;
3921 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
3923 else if cmd
= 'g_warmup_time' then
3925 if Length(P
) > 1 then
3927 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
3928 if g_Game_IsServer
then
3930 gGameSettings
.WarmupTime
:= gsWarmupTime
;
3931 // extend warmup if it's already going
3932 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
3934 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
3935 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3937 if g_Game_IsNet
then MH_SEND_GameSettings
;
3941 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
3942 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3944 else if cmd
= 'g_spawn_invul' then
3946 if Length(P
) > 1 then
3948 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
3949 if g_Game_IsServer
then
3951 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
3952 if g_Game_IsNet
then MH_SEND_GameSettings
;
3956 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
3958 else if cmd
= 'g_item_respawn_time' then
3960 if Length(P
) > 1 then
3962 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
3963 if g_Game_IsServer
then
3965 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
3966 if g_Game_IsNet
then MH_SEND_GameSettings
;
3970 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
3971 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3973 else if cmd
= 'sv_intertime' then
3975 if (Length(P
) > 1) then
3976 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
3978 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
3980 else if cmd
= 'g_max_particles' then
3982 if Length(p
) = 2 then
3984 a
:= Max(0, StrToIntDef(p
[1], 0));
3987 else if Length(p
) = 1 then
3989 e_LogWritefln('%s', [g_GFX_GetMax()])
3993 e_LogWritefln('usage: %s <n>', [cmd
])
3996 else if cmd
= 'g_max_shells' then
3998 if Length(p
) = 2 then
4000 a
:= Max(0, StrToIntDef(p
[1], 0));
4003 else if Length(p
) = 1 then
4005 e_LogWritefln('%s', [g_Shells_GetMax()])
4009 e_LogWritefln('usage: %s <n>', [cmd
])
4012 else if cmd
= 'g_max_gibs' then
4014 if Length(p
) = 2 then
4016 a
:= Max(0, StrToIntDef(p
[1], 0));
4019 else if Length(p
) = 1 then
4021 e_LogWritefln('%s', [g_Gibs_GetMax()])
4025 e_LogWritefln('usage: %s <n>', [cmd
])
4028 else if cmd
= 'g_max_corpses' then
4030 if Length(p
) = 2 then
4032 a
:= Max(0, StrToIntDef(p
[1], 0));
4035 else if Length(p
) = 1 then
4037 e_LogWritefln('%s', [g_Corpses_GetMax()])
4041 e_LogWritefln('usage: %s <n>', [cmd
])
4044 else if cmd
= 'g_force_model' then
4046 if Length(p
) = 2 then
4048 a
:= StrToIntDef(p
[1], 0);
4049 g_Force_Model_Set(a
);
4050 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4052 for a
:= Low(gPlayers
) to High(gPlayers
) do
4054 if (gPlayers
[a
] <> nil) then
4056 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4058 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4060 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4064 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4066 for a
:= Low(gPlayers
) to High(gPlayers
) do
4068 if (gPlayers
[a
] <> nil) then
4070 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4072 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4074 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4080 else if cmd
= 'g_force_model_name' then
4082 if (Length(P
) > 1) then
4084 cmd
:= b_Text_Unformat(P
[1]);
4085 g_Forced_Model_SetName(cmd
);
4086 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4088 for a
:= Low(gPlayers
) to High(gPlayers
) do
4090 if (gPlayers
[a
] <> nil) then
4092 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4094 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4096 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4102 else if cmd
= 'g_scorelimit' then
4104 if Length(P
) > 1 then
4106 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4108 if g_Game_IsServer
then
4111 if gGameSettings
.GameMode
= GM_DM
then
4113 stat
:= g_Player_GetStats();
4115 for a
:= 0 to High(stat
) do
4116 if stat
[a
].Frags
> b
then
4120 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4122 // if someone has a higher score, set it to that instead
4123 gsScoreLimit
:= max(gsScoreLimit
, b
);
4124 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4126 if g_Game_IsNet
then MH_SEND_GameSettings
;
4130 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4132 else if cmd
= 'g_timelimit' then
4134 if Length(P
) > 1 then
4136 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4137 if g_Game_IsServer
then
4139 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4140 if g_Game_IsNet
then MH_SEND_GameSettings
;
4143 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4144 [gsTimeLimit
div 3600,
4145 (gsTimeLimit
div 60) mod 60,
4146 gsTimeLimit
mod 60]));
4148 else if cmd
= 'g_max_bots' then
4150 if Length(P
) > 1 then
4151 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4152 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4154 else if cmd
= 'g_maxlives' then
4156 if Length(P
) > 1 then
4158 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4159 if g_Game_IsServer
then
4161 gGameSettings
.MaxLives
:= gsMaxLives
;
4162 if g_Game_IsNet
then MH_SEND_GameSettings
;
4166 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4170 procedure PlayerSettingsCVars(P
: SSArray
);
4175 function ParseTeam(s
: string): Byte;
4179 'red', '1': result
:= TEAM_RED
;
4180 'blue', '2': result
:= TEAM_BLUE
;
4181 else result
:= TEAM_NONE
;
4185 cmd
:= LowerCase(P
[0]);
4189 if (Length(P
) > 1) then
4191 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4192 if g_Game_IsClient
then
4193 MC_SEND_PlayerSettings
4194 else if gGameOn
and (gPlayer1
<> nil) then
4196 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4197 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4203 if (Length(P
) > 1) then
4205 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4206 if g_Game_IsClient
then
4207 MC_SEND_PlayerSettings
4208 else if gGameOn
and (gPlayer2
<> nil) then
4210 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4211 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4217 if Length(P
) > 3 then
4219 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4220 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4221 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4222 if g_Game_IsClient
then
4223 MC_SEND_PlayerSettings
4224 else if gGameOn
and (gPlayer1
<> nil) then
4226 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4227 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4233 if Length(P
) > 3 then
4235 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4236 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4237 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4238 if g_Game_IsClient
then
4239 MC_SEND_PlayerSettings
4240 else if gGameOn
and (gPlayer2
<> nil) then
4242 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4243 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4249 if (Length(P
) > 1) then
4251 gPlayer1Settings
.Model
:= P
[1];
4252 if g_Game_IsClient
then
4253 MC_SEND_PlayerSettings
4254 else if gGameOn
and (gPlayer1
<> nil) then
4256 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4257 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4258 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4264 if (Length(P
) > 1) then
4266 gPlayer2Settings
.Model
:= P
[1];
4267 if g_Game_IsClient
then
4268 MC_SEND_PlayerSettings
4269 else if gGameOn
and (gPlayer2
<> nil) then
4271 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4272 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4273 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4279 // TODO: switch teams if in game or store this separately
4280 if (Length(P
) > 1) then
4282 team
:= ParseTeam(P
[1]);
4283 if team
= TEAM_NONE
then
4284 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4285 else if not gGameOn
and not g_Game_IsNet
then
4286 gPlayer1Settings
.Team
:= team
4288 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4293 // TODO: switch teams if in game or store this separately
4294 if (Length(P
) > 1) then
4296 team
:= ParseTeam(P
[1]);
4297 if team
= TEAM_NONE
then
4298 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4299 else if not gGameOn
and not g_Game_IsNet
then
4300 gPlayer2Settings
.Team
:= team
4302 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4307 if (Length(P
) = 2) then
4308 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4312 if (Length(P
) = 2) then
4313 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4317 if (Length(P
) = 2) then
4318 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4322 if (Length(P
) = 2) then
4323 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4327 if (Length(P
) = 2) then
4328 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4332 if (Length(P
) = 2) then
4333 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4335 'p1_priority_kastet':
4337 if (Length(P
) = 2) then
4338 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4340 'p2_priority_kastet':
4342 if (Length(P
) = 2) then
4343 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4347 if (Length(P
) = 2) then
4348 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4352 if (Length(P
) = 2) then
4353 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4355 'p1_priority_pistol':
4357 if (Length(P
) = 2) then
4358 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4360 'p2_priority_pistol':
4362 if (Length(P
) = 2) then
4363 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4365 'p1_priority_shotgun1':
4367 if (Length(P
) = 2) then
4368 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4370 'p2_priority_shotgun1':
4372 if (Length(P
) = 2) then
4373 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4375 'p1_priority_shotgun2':
4377 if (Length(P
) = 2) then
4378 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4380 'p2_priority_shotgun2':
4382 if (Length(P
) = 2) then
4383 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4385 'p1_priority_chaingun':
4387 if (Length(P
) = 2) then
4388 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4390 'p2_priority_chaingun':
4392 if (Length(P
) = 2) then
4393 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4395 'p1_priority_rocketlauncher':
4397 if (Length(P
) = 2) then
4398 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4400 'p2_priority_rocketlauncher':
4402 if (Length(P
) = 2) then
4403 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4405 'p1_priority_plasma':
4407 if (Length(P
) = 2) then
4408 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4410 'p2_priority_plasma':
4412 if (Length(P
) = 2) then
4413 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4417 if (Length(P
) = 2) then
4418 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4422 if (Length(P
) = 2) then
4423 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4425 'p1_priority_super':
4427 if (Length(P
) = 2) then
4428 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4430 'p2_priority_super':
4432 if (Length(P
) = 2) then
4433 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4435 'p1_priority_flamethrower':
4437 if (Length(P
) = 2) then
4438 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4440 'p2_priority_flamethrower':
4442 if (Length(P
) = 2) then
4443 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4445 'p1_priority_berserk':
4447 if (Length(P
) = 2) then
4448 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4450 'p2_priority_berserk':
4452 if (Length(P
) = 2) then
4453 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4458 procedure PrintHeapStats();
4462 hs
:= GetFPCHeapStatus();
4463 e_LogWriteLn ('v===== heap status =====v');
4464 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4465 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4466 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4467 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4468 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4469 e_LogWriteLn ('^=======================^');
4472 procedure DebugCommands(P
: SSArray
);
4479 // Команды отладочного режима:
4480 if {gDebugMode}conIsCheatsEnabled
then
4482 cmd
:= LowerCase(P
[0]);
4483 if cmd
= 'd_window' then
4485 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4486 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4488 else if cmd
= 'd_sounds' then
4490 if (Length(P
) > 1) and
4491 ((P
[1] = '1') or (P
[1] = '0')) then
4492 g_Debug_Sounds
:= (P
[1][1] = '1');
4494 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4496 else if cmd
= 'd_frames' then
4498 if (Length(P
) > 1) and
4499 ((P
[1] = '1') or (P
[1] = '0')) then
4500 g_Debug_Frames
:= (P
[1][1] = '1');
4502 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4504 else if cmd
= 'd_winmsg' then
4506 if (Length(P
) > 1) and
4507 ((P
[1] = '1') or (P
[1] = '0')) then
4508 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4510 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4512 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4514 if (Length(P
) > 1) and
4515 ((P
[1] = '1') or (P
[1] = '0')) then
4516 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4518 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4520 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4522 if Length(P
) > 1 then
4524 '0': g_debug_BotAIOff
:= 0;
4525 '1': g_debug_BotAIOff
:= 1;
4526 '2': g_debug_BotAIOff
:= 2;
4527 '3': g_debug_BotAIOff
:= 3;
4530 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4532 else if cmd
= 'd_monster' then
4534 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4535 if Length(P
) < 2 then
4537 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4538 g_Console_Add('ID | Name');
4539 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4540 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4541 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4544 a
:= StrToIntDef(P
[1], 0);
4545 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4546 a
:= g_Mons_TypeIdByName(P
[1]);
4548 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4549 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4552 with gPlayer1
.Obj
do
4554 mon
:= g_Monsters_Create(a
,
4555 X
+ Rect
.X
+ (Rect
.Width
div 2),
4556 Y
+ Rect
.Y
+ Rect
.Height
,
4557 gPlayer1
.Direction
, True);
4559 if (Length(P
) > 2) and (mon
<> nil) then
4561 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4562 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4563 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4564 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4565 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4566 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4567 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4568 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4569 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4574 else if (cmd
= 'd_health') then
4576 if (Length(P
) > 1) and
4577 ((P
[1] = '1') or (P
[1] = '0')) then
4578 g_debug_HealthBar
:= (P
[1][1] = '1');
4580 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4582 else if (cmd
= 'd_player') then
4584 if (Length(P
) > 1) and
4585 ((P
[1] = '1') or (P
[1] = '0')) then
4586 g_debug_Player
:= (P
[1][1] = '1');
4588 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4590 else if (cmd
= 'd_mem') then
4596 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4600 procedure GameCheats(P
: SSArray
);
4606 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4608 g_Console_Add('not available');
4614 g_Console_Add('where is the player?!');
4617 cmd
:= LowerCase(P
[0]);
4621 plr
.GodMode
:= not plr
.GodMode
;
4622 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4625 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4626 if cmd
= 'give' then
4628 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4629 for f
:= 1 to High(P
) do
4631 cmd
:= LowerCase(P
[f
]);
4632 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4633 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4634 if cmd
= 'exit' then
4636 if gTriggers
<> nil then
4638 for a
:= 0 to High(gTriggers
) do
4640 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4642 g_Console_Add('player left the map');
4643 gExitByTrigger
:= True;
4644 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4645 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4653 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4654 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4655 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4656 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4657 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4659 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4660 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4662 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4663 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;
4665 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4666 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4668 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4669 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4671 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4672 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4674 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4675 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4676 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4678 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4679 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4680 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4681 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;
4682 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4683 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4685 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;
4686 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;
4687 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;
4688 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;
4689 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;
4690 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;
4692 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4693 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;
4695 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;
4696 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;
4698 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4700 if cmd
= 'ammo' then
4702 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4703 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4704 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4705 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4706 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4707 g_Console_Add('player got some ammo');
4711 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4712 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4714 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4715 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4717 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4718 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4720 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4721 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4723 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4725 if cmd
= 'weapons' then
4727 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4728 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4729 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4730 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4731 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4732 plr
.GiveItem(ITEM_WEAPON_BFG
);
4733 g_Console_Add('player got weapons');
4737 if cmd
= 'keys' then
4739 plr
.GiveItem(ITEM_KEY_RED
);
4740 plr
.GiveItem(ITEM_KEY_GREEN
);
4741 plr
.GiveItem(ITEM_KEY_BLUE
);
4742 g_Console_Add('player got all keys');
4746 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4751 if cmd
= 'open' then
4753 g_Console_Add('player activated sesame');
4754 g_Triggers_OpenAll();
4761 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4765 if cmd
= 'noclip' then
4768 g_Console_Add('wall hardeness adjusted');
4772 if cmd
= 'notarget' then
4774 plr
.NoTarget
:= not plr
.NoTarget
;
4775 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4779 if cmd
= 'noreload' then
4781 plr
.NoReload
:= not plr
.NoReload
;
4782 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4786 if cmd
= 'speedy' then
4788 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4789 g_Console_Add('speed adjusted');
4793 if cmd
= 'jumpy' then
4795 VEL_JUMP
:= 30-VEL_JUMP
;
4796 g_Console_Add('jump height adjusted');
4800 if cmd
= 'automap' then
4802 gShowMap
:= not gShowMap
;
4803 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4807 if cmd
= 'aimline' then
4809 gAimLine
:= not gAimLine
;
4810 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4815 procedure GameCommands(P
: SSArray
);
4821 pl
: pTNetClient
= nil;
4829 cmd
:= LowerCase(P
[0]);
4831 if cmd
= 'pause' then
4833 if (g_ActiveWindow
= nil) then
4834 g_Game_Pause(not gPauseMain
);
4836 else if cmd
= 'endgame' then
4837 gExit
:= EXIT_SIMPLE
4838 else if cmd
= 'restart' then
4840 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4842 if g_Game_IsClient
then
4844 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4849 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4851 else if cmd
= 'kick' then
4853 if g_Game_IsServer
then
4855 if Length(P
) < 2 then
4857 g_Console_Add('kick <name>');
4862 g_Console_Add('kick <name>');
4866 if g_Game_IsNet
then
4867 pl
:= g_Net_Client_ByName(P
[1]);
4870 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4871 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4872 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4873 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4874 g_Net_Slist_ServerPlayerLeaves();
4875 end else if gPlayers
<> nil then
4876 for a
:= Low(gPlayers
) to High(gPlayers
) do
4877 if gPlayers
[a
] <> nil then
4878 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4880 // Не отключать основных игроков в сингле
4881 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4883 gPlayers
[a
].Lives
:= 0;
4884 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4885 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4886 g_Player_Remove(gPlayers
[a
].UID
);
4887 g_Net_Slist_ServerPlayerLeaves();
4888 // Если не перемешать, при добавлении новых ботов появятся старые
4892 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4894 else if cmd
= 'kick_id' then
4896 if g_Game_IsServer
and g_Game_IsNet
then
4898 if Length(P
) < 2 then
4900 g_Console_Add('kick_id <client ID>');
4905 g_Console_Add('kick_id <client ID>');
4909 a
:= StrToIntDef(P
[1], 0);
4910 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4912 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4914 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4915 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
4916 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4917 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4918 g_Net_Slist_ServerPlayerLeaves();
4922 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4924 else if cmd
= 'kick_pid' then
4926 if g_Game_IsServer
and g_Game_IsNet
then
4928 if Length(P
) < 2 then
4930 g_Console_Add('kick_pid <player ID>');
4935 g_Console_Add('kick_pid <player ID>');
4939 a
:= StrToIntDef(P
[1], 0);
4940 pl
:= g_Net_Client_ByPlayer(a
);
4941 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4943 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4944 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4945 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4946 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4947 g_Net_Slist_ServerPlayerLeaves();
4950 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4952 else if cmd
= 'ban' then
4954 if g_Game_IsServer
and g_Game_IsNet
then
4956 if Length(P
) < 2 then
4958 g_Console_Add('ban <name>');
4963 g_Console_Add('ban <name>');
4967 pl
:= g_Net_Client_ByName(P
[1]);
4970 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4971 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4972 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
4973 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4974 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4975 g_Net_Slist_ServerPlayerLeaves();
4977 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4979 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4981 else if cmd
= 'ban_id' then
4983 if g_Game_IsServer
and g_Game_IsNet
then
4985 if Length(P
) < 2 then
4987 g_Console_Add('ban_id <client ID>');
4992 g_Console_Add('ban_id <client ID>');
4996 a
:= StrToIntDef(P
[1], 0);
4997 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4998 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5000 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5001 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5002 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5003 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5004 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5005 g_Net_Slist_ServerPlayerLeaves();
5008 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5010 else if cmd
= 'ban_pid' then
5012 if g_Game_IsServer
and g_Game_IsNet
then
5014 if Length(P
) < 2 then
5016 g_Console_Add('ban_pid <player ID>');
5021 g_Console_Add('ban_pid <player ID>');
5025 a
:= StrToIntDef(P
[1], 0);
5026 pl
:= g_Net_Client_ByPlayer(a
);
5027 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5029 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5030 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5031 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5032 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5033 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5034 g_Net_Slist_ServerPlayerLeaves();
5037 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5039 else if cmd
= 'permban' then
5041 if g_Game_IsServer
and g_Game_IsNet
then
5043 if Length(P
) < 2 then
5045 g_Console_Add('permban <name>');
5050 g_Console_Add('permban <name>');
5054 pl
:= g_Net_Client_ByName(P
[1]);
5057 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5058 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5059 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5060 g_Net_SaveBanList();
5061 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5062 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5063 g_Net_Slist_ServerPlayerLeaves();
5065 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5067 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5069 else if cmd
= 'permban_id' then
5071 if g_Game_IsServer
and g_Game_IsNet
then
5073 if Length(P
) < 2 then
5075 g_Console_Add('permban_id <client ID>');
5080 g_Console_Add('permban_id <client ID>');
5084 a
:= StrToIntDef(P
[1], 0);
5085 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5086 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5088 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5089 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5090 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5091 g_Net_SaveBanList();
5092 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5093 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5094 g_Net_Slist_ServerPlayerLeaves();
5097 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5099 else if cmd
= 'permban_pid' then
5101 if g_Game_IsServer
and g_Game_IsNet
then
5103 if Length(P
) < 2 then
5105 g_Console_Add('permban_pid <player ID>');
5110 g_Console_Add('permban_pid <player ID>');
5114 a
:= StrToIntDef(P
[1], 0);
5115 pl
:= g_Net_Client_ByPlayer(a
);
5116 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5118 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5119 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5120 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5121 g_Net_SaveBanList();
5122 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5123 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5124 g_Net_Slist_ServerPlayerLeaves();
5127 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5129 else if cmd
= 'permban_ip' then
5131 if g_Game_IsServer
and g_Game_IsNet
then
5133 if Length(P
) < 2 then
5135 g_Console_Add('permban_ip <IP address>');
5140 g_Console_Add('permban_ip <IP address>');
5144 g_Net_BanHost(P
[1]);
5145 g_Net_SaveBanList();
5146 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5148 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5150 else if cmd
= 'unban' then
5152 if g_Game_IsServer
and g_Game_IsNet
then
5154 if Length(P
) < 2 then
5156 g_Console_Add('unban <IP Address>');
5161 g_Console_Add('unban <IP Address>');
5165 if g_Net_UnbanHost(P
[1]) then
5167 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5168 g_Net_SaveBanList();
5170 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5172 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5174 else if cmd
= 'clientlist' then
5176 if g_Game_IsServer
and g_Game_IsNet
then
5179 if NetClients
<> nil then
5180 for a
:= Low(NetClients
) to High(NetClients
) do
5181 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5183 plr
:= g_Player_Get(NetClients
[a
].Player
);
5184 if plr
= nil then continue
;
5186 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5187 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5190 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5192 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5194 else if cmd
= 'connect' then
5196 if (NetMode
= NET_NONE
) then
5198 if Length(P
) < 2 then
5200 g_Console_Add('connect <IP> [port] [password]');
5205 g_Console_Add('connect <IP> [port] [password]');
5209 if Length(P
) > 2 then
5210 prt
:= StrToIntDef(P
[2], 25666)
5214 if Length(P
) > 3 then
5219 g_Game_StartClient(P
[1], prt
, pw
);
5222 else if cmd
= 'disconnect' then
5224 if (NetMode
= NET_CLIENT
) then
5227 else if cmd
= 'reconnect' then
5229 if (NetMode
= NET_SERVER
) then
5232 if (NetMode
= NET_CLIENT
) then
5235 gExit
:= EXIT_SIMPLE
;
5239 //TODO: Use last successful password to reconnect, instead of ''
5240 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5242 else if (cmd
= 'addbot') or
5243 (cmd
= 'bot_add') then
5245 if Length(P
) > 2 then
5246 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5247 else if Length(P
) > 1 then
5248 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5250 g_Bot_Add(TEAM_NONE
, 2);
5252 else if cmd
= 'bot_addlist' then
5254 if Length(P
) > 1 then
5256 if Length(P
) = 2 then
5257 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5258 else if Length(P
) = 3 then
5259 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5261 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5264 else if cmd
= 'bot_removeall' then
5266 else if cmd
= 'chat' then
5268 if g_Game_IsNet
then
5270 if Length(P
) > 1 then
5272 for a
:= 1 to High(P
) do
5273 chstr
:= chstr
+ P
[a
] + ' ';
5275 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5277 if Length(chstr
) < 1 then
5279 g_Console_Add('chat <text>');
5283 chstr
:= b_Text_Format(chstr
);
5284 if g_Game_IsClient
then
5285 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5287 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5290 g_Console_Add('chat <text>');
5292 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5294 else if cmd
= 'teamchat' then
5296 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5298 if Length(P
) > 1 then
5300 for a
:= 1 to High(P
) do
5301 chstr
:= chstr
+ P
[a
] + ' ';
5303 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5305 if Length(chstr
) < 1 then
5307 g_Console_Add('teamchat <text>');
5311 chstr
:= b_Text_Format(chstr
);
5312 if g_Game_IsClient
then
5313 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5315 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5316 gPlayer1Settings
.Team
);
5319 g_Console_Add('teamchat <text>');
5321 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5323 else if (cmd
= 'an') or (cmd
= 'announce') then
5325 if g_Game_IsNet
then
5327 if Length(P
) > 1 then
5329 for a
:= 1 to High(P
) do
5330 chstr
:= chstr
+ P
[a
] + ' ';
5332 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5334 if Length(chstr
) < 1 then
5336 g_Console_Add('announce <text>');
5340 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5341 if g_Game_IsClient
then
5342 MC_SEND_RCONCommand(chstr
)
5344 g_Console_Process(chstr
, True);
5347 g_Console_Add('announce <text>');
5349 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5351 else if cmd
= 'game' then
5353 if gGameSettings
.GameType
<> GT_NONE
then
5355 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5358 if Length(P
) = 1 then
5360 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5363 // game not started yet, load fist map from some wad
5365 s
:= addWadExtension(P
[1]);
5366 found
:= e_FindResource(AllMapDirs
, s
);
5370 P
[1] := ExpandFileName(P
[1]);
5371 // if map not choosed then set first map
5372 if Length(P
) < 3 then
5375 P
[2] := g_Game_GetFirstMap(P
[1]);
5378 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5380 if g_Map_Exist(s
) then
5384 with gGameSettings
do
5386 Options
:= gsGameFlags
;
5387 GameMode
:= g_Game_TextToMode(gsGameMode
);
5388 if gSwitchGameMode
<> GM_NONE
then
5389 GameMode
:= gSwitchGameMode
;
5390 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5391 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5393 if Length(P
) >= 4 then
5394 b
:= StrToIntDef(P
[3], 1);
5395 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5396 ScoreLimit
, MaxLives
, Options
, b
);
5401 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5403 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5405 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5407 else if cmd
= 'host' then
5409 if gGameSettings
.GameType
<> GT_NONE
then
5411 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5414 if Length(P
) < 4 then
5416 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5419 if not StrToIp(P
[1], listen
) then
5421 prt
:= StrToIntDef(P
[2], 25666);
5423 s
:= addWadExtension(P
[3]);
5424 found
:= e_FindResource(AllMapDirs
, s
);
5428 // get first map in wad, if not specified
5429 if Length(P
) < 5 then
5432 P
[4] := g_Game_GetFirstMap(P
[1]);
5434 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5435 if g_Map_Exist(s
) then
5439 with gGameSettings
do
5441 Options
:= gsGameFlags
;
5442 GameMode
:= g_Game_TextToMode(gsGameMode
);
5443 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5444 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5445 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5447 if Length(P
) >= 6 then
5448 b
:= StrToIntDef(P
[5], 0);
5449 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5455 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5457 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5462 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5465 else if cmd
= 'map' then
5467 if Length(P
) = 1 then
5469 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5471 g_Console_Add(cmd
+ ' <MAP>');
5472 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5476 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5481 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5483 if Length(P
) < 3 then
5485 // first param is map or wad
5486 s
:= UpperCase(P
[1]);
5487 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5489 gExitByTrigger
:= False;
5492 // already in game, finish current map
5494 gExit
:= EXIT_ENDLEVELCUSTOM
;
5498 // intermission, so change map immediately
5505 found
:= e_FindResource(AllMapDirs
, s
);
5507 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5510 // no such map, found wad
5513 P
[1] := ExpandFileName(pw
);
5514 P
[2] := g_Game_GetFirstMap(P
[1]);
5515 s
:= P
[1] + ':\' + P
[2];
5516 if g_Map_Exist(s
) then
5518 gExitByTrigger
:= False;
5521 // already in game, finish current map
5523 gExit
:= EXIT_ENDLEVELCUSTOM
5527 // intermission, so change map immediately
5534 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5536 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5541 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5547 s
:= addWadExtension(P
[1]);
5548 found
:= e_FindResource(AllMapDirs
, s
);
5552 P
[2] := UpperCase(P
[2]);
5553 s
:= P
[1] + ':\' + P
[2];
5554 if g_Map_Exist(s
) then
5556 gExitByTrigger
:= False;
5560 gExit
:= EXIT_ENDLEVELCUSTOM
5569 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5574 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5580 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5584 else if cmd
= 'nextmap' then
5586 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5588 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5593 if Length(P
) = 1 then
5595 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5597 g_Console_Add(cmd
+ ' <MAP>');
5598 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5603 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5609 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5611 if Length(P
) < 3 then
5613 // first param is map or wad
5614 s
:= UpperCase(P
[1]);
5615 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5618 gExitByTrigger
:= False;
5624 // no such map, found wad
5625 pw
:= addWadExtension(P
[1]);
5626 found
:= e_FindResource(MapDirs
, pw
);
5628 found
:= e_FindResource(WadDirs
, pw
);
5630 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5633 // map not specified, select first map
5635 P
[2] := g_Game_GetFirstMap(P
[1]);
5636 s
:= P
[1] + ':\' + P
[2];
5637 if g_Map_Exist(s
) then
5639 gExitByTrigger
:= False;
5646 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5648 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5653 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5659 // specified two params wad + map
5660 pw
:= addWadExtension(P
[1]);
5661 found
:= e_FindResource(MapDirs
, pw
);
5663 found
:= e_FindResource(MapDirs
, pw
);
5667 P
[2] := UpperCase(P
[2]);
5668 s
:= P
[1] + ':\' + P
[2];
5669 if g_Map_Exist(s
) then
5671 gExitByTrigger
:= False;
5677 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5682 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5688 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5693 if gNextMap
= '' then
5694 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5696 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5700 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5704 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5708 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5710 gExitByTrigger
:= False;
5711 // next map not specified, try to find trigger EXIT
5712 if (gNextMap
= '') and (gTriggers
<> nil) then
5714 for a
:= 0 to High(gTriggers
) do
5716 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5718 gExitByTrigger
:= True;
5719 //gNextMap := gTriggers[a].Data.MapName;
5720 gNextMap
:= gTriggers
[a
].tgcMap
;
5725 if gNextMap
= '' then
5726 gNextMap
:= g_Game_GetNextMap();
5727 if not isWadPath(gNextMap
) then
5728 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5731 if g_Map_Exist(s
) then
5732 gExit
:= EXIT_ENDLEVELCUSTOM
5734 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5738 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5742 else if (cmd
= 'event') then
5744 if (Length(P
) <= 1) then
5746 for a
:= 0 to High(gEvents
) do
5747 if gEvents
[a
].Command
= '' then
5748 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5750 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5753 if (Length(P
) = 2) then
5755 for a
:= 0 to High(gEvents
) do
5756 if gEvents
[a
].Name
= P
[1] then
5757 if gEvents
[a
].Command
= '' then
5758 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5760 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5763 for a
:= 0 to High(gEvents
) do
5764 if gEvents
[a
].Name
= P
[1] then
5766 gEvents
[a
].Command
:= '';
5767 for b
:= 2 to High(P
) do
5768 if Pos(' ', P
[b
]) = 0 then
5769 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5771 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5772 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5776 else if cmd
= 'suicide' then
5780 if g_Game_IsClient
then
5781 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5784 if gPlayer1
<> nil then
5785 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5786 if gPlayer2
<> nil then
5787 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5791 else if cmd
= 'screenshot' then
5797 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5799 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5801 gWeaponAction
[0, WP_PREV
] := True;
5803 gWeaponAction
[0, WP_NEXT
] := True;
5805 else if cmd
= 'weapon' then
5807 if Length(p
) = 2 then
5809 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5810 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5811 gSelectWeapon
[0, a
] := True
5814 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5815 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5817 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5818 b
:= ord(cmd
[2]) - ord('1');
5820 gWeaponAction
[b
, WP_PREV
] := True;
5822 gWeaponAction
[b
, WP_NEXT
] := True;
5824 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5826 if Length(p
) = 2 then
5828 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5829 b
:= ord(cmd
[2]) - ord('1');
5830 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5831 gSelectWeapon
[b
, a
] := True
5834 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
5836 b
:= ord(cmd
[2]) - ord('1');
5838 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
5840 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
5842 else if (cmd
= 'dropflag') then
5844 if g_Game_IsServer
then
5846 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
5847 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
5850 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5852 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
5854 b
:= ord(cmd
[2]) - ord('1');
5855 if g_Game_IsServer
then
5857 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
5858 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
5861 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5863 // Команды Своей игры:
5864 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5866 if cmd
= 'bot_addred' then
5868 if Length(P
) > 1 then
5869 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5871 g_Bot_Add(TEAM_RED
, 2);
5873 else if cmd
= 'bot_addblue' then
5875 if Length(P
) > 1 then
5876 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5878 g_Bot_Add(TEAM_BLUE
, 2);
5880 else if cmd
= 'spectate' then
5886 else if cmd
= 'say' then
5888 if g_Game_IsServer
and g_Game_IsNet
then
5890 if Length(P
) > 1 then
5893 for a
:= 1 to High(P
) do
5894 chstr
:= chstr
+ P
[a
] + ' ';
5896 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5898 if Length(chstr
) < 1 then
5900 g_Console_Add('say <text>');
5904 chstr
:= b_Text_Format(chstr
);
5905 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5907 else g_Console_Add('say <text>');
5909 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5911 else if cmd
= 'tell' then
5913 if g_Game_IsServer
and g_Game_IsNet
then
5915 if (Length(P
) > 2) and (P
[1] <> '') then
5918 for a
:= 2 to High(P
) do
5919 chstr
:= chstr
+ P
[a
] + ' ';
5921 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5923 if Length(chstr
) < 1 then
5925 g_Console_Add('tell <playername> <text>');
5929 pl
:= g_Net_Client_ByName(P
[1]);
5931 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5933 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5935 else g_Console_Add('tell <playername> <text>');
5937 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5939 else if cmd
= 'centerprint' then
5941 if (Length(P
) > 2) and (P
[1] <> '') then
5944 for a
:= 2 to High(P
) do
5945 chstr
:= chstr
+ P
[a
] + ' ';
5947 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5949 if Length(chstr
) < 1 then
5951 g_Console_Add('centerprint <timeout> <text>');
5955 a
:= StrToIntDef(P
[1], 100);
5956 chstr
:= b_Text_Format(chstr
);
5957 g_Game_Message(chstr
, a
);
5958 if g_Game_IsNet
and g_Game_IsServer
then
5959 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
5961 else g_Console_Add('centerprint <timeout> <text>');
5963 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5965 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5967 // Дополнительное время:
5968 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5970 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5971 [gGameSettings
.TimeLimit
div 3600,
5972 (gGameSettings
.TimeLimit
div 60) mod 60,
5973 gGameSettings
.TimeLimit
mod 60]));
5974 if g_Game_IsNet
then MH_SEND_GameSettings
;
5976 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5978 if (Length(P
) <= 1) then
5979 g_Console_Add('rcon_password <password>')
5981 MC_SEND_RCONPassword(P
[1]);
5983 else if cmd
= 'rcon' then
5985 if g_Game_IsClient
then
5987 if Length(P
) > 1 then
5990 for a
:= 1 to High(P
) do
5991 chstr
:= chstr
+ P
[a
] + ' ';
5993 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5995 if Length(chstr
) < 1 then
5997 g_Console_Add('rcon <command>');
6001 MC_SEND_RCONCommand(chstr
);
6003 else g_Console_Add('rcon <command>');
6006 else if cmd
= 'ready' then
6008 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6009 gLMSRespawnTime
:= gTime
+ 100;
6011 else if (cmd
= 'callvote') and g_Game_IsNet
then
6013 if Length(P
) > 1 then
6016 for a
:= 1 to High(P
) do begin
6017 if a
> 1 then chstr
:= chstr
+ ' ';
6018 chstr
:= chstr
+ P
[a
];
6021 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6023 if Length(chstr
) < 1 then
6025 g_Console_Add('callvote <command>');
6029 if g_Game_IsClient
then
6030 MC_SEND_Vote(True, chstr
)
6032 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6033 g_Console_Process('vote', True);
6036 g_Console_Add('callvote <command>');
6038 else if (cmd
= 'vote') and g_Game_IsNet
then
6040 if g_Game_IsClient
then
6042 else if gVoteInProgress
then
6044 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6045 a
:= Floor((NetClientCount
+1)/2.0) + 1
6047 a
:= Floor(NetClientCount
/2.0) + 1;
6052 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6053 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6059 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6060 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6068 procedure SystemCommands(P
: SSArray
);
6072 cmd
:= LowerCase(P
[0]);
6085 if Length(p
) = 2 then
6087 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6089 gFrameTime
:= 1000 div gMaxFPS
6093 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6097 if Length(p
) = 2 then
6099 gAskLanguage
:= true;
6100 gLanguage
:= LANGUAGE_ENGLISH
;
6101 case LowerCase(p
[1]) of
6104 gAskLanguage
:= false;
6105 gLanguage
:= LANGUAGE_ENGLISH
;
6109 gAskLanguage
:= false;
6110 gLanguage
:= LANGUAGE_RUSSIAN
;
6114 gAskLanguage
:= true;
6115 gLanguage
:= LANGUAGE_ENGLISH
;
6118 g_Language_Set(gLanguage
);
6122 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6129 procedure g_TakeScreenShot(Filename
: string = '');
6130 var t
: TDateTime
; dir
, date
, name
: String;
6132 if e_NoGraphics
then
6135 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6136 if Filename
= '' then
6139 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6140 Filename
:= 'screenshot-' + date
;
6143 name
:= e_CatPath(dir
, Filename
+ '.png');
6144 if r_Render_WriteScreenShot(name
) then
6145 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6147 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6151 procedure g_Game_InGameMenu(Show
: Boolean);
6153 if (g_ActiveWindow
= nil) and Show
then
6155 if gGameSettings
.GameType
= GT_SINGLE
then
6156 g_GUI_ShowWindow('GameSingleMenu')
6159 if g_Game_IsClient
then
6160 g_GUI_ShowWindow('GameClientMenu')
6162 if g_Game_IsNet
then
6163 g_GUI_ShowWindow('GameServerMenu')
6165 g_GUI_ShowWindow('GameCustomMenu');
6167 g_Sound_PlayEx('MENU_OPEN');
6169 // Пауза при меню только в одиночной игре:
6170 if (not g_Game_IsNet
) then
6174 if (g_ActiveWindow
<> nil) and (not Show
) then
6176 // Пауза при меню только в одиночной игре:
6177 if (not g_Game_IsNet
) then
6178 g_Game_Pause(False);
6182 procedure g_Game_Pause (Enable
: Boolean);
6186 if not gGameOn
then exit
;
6188 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6191 gPauseMain
:= Enable
;
6193 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6196 procedure g_Game_HolmesPause (Enable
: Boolean);
6200 if not gGameOn
then exit
;
6201 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6204 gPauseHolmes
:= Enable
;
6206 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6209 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6214 if gTriggers
<> nil then
6215 for i
:= 0 to High(gTriggers
) do
6216 with gTriggers
[i
] do
6217 if (TriggerType
= TRIGGER_SOUND
) and
6219 Sound
.IsPlaying() then
6221 Sound
.Pause(Enable
);
6225 if gPlayers
<> nil then
6226 for i
:= 0 to High(gPlayers
) do
6227 if gPlayers
[i
] <> nil then
6228 gPlayers
[i
].PauseSounds(Enable
);
6231 if gMusic
<> nil then
6232 gMusic
.Pause(Enable
);
6235 procedure g_Game_StopAllSounds(all
: Boolean);
6239 if gTriggers
<> nil then
6240 for i
:= 0 to High(gTriggers
) do
6241 with gTriggers
[i
] do
6242 if (TriggerType
= TRIGGER_SOUND
) and
6246 if gMusic
<> nil then
6253 procedure g_Game_UpdateTriggerSounds
;
6256 if gTriggers
<> nil then
6257 for i
:= 0 to High(gTriggers
) do
6258 with gTriggers
[i
] do
6259 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6260 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6263 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6266 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6271 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6276 if gSpectMode
<> SPECT_PLAYERS
then
6278 if gSpectPID1
= UID
then
6283 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6290 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6295 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6300 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6305 if gSpectMode
<> SPECT_PLAYERS
then
6307 Pl
:= g_Player_Get(gSpectPID1
);
6308 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6313 if gSpectViewTwo
then
6315 Pl
:= g_Player_Get(gSpectPID2
);
6316 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6324 procedure g_Game_Message (Msg
: string; Time
: Word);
6327 MessageTime
:= Time
;
6330 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6332 punct
: Array[0..13] of String =
6333 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6339 function IsPunctuation(S
: String): Boolean;
6344 if Length(S
) <> 1 then
6346 for i
:= Low(punct
) to High(punct
) do
6347 if S
= punct
[i
] then
6353 function FilterPunctuation(S
: String): String;
6357 for i
:= Low(punct
) to High(punct
) do
6358 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6364 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6366 // remove player name
6367 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6368 // for FullWord check
6369 Text := toLowerCase1251(' ' + Text + ' ');
6370 fpText
:= FilterPunctuation(Text);
6372 for i
:= 0 to Length(gChatSounds
) - 1 do
6375 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6377 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6378 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6380 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6386 gChatSounds
[i
].Sound
.Play();
6392 g_Sound_PlayEx('SOUND_GAME_RADIO');
6395 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6404 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6408 if goodsnd
[a
].IsPlaying() then
6411 goodsnd
[Random(4)].Play();
6414 procedure g_Game_Announce_KillCombo(Param
: Integer);
6421 UID
:= Param
and $FFFF;
6426 Pl
:= g_Player_Get(UID
);
6435 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6439 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6443 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6447 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6455 if not g_Game_IsWatchedPlayer(UID
) then
6458 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6462 if killsnd
[n
].IsPlaying() then
6467 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6475 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6479 if hahasnd
[a
].IsPlaying() then
6482 hahasnd
[Random(3)].Play();
6485 procedure g_Game_StartVote(Command
, Initiator
: string);
6489 if not gVotesEnabled
then Exit
;
6490 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6491 if gVoteInProgress
or gVotePassed
then
6493 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6494 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6497 gVoteInProgress
:= True;
6498 gVotePassed
:= False;
6499 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6502 gVoteCommand
:= Command
;
6504 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6505 Need
:= Floor((NetClientCount
+1)/2.0)+1
6507 Need
:= Floor(NetClientCount
/2.0)+1;
6508 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6509 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6512 procedure g_Game_CheckVote
;
6516 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6517 if not gVoteInProgress
then Exit
;
6519 if (gTime
>= gVoteTimer
) then
6521 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6522 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6524 Need
:= Floor(NetClientCount
/2.0) + 1;
6525 if gVoteCount
>= Need
then
6527 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6528 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6529 gVotePassed
:= True;
6530 gVoteCmdTimer
:= gTime
+ 5000;
6534 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6535 MH_SEND_VoteEvent(NET_VE_FAILED
);
6537 if NetClients
<> nil then
6538 for I
:= Low(NetClients
) to High(NetClients
) do
6539 if NetClients
[i
].Used
then
6540 NetClients
[i
].Voted
:= False;
6541 gVoteInProgress
:= False;
6547 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6548 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6550 Need
:= Floor(NetClientCount
/2.0) + 1;
6551 if gVoteCount
>= Need
then
6553 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6554 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6555 gVoteInProgress
:= False;
6556 gVotePassed
:= True;
6557 gVoteCmdTimer
:= gTime
+ 5000;
6560 if NetClients
<> nil then
6561 for I
:= Low(NetClients
) to High(NetClients
) do
6562 if NetClients
[i
].Used
then
6563 NetClients
[i
].Voted
:= False;
6568 procedure g_Game_LoadMapList(FileName
: string);
6576 if not FileExists(FileName
) then Exit
;
6578 AssignFile(ListFile
, FileName
);
6580 while not EOF(ListFile
) do
6582 ReadLn(ListFile
, s
);
6585 if s
= '' then Continue
;
6587 SetLength(MapList
, Length(MapList
)+1);
6588 MapList
[High(MapList
)] := s
;
6590 CloseFile(ListFile
);
6593 procedure g_Game_SetDebugMode();
6596 // Читы (даже в своей игре):
6600 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6604 if Length(LoadingStat
.Msgs
) = 0 then
6610 begin // Переходим на следующую строку или скроллируем:
6611 if NextMsg
= Length(Msgs
) then
6613 for i
:= 0 to High(Msgs
)-1 do
6614 Msgs
[i
] := Msgs
[i
+1];
6622 Msgs
[NextMsg
-1] := Text;
6626 PBarWasHere
:= false;
6629 g_ActiveWindow
:= nil;
6630 ProcessLoading(True);
6633 procedure g_Game_StepLoading(Value
: Integer = -1);
6645 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6648 ProcessLoading(False);
6653 procedure g_Game_ClearLoading();
6662 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6663 if len
< 1 then len
:= 1;
6664 SetLength(Msgs
, len
);
6665 for len
:= Low(Msgs
) to High(Msgs
) do
6668 PBarWasHere
:= false;
6672 procedure Parse_Params(var pars
: TParamStrValues
);
6679 while i
<= ParamCount
do
6682 if (Length(s
) > 1) and (s
[1] = '-') then
6684 if (Length(s
) > 2) and (s
[2] = '-') then
6685 begin // Одиночный параметр
6686 SetLength(pars
, Length(pars
) + 1);
6687 with pars
[High(pars
)] do
6689 Name
:= LowerCase(s
);
6694 if (i
< ParamCount
) then
6695 begin // Параметр со значением
6697 SetLength(pars
, Length(pars
) + 1);
6698 with pars
[High(pars
)] do
6700 Name
:= LowerCase(s
);
6701 Value
:= LowerCase(ParamStr(i
));
6710 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6715 for i
:= 0 to High(pars
) do
6716 if pars
[i
].Name
= aName
then
6718 Result
:= pars
[i
].Value
;
6723 procedure g_Game_Process_Params();
6725 pars
: TParamStrValues
;
6728 LimT
, LimS
: Integer;
6739 s
:= Find_Param_Value(pars
, '--debug');
6742 g_Game_SetDebugMode();
6743 s
:= Find_Param_Value(pars
, '--netdump');
6748 // Connect when game loads
6749 ip
:= Find_Param_Value(pars
, '-connect');
6753 s
:= Find_Param_Value(pars
, '-port');
6754 if (s
= '') or not TryStrToInt(s
, Port
) then
6757 s
:= Find_Param_Value(pars
, '-pw');
6759 g_Game_StartClient(ip
, Port
, s
);
6763 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6766 gDefaultMegawadStart
:= s
;
6769 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6770 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6772 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6775 // Start map when game loads:
6776 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6777 if isWadPath(map
) then
6780 s
:= Find_Param_Value(pars
, '-gm');
6781 GMode
:= g_Game_TextToMode(s
);
6782 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6783 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6786 s
:= Find_Param_Value(pars
, '-limt');
6787 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6793 s
:= Find_Param_Value(pars
, '-lims');
6794 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6800 s
:= Find_Param_Value(pars
, '-lives');
6801 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6807 s
:= Find_Param_Value(pars
, '-opt');
6811 Opt
:= StrToIntDef(s
, 0);
6814 s
:= Find_Param_Value(pars
, '--close');
6818 // Override map to test:
6819 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6822 if e_IsValidResourceName(s
) then
6823 e_FindResource(AllMapDirs
, s
);
6824 gTestMap
:= ExpandFileName(s
);
6827 // Delete test map after play:
6828 s
:= Find_Param_Value(pars
, '--testdelete');
6831 //gMapToDelete := MapsDir + map;
6832 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6836 // Delete temporary WAD after play:
6837 s
:= Find_Param_Value(pars
, '--tempdelete');
6838 if (s
<> '') and (gTestMap
<> '') then
6840 gMapToDelete
:= gTestMap
;
6841 gTempDelete
:= True;
6844 // Number of players:
6845 s
:= Find_Param_Value(pars
, '-pl');
6847 n
:= DEFAULT_PLAYERS
6849 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6852 s
:= Find_Param_Value(pars
, '-port');
6853 if (s
= '') or not TryStrToInt(s
, Port
) then
6854 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6856 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6859 // Execute script when game loads:
6860 s
:= Find_Param_Value(pars
, '-exec');
6863 // if not isWadPath(s) then
6864 // s := GameDir + '/' + 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 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6877 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6882 if IOResult
<> 0 then
6884 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6885 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6889 if Pos('#', s
) <> 1 then // script comment
6890 g_Console_Process(s
, True);
6901 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6902 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6903 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6904 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6906 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6907 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6908 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6909 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6911 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6912 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6914 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6915 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6917 {$IFDEF ENABLE_HOLMES}
6918 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6921 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6923 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6924 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6926 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6927 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6929 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6930 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6931 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6932 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
6933 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6934 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6935 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6936 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6937 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');