1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 g_base
, g_basic
, g_player
, r_graphics
, g_res_downloader
,
24 g_sound
, g_gui
, utils
, md5
, mempool
, xprofiler
,
28 TGameSettings
= record
35 ItemRespawnTime
: Word;
46 TDelayedEvent
= record
55 Sound
: TPlayableSound
;
56 Tags
: Array of String;
60 TPlayerSettings
= record
79 function g_Game_IsNet(): Boolean;
80 function g_Game_IsServer(): Boolean;
81 function g_Game_IsClient(): Boolean;
82 procedure g_Game_Init();
83 procedure g_Game_Free (freeTextures
: Boolean=true);
84 procedure g_Game_LoadData();
85 procedure g_Game_FreeData();
86 procedure g_Game_Update();
87 procedure g_Game_PreUpdate();
88 procedure g_Game_Quit();
89 procedure g_Game_SetupScreenSize();
90 function g_Game_ModeToText(Mode
: Byte): string;
91 function g_Game_TextToMode(Mode
: string): Byte;
92 procedure g_Game_ExecuteEvent(Name
: String);
93 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
94 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
95 procedure g_Game_RemovePlayer();
96 procedure g_Game_Spectate();
97 procedure g_Game_SpectateCenterView();
98 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
99 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
100 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
101 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
102 procedure g_Game_Restart();
103 procedure g_Game_RestartLevel();
104 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
105 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
106 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
107 procedure g_Game_ChangeMap(const MapPath
: String);
108 procedure g_Game_ExitLevel(const Map
: AnsiString);
109 function g_Game_GetFirstMap(WAD
: String): String;
110 function g_Game_GetNextMap(): String;
111 procedure g_Game_NextLevel();
112 procedure g_Game_Pause(Enable
: Boolean);
113 procedure g_Game_HolmesPause(Enable
: Boolean);
114 procedure g_Game_InGameMenu(Show
: Boolean);
115 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
116 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
117 procedure g_Game_Message(Msg
: String; Time
: Word);
118 procedure g_Game_LoadMapList(FileName
: String);
119 procedure g_Game_PauseAllSounds(Enable
: Boolean);
120 procedure g_Game_StopAllSounds(all
: Boolean);
121 procedure g_Game_UpdateTriggerSounds();
122 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
123 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
124 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
125 procedure g_Game_Announce_KillCombo(Param
: Integer);
126 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
127 procedure g_Game_StartVote(Command
, Initiator
: string);
128 procedure g_Game_CheckVote
;
129 procedure g_TakeScreenShot(Filename
: string = '');
130 procedure g_FatalError(Text: String);
131 procedure g_SimpleError(Text: String);
132 function g_Game_IsTestMap(): Boolean;
133 procedure g_Game_DeleteTestMap();
134 procedure GameCVars(P
: SSArray
);
135 procedure PlayerSettingsCVars(P
: SSArray
);
136 procedure SystemCommands(P
: SSArray
);
137 procedure GameCommands(P
: SSArray
);
138 procedure GameCheats(P
: SSArray
);
139 procedure DebugCommands(P
: SSArray
);
140 procedure g_Game_Process_Params
;
141 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
142 procedure g_Game_StepLoading(Value
: Integer = -1);
143 procedure g_Game_ClearLoading();
144 procedure g_Game_SetDebugMode();
146 function IsActivePlayer(p
: TPlayer
): Boolean;
147 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
148 procedure SortGameStat(var stat
: TPlayerStatArray
);
150 procedure KeyPress (K
: Word);
151 procedure CharPress (C
: AnsiChar);
153 { procedure SetWinPause(Enable: Boolean); }
158 LOADING_SHOW_STEP
= 100;
159 LOADING_INTERLINE
= 20;
174 MESSAGE_DIKEY
= WM_USER
+ 1;
179 EXIT_ENDLEVELSINGLE
= 4;
180 EXIT_ENDLEVELCUSTOM
= 5;
182 GAME_OPTION_RESERVED
= 1;
183 GAME_OPTION_TEAMDAMAGE
= 2;
184 GAME_OPTION_ALLOWEXIT
= 4;
185 GAME_OPTION_WEAPONSTAY
= 8;
186 GAME_OPTION_MONSTERS
= 16;
187 GAME_OPTION_BOTVSPLAYER
= 32;
188 GAME_OPTION_BOTVSMONSTER
= 64;
189 GAME_OPTION_DMKEYS
= 128;
190 GAME_OPTION_TEAMHITTRACE
= 256;
191 GAME_OPTION_TEAMHITPROJECTILE
= 512;
192 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
197 STATE_INTERCUSTOM
= 3;
198 STATE_INTERSINGLE
= 4;
204 LMS_RESPAWN_NONE
= 0;
205 LMS_RESPAWN_WARMUP
= 1;
206 LMS_RESPAWN_FINAL
= 2;
223 CONFIG_FILENAME
= 'Doom2DF.cfg';
225 TEST_MAP_NAME
= '$$$_TEST_$$$';
227 STD_PLAYER_MODEL
= 'Doomer';
235 STATFILE_VERSION
= $03;
239 gGameSettings
: TGameSettings
;
240 gPlayer1Settings
: TPlayerSettings
;
241 gPlayer2Settings
: TPlayerSettings
;
243 gPlayerScreenSize
: TDFPoint
;
244 gPlayer1ScreenCoord
: TDFPoint
;
245 gPlayer2ScreenCoord
: TDFPoint
;
246 gPlayer1
: TPlayer
= nil;
247 gPlayer2
: TPlayer
= nil;
248 gPlayerDrawn
: TPlayer
= nil;
250 gLerpFactor
: Single = 1.0;
251 gSwitchGameMode
: Byte = GM_DM
;
252 gHearPoint1
, gHearPoint2
: THearPoint
;
253 gSoundEffectsDF
: Boolean = False;
254 gSoundTriggerTime
: Word = 0;
255 gAnnouncer
: Integer = ANNOUNCE_NONE
;
256 goodsnd
: array[0..3] of TPlayableSound
;
257 killsnd
: array[0..3] of TPlayableSound
;
258 hahasnd
: array[0..2] of TPlayableSound
;
259 sound_get_flag
: array[0..1] of TPlayableSound
;
260 sound_lost_flag
: array[0..1] of TPlayableSound
;
261 sound_ret_flag
: array[0..1] of TPlayableSound
;
262 sound_cap_flag
: array[0..1] of TPlayableSound
;
263 gBodyKillEvent
: Integer = -1;
264 gDefInterTime
: ShortInt = -1;
265 gInterEndTime
: LongWord = 0;
266 gInterTime
: LongWord = 0;
267 gServInterTime
: Byte = 0;
268 gGameStartTime
: LongWord = 0;
269 gTotalMonsters
: Integer = 0;
270 gPauseMain
: Boolean = false;
271 gPauseHolmes
: Boolean = false;
272 gShowTime
: Boolean = False;
273 gShowFPS
: Boolean = False;
274 gShowGoals
: Boolean = True;
275 gShowStat
: Boolean = True;
276 gShowPIDs
: Boolean = False;
277 gShowKillMsg
: Boolean = True;
278 gShowLives
: Boolean = True;
279 gShowPing
: Boolean = False;
280 gShowMap
: Boolean = False;
282 gState
: Byte = STATE_NONE
;
284 sWidth
, sHeight
: Word;
285 gSpectMode
: Byte = SPECT_NONE
;
286 gSpectHUD
: Boolean = True;
287 gSpectKeyPress
: Boolean = False;
288 gSpectX
: Integer = 0;
289 gSpectY
: Integer = 0;
290 gSpectStep
: Byte = 8;
291 gSpectViewTwo
: Boolean = False;
292 gSpectPID1
: Integer = -1;
293 gSpectPID2
: Integer = -1;
294 gSpectAuto
: Boolean = False;
295 gSpectAutoNext
: LongWord;
296 gSpectAutoStepX
: Integer;
297 gSpectAutoStepY
: Integer;
298 gMusic
: TMusic
= nil;
299 gLoadGameMode
: Boolean;
300 gCheats
: Boolean = False;
301 gMapOnce
: Boolean = False;
302 gMapToDelete
: String;
303 gTempDelete
: Boolean = False;
304 gLastMap
: Boolean = False;
307 gResolutionChange
: Boolean = False;
308 gRC_Width
, gRC_Height
: Integer;
309 gRC_FullScreen
, gRC_Maximized
: Boolean;
310 gLanguageChange
: Boolean = False;
311 gDebugMode
: Boolean = False;
312 g_debug_Sounds
: Boolean = False;
313 g_debug_Frames
: Boolean = False;
314 g_debug_WinMsgs
: Boolean = False;
315 g_debug_MonsterOff
: Boolean = False;
316 g_debug_BotAIOff
: Byte = 0;
317 g_debug_HealthBar
: Boolean = False;
318 g_Debug_Player
: Boolean = False;
319 gCoopMonstersKilled
: Word = 0;
320 gCoopSecretsFound
: Word = 0;
321 gCoopTotalMonstersKilled
: Word = 0;
322 gCoopTotalSecretsFound
: Word = 0;
323 gCoopTotalMonsters
: Word = 0;
324 gCoopTotalSecrets
: Word = 0;
325 gStatsOff
: Boolean = False;
326 gStatsPressed
: Boolean = False;
327 gExitByTrigger
: Boolean = False;
328 gNextMap
: String = '';
329 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
330 gLMSRespawnTime
: Cardinal = 0;
331 gLMSSoftSpawn
: Boolean = False;
332 gMissionFailed
: Boolean = False;
333 gVoteInProgress
: Boolean = False;
334 gVotePassed
: Boolean = False;
335 gVoteCommand
: string = '';
336 gVoteTimer
: Cardinal = 0;
337 gVoteCmdTimer
: Cardinal = 0;
338 gVoteCount
: Integer = 0;
339 gVoteTimeout
: Cardinal = 30;
340 gVoted
: Boolean = False;
341 gVotesEnabled
: Boolean = True;
342 gEvents
: Array of TGameEvent
;
343 gDelayedEvents
: Array of TDelayedEvent
;
344 gUseChatSounds
: Boolean = True;
345 gChatSounds
: Array of TChatSound
;
346 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
347 gInterReadyCount
: Integer = 0;
349 g_dbg_ignore_bounds
: Boolean = false;
350 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
351 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
353 // move button values:
354 // bits 0-1: l/r state:
355 // 0: neither left, nor right pressed
358 // bits 4-5: l/r state when strafe was pressed
359 P1MoveButton
: Byte = 0;
360 P2MoveButton
: Byte = 0;
362 g_profile_frame_update
: Boolean = false;
363 g_profile_frame_draw
: Boolean = false;
364 g_profile_collision
: Boolean = false;
365 g_profile_los
: Boolean = false;
366 g_profile_history_size
: Integer = 1000;
368 g_rlayer_back
: Boolean = true;
369 g_rlayer_step
: Boolean = true;
370 g_rlayer_wall
: Boolean = true;
371 g_rlayer_door
: Boolean = true;
372 g_rlayer_acid1
: Boolean = true;
373 g_rlayer_acid2
: Boolean = true;
374 g_rlayer_water
: Boolean = true;
375 g_rlayer_fore
: Boolean = true;
377 wNeedTimeReset
: Boolean = false;
379 procedure g_ResetDynlights ();
380 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
381 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
383 function conIsCheatsEnabled (): Boolean; inline;
384 function gPause (): Boolean; inline;
386 type (* private state *)
387 TEndCustomGameStat
= record
388 PlayerStat
: TPlayerStatArray
;
392 Map
, MapName
: String;
395 TEndSingleGameStat
= record
396 PlayerStat
: Array [0..1] of record
402 TotalSecrets
: Integer;
405 TLoadingStat
= record
409 Msgs
: Array of String;
411 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
415 x
, y
, radius
: Integer;
418 exploRadius
: Integer;
421 var (* private state *)
422 CustomStat
: TEndCustomGameStat
;
423 StatShotDone
: Boolean;
424 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
425 SingleStat
: TEndSingleGameStat
;
427 LoadingStat
: TLoadingStat
;
430 EndingGameCounter
: Byte;
432 g_playerLight
: Boolean;
433 g_dynLights
: array of TDynLight
= nil;
434 g_dynLightCount
: Integer = 0;
439 {$IFDEF ENABLE_HOLMES}
442 e_res
, g_window
, g_menu
, r_render
, r_textures
, r_animations
, r_gfx
, r_map
,
443 e_input
, e_log
, g_console
, r_console
, g_items
, g_map
, g_panel
,
444 g_playermodel
, g_gfx
, g_options
, Math
,
445 g_triggers
, g_monsters
, e_sound
, CONFIG
,
446 g_language
, g_net
, g_phys
,
447 ENet
, e_msg
, g_netmsg
, g_netmaster
,
448 sfs
, wadreader
, g_system
, r_playermodel
;
451 charbuff
: packed array [0..15] of AnsiChar = (
452 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
455 function Translit (const S
: AnsiString): AnsiString;
460 for i
:= 1 to Length(Result
) do
463 #
$C9: Result
[i
] := 'Q';
464 #
$D6: Result
[i
] := 'W';
465 #
$D3: Result
[i
] := 'E';
466 #
$CA: Result
[i
] := 'R';
467 #
$C5: Result
[i
] := 'T';
468 #
$CD: Result
[i
] := 'Y';
469 #
$C3: Result
[i
] := 'U';
470 #
$D8: Result
[i
] := 'I';
471 #
$D9: Result
[i
] := 'O';
472 #
$C7: Result
[i
] := 'P';
473 #
$D5: Result
[i
] := '['; //Chr(219);
474 #
$DA: Result
[i
] := ']'; //Chr(221);
475 #
$D4: Result
[i
] := 'A';
476 #
$DB: Result
[i
] := 'S';
477 #
$C2: Result
[i
] := 'D';
478 #
$C0: Result
[i
] := 'F';
479 #
$CF: Result
[i
] := 'G';
480 #
$D0: Result
[i
] := 'H';
481 #
$CE: Result
[i
] := 'J';
482 #
$CB: Result
[i
] := 'K';
483 #
$C4: Result
[i
] := 'L';
484 #
$C6: Result
[i
] := ';'; //Chr(186);
485 #
$DD: Result
[i
] := #39; //Chr(222);
486 #
$DF: Result
[i
] := 'Z';
487 #
$D7: Result
[i
] := 'X';
488 #
$D1: Result
[i
] := 'C';
489 #
$CC: Result
[i
] := 'V';
490 #
$C8: Result
[i
] := 'B';
491 #
$D2: Result
[i
] := 'N';
492 #
$DC: Result
[i
] := 'M';
493 #
$C1: Result
[i
] := ','; //Chr(188);
494 #
$DE: Result
[i
] := '.'; //Chr(190);
500 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
505 ls2
:= Translit(CheatRus
[ct
]);
506 if length(ls1
) = 0 then ls1
:= '~';
507 if length(ls2
) = 0 then ls2
:= '~';
509 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
510 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
511 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
512 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
514 if ct = I_GAME_CHEAT_JETPACK then
516 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
517 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
518 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
519 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
520 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
521 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
537 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
538 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
539 or g_Game_IsNet then Exit;
541 if not gGameOn
then exit
;
542 if not conIsCheatsEnabled
then exit
;
544 s
:= 'SOUND_GAME_RADIO';
547 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
549 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
550 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
554 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
556 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
557 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
561 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
563 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
564 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
568 if CheckCheat(I_GAME_CHEAT_DEATH
) then
570 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
571 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
572 s
:= 'SOUND_MONSTER_HAHA';
576 if CheckCheat(I_GAME_CHEAT_DOORS
) then
578 g_Triggers_OpenAll();
582 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
584 if gTriggers
<> nil then
585 for a
:= 0 to High(gTriggers
) do
586 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
588 gExitByTrigger
:= True;
589 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
590 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
596 s2
:= Copy(charbuff
, 15, 2);
597 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
599 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
607 if CheckCheat(I_GAME_CHEAT_FLY
) then
613 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
615 VEL_JUMP
:= 30-VEL_JUMP
;
619 if CheckCheat(I_GAME_CHEAT_SPEED
) then
621 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
625 if CheckCheat(I_GAME_CHEAT_SUIT
) then
627 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
628 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
632 if CheckCheat(I_GAME_CHEAT_AIR
) then
634 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
635 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
639 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
641 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
642 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
646 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
648 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
649 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
653 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
655 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
656 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
660 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
662 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
663 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
667 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
669 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
670 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
673 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
675 gAimLine
:= not gAimLine
;
678 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
680 gShowMap
:= not gShowMap
;
690 procedure KeyPress (K
: Word);
700 if (g_ActiveWindow
<> nil) then
702 Msg
.Msg
:= WM_KEYDOWN
;
703 Msg
.WParam
:= VK_ESCAPE
;
704 g_ActiveWindow
.OnMessage(Msg
);
705 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
707 else if (gState
<> STATE_FOLD
) then
709 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
711 g_Game_InGameMenu(True);
713 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
715 if (gState
<> STATE_MENU
) then
717 if (NetMode
<> NET_NONE
) then
719 g_Game_StopAllSounds(True);
721 gState
:= STATE_MENU
;
725 g_GUI_ShowWindow('MainMenu');
726 g_Sound_PlayEx('MENU_OPEN');
731 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
732 begin // <F2> .. <F6> � <F12>
733 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
735 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
736 if (not g_Game_IsNet
) then g_Game_Pause(True);
738 IK_F2
: g_Menu_Show_SaveMenu();
739 IK_F3
: g_Menu_Show_LoadMenu();
740 IK_F4
: g_Menu_Show_GameSetGame();
741 IK_F5
: g_Menu_Show_OptionsVideo();
742 IK_F6
: g_Menu_Show_OptionsSound();
743 IK_F7
: g_Menu_Show_EndGameMenu();
744 IK_F10
: g_Menu_Show_QuitGameMenu();
751 gJustChatted
:= False;
752 if gConsoleShow
or gChatShow
then
754 g_Console_Control(K
);
756 else if (g_ActiveWindow
<> nil) then
758 Msg
.Msg
:= WM_KEYDOWN
;
760 g_ActiveWindow
.OnMessage(Msg
);
762 else if (gState
= STATE_MENU
) then
764 g_GUI_ShowWindow('MainMenu');
765 g_Sound_PlayEx('MENU_OPEN');
772 procedure CharPress (C
: AnsiChar);
777 if gConsoleShow
or gChatShow
then
781 else if (g_ActiveWindow
<> nil) then
784 Msg
.WParam
:= Ord(C
);
785 g_ActiveWindow
.OnMessage(Msg
);
789 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
790 charbuff
[15] := upcase1251(C
);
796 // ////////////////////////////////////////////////////////////////////////// //
797 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
799 procedure g_ResetDynlights ();
803 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
805 for idx
:= 0 to g_dynLightCount
-1 do
807 if g_dynLights
[idx
].exploCount
= -666 then
814 Inc(g_dynLights
[idx
].exploCount
);
815 if (g_dynLights
[idx
].exploCount
< 10) then
817 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
818 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
819 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
820 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
825 g_dynLightCount
:= lnum
;
828 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
830 if not gwin_has_stencil
then exit
;
831 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
832 g_dynLights
[g_dynLightCount
].x
:= x
;
833 g_dynLights
[g_dynLightCount
].y
:= y
;
834 g_dynLights
[g_dynLightCount
].radius
:= radius
;
835 g_dynLights
[g_dynLightCount
].r
:= r
;
836 g_dynLights
[g_dynLightCount
].g
:= g
;
837 g_dynLights
[g_dynLightCount
].b
:= b
;
838 g_dynLights
[g_dynLightCount
].a
:= a
;
839 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
840 Inc(g_dynLightCount
);
843 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
845 if not gwin_has_stencil
then exit
;
846 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
847 g_dynLights
[g_dynLightCount
].x
:= x
;
848 g_dynLights
[g_dynLightCount
].y
:= y
;
849 g_dynLights
[g_dynLightCount
].radius
:= 0;
850 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
851 g_dynLights
[g_dynLightCount
].r
:= r
;
852 g_dynLights
[g_dynLightCount
].g
:= g
;
853 g_dynLights
[g_dynLightCount
].b
:= b
;
854 g_dynLights
[g_dynLightCount
].a
:= 0;
855 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
856 Inc(g_dynLightCount
);
859 // ////////////////////////////////////////////////////////////////////////// //
860 function conIsCheatsEnabled (): Boolean; inline;
863 if g_Game_IsNet
then exit
;
864 if not gDebugMode
then
866 //if not gCheats then exit;
867 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
868 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
873 // ////////////////////////////////////////////////////////////////////////// //
875 TParamStrValue
= record
880 TParamStrValues
= Array of TParamStrValue
;
883 INTER_ACTION_TEXT
= 1;
884 INTER_ACTION_PIC
= 2;
885 INTER_ACTION_MUSIC
= 3;
890 DataLoaded
: Boolean = False;
892 MessageLineLength
: Integer = 80;
893 MapList
: SSArray
= nil;
894 MapIndex
: Integer = -1;
895 InterReadyTime
: Integer = -1;
896 StatDate
: string = '';
902 text: Array of ShortString;
903 anim
: Array of ShortString;
904 pic
: Array of ShortString;
905 mus
: Array of ShortString;
907 triggers
: Array of record
909 actions
: Array of record
910 action
, p1
, p2
: Integer;
913 cur_trigger
: Integer;
926 function Compare(a
, b
: TPlayerStat
): Integer;
928 if a
.Spectator
then Result
:= 1
929 else if b
.Spectator
then Result
:= -1
930 else if a
.Frags
< b
.Frags
then Result
:= 1
931 else if a
.Frags
> b
.Frags
then Result
:= -1
932 else if a
.Deaths
< b
.Deaths
then Result
:= -1
933 else if a
.Deaths
> b
.Deaths
then Result
:= 1
934 else if a
.Kills
< b
.Kills
then Result
:= -1
938 procedure SortGameStat(var stat
: TPlayerStatArray
);
943 if stat
= nil then Exit
;
945 for I
:= High(stat
) downto Low(stat
) do
946 for J
:= Low(stat
) to High(stat
) - 1 do
947 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
950 stat
[J
] := stat
[J
+ 1];
955 // saves a shitty CSV containing the game stats passed to it
956 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
959 dir
, fname
, map
, mode
, etime
: String;
963 dir
:= e_GetWriteableDir(StatsDirs
);
964 // stats are placed in stats/yy/mm/dd/*.csv
965 fname
:= e_CatPath(dir
, Path
);
966 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
967 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
968 AssignFile(s
, fname
);
971 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
972 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
973 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
974 mode
:= g_Game_ModeToText(Stat
.GameMode
);
975 etime
:= Format('%d:%.2d:%.2d', [
976 Stat
.GameTime
div 1000 div 3600,
977 (Stat
.GameTime
div 1000 div 60) mod 60,
978 Stat
.GameTime
div 1000 mod 60
980 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
981 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
987 gGameSettings
.TimeLimit
,
988 gGameSettings
.GoalLimit
,
989 gGameSettings
.Options
,
991 Length(Stat
.PlayerStat
)
993 // line 2: game specific shit
994 // if it's a team game: red score, blue score
995 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
997 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
999 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
1000 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1002 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1003 // lines 3-...: team, player name, frags, deaths
1004 WriteLn(s
, 'team,name,frags,deaths');
1005 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1006 with Stat
.PlayerStat
[I
] do
1007 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1009 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1012 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1017 function g_Game_ModeToText(Mode
: Byte): string;
1021 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1022 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1023 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1024 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1025 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1029 function g_Game_TextToMode(Mode
: string): Byte;
1032 Mode
:= UpperCase(Mode
);
1033 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1038 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1043 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1048 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1053 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1055 Result
:= GM_SINGLE
;
1060 function g_Game_IsNet(): Boolean;
1062 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1065 function g_Game_IsServer(): Boolean;
1067 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1070 function g_Game_IsClient(): Boolean;
1072 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1075 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1082 Result
.name
:= ExtractFileName(WAD
);
1083 Result
.description
:= '';
1084 Result
.author
:= '';
1086 w
:= TWADFile
.Create();
1089 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1095 cfg
:= TConfig
.CreateMem(p
, len
);
1096 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1097 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1098 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1099 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1105 procedure g_Game_FreeWAD();
1109 for a
:= 0 to High(MegaWAD
.res
.pic
) do
1110 if MegaWAD
.res
.pic
[a
] <> '' then
1111 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
1113 for a
:= 0 to High(MegaWAD
.res
.mus
) do
1114 if MegaWAD
.res
.mus
[a
] <> '' then
1115 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
1117 MegaWAD
.res
.pic
:= nil;
1118 MegaWAD
.res
.text := nil;
1119 MegaWAD
.res
.anim
:= nil;
1120 MegaWAD
.res
.mus
:= nil;
1121 MegaWAD
.triggers
:= nil;
1123 g_Texture_Delete('TEXTURE_endpic');
1124 g_Sound_Delete('MUSIC_endmus');
1126 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1127 gGameSettings
.WAD
:= '';
1130 procedure g_Game_LoadWAD(WAD
: string);
1139 gGameSettings
.WAD
:= WAD
;
1140 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1143 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1145 w
:= TWADFile
.Create();
1148 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1154 cfg
:= TConfig
.CreateMem(p
, len
);
1159 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
1160 if s = '' then Break;
1163 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
1164 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
1166 g_Texture_CreateWADEx(s, s);
1172 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
1173 if s = '' then Break;
1176 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
1177 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
1179 g_Music_CreateWADEx(s, s);
1182 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1183 if MegaWAD
.endpic
<> '' then
1185 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1186 g_Texture_CreateWADEx('TEXTURE_endpic', s
, gTextureFilter
);
1188 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1189 if MegaWAD
.endmus
<> '' then
1191 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1192 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1200 {procedure start_trigger(t: string);
1204 function next_trigger(): Boolean;
1208 procedure DisableCheats();
1214 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1215 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1216 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1217 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1219 {$IF DEFINED(D2F_DEBUG)}
1220 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1221 gAimLine
:= g_dbg_aimline_on
;
1225 procedure g_Game_ExecuteEvent(Name
: String);
1231 if gEvents
= nil then
1233 for a
:= 0 to High(gEvents
) do
1234 if gEvents
[a
].Name
= Name
then
1236 if gEvents
[a
].Command
<> '' then
1237 g_Console_Process(gEvents
[a
].Command
, True);
1242 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1247 if gDelayedEvents
<> nil then
1248 for a
:= 0 to High(gDelayedEvents
) do
1249 if not gDelayedEvents
[a
].Pending
then
1256 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1257 n
:= High(gDelayedEvents
);
1259 gDelayedEvents
[n
].Pending
:= True;
1260 gDelayedEvents
[n
].DEType
:= DEType
;
1261 gDelayedEvents
[n
].DENum
:= Num
;
1262 gDelayedEvents
[n
].DEStr
:= Str
;
1263 if DEType
= DE_GLOBEVENT
then
1264 gDelayedEvents
[n
].Time
:= (GetTickCount64() {div 1000}) + Time
1266 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1270 procedure EndGame();
1276 if g_Game_IsNet
and g_Game_IsServer
then
1277 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1280 gPauseMain
:= false;
1281 gPauseHolmes
:= false;
1284 g_Game_StopAllSounds(False);
1289 EndingGameCounter
:= 0;
1290 g_ActiveWindow
:= nil;
1292 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1293 gLMSRespawnTime
:= 0;
1296 EXIT_SIMPLE
: // Выход через меню или конец теста
1301 begin // Это был тест
1305 begin // Выход в главное меню
1306 gMusic
.SetByName('MUSIC_MENU');
1308 if gState
<> STATE_SLIST
then
1310 g_GUI_ShowWindow('MainMenu');
1311 gState
:= STATE_MENU
;
1314 // Обновляем список серверов
1315 slReturnPressed
:= True;
1316 if g_Net_Slist_Fetch(slCurrent
) then
1318 if slCurrent
= nil then
1319 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1322 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1323 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1326 g_Game_ExecuteEvent('ongameend');
1330 EXIT_RESTART
: // Начать уровень сначала
1332 if not g_Game_IsClient
then g_Game_Restart();
1335 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1337 // Статистика Своей игры:
1338 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1340 CustomStat
.GameTime
:= gTime
;
1341 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1342 CustomStat
.MapName
:= gMapInfo
.Name
;
1343 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1344 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1345 CustomStat
.TeamStat
:= gTeamStat
;
1347 CustomStat
.PlayerStat
:= nil;
1349 // Статистика игроков:
1350 if gPlayers
<> nil then
1352 for a
:= 0 to High(gPlayers
) do
1353 if gPlayers
[a
] <> nil then
1355 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1356 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1359 Name
:= gPlayers
[a
].Name
;
1360 Frags
:= gPlayers
[a
].Frags
;
1361 Deaths
:= gPlayers
[a
].Death
;
1362 Kills
:= gPlayers
[a
].Kills
;
1363 Team
:= gPlayers
[a
].Team
;
1364 Color
:= gPlayers
[a
].Model
.Color
;
1365 Spectator
:= gPlayers
[a
].FSpectator
;
1369 SortGameStat(CustomStat
.PlayerStat
);
1371 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1374 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1375 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1376 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1377 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1379 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1382 StatShotDone
:= False;
1385 g_Game_ExecuteEvent('onmapend');
1386 if not g_Game_IsClient
then g_Player_ResetReady
;
1387 gInterReadyCount
:= 0;
1389 // Затухающий экран:
1390 EndingGameCounter
:= 255;
1391 gState
:= STATE_FOLD
;
1393 if gDefInterTime
< 0 then
1394 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1396 gInterEndTime
:= gDefInterTime
* 1000;
1399 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1401 // Статистика Одиночной игры:
1402 SingleStat
.GameTime
:= gTime
;
1403 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1404 SingleStat
.TotalSecrets
:= gSecretsCount
;
1405 // Статистика первого игрока:
1406 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1407 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1408 // Статистика второго игрока (если есть):
1409 if SingleStat
.TwoPlayers
then
1411 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1412 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1415 g_Game_ExecuteEvent('onmapend');
1418 if gNextMap
<> '' then
1420 gMusic
.SetByName('MUSIC_INTERMUS');
1422 gState
:= STATE_INTERSINGLE
;
1425 g_Game_ExecuteEvent('oninter');
1427 else // Больше нет карт
1429 // Затухающий экран:
1430 EndingGameCounter
:= 255;
1431 gState
:= STATE_FOLD
;
1436 // Окончание обработано:
1437 if gExit
<> EXIT_QUIT
then
1441 procedure g_Game_Init();
1445 gTempDelete
:= False;
1447 sfsGCDisable(); // temporary disable removing of temporary volumes
1450 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE', gTextureFilter
);
1451 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER', gTextureFilter
);
1452 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN', gTextureFilter
);
1453 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU', gTextureFilter
);
1455 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1456 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1457 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1459 g_Game_ClearLoading();
1460 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1461 g_Game_SetLoadingText('', 0, False);
1463 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1466 gPauseMain
:= false;
1467 gPauseHolmes
:= false;
1470 {e_MouseInfo.Accel := 1.0;}
1472 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1475 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1476 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1477 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1478 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1479 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1481 gMusic
:= TMusic
.Create();
1482 gMusic
.SetByName('MUSIC_MENU');
1485 gGameSettings
.WarmupTime
:= 30;
1487 gState
:= STATE_MENU
;
1489 SetLength(gEvents
, 6);
1490 gEvents
[0].Name
:= 'ongamestart';
1491 gEvents
[1].Name
:= 'ongameend';
1492 gEvents
[2].Name
:= 'onmapstart';
1493 gEvents
[3].Name
:= 'onmapend';
1494 gEvents
[4].Name
:= 'oninter';
1495 gEvents
[5].Name
:= 'onwadend';
1497 sfsGCEnable(); // enable releasing unused volumes
1501 procedure g_Game_Free(freeTextures
: Boolean=true);
1503 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1504 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1506 g_Map_Free(freeTextures
);
1508 g_Player_RemoveAllCorpses();
1510 gGameSettings
.GameType
:= GT_NONE
;
1511 if gGameSettings
.GameMode
= GM_SINGLE
then
1512 gGameSettings
.GameMode
:= GM_DM
;
1513 gSwitchGameMode
:= gGameSettings
.GameMode
;
1516 gExitByTrigger
:= False;
1519 function IsActivePlayer(p
: TPlayer
): Boolean;
1524 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1527 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1533 if gPlayers
= nil then
1537 for a
:= Low(gPlayers
) to High(gPlayers
) do
1538 if IsActivePlayer(gPlayers
[a
]) then
1540 SetLength(ids
, Length(ids
) + 1);
1541 ids
[High(ids
)] := gPlayers
[a
].UID
;
1542 if gPlayers
[a
].UID
= Skip
then
1545 if Length(ids
) = 0 then
1550 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1553 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1559 if gPlayers
= nil then
1563 for a
:= Low(gPlayers
) to High(gPlayers
) do
1564 if IsActivePlayer(gPlayers
[a
]) then
1566 SetLength(ids
, Length(ids
) + 1);
1567 ids
[High(ids
)] := gPlayers
[a
].UID
;
1568 if gPlayers
[a
].UID
= Skip
then
1571 if Length(ids
) = 0 then
1574 Result
:= ids
[Length(ids
) - 1]
1576 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1579 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1585 if gPlayers
= nil then
1589 for a
:= Low(gPlayers
) to High(gPlayers
) do
1590 if IsActivePlayer(gPlayers
[a
]) then
1592 SetLength(ids
, Length(ids
) + 1);
1593 ids
[High(ids
)] := gPlayers
[a
].UID
;
1594 if gPlayers
[a
].UID
= Skip
then
1597 if Length(ids
) = 0 then
1599 if Length(ids
) = 1 then
1604 Result
:= ids
[Random(Length(ids
))];
1606 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1608 Result
:= ids
[Random(Length(ids
))];
1613 function GetRandomSpectMode(Current
: Byte): Byte;
1620 0: Result
:= SPECT_STATS
;
1621 1: Result
:= SPECT_MAPVIEW
;
1622 2: Result
:= SPECT_MAPVIEW
;
1623 3: Result
:= SPECT_PLAYERS
;
1624 4: Result
:= SPECT_PLAYERS
;
1625 5: Result
:= SPECT_PLAYERS
;
1626 6: Result
:= SPECT_PLAYERS
;
1628 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1632 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1638 if (plr
= nil) then exit
;
1639 if (p
= 2) then time
:= 1000 else time
:= 1;
1640 strafeDir
:= MoveButton
shr 4;
1641 MoveButton
:= MoveButton
and $0F;
1643 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1644 MoveButton
:= 1 // Нажата только "Влево"
1645 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1646 MoveButton
:= 2 // Нажата только "Вправо"
1647 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1648 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1650 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1651 if MoveButton
= 1 then
1652 plr
.PressKey(KEY_LEFT
, time
)
1653 else if MoveButton
= 2 then
1654 plr
.PressKey(KEY_RIGHT
, time
);
1656 // if we have "strafe" key, turn off old strafe mechanics
1657 if gPlayerAction
[p
, ACTION_STRAFE
] then
1659 // new strafe mechanics
1660 if (strafeDir
= 0) then
1661 strafeDir
:= MoveButton
; // start strafing
1662 // now set direction according to strafe (reversed)
1663 if (strafeDir
= 2) then
1664 plr
.SetDirection(TDirection
.D_LEFT
)
1665 else if (strafeDir
= 1) then
1666 plr
.SetDirection(TDirection
.D_RIGHT
)
1670 strafeDir
:= 0; // not strafing anymore
1671 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1672 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1673 plr
.SetDirection(TDirection
.D_LEFT
)
1674 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1675 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1676 plr
.SetDirection(TDirection
.D_RIGHT
)
1677 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1678 else if MoveButton
<> 0 then
1679 plr
.SetDirection(TDirection(MoveButton
-1))
1682 // fix movebutton state
1683 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1685 // Остальные клавиши:
1686 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1687 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1688 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1689 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1690 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1691 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1692 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1694 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1695 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1697 for i
:= WP_FIRST
to WP_LAST
do
1699 if gSelectWeapon
[p
, i
] then
1701 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1702 gSelectWeapon
[p
, i
] := False
1706 // HACK: add dynlight here
1707 if gwin_k8_enable_light_experiments
then
1709 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1711 g_playerLight
:= true;
1713 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1715 g_playerLight
:= false;
1719 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1722 // HACK: don't have a "key was pressed" function
1723 procedure InterReady();
1725 if InterReadyTime
> gTime
then Exit
;
1726 InterReadyTime
:= gTime
+ 3000;
1727 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1730 procedure g_Game_PreUpdate();
1732 // these are in separate PreUpdate functions because they can interact during Update()
1733 // and are synced over the net
1734 // we don't care that much about corpses and gibs
1735 g_Player_PreUpdate();
1736 g_Monsters_PreUpdate();
1737 g_Items_PreUpdate();
1738 g_Weapon_PreUpdate();
1741 procedure g_Game_Update();
1743 Msg
: g_gui
.TMessage
;
1749 function sendMonsPos (mon
: TMonster
): Boolean;
1751 result
:= false; // don't stop
1752 // this will also reset "need-send" flag
1753 if mon
.gncNeedSend
then
1755 MH_SEND_MonsterPos(mon
.UID
);
1757 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1759 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1761 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1763 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1767 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1769 result
:= false; // don't stop
1770 // this will also reset "need-send" flag
1771 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1775 reliableUpdate
: Boolean;
1780 // Пора выключать игру:
1781 if gExit
= EXIT_QUIT
then
1783 // Игра закончилась - обрабатываем:
1787 if gExit
= EXIT_QUIT
then
1791 // Читаем клавиатуру и джойстик, если окно активно
1792 // no need to, as we'll do it in event handler
1794 // Обновляем консоль (движение и сообщения):
1798 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1800 gExit
:= EXIT_SIMPLE
;
1805 // process master server communications
1806 g_Net_Slist_Pulse();
1809 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1810 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1811 STATE_INTERTEXT
, // Текст между уровнями
1812 STATE_INTERPIC
: // Картинка между уровнями
1814 if g_Game_IsNet
and g_Game_IsServer
then
1816 gInterTime
:= gInterTime
+ GAME_TICK
;
1817 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1818 if a
<> gServInterTime
then
1820 gServInterTime
:= a
;
1821 MH_SEND_TimeSync(gServInterTime
);
1825 if (not g_Game_IsClient
) and
1829 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1830 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1831 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1832 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1834 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1835 and (g_ActiveWindow
= nil)
1837 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1840 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1841 g_Game_StopAllSounds(True);
1843 if gMapOnce
then // Это был тест
1844 gExit
:= EXIT_SIMPLE
1846 if gNextMap
<> '' then // Переходим на следующую карту
1847 g_Game_ChangeMap(gNextMap
)
1848 else // Следующей карты нет
1850 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1852 // Выход в главное меню:
1854 g_GUI_ShowWindow('MainMenu');
1855 gMusic
.SetByName('MUSIC_MENU');
1857 gState
:= STATE_MENU
;
1860 // Финальная картинка:
1861 g_Game_ExecuteEvent('onwadend');
1863 if not gMusic
.SetByName('MUSIC_endmus') then
1864 gMusic
.SetByName('MUSIC_STDENDMUS');
1866 gState
:= STATE_ENDPIC
;
1868 g_Game_ExecuteEvent('ongameend');
1873 else if g_Game_IsClient
and
1876 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1877 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1878 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1879 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1881 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1882 and (g_ActiveWindow
= nil)
1890 if gState
= STATE_INTERTEXT
then
1891 if InterText
.counter
> 0 then
1892 InterText
.counter
:= InterText
.counter
- 1;
1895 STATE_FOLD
: // Затухание экрана
1897 if EndingGameCounter
= 0 then
1899 // Закончился уровень в Своей игре:
1900 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1902 InterReadyTime
:= -1;
1903 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1905 g_Game_ExecuteEvent('onwadend');
1906 if not gMusic
.SetByName('MUSIC_endmus') then
1907 gMusic
.SetByName('MUSIC_STDENDMUS');
1910 gMusic
.SetByName('MUSIC_ROUNDMUS');
1913 gState
:= STATE_INTERCUSTOM
;
1916 else // Закончилась последняя карта в Одиночной игре
1918 gMusic
.SetByName('MUSIC_INTERMUS');
1920 gState
:= STATE_INTERSINGLE
;
1923 g_Game_ExecuteEvent('oninter');
1926 DecMin(EndingGameCounter
, 6, 0);
1929 STATE_ENDPIC
: // Картинка окончания мегаВада
1931 if gMapOnce
then // Это был тест
1933 gExit
:= EXIT_SIMPLE
;
1939 g_Serverlist_Control(slCurrent
, slTable
);
1942 // Статистика по Tab:
1944 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1947 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1949 // Время += 28 миллисекунд:
1950 gTime
:= gTime
+ GAME_TICK
;
1952 // Сообщение посередине экрана:
1953 if MessageTime
= 0 then
1955 if MessageTime
> 0 then
1956 MessageTime
:= MessageTime
- 1;
1958 if (g_Game_IsServer
) then
1960 // Был задан лимит времени:
1961 if (gGameSettings
.TimeLimit
> 0) then
1962 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1963 begin // Он прошел => конец уровня
1968 // Надо респавнить игроков в LMS:
1969 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1970 g_Game_RestartRound(gLMSSoftSpawn
);
1972 // Проверим результат голосования, если время прошло
1973 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1975 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1977 g_Console_Process(gVoteCommand
);
1979 gVotePassed
:= False;
1982 // Замеряем время захвата флагов
1983 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1984 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1985 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1986 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1988 // Был задан лимит побед:
1989 if (gGameSettings
.GoalLimit
> 0) then
1993 if gGameSettings
.GameMode
= GM_DM
then
1994 begin // В DM ищем игрока с max фрагами
1995 for i
:= 0 to High(gPlayers
) do
1996 if gPlayers
[i
] <> nil then
1997 if gPlayers
[i
].Frags
> b
then
1998 b
:= gPlayers
[i
].Frags
;
2001 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2002 begin // В CTF/TDM выбираем команду с наибольшим счетом
2003 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
2006 // Лимит побед набран => конец уровня:
2007 if b
>= gGameSettings
.GoalLimit
then
2014 // Обрабатываем клавиши игроков:
2015 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2016 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2017 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2019 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2020 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2021 end // if not console
2024 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2026 // process weapon switch queue
2030 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2031 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2033 if not gSpectKeyPress
then
2035 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2037 // switch spect mode
2039 SPECT_NONE
: ; // not spectator
2041 SPECT_MAPVIEW
: Inc(gSpectMode
);
2042 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2044 gSpectKeyPress
:= True;
2046 if (gSpectMode
= SPECT_MAPVIEW
)
2047 and (not gSpectAuto
) then
2049 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2050 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2051 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2052 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2053 if gPlayerAction
[0, ACTION_LOOKUP
] then
2054 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2055 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2056 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2057 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2060 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2061 gSpectKeyPress
:= True;
2063 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2066 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2067 gSpectKeyPress
:= True;
2070 if (gSpectMode
= SPECT_PLAYERS
)
2071 and (not gSpectAuto
) then
2073 if gPlayerAction
[0, ACTION_LOOKUP
] then
2076 gSpectViewTwo
:= True;
2077 gSpectKeyPress
:= True;
2079 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2081 // remove second view
2082 gSpectViewTwo
:= False;
2083 gSpectKeyPress
:= True;
2085 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2087 // prev player (view 1)
2088 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2089 gSpectKeyPress
:= True;
2091 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2093 // next player (view 1)
2094 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2095 gSpectKeyPress
:= True;
2097 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2099 // prev player (view 2)
2100 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2101 gSpectKeyPress
:= True;
2103 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2105 // next player (view 2)
2106 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2107 gSpectKeyPress
:= True;
2110 if gPlayerAction
[0, ACTION_ATTACK
] then
2112 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2115 gSpectAutoNext
:= 0;
2116 gSpectViewTwo
:= False;
2117 gSpectKeyPress
:= True;
2122 gSpectMode
:= SPECT_STATS
;
2123 gSpectAuto
:= False;
2124 gSpectKeyPress
:= True;
2129 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2130 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2131 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2132 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2133 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2134 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2135 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2136 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2137 gSpectKeyPress
:= False;
2141 if gSpectMode
= SPECT_MAPVIEW
then
2143 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2145 gSpectAutoNext
:= gTime
2148 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2150 gSpectAutoNext
:= gTime
2154 if gSpectAutoNext
<= gTime
then
2156 if gSpectAutoNext
> 0 then
2158 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2162 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2163 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2164 gSpectAutoStepX
:= Random(9) - 4;
2165 gSpectAutoStepY
:= Random(9) - 4;
2166 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2167 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2168 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2169 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2170 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2171 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2175 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2180 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2181 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2182 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2188 // Обновляем все остальное:
2191 g_Triggers_Update();
2193 g_Monsters_Update();
2196 g_Player_UpdateAll();
2197 g_Player_UpdatePhysicalObjects();
2199 // server: send newly spawned monsters unconditionally
2200 if (gGameSettings
.GameType
= GT_SERVER
) then
2202 if (Length(gMonstersSpawned
) > 0) then
2204 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2205 SetLength(gMonstersSpawned
, 0);
2209 if (gSoundTriggerTime
> 8) then
2211 g_Game_UpdateTriggerSounds();
2212 gSoundTriggerTime
:= 0;
2216 Inc(gSoundTriggerTime
);
2219 if (NetMode
= NET_SERVER
) then
2221 Inc(NetTimeToUpdate
);
2222 Inc(NetTimeToReliable
);
2224 // send monster updates
2225 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2227 // send all monsters (periodic sync)
2228 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2230 for I
:= 0 to High(gPlayers
) do
2232 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2235 g_Mons_ForEach(sendMonsPos
);
2237 if reliableUpdate
then
2239 NetTimeToReliable
:= 0;
2240 NetTimeToUpdate
:= NetUpdateRate
;
2244 NetTimeToUpdate
:= 0;
2249 // send only mosters with some unexpected changes
2250 g_Mons_ForEach(sendMonsPosUnexpected
);
2253 // send unexpected platform changes
2254 g_Map_NetSendInterestingPanels();
2256 g_Net_Slist_ServerUpdate();
2258 if NetUseMaster then
2260 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2262 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2264 NetTimeToMaster := gTime + NetMasterRate;
2269 else if (NetMode
= NET_CLIENT
) then
2271 MC_SEND_PlayerPos();
2273 end; // if gameOn ...
2275 // Активно окно интерфейса - передаем клавиши ему:
2276 if g_ActiveWindow
<> nil then
2278 w
:= e_GetFirstKeyPressed();
2280 if (w
<> IK_INVALID
) then
2282 Msg
.Msg
:= MESSAGE_DIKEY
;
2284 g_ActiveWindow
.OnMessage(Msg
);
2287 // Если оно от этого не закрылось, то обновляем:
2288 if g_ActiveWindow
<> nil then
2289 g_ActiveWindow
.Update();
2291 // Нужно сменить разрешение:
2292 if gResolutionChange
then
2294 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2296 gResolutionChange
:= False;
2297 g_ActiveWindow
:= nil;
2300 // Нужно сменить язык:
2301 if gLanguageChange
then
2303 //e_WriteLog('Read language file', MSG_NOTIFY);
2304 //g_Language_Load(DataDir + gLanguage + '.txt');
2305 g_Language_Set(gLanguage
);
2309 gLanguageChange
:= False;
2313 // Горячая клавиша для вызова меню выхода из игры (F10):
2314 if e_KeyPressed(IK_F10
) and
2316 (not gConsoleShow
) and
2317 (g_ActiveWindow
= nil) then
2322 Time
:= GetTickCount64() {div 1000};
2324 // Обработка отложенных событий:
2325 if gDelayedEvents
<> nil then
2326 for a
:= 0 to High(gDelayedEvents
) do
2327 if gDelayedEvents
[a
].Pending
and
2329 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2330 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2333 case gDelayedEvents
[a
].DEType
of
2335 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2338 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2342 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2343 if g_Game_IsNet
and g_Game_IsServer
then
2344 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2348 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2350 gDelayedEvents
[a
].Pending
:= False;
2353 // Каждую секунду обновляем счетчик обновлений:
2354 UPSCounter
:= UPSCounter
+ 1;
2355 if Time
- UPSTime
>= 1000 then
2364 g_Weapon_AddDynLights();
2365 g_Items_AddDynLights();
2369 procedure g_Game_LoadChatSounds(Resource
: string);
2372 FileName
, Snd
: string;
2374 len
, cnt
, tags
, i
, j
: Integer;
2377 FileName
:= g_ExtractWadName(Resource
);
2379 WAD
:= TWADFile
.Create();
2380 WAD
.ReadFile(FileName
);
2382 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2389 cfg
:= TConfig
.CreateMem(p
, len
);
2390 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2392 SetLength(gChatSounds
, cnt
);
2393 for i
:= 0 to Length(gChatSounds
) - 1 do
2395 gChatSounds
[i
].Sound
:= nil;
2396 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2397 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2398 if (Snd
= '') or (Tags
<= 0) then
2400 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2401 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2402 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2403 SetLength(gChatSounds
[i
].Tags
, tags
);
2404 for j
:= 0 to tags
- 1 do
2405 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2406 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2413 procedure g_Game_FreeChatSounds();
2417 for i
:= 0 to Length(gChatSounds
) - 1 do
2419 gChatSounds
[i
].Sound
.Free();
2420 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2422 SetLength(gChatSounds
, 0);
2426 procedure g_Game_LoadData();
2433 if DataLoaded
then Exit
;
2435 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2437 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2438 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2439 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2440 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2441 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2442 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2443 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2444 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2445 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2446 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2447 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2448 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2449 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2450 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2451 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2454 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2455 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2456 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2457 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2461 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2462 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2463 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2464 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2465 if (wl
> 0) and (hl
> 0) and (wr
> 0) and (hr
= hl
) and (wb
> 0) and (hb
= hl
) and (wm
> 0) and (hm
> 0) and (hm
<= hl
) then
2471 hasPBarGfx
:= false;
2475 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2476 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2477 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2478 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2479 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2480 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2481 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2482 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2483 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2484 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2485 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2486 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2487 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2488 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2489 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2490 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2491 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2492 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2493 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2494 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2495 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2496 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2497 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2498 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2499 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2500 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2501 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2502 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2503 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2504 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2505 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2506 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2507 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2508 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2509 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2510 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2511 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2512 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2514 goodsnd
[0] := TPlayableSound
.Create();
2515 goodsnd
[1] := TPlayableSound
.Create();
2516 goodsnd
[2] := TPlayableSound
.Create();
2517 goodsnd
[3] := TPlayableSound
.Create();
2519 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2520 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2521 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2522 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2524 killsnd
[0] := TPlayableSound
.Create();
2525 killsnd
[1] := TPlayableSound
.Create();
2526 killsnd
[2] := TPlayableSound
.Create();
2527 killsnd
[3] := TPlayableSound
.Create();
2529 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2530 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2531 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2532 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2534 hahasnd
[0] := TPlayableSound
.Create();
2535 hahasnd
[1] := TPlayableSound
.Create();
2536 hahasnd
[2] := TPlayableSound
.Create();
2538 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2539 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2540 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2542 sound_get_flag
[0] := TPlayableSound
.Create();
2543 sound_get_flag
[1] := TPlayableSound
.Create();
2544 sound_lost_flag
[0] := TPlayableSound
.Create();
2545 sound_lost_flag
[1] := TPlayableSound
.Create();
2546 sound_ret_flag
[0] := TPlayableSound
.Create();
2547 sound_ret_flag
[1] := TPlayableSound
.Create();
2548 sound_cap_flag
[0] := TPlayableSound
.Create();
2549 sound_cap_flag
[1] := TPlayableSound
.Create();
2551 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2552 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2553 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2554 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2555 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2556 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2557 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2558 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2560 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2562 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2565 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2566 g_Weapon_LoadData();
2568 g_Monsters_LoadData();
2573 procedure g_Game_Quit();
2575 g_Game_StopAllSounds(True);
2578 g_PlayerModel_FreeData();
2579 g_Texture_DeleteAll();
2580 g_Frames_DeleteAll();
2582 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2585 if NetInitDone
then g_Net_Free
;
2587 // remove map after test
2588 if gMapToDelete
<> '' then
2589 g_Game_DeleteTestMap();
2595 procedure g_Game_FreeData();
2597 if not DataLoaded
then Exit
;
2600 g_Weapon_FreeData();
2601 g_Monsters_FreeData();
2603 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2605 g_Texture_Delete('NOTEXTURE');
2606 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2607 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2608 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2609 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2610 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2611 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2612 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2613 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2614 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2615 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2616 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2617 g_Frames_DeleteByName('FRAMES_PUNCH');
2618 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2619 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2620 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2621 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2622 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2623 g_Sound_Delete('SOUND_GAME_TELEPORT');
2624 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2625 g_Sound_Delete('SOUND_GAME_SECRET');
2626 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2627 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2628 g_Sound_Delete('SOUND_GAME_BULK1');
2629 g_Sound_Delete('SOUND_GAME_BULK2');
2630 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2631 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2632 g_Sound_Delete('SOUND_GAME_BURNING');
2633 g_Sound_Delete('SOUND_GAME_SWITCH1');
2634 g_Sound_Delete('SOUND_GAME_SWITCH0');
2641 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2642 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2643 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2644 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2651 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2652 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2653 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2654 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2660 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2661 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2662 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2664 sound_get_flag
[0].Free();
2665 sound_get_flag
[1].Free();
2666 sound_lost_flag
[0].Free();
2667 sound_lost_flag
[1].Free();
2668 sound_ret_flag
[0].Free();
2669 sound_ret_flag
[1].Free();
2670 sound_cap_flag
[0].Free();
2671 sound_cap_flag
[1].Free();
2673 g_Sound_Delete('SOUND_CTF_GET1');
2674 g_Sound_Delete('SOUND_CTF_GET2');
2675 g_Sound_Delete('SOUND_CTF_LOST1');
2676 g_Sound_Delete('SOUND_CTF_LOST2');
2677 g_Sound_Delete('SOUND_CTF_RETURN1');
2678 g_Sound_Delete('SOUND_CTF_RETURN2');
2679 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2680 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2682 g_Game_FreeChatSounds();
2684 DataLoaded
:= False;
2687 procedure g_FatalError(Text: String);
2689 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2690 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2692 gExit
:= EXIT_SIMPLE
;
2693 if gGameOn
then EndGame
;
2696 procedure g_SimpleError(Text: String);
2698 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2699 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2702 procedure g_Game_SetupScreenSize();
2704 RES_FACTOR
= 4.0 / 3.0;
2710 // Размер экранов игроков:
2711 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2712 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2713 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
2715 gPlayerScreenSize
.Y
:= gScreenHeight
;
2717 // Размер заднего плана:
2718 if BackID
<> DWORD(-1) then
2721 if (gScreenWidth
*s
> gMapInfo
.Width
) or
2722 (gScreenHeight
*s
> gMapInfo
.Height
) then
2724 gBackSize
.X
:= gScreenWidth
;
2725 gBackSize
.Y
:= gScreenHeight
;
2729 e_GetTextureSize(BackID
, @bw
, @bh
);
2730 rf
:= Single(bw
) / Single(bh
);
2731 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
2732 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
2733 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
2734 if (s
< 1.0) then s
:= 1.0;
2735 gBackSize
.X
:= Round(bw
*s
);
2736 gBackSize
.Y
:= Round(bh
*s
);
2741 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2743 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2744 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2747 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2750 if gPlayer1
= nil then
2752 if g_Game_IsClient
then
2754 if NetPlrUID1
> -1 then
2755 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2759 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2760 Team
:= gPlayer1Settings
.Team
;
2762 // Создание первого игрока:
2763 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2764 gPlayer1Settings
.Color
,
2766 if gPlayer1
= nil then
2767 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2770 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2771 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2772 if g_Game_IsServer
and g_Game_IsNet
then
2773 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2774 gPlayer1
.Respawn(False, True);
2775 g_Net_Slist_ServerPlayerComes();
2780 if gPlayer2
= nil then
2782 if g_Game_IsClient
then
2784 if NetPlrUID2
> -1 then
2785 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2789 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2790 Team
:= gPlayer2Settings
.Team
;
2792 // Создание второго игрока:
2793 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2794 gPlayer2Settings
.Color
,
2796 if gPlayer2
= nil then
2797 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2800 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2801 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2802 if g_Game_IsServer
and g_Game_IsNet
then
2803 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2804 gPlayer2
.Respawn(False, True);
2805 g_Net_Slist_ServerPlayerComes();
2812 procedure g_Game_RemovePlayer();
2816 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2817 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2822 if g_Game_IsServer
then
2825 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2826 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2827 g_Player_Remove(Pl
.UID
);
2828 g_Net_Slist_ServerPlayerLeaves();
2832 gSpectLatchPID2
:= Pl
.UID
;
2840 if g_Game_IsServer
then
2843 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2844 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2845 g_Player_Remove(Pl
.UID
);
2846 g_Net_Slist_ServerPlayerLeaves();
2849 gSpectLatchPID1
:= Pl
.UID
;
2851 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2855 g_Net_Slist_ServerPlayerLeaves();
2858 procedure g_Game_Spectate();
2860 g_Game_RemovePlayer();
2861 if gPlayer1
<> nil then
2862 g_Game_RemovePlayer();
2865 procedure g_Game_SpectateCenterView();
2867 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2868 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2871 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2878 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2880 g_Game_ClearLoading();
2883 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2886 gGameSettings
.GameType
:= GT_SINGLE
;
2887 gGameSettings
.MaxLives
:= 0;
2888 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2889 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2890 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2891 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2892 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2893 gSwitchGameMode
:= GM_SINGLE
;
2895 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2896 gLMSRespawnTime
:= 0;
2897 gSpectLatchPID1
:= 0;
2898 gSpectLatchPID2
:= 0;
2900 g_Game_ExecuteEvent('ongamestart');
2902 // Установка размеров окон игроков:
2903 g_Game_SetupScreenSize();
2905 // Создание первого игрока:
2906 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2907 gPlayer1Settings
.Color
,
2908 gPlayer1Settings
.Team
, False));
2909 if gPlayer1
= nil then
2911 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2915 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2918 // Создание второго игрока, если есть:
2921 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2922 gPlayer2Settings
.Color
,
2923 gPlayer2Settings
.Team
, False));
2924 if gPlayer2
= nil then
2926 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2930 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2934 // Загрузка и запуск карты:
2935 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2937 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2938 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2942 // Настройки игроков и ботов:
2946 for i
:= nPl
+1 to nPlayers
do
2947 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2950 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2951 TimeLimit
, GoalLimit
: Word;
2953 Options
: LongWord; nPlayers
: Byte);
2959 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2961 g_Game_ClearLoading();
2964 gGameSettings
.GameType
:= GT_CUSTOM
;
2965 gGameSettings
.GameMode
:= GameMode
;
2966 gSwitchGameMode
:= GameMode
;
2967 gGameSettings
.TimeLimit
:= TimeLimit
;
2968 gGameSettings
.GoalLimit
:= GoalLimit
;
2969 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2970 gGameSettings
.Options
:= Options
;
2972 gCoopTotalMonstersKilled
:= 0;
2973 gCoopTotalSecretsFound
:= 0;
2974 gCoopTotalMonsters
:= 0;
2975 gCoopTotalSecrets
:= 0;
2979 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2980 gLMSRespawnTime
:= 0;
2981 gSpectLatchPID1
:= 0;
2982 gSpectLatchPID2
:= 0;
2984 g_Game_ExecuteEvent('ongamestart');
2986 // Установка размеров окон игроков:
2987 g_Game_SetupScreenSize();
2989 // Режим наблюдателя:
2990 if nPlayers
= 0 then
2997 if nPlayers
>= 1 then
2999 // Создание первого игрока:
3000 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3001 gPlayer1Settings
.Color
,
3002 gPlayer1Settings
.Team
, False));
3003 if gPlayer1
= nil then
3005 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3009 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3013 if nPlayers
>= 2 then
3015 // Создание второго игрока:
3016 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3017 gPlayer2Settings
.Color
,
3018 gPlayer2Settings
.Team
, False));
3019 if gPlayer2
= nil then
3021 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3025 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3029 // Загрузка и запуск карты:
3030 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3032 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3036 // Нет точек появления:
3037 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3038 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3039 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3040 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3041 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3043 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3047 // Настройки игроков и ботов:
3051 for i
:= nPl
+1 to nPlayers
do
3052 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3055 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3056 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3057 Options
: LongWord; nPlayers
: Byte;
3058 IPAddr
: LongWord; Port
: Word);
3061 g_Net_Slist_ServerClosed();
3063 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3065 g_Game_ClearLoading();
3068 gGameSettings
.GameType
:= GT_SERVER
;
3069 gGameSettings
.GameMode
:= GameMode
;
3070 gSwitchGameMode
:= GameMode
;
3071 gGameSettings
.TimeLimit
:= TimeLimit
;
3072 gGameSettings
.GoalLimit
:= GoalLimit
;
3073 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3074 gGameSettings
.Options
:= Options
;
3076 gCoopTotalMonstersKilled
:= 0;
3077 gCoopTotalSecretsFound
:= 0;
3078 gCoopTotalMonsters
:= 0;
3079 gCoopTotalSecrets
:= 0;
3083 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3084 gLMSRespawnTime
:= 0;
3085 gSpectLatchPID1
:= 0;
3086 gSpectLatchPID2
:= 0;
3088 g_Game_ExecuteEvent('ongamestart');
3090 // Установка размеров окна игрока
3091 g_Game_SetupScreenSize();
3093 // Режим наблюдателя:
3094 if nPlayers
= 0 then
3100 if nPlayers
>= 1 then
3102 // Создание первого игрока:
3103 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3104 gPlayer1Settings
.Color
,
3105 gPlayer1Settings
.Team
, False));
3106 if gPlayer1
= nil then
3108 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3112 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3115 if nPlayers
>= 2 then
3117 // Создание второго игрока:
3118 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3119 gPlayer2Settings
.Color
,
3120 gPlayer2Settings
.Team
, False));
3121 if gPlayer2
= nil then
3123 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3127 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3130 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3131 if NetForwardPorts
then
3132 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3135 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3137 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3141 g_Net_Slist_Set(NetMasterList
);
3143 g_Net_Slist_ServerStarted();
3145 // Загрузка и запуск карты:
3146 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3148 g_Net_Slist_ServerClosed();
3149 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3153 // Нет точек появления:
3154 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3155 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3156 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3157 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3158 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3160 g_Net_Slist_ServerClosed();
3161 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3165 // Настройки игроков и ботов:
3168 g_Net_Slist_ServerMapStarted();
3169 NetState
:= NET_STATE_GAME
;
3172 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3187 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3188 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3190 g_Game_ClearLoading();
3193 gGameSettings
.GameType
:= GT_CLIENT
;
3195 gCoopTotalMonstersKilled
:= 0;
3196 gCoopTotalSecretsFound
:= 0;
3197 gCoopTotalMonsters
:= 0;
3198 gCoopTotalSecrets
:= 0;
3202 g_Game_ExecuteEvent('ongamestart');
3204 // Установка размеров окон игроков:
3205 g_Game_SetupScreenSize();
3207 NetState
:= NET_STATE_AUTH
;
3209 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3211 // create (or update) map/resource databases
3212 g_Res_CreateDatabases(true);
3214 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3215 gLMSRespawnTime
:= 0;
3216 gSpectLatchPID1
:= 0;
3217 gSpectLatchPID2
:= 0;
3220 if not g_Net_Connect(Addr
, Port
) then
3222 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3223 NetState
:= NET_STATE_NONE
;
3227 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3229 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3234 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3235 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3236 // thank you, enet. let's ignore failures altogether then.
3237 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3239 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3241 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
3243 // ignore all download packets, they're processed by separate code
3244 enet_packet_destroy(NetEvent
.packet
);
3247 Ptr
:= NetEvent
.packet
^.data
;
3248 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3250 enet_packet_destroy(NetEvent
.packet
);
3254 InMsg
.ReadLongWord(); // skip size
3255 MID
:= InMsg
.ReadByte();
3257 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3259 NetMyID
:= InMsg
.ReadByte();
3260 NetPlrUID1
:= InMsg
.ReadWord();
3262 WadName
:= InMsg
.ReadString();
3263 Map
:= InMsg
.ReadString();
3265 gWADHash
:= InMsg
.ReadMD5();
3267 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3268 gSwitchGameMode
:= gGameSettings
.GameMode
;
3269 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
3270 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3271 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3272 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3273 T
:= InMsg
.ReadLongWord();
3275 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3276 //if newResPath = '' then
3278 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3279 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3280 if newResPath
= '' then
3282 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3283 enet_packet_destroy(NetEvent
.packet
);
3284 NetState
:= NET_STATE_NONE
;
3287 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3289 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3292 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3293 gPlayer1Settings
.Color
,
3294 gPlayer1Settings
.Team
, False));
3296 if gPlayer1
= nil then
3298 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3300 enet_packet_destroy(NetEvent
.packet
);
3301 NetState
:= NET_STATE_NONE
;
3305 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3306 gPlayer1
.UID
:= NetPlrUID1
;
3307 gPlayer1
.Reset(True);
3309 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3311 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3313 enet_packet_destroy(NetEvent
.packet
);
3314 NetState
:= NET_STATE_NONE
;
3322 enet_packet_destroy(NetEvent
.packet
);
3326 enet_packet_destroy(NetEvent
.packet
);
3330 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3333 if (NetEvent
.data
<= NET_DISC_MAX
) then
3334 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3335 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3342 ProcessLoading(true);
3344 if g_Net_UserRequestExit() then
3353 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3354 NetState
:= NET_STATE_NONE
;
3359 NetState
:= NET_STATE_GAME
;
3360 MC_SEND_FullStateRequest
;
3361 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3365 lastAsMegaWad
: Boolean = false;
3367 procedure g_Game_ChangeMap(const MapPath
: String);
3371 g_Game_ClearLoading();
3373 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3374 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3375 if gExitByTrigger
then
3378 gExitByTrigger
:= False;
3380 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3381 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3384 procedure g_Game_Restart();
3388 if g_Game_IsClient
then
3390 map
:= g_ExtractFileName(gMapInfo
.Map
);
3391 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3395 g_Game_ClearLoading();
3396 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3399 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3401 NewWAD
, ResName
: String;
3405 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3406 g_Player_RemoveAllCorpses();
3408 if (not g_Game_IsClient
) and
3409 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3410 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3412 if gSwitchGameMode
= GM_CTF
then
3413 gGameSettings
.MaxLives
:= 0;
3414 gGameSettings
.GameMode
:= gSwitchGameMode
;
3417 gSwitchGameMode
:= gGameSettings
.GameMode
;
3419 g_Player_ResetTeams();
3421 lastAsMegaWad
:= asMegawad
;
3422 if isWadPath(Map
) then
3424 NewWAD
:= g_ExtractWadName(Map
);
3425 ResName
:= g_ExtractFileName(Map
);
3426 if g_Game_IsServer
then
3428 nws
:= findDiskWad(NewWAD
);
3429 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3432 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3433 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3437 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3438 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3440 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3441 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3443 if (length(nws
) = 0) then
3445 ResName
:= ''; // failed
3450 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3451 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3452 g_Game_LoadWAD(NewWAD
);
3457 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3458 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3463 NewWAD
:= gGameSettings
.WAD
;
3469 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3471 if (ResName
<> '') and (NewWAD
<> '') then
3473 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3474 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3479 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3481 gState
:= STATE_NONE
;
3482 g_ActiveWindow
:= nil;
3486 wNeedTimeReset
:= True;
3488 if gGameSettings
.GameMode
= GM_CTF
then
3490 g_Map_ResetFlag(FLAG_RED
);
3491 g_Map_ResetFlag(FLAG_BLUE
);
3492 // CTF, а флагов нет:
3493 if not g_Map_HaveFlagPoints() then
3494 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3499 gState
:= STATE_MENU
;
3504 gPauseMain
:= false;
3505 gPauseHolmes
:= false;
3506 NetTimeToUpdate
:= 1;
3507 NetTimeToReliable
:= 0;
3508 NetTimeToMaster
:= NetMasterRate
;
3509 gSpectLatchPID1
:= 0;
3510 gSpectLatchPID2
:= 0;
3511 gMissionFailed
:= False;
3514 gCoopMonstersKilled
:= 0;
3515 gCoopSecretsFound
:= 0;
3517 gVoteInProgress
:= False;
3518 gVotePassed
:= False;
3524 if not gGameOn
then Exit
;
3526 g_Game_SpectateCenterView();
3528 if g_Game_IsServer
then
3530 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3532 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3533 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3534 gLMSSoftSpawn
:= True;
3535 if g_Game_IsNet
then
3536 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3540 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3541 gLMSRespawnTime
:= 0;
3545 if NetMode
= NET_SERVER
then
3547 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3550 g_Net_Slist_ServerMapStarted();
3552 if NetClients
<> nil then
3553 for I
:= 0 to High(NetClients
) do
3554 if NetClients
[I
].Used
then
3556 NetClients
[I
].Voted
:= False;
3557 if NetClients
[I
].RequestedFullUpdate
then
3559 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3560 NetClients
[I
].RequestedFullUpdate
:= False;
3564 g_Net_UnbanNonPermHosts();
3569 gCoopTotalMonstersKilled
:= 0;
3570 gCoopTotalSecretsFound
:= 0;
3571 gCoopTotalMonsters
:= 0;
3572 gCoopTotalSecrets
:= 0;
3576 g_Game_ExecuteEvent('onmapstart');
3579 procedure SetFirstLevel
;
3583 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3584 if MapList
= nil then
3587 SortSArray(MapList
);
3588 gNextMap
:= MapList
[Low(MapList
)];
3593 procedure g_Game_ExitLevel(const Map
: AnsiString);
3597 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3598 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3599 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3600 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3602 // Вышли в выход в Одиночной игре:
3603 if gGameSettings
.GameType
= GT_SINGLE
then
3604 gExit
:= EXIT_ENDLEVELSINGLE
3605 else // Вышли в выход в Своей игре
3607 gExit
:= EXIT_ENDLEVELCUSTOM
;
3608 if gGameSettings
.GameMode
= GM_COOP
then
3609 g_Player_RememberAll
;
3611 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3614 if gGameSettings
.GameMode
= GM_COOP
then
3617 gStatsPressed
:= True;
3618 gNextMap
:= 'MAP01';
3620 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3623 if g_Game_IsNet
then
3625 MH_SEND_GameStats();
3626 MH_SEND_CoopStats();
3632 procedure g_Game_RestartLevel();
3636 if gGameSettings
.GameMode
= GM_SINGLE
then
3641 gExit
:= EXIT_ENDLEVELCUSTOM
;
3642 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3646 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3648 gWAD
{, xwad}: String;
3651 if not g_Game_IsClient
then Exit
;
3652 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3654 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3659 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3663 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3666 g_Game_LoadWAD(NewWAD
);
3670 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3671 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3674 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3675 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3679 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3683 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3684 g_Game_LoadWAD(NewWAD);
3688 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3690 i
, n
, nb
, nr
: Integer;
3692 if not g_Game_IsServer
then Exit
;
3693 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3694 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3695 gLMSRespawnTime
:= 0;
3698 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3700 gMissionFailed
:= True;
3701 g_Game_RestartLevel
;
3705 n
:= 0; nb
:= 0; nr
:= 0;
3706 for i
:= Low(gPlayers
) to High(gPlayers
) do
3707 if (gPlayers
[i
] <> nil) and
3708 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3709 (gPlayers
[i
] is TBot
)) then
3712 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3713 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3716 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3718 // wait a second until the fuckers finally decide to join
3719 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3720 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3721 gLMSSoftSpawn
:= NoMapRestart
;
3722 if g_Game_IsNet
then
3723 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3727 g_Player_RemoveAllCorpses
;
3728 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3729 if g_Game_IsNet
then
3730 MH_SEND_GameEvent(NET_EV_LMS_START
);
3732 for i
:= Low(gPlayers
) to High(gPlayers
) do
3734 if gPlayers
[i
] = nil then continue
;
3735 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3736 // don't touch normal spectators
3737 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3739 gPlayers
[i
].FNoRespawn
:= True;
3740 gPlayers
[i
].Lives
:= 0;
3741 if g_Game_IsNet
then
3742 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3745 gPlayers
[i
].FNoRespawn
:= False;
3746 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3747 gPlayers
[i
].Respawn(False, True);
3748 if gGameSettings
.GameMode
= GM_COOP
then
3750 gPlayers
[i
].Frags
:= 0;
3751 gPlayers
[i
].RecallState
;
3753 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3754 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3755 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3756 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3759 g_Items_RestartRound();
3761 gLMSSoftSpawn
:= False;
3764 function g_Game_GetFirstMap(WAD
: String): String;
3768 MapList
:= g_Map_GetMapsList(WAD
);
3769 if MapList
= nil then
3772 SortSArray(MapList
);
3773 Result
:= MapList
[Low(MapList
)];
3775 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3781 function g_Game_GetNextMap(): String;
3788 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3789 if MapList
= nil then
3792 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3794 SortSArray(MapList
);
3796 for I
:= Low(MapList
) to High(MapList
) do
3797 if Map
= MapList
[I
] then
3803 if MapIndex
<> -255 then
3805 if MapIndex
= High(MapList
) then
3806 Result
:= MapList
[Low(MapList
)]
3808 Result
:= MapList
[MapIndex
+ 1];
3810 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3816 procedure g_Game_NextLevel();
3818 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3819 gExit
:= EXIT_ENDLEVELCUSTOM
3822 gExit
:= EXIT_ENDLEVELSINGLE
;
3826 if gNextMap
<> '' then Exit
;
3827 gNextMap
:= g_Game_GetNextMap();
3830 function g_Game_IsTestMap(): Boolean;
3832 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3835 procedure g_Game_DeleteTestMap();
3838 //MapName: AnsiString;
3846 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3847 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3848 if (a
= 0) then exit
;
3850 // Выделяем имя wad-файла и имя карты
3851 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3852 Delete(gMapToDelete
, 1, a
+5);
3853 gMapToDelete
:= UpperCase(gMapToDelete
);
3855 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3858 // Имя карты не стандартное тестовое:
3859 if MapName <> TEST_MAP_NAME then
3862 if not gTempDelete then
3864 time := g_GetFileTime(WadName);
3865 WAD := TWADFile.Create();
3868 if not WAD.ReadFile(WadName) then
3869 begin // Нет такого WAD-файла
3874 // Составляем список карт и ищем нужную:
3876 MapList := WAD.GetResourcesList('');
3878 if MapList <> nil then
3879 for a := 0 to High(MapList) do
3880 if MapList[a] = MapName then
3882 // Удаляем и сохраняем:
3883 WAD.RemoveResource('', MapName);
3884 WAD.SaveTo(WadName);
3889 g_SetFileTime(WadName, time);
3892 if gTempDelete
then DeleteFile(WadName
);
3895 procedure GameCVars(P
: SSArray
);
3898 stat
: TPlayerStatArray
;
3901 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3905 if Length(P
) > 1 then
3910 gsGameFlags
:= gsGameFlags
or Flag
3912 gsGameFlags
:= gsGameFlags
and (not Flag
);
3914 if g_Game_IsServer
then
3917 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3919 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3920 if g_Game_IsNet
then MH_SEND_GameSettings
;
3924 if LongBool(gsGameFlags
and Flag
) then
3925 g_Console_Add(_lc
[OnMsg
])
3927 g_Console_Add(_lc
[OffMsg
]);
3929 if OnMapChange
and g_Game_IsServer
then
3930 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3935 cmd
:= LowerCase(P
[0]);
3937 if cmd
= 'g_gamemode' then
3939 if (Length(P
) > 1) then
3941 a
:= g_Game_TextToMode(P
[1]);
3942 if a
= GM_SINGLE
then a
:= GM_COOP
;
3943 gsGameMode
:= g_Game_ModeToText(a
);
3944 if g_Game_IsServer
then
3946 gSwitchGameMode
:= a
;
3947 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3948 (gState
= STATE_INTERSINGLE
) then
3949 gSwitchGameMode
:= GM_SINGLE
;
3951 gGameSettings
.GameMode
:= gSwitchGameMode
;
3955 if gSwitchGameMode
= gGameSettings
.GameMode
then
3956 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3957 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3959 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3960 [g_Game_ModeToText(gGameSettings
.GameMode
),
3961 g_Game_ModeToText(gSwitchGameMode
)]));
3963 else if cmd
= 'g_friendlyfire' then
3965 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3967 else if cmd
= 'g_friendly_absorb_damage' then
3969 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3971 else if cmd
= 'g_friendly_hit_trace' then
3973 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3975 else if cmd
= 'g_friendly_hit_projectile' then
3977 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3979 else if cmd
= 'g_weaponstay' then
3981 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3983 else if cmd
= 'g_allow_exit' then
3985 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3987 else if cmd
= 'g_allow_monsters' then
3989 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3991 else if cmd
= 'g_bot_vsplayers' then
3993 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3995 else if cmd
= 'g_bot_vsmonsters' then
3997 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3999 else if cmd
= 'g_dm_keys' then
4001 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4003 else if cmd
= 'g_gameflags' then
4005 if Length(P
) > 1 then
4007 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4008 if g_Game_IsServer
then
4010 gGameSettings
.Options
:= gsGameFlags
;
4011 if g_Game_IsNet
then MH_SEND_GameSettings
;
4015 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4017 else if cmd
= 'g_warmup_time' then
4019 if Length(P
) > 1 then
4021 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4022 if g_Game_IsServer
then
4024 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4025 // extend warmup if it's already going
4026 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4028 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4029 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4031 if g_Game_IsNet
then MH_SEND_GameSettings
;
4035 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4036 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4038 else if cmd
= 'g_spawn_invul' then
4040 if Length(P
) > 1 then
4042 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4043 if g_Game_IsServer
then
4045 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4046 if g_Game_IsNet
then MH_SEND_GameSettings
;
4050 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4052 else if cmd
= 'g_item_respawn_time' then
4054 if Length(P
) > 1 then
4056 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4057 if g_Game_IsServer
then
4059 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4060 if g_Game_IsNet
then MH_SEND_GameSettings
;
4064 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4065 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4067 else if cmd
= 'sv_intertime' then
4069 if (Length(P
) > 1) then
4070 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4072 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4074 else if cmd
= 'g_max_particles' then
4076 if Length(p
) = 2 then
4078 a
:= Max(0, StrToInt(p
[1]));
4081 else if Length(p
) = 1 then
4083 e_LogWritefln('%s', [g_GFX_GetMax()])
4087 e_LogWritefln('usage: %s <n>', [cmd
])
4090 else if cmd
= 'g_max_shells' then
4092 if Length(p
) = 2 then
4094 a
:= Max(0, StrToInt(p
[1]));
4097 else if Length(p
) = 1 then
4099 e_LogWritefln('%s', [g_Shells_GetMax()])
4103 e_LogWritefln('usage: %s <n>', [cmd
])
4106 else if cmd
= 'g_max_gibs' then
4108 if Length(p
) = 2 then
4110 a
:= Max(0, StrToInt(p
[1]));
4113 else if Length(p
) = 1 then
4115 e_LogWritefln('%s', [g_Gibs_GetMax()])
4119 e_LogWritefln('usage: %s <n>', [cmd
])
4122 else if cmd
= 'g_max_corpses' then
4124 if Length(p
) = 2 then
4126 a
:= Max(0, StrToInt(p
[1]));
4129 else if Length(p
) = 1 then
4131 e_LogWritefln('%s', [g_Corpses_GetMax()])
4135 e_LogWritefln('usage: %s <n>', [cmd
])
4138 else if cmd
= 'g_scorelimit' then
4140 if Length(P
) > 1 then
4142 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
4144 if g_Game_IsServer
then
4147 if gGameSettings
.GameMode
= GM_DM
then
4149 stat
:= g_Player_GetStats();
4151 for a
:= 0 to High(stat
) do
4152 if stat
[a
].Frags
> b
then
4156 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4158 // if someone has a higher score, set it to that instead
4159 gsGoalLimit
:= max(gsGoalLimit
, b
);
4160 gGameSettings
.GoalLimit
:= gsGoalLimit
;
4162 if g_Game_IsNet
then MH_SEND_GameSettings
;
4166 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
4168 else if cmd
= 'g_timelimit' then
4170 if Length(P
) > 1 then
4172 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4173 if g_Game_IsServer
then
4175 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4176 if g_Game_IsNet
then MH_SEND_GameSettings
;
4179 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4180 [gsTimeLimit
div 3600,
4181 (gsTimeLimit
div 60) mod 60,
4182 gsTimeLimit
mod 60]));
4184 else if cmd
= 'g_maxlives' then
4186 if Length(P
) > 1 then
4188 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4189 if g_Game_IsServer
then
4191 gGameSettings
.MaxLives
:= gsMaxLives
;
4192 if g_Game_IsNet
then MH_SEND_GameSettings
;
4196 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4200 procedure PlayerSettingsCVars(P
: SSArray
);
4205 function ParseTeam(s
: string): Byte;
4209 'red', '1': result
:= TEAM_RED
;
4210 'blue', '2': result
:= TEAM_BLUE
;
4211 else result
:= TEAM_NONE
;
4215 cmd
:= LowerCase(P
[0]);
4219 if (Length(P
) > 1) then
4221 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4222 if g_Game_IsClient
then
4223 MC_SEND_PlayerSettings
4224 else if gGameOn
and (gPlayer1
<> nil) then
4226 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4227 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4233 if (Length(P
) > 1) then
4235 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4236 if g_Game_IsClient
then
4237 MC_SEND_PlayerSettings
4238 else if gGameOn
and (gPlayer2
<> nil) then
4240 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4241 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4247 if Length(P
) > 3 then
4249 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4250 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4251 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4252 if g_Game_IsClient
then
4253 MC_SEND_PlayerSettings
4254 else if gGameOn
and (gPlayer1
<> nil) then
4256 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4257 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4263 if Length(P
) > 3 then
4265 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4266 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4267 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4268 if g_Game_IsClient
then
4269 MC_SEND_PlayerSettings
4270 else if gGameOn
and (gPlayer2
<> nil) then
4272 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4273 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4279 if (Length(P
) > 1) then
4281 gPlayer1Settings
.Model
:= P
[1];
4282 if g_Game_IsClient
then
4283 MC_SEND_PlayerSettings
4284 else if gGameOn
and (gPlayer1
<> nil) then
4286 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4287 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4288 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4294 if (Length(P
) > 1) then
4296 gPlayer2Settings
.Model
:= P
[1];
4297 if g_Game_IsClient
then
4298 MC_SEND_PlayerSettings
4299 else if gGameOn
and (gPlayer2
<> nil) then
4301 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4302 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4303 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4309 // TODO: switch teams if in game or store this separately
4310 if (Length(P
) > 1) then
4312 team
:= ParseTeam(P
[1]);
4313 if team
= TEAM_NONE
then
4314 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4315 else if not gGameOn
and not g_Game_IsNet
then
4316 gPlayer1Settings
.Team
:= team
4318 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4323 // TODO: switch teams if in game or store this separately
4324 if (Length(P
) > 1) then
4326 team
:= ParseTeam(P
[1]);
4327 if team
= TEAM_NONE
then
4328 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4329 else if not gGameOn
and not g_Game_IsNet
then
4330 gPlayer2Settings
.Team
:= team
4332 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4338 procedure PrintHeapStats();
4342 hs
:= GetFPCHeapStatus();
4343 e_LogWriteLn ('v===== heap status =====v');
4344 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4345 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4346 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4347 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4348 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4349 e_LogWriteLn ('^=======================^');
4352 procedure DebugCommands(P
: SSArray
);
4359 // Команды отладочного режима:
4360 if {gDebugMode}conIsCheatsEnabled
then
4362 cmd
:= LowerCase(P
[0]);
4363 if cmd
= 'd_window' then
4365 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4366 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4368 else if cmd
= 'd_sounds' then
4370 if (Length(P
) > 1) and
4371 ((P
[1] = '1') or (P
[1] = '0')) then
4372 g_Debug_Sounds
:= (P
[1][1] = '1');
4374 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4376 else if cmd
= 'd_frames' then
4378 if (Length(P
) > 1) and
4379 ((P
[1] = '1') or (P
[1] = '0')) then
4380 g_Debug_Frames
:= (P
[1][1] = '1');
4382 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4384 else if cmd
= 'd_winmsg' then
4386 if (Length(P
) > 1) and
4387 ((P
[1] = '1') or (P
[1] = '0')) then
4388 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4390 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4392 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4394 if (Length(P
) > 1) and
4395 ((P
[1] = '1') or (P
[1] = '0')) then
4396 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4398 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4400 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4402 if Length(P
) > 1 then
4404 '0': g_debug_BotAIOff
:= 0;
4405 '1': g_debug_BotAIOff
:= 1;
4406 '2': g_debug_BotAIOff
:= 2;
4407 '3': g_debug_BotAIOff
:= 3;
4410 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4412 else if cmd
= 'd_monster' then
4414 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4415 if Length(P
) < 2 then
4417 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4418 g_Console_Add('ID | Name');
4419 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4420 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4421 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4424 a
:= StrToIntDef(P
[1], 0);
4425 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4426 a
:= g_Mons_TypeIdByName(P
[1]);
4428 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4429 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4432 with gPlayer1
.Obj
do
4434 mon
:= g_Monsters_Create(a
,
4435 X
+ Rect
.X
+ (Rect
.Width
div 2),
4436 Y
+ Rect
.Y
+ Rect
.Height
,
4437 gPlayer1
.Direction
, True);
4439 if (Length(P
) > 2) and (mon
<> nil) then
4441 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4442 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4443 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4444 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4445 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4446 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4447 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4448 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4449 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4454 else if (cmd
= 'd_health') then
4456 if (Length(P
) > 1) and
4457 ((P
[1] = '1') or (P
[1] = '0')) then
4458 g_debug_HealthBar
:= (P
[1][1] = '1');
4460 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4462 else if (cmd
= 'd_player') then
4464 if (Length(P
) > 1) and
4465 ((P
[1] = '1') or (P
[1] = '0')) then
4466 g_debug_Player
:= (P
[1][1] = '1');
4468 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4470 else if (cmd
= 'd_mem') then
4476 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4480 procedure GameCheats(P
: SSArray
);
4486 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4488 g_Console_Add('not available');
4494 g_Console_Add('where is the player?!');
4497 cmd
:= LowerCase(P
[0]);
4501 plr
.GodMode
:= not plr
.GodMode
;
4502 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4505 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4506 if cmd
= 'give' then
4508 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4509 for f
:= 1 to High(P
) do
4511 cmd
:= LowerCase(P
[f
]);
4512 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4513 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4514 if cmd
= 'exit' then
4516 if gTriggers
<> nil then
4518 for a
:= 0 to High(gTriggers
) do
4520 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4522 g_Console_Add('player left the map');
4523 gExitByTrigger
:= True;
4524 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4525 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4533 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4534 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4535 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4536 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4537 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4539 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4540 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4542 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4543 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;
4545 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4546 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4548 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4549 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4551 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4552 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4554 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4555 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4556 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4558 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4559 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4560 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4561 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;
4562 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4563 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4565 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;
4566 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;
4567 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;
4568 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;
4569 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;
4570 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;
4572 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4573 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;
4575 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;
4576 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;
4578 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4580 if cmd
= 'ammo' then
4582 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4583 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4584 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4585 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4586 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4587 g_Console_Add('player got some ammo');
4591 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4592 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4594 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4595 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4597 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4598 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4600 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4601 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4603 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4605 if cmd
= 'weapons' then
4607 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4608 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4609 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4610 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4611 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4612 plr
.GiveItem(ITEM_WEAPON_BFG
);
4613 g_Console_Add('player got weapons');
4617 if cmd
= 'keys' then
4619 plr
.GiveItem(ITEM_KEY_RED
);
4620 plr
.GiveItem(ITEM_KEY_GREEN
);
4621 plr
.GiveItem(ITEM_KEY_BLUE
);
4622 g_Console_Add('player got all keys');
4626 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4631 if cmd
= 'open' then
4633 g_Console_Add('player activated sesame');
4634 g_Triggers_OpenAll();
4641 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4645 if cmd
= 'noclip' then
4648 g_Console_Add('wall hardeness adjusted');
4652 if cmd
= 'notarget' then
4654 plr
.NoTarget
:= not plr
.NoTarget
;
4655 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4659 if cmd
= 'noreload' then
4661 plr
.NoReload
:= not plr
.NoReload
;
4662 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4666 if cmd
= 'speedy' then
4668 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4669 g_Console_Add('speed adjusted');
4673 if cmd
= 'jumpy' then
4675 VEL_JUMP
:= 30-VEL_JUMP
;
4676 g_Console_Add('jump height adjusted');
4680 if cmd
= 'automap' then
4682 gShowMap
:= not gShowMap
;
4683 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4687 if cmd
= 'aimline' then
4689 gAimLine
:= not gAimLine
;
4690 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4695 procedure GameCommands(P
: SSArray
);
4701 pl
: pTNetClient
= nil;
4709 cmd
:= LowerCase(P
[0]);
4711 if cmd
= 'pause' then
4713 if (g_ActiveWindow
= nil) then
4714 g_Game_Pause(not gPauseMain
);
4716 else if cmd
= 'endgame' then
4717 gExit
:= EXIT_SIMPLE
4718 else if cmd
= 'restart' then
4720 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4722 if g_Game_IsClient
then
4724 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4729 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4731 else if cmd
= 'kick' then
4733 if g_Game_IsServer
then
4735 if Length(P
) < 2 then
4737 g_Console_Add('kick <name>');
4742 g_Console_Add('kick <name>');
4746 if g_Game_IsNet
then
4747 pl
:= g_Net_Client_ByName(P
[1]);
4750 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4751 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4752 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4753 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4754 g_Net_Slist_ServerPlayerLeaves();
4755 end else if gPlayers
<> nil then
4756 for a
:= Low(gPlayers
) to High(gPlayers
) do
4757 if gPlayers
[a
] <> nil then
4758 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4760 // Не отключать основных игроков в сингле
4761 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4763 gPlayers
[a
].Lives
:= 0;
4764 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4765 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4766 g_Player_Remove(gPlayers
[a
].UID
);
4767 g_Net_Slist_ServerPlayerLeaves();
4768 // Если не перемешать, при добавлении новых ботов появятся старые
4772 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4774 else if cmd
= 'kick_id' then
4776 if g_Game_IsServer
and g_Game_IsNet
then
4778 if Length(P
) < 2 then
4780 g_Console_Add('kick_id <client ID>');
4785 g_Console_Add('kick_id <client ID>');
4789 a
:= StrToIntDef(P
[1], 0);
4790 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4792 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4794 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4795 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
4796 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4797 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4798 g_Net_Slist_ServerPlayerLeaves();
4802 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4804 else if cmd
= 'kick_pid' then
4806 if g_Game_IsServer
and g_Game_IsNet
then
4808 if Length(P
) < 2 then
4810 g_Console_Add('kick_pid <player ID>');
4815 g_Console_Add('kick_pid <player ID>');
4819 a
:= StrToIntDef(P
[1], 0);
4820 pl
:= g_Net_Client_ByPlayer(a
);
4821 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4823 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4824 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4825 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4826 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4827 g_Net_Slist_ServerPlayerLeaves();
4830 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4832 else if cmd
= 'ban' then
4834 if g_Game_IsServer
and g_Game_IsNet
then
4836 if Length(P
) < 2 then
4838 g_Console_Add('ban <name>');
4843 g_Console_Add('ban <name>');
4847 pl
:= g_Net_Client_ByName(P
[1]);
4850 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4851 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4852 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4853 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4854 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4855 g_Net_Slist_ServerPlayerLeaves();
4857 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4859 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4861 else if cmd
= 'ban_id' then
4863 if g_Game_IsServer
and g_Game_IsNet
then
4865 if Length(P
) < 2 then
4867 g_Console_Add('ban_id <client ID>');
4872 g_Console_Add('ban_id <client ID>');
4876 a
:= StrToIntDef(P
[1], 0);
4877 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4878 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4880 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4881 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
4882 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
4883 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4884 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4885 g_Net_Slist_ServerPlayerLeaves();
4888 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4890 else if cmd
= 'ban_pid' then
4892 if g_Game_IsServer
and g_Game_IsNet
then
4894 if Length(P
) < 2 then
4896 g_Console_Add('ban_pid <player ID>');
4901 g_Console_Add('ban_pid <player ID>');
4905 a
:= StrToIntDef(P
[1], 0);
4906 pl
:= g_Net_Client_ByPlayer(a
);
4907 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4909 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4910 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4911 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4912 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4913 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4914 g_Net_Slist_ServerPlayerLeaves();
4917 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4919 else if cmd
= 'permban' then
4921 if g_Game_IsServer
and g_Game_IsNet
then
4923 if Length(P
) < 2 then
4925 g_Console_Add('permban <name>');
4930 g_Console_Add('permban <name>');
4934 pl
:= g_Net_Client_ByName(P
[1]);
4937 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4938 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4939 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
4940 g_Net_SaveBanList();
4941 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4942 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4943 g_Net_Slist_ServerPlayerLeaves();
4945 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4947 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4949 else if cmd
= 'permban_id' then
4951 if g_Game_IsServer
and g_Game_IsNet
then
4953 if Length(P
) < 2 then
4955 g_Console_Add('permban_id <client ID>');
4960 g_Console_Add('permban_id <client ID>');
4964 a
:= StrToIntDef(P
[1], 0);
4965 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4966 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4968 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4969 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
4970 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
4971 g_Net_SaveBanList();
4972 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4973 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4974 g_Net_Slist_ServerPlayerLeaves();
4977 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4979 else if cmd
= 'permban_pid' then
4981 if g_Game_IsServer
and g_Game_IsNet
then
4983 if Length(P
) < 2 then
4985 g_Console_Add('permban_pid <player ID>');
4990 g_Console_Add('permban_pid <player ID>');
4994 a
:= StrToIntDef(P
[1], 0);
4995 pl
:= g_Net_Client_ByPlayer(a
);
4996 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4998 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4999 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5000 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5001 g_Net_SaveBanList();
5002 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5003 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5004 g_Net_Slist_ServerPlayerLeaves();
5007 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5009 else if cmd
= 'permban_ip' then
5011 if g_Game_IsServer
and g_Game_IsNet
then
5013 if Length(P
) < 2 then
5015 g_Console_Add('permban_ip <IP address>');
5020 g_Console_Add('permban_ip <IP address>');
5024 g_Net_BanHost(P
[1]);
5025 g_Net_SaveBanList();
5026 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5028 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5030 else if cmd
= 'unban' then
5032 if g_Game_IsServer
and g_Game_IsNet
then
5034 if Length(P
) < 2 then
5036 g_Console_Add('unban <IP Address>');
5041 g_Console_Add('unban <IP Address>');
5045 if g_Net_UnbanHost(P
[1]) then
5047 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5048 g_Net_SaveBanList();
5050 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5052 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5054 else if cmd
= 'clientlist' then
5056 if g_Game_IsServer
and g_Game_IsNet
then
5059 if NetClients
<> nil then
5060 for a
:= Low(NetClients
) to High(NetClients
) do
5061 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5063 plr
:= g_Player_Get(NetClients
[a
].Player
);
5064 if plr
= nil then continue
;
5066 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5067 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5070 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5072 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5074 else if cmd
= 'connect' then
5076 if (NetMode
= NET_NONE
) then
5078 if Length(P
) < 2 then
5080 g_Console_Add('connect <IP> [port] [password]');
5085 g_Console_Add('connect <IP> [port] [password]');
5089 if Length(P
) > 2 then
5090 prt
:= StrToIntDef(P
[2], 25666)
5094 if Length(P
) > 3 then
5099 g_Game_StartClient(P
[1], prt
, pw
);
5102 else if cmd
= 'disconnect' then
5104 if (NetMode
= NET_CLIENT
) then
5107 else if cmd
= 'reconnect' then
5109 if (NetMode
= NET_SERVER
) then
5112 if (NetMode
= NET_CLIENT
) then
5115 gExit
:= EXIT_SIMPLE
;
5119 //TODO: Use last successful password to reconnect, instead of ''
5120 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5122 else if (cmd
= 'addbot') or
5123 (cmd
= 'bot_add') then
5125 if Length(P
) > 2 then
5126 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5127 else if Length(P
) > 1 then
5128 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5130 g_Bot_Add(TEAM_NONE
, 2);
5132 else if cmd
= 'bot_addlist' then
5134 if Length(P
) > 1 then
5136 if Length(P
) = 2 then
5137 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5138 else if Length(P
) = 3 then
5139 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5141 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5144 else if cmd
= 'bot_removeall' then
5146 else if cmd
= 'chat' then
5148 if g_Game_IsNet
then
5150 if Length(P
) > 1 then
5152 for a
:= 1 to High(P
) do
5153 chstr
:= chstr
+ P
[a
] + ' ';
5155 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5157 if Length(chstr
) < 1 then
5159 g_Console_Add('chat <text>');
5163 chstr
:= b_Text_Format(chstr
);
5164 if g_Game_IsClient
then
5165 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5167 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5170 g_Console_Add('chat <text>');
5172 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5174 else if cmd
= 'teamchat' then
5176 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5178 if Length(P
) > 1 then
5180 for a
:= 1 to High(P
) do
5181 chstr
:= chstr
+ P
[a
] + ' ';
5183 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5185 if Length(chstr
) < 1 then
5187 g_Console_Add('teamchat <text>');
5191 chstr
:= b_Text_Format(chstr
);
5192 if g_Game_IsClient
then
5193 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5195 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5196 gPlayer1Settings
.Team
);
5199 g_Console_Add('teamchat <text>');
5201 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5203 else if cmd
= 'game' then
5205 if gGameSettings
.GameType
<> GT_NONE
then
5207 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5210 if Length(P
) = 1 then
5212 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5215 // game not started yet, load fist map from some wad
5217 s
:= addWadExtension(P
[1]);
5218 found
:= e_FindResource(AllMapDirs
, s
);
5222 P
[1] := ExpandFileName(P
[1]);
5223 // if map not choosed then set first map
5224 if Length(P
) < 3 then
5227 P
[2] := g_Game_GetFirstMap(P
[1]);
5230 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5232 if g_Map_Exist(s
) then
5236 with gGameSettings
do
5238 Options
:= gsGameFlags
;
5239 GameMode
:= g_Game_TextToMode(gsGameMode
);
5240 if gSwitchGameMode
<> GM_NONE
then
5241 GameMode
:= gSwitchGameMode
;
5242 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5243 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5245 if Length(P
) >= 4 then
5246 b
:= StrToIntDef(P
[3], 1);
5247 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5248 GoalLimit
, MaxLives
, Options
, b
);
5253 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5255 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5257 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5259 else if cmd
= 'host' then
5261 if gGameSettings
.GameType
<> GT_NONE
then
5263 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5266 if Length(P
) < 4 then
5268 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5271 if not StrToIp(P
[1], listen
) then
5273 prt
:= StrToIntDef(P
[2], 25666);
5275 s
:= addWadExtension(P
[3]);
5276 found
:= e_FindResource(AllMapDirs
, s
);
5280 // get first map in wad, if not specified
5281 if Length(P
) < 5 then
5284 P
[4] := g_Game_GetFirstMap(P
[1]);
5286 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5287 if g_Map_Exist(s
) then
5291 with gGameSettings
do
5293 Options
:= gsGameFlags
;
5294 GameMode
:= g_Game_TextToMode(gsGameMode
);
5295 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5296 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5297 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5299 if Length(P
) >= 6 then
5300 b
:= StrToIntDef(P
[5], 0);
5301 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
5307 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5309 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5314 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5317 else if cmd
= 'map' then
5319 if Length(P
) = 1 then
5321 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5323 g_Console_Add(cmd
+ ' <MAP>');
5324 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5328 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5333 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5335 if Length(P
) < 3 then
5337 // first param is map or wad
5338 s
:= UpperCase(P
[1]);
5339 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5341 gExitByTrigger
:= False;
5344 // already in game, finish current map
5346 gExit
:= EXIT_ENDLEVELCUSTOM
;
5350 // intermission, so change map immediately
5357 found
:= e_FindResource(AllMapDirs
, s
);
5359 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5362 // no such map, found wad
5365 P
[1] := ExpandFileName(pw
);
5366 P
[2] := g_Game_GetFirstMap(P
[1]);
5367 s
:= P
[1] + ':\' + P
[2];
5368 if g_Map_Exist(s
) then
5370 gExitByTrigger
:= False;
5373 // already in game, finish current map
5375 gExit
:= EXIT_ENDLEVELCUSTOM
5379 // intermission, so change map immediately
5386 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5388 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5393 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5399 s
:= addWadExtension(P
[1]);
5400 found
:= e_FindResource(AllMapDirs
, s
);
5404 P
[2] := UpperCase(P
[2]);
5405 s
:= P
[1] + ':\' + P
[2];
5406 if g_Map_Exist(s
) then
5408 gExitByTrigger
:= False;
5412 gExit
:= EXIT_ENDLEVELCUSTOM
5421 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5426 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5432 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5436 else if cmd
= 'nextmap' then
5438 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5440 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5445 if Length(P
) = 1 then
5447 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5449 g_Console_Add(cmd
+ ' <MAP>');
5450 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5455 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5461 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5463 if Length(P
) < 3 then
5465 // first param is map or wad
5466 s
:= UpperCase(P
[1]);
5467 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5470 gExitByTrigger
:= False;
5476 // no such map, found wad
5477 pw
:= addWadExtension(P
[1]);
5478 found
:= e_FindResource(MapDirs
, pw
);
5480 found
:= e_FindResource(WadDirs
, pw
);
5482 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5485 // map not specified, select first map
5487 P
[2] := g_Game_GetFirstMap(P
[1]);
5488 s
:= P
[1] + ':\' + P
[2];
5489 if g_Map_Exist(s
) then
5491 gExitByTrigger
:= False;
5498 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5500 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5505 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5511 // specified two params wad + map
5512 pw
:= addWadExtension(P
[1]);
5513 found
:= e_FindResource(MapDirs
, pw
);
5515 found
:= e_FindResource(MapDirs
, pw
);
5519 P
[2] := UpperCase(P
[2]);
5520 s
:= P
[1] + ':\' + P
[2];
5521 if g_Map_Exist(s
) then
5523 gExitByTrigger
:= False;
5529 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5534 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5540 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5545 if gNextMap
= '' then
5546 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5548 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5552 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5556 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5560 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5562 gExitByTrigger
:= False;
5563 // next map not specified, try to find trigger EXIT
5564 if (gNextMap
= '') and (gTriggers
<> nil) then
5566 for a
:= 0 to High(gTriggers
) do
5568 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5570 gExitByTrigger
:= True;
5571 //gNextMap := gTriggers[a].Data.MapName;
5572 gNextMap
:= gTriggers
[a
].tgcMap
;
5577 if gNextMap
= '' then
5578 gNextMap
:= g_Game_GetNextMap();
5579 if not isWadPath(gNextMap
) then
5580 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5583 if g_Map_Exist(s
) then
5584 gExit
:= EXIT_ENDLEVELCUSTOM
5586 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5590 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5594 else if (cmd
= 'event') then
5596 if (Length(P
) <= 1) then
5598 for a
:= 0 to High(gEvents
) do
5599 if gEvents
[a
].Command
= '' then
5600 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5602 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5605 if (Length(P
) = 2) then
5607 for a
:= 0 to High(gEvents
) do
5608 if gEvents
[a
].Name
= P
[1] then
5609 if gEvents
[a
].Command
= '' then
5610 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5612 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5615 for a
:= 0 to High(gEvents
) do
5616 if gEvents
[a
].Name
= P
[1] then
5618 gEvents
[a
].Command
:= '';
5619 for b
:= 2 to High(P
) do
5620 if Pos(' ', P
[b
]) = 0 then
5621 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5623 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5624 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5628 else if cmd
= 'suicide' then
5632 if g_Game_IsClient
then
5633 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5636 if gPlayer1
<> nil then
5637 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5638 if gPlayer2
<> nil then
5639 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5643 else if cmd
= 'screenshot' then
5647 else if cmd
= 'weapon' then
5649 if Length(p
) = 2 then
5651 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
5652 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5653 gSelectWeapon
[0, a
] := True
5656 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5658 if Length(p
) = 2 then
5660 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
5661 b
:= ord(cmd
[2]) - ord('1');
5662 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5663 gSelectWeapon
[b
, a
] := True
5666 // Команды Своей игры:
5667 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5669 if cmd
= 'bot_addred' then
5671 if Length(P
) > 1 then
5672 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5674 g_Bot_Add(TEAM_RED
, 2);
5676 else if cmd
= 'bot_addblue' then
5678 if Length(P
) > 1 then
5679 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5681 g_Bot_Add(TEAM_BLUE
, 2);
5683 else if cmd
= 'spectate' then
5689 else if cmd
= 'say' then
5691 if g_Game_IsServer
and g_Game_IsNet
then
5693 if Length(P
) > 1 then
5696 for a
:= 1 to High(P
) do
5697 chstr
:= chstr
+ P
[a
] + ' ';
5699 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5701 if Length(chstr
) < 1 then
5703 g_Console_Add('say <text>');
5707 chstr
:= b_Text_Format(chstr
);
5708 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5710 else g_Console_Add('say <text>');
5712 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5714 else if cmd
= 'tell' then
5716 if g_Game_IsServer
and g_Game_IsNet
then
5718 if (Length(P
) > 2) and (P
[1] <> '') then
5721 for a
:= 2 to High(P
) do
5722 chstr
:= chstr
+ P
[a
] + ' ';
5724 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5726 if Length(chstr
) < 1 then
5728 g_Console_Add('tell <playername> <text>');
5732 pl
:= g_Net_Client_ByName(P
[1]);
5734 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5736 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5738 else g_Console_Add('tell <playername> <text>');
5740 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5742 else if cmd
= 'centerprint' then
5744 if (Length(P
) > 2) and (P
[1] <> '') then
5747 for a
:= 2 to High(P
) do
5748 chstr
:= chstr
+ P
[a
] + ' ';
5750 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5752 if Length(chstr
) < 1 then
5754 g_Console_Add('centerprint <timeout> <text>');
5758 a
:= StrToIntDef(P
[1], 100);
5759 chstr
:= b_Text_Format(chstr
);
5760 g_Game_Message(chstr
, a
);
5761 if g_Game_IsNet
and g_Game_IsServer
then
5762 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
5764 else g_Console_Add('centerprint <timeout> <text>');
5766 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5768 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5770 // Дополнительное время:
5771 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5773 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5774 [gGameSettings
.TimeLimit
div 3600,
5775 (gGameSettings
.TimeLimit
div 60) mod 60,
5776 gGameSettings
.TimeLimit
mod 60]));
5777 if g_Game_IsNet
then MH_SEND_GameSettings
;
5779 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5781 if (Length(P
) <= 1) then
5782 g_Console_Add('rcon_password <password>')
5784 MC_SEND_RCONPassword(P
[1]);
5786 else if cmd
= 'rcon' then
5788 if g_Game_IsClient
then
5790 if Length(P
) > 1 then
5793 for a
:= 1 to High(P
) do
5794 chstr
:= chstr
+ P
[a
] + ' ';
5796 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5798 if Length(chstr
) < 1 then
5800 g_Console_Add('rcon <command>');
5804 MC_SEND_RCONCommand(chstr
);
5806 else g_Console_Add('rcon <command>');
5809 else if cmd
= 'ready' then
5811 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5812 gLMSRespawnTime
:= gTime
+ 100;
5814 else if (cmd
= 'callvote') and g_Game_IsNet
then
5816 if Length(P
) > 1 then
5819 for a
:= 1 to High(P
) do begin
5820 if a
> 1 then chstr
:= chstr
+ ' ';
5821 chstr
:= chstr
+ P
[a
];
5824 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5826 if Length(chstr
) < 1 then
5828 g_Console_Add('callvote <command>');
5832 if g_Game_IsClient
then
5833 MC_SEND_Vote(True, chstr
)
5835 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5836 g_Console_Process('vote', True);
5839 g_Console_Add('callvote <command>');
5841 else if (cmd
= 'vote') and g_Game_IsNet
then
5843 if g_Game_IsClient
then
5845 else if gVoteInProgress
then
5847 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5848 a
:= Floor((NetClientCount
+1)/2.0) + 1
5850 a
:= Floor(NetClientCount
/2.0) + 1;
5855 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5856 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5862 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5863 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5871 procedure SystemCommands(P
: SSArray
);
5875 cmd
:= LowerCase(P
[0]);
5886 if Length(p
) = 2 then
5888 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
5890 gFrameTime
:= 1000 div gMaxFPS
5894 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
5898 if Length(p
) = 2 then
5900 gAskLanguage
:= true;
5901 gLanguage
:= LANGUAGE_ENGLISH
;
5902 case LowerCase(p
[1]) of
5905 gAskLanguage
:= false;
5906 gLanguage
:= LANGUAGE_ENGLISH
;
5910 gAskLanguage
:= false;
5911 gLanguage
:= LANGUAGE_RUSSIAN
;
5915 gAskLanguage
:= true;
5916 gLanguage
:= LANGUAGE_ENGLISH
;
5919 g_Language_Set(gLanguage
);
5923 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
5929 procedure g_TakeScreenShot(Filename
: string = '');
5930 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
5932 if e_NoGraphics
then Exit
;
5934 dir
:= e_GetWriteableDir(ScreenshotDirs
);
5936 if Filename
= '' then
5939 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
5940 Filename
:= 'screenshot-' + date
;
5943 name
:= e_CatPath(dir
, Filename
+ '.png');
5944 s
:= createDiskFile(name
);
5946 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
5948 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
5950 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
5955 g_Console_Add('oh shit, i can''t create screenshot!')
5959 procedure g_Game_InGameMenu(Show
: Boolean);
5961 if (g_ActiveWindow
= nil) and Show
then
5963 if gGameSettings
.GameType
= GT_SINGLE
then
5964 g_GUI_ShowWindow('GameSingleMenu')
5967 if g_Game_IsClient
then
5968 g_GUI_ShowWindow('GameClientMenu')
5970 if g_Game_IsNet
then
5971 g_GUI_ShowWindow('GameServerMenu')
5973 g_GUI_ShowWindow('GameCustomMenu');
5975 g_Sound_PlayEx('MENU_OPEN');
5977 // Пауза при меню только в одиночной игре:
5978 if (not g_Game_IsNet
) then
5982 if (g_ActiveWindow
<> nil) and (not Show
) then
5984 // Пауза при меню только в одиночной игре:
5985 if (not g_Game_IsNet
) then
5986 g_Game_Pause(False);
5990 procedure g_Game_Pause (Enable
: Boolean);
5994 if not gGameOn
then exit
;
5996 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
5999 gPauseMain
:= Enable
;
6001 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6004 procedure g_Game_HolmesPause (Enable
: Boolean);
6008 if not gGameOn
then exit
;
6009 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6012 gPauseHolmes
:= Enable
;
6014 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6017 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6022 if gTriggers
<> nil then
6023 for i
:= 0 to High(gTriggers
) do
6024 with gTriggers
[i
] do
6025 if (TriggerType
= TRIGGER_SOUND
) and
6027 Sound
.IsPlaying() then
6029 Sound
.Pause(Enable
);
6033 if gPlayers
<> nil then
6034 for i
:= 0 to High(gPlayers
) do
6035 if gPlayers
[i
] <> nil then
6036 gPlayers
[i
].PauseSounds(Enable
);
6039 if gMusic
<> nil then
6040 gMusic
.Pause(Enable
);
6043 procedure g_Game_StopAllSounds(all
: Boolean);
6047 if gTriggers
<> nil then
6048 for i
:= 0 to High(gTriggers
) do
6049 with gTriggers
[i
] do
6050 if (TriggerType
= TRIGGER_SOUND
) and
6054 if gMusic
<> nil then
6061 procedure g_Game_UpdateTriggerSounds
;
6064 if gTriggers
<> nil then
6065 for i
:= 0 to High(gTriggers
) do
6066 with gTriggers
[i
] do
6067 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6068 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6071 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6074 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6079 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6084 if gSpectMode
<> SPECT_PLAYERS
then
6086 if gSpectPID1
= UID
then
6091 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6098 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6103 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6108 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6113 if gSpectMode
<> SPECT_PLAYERS
then
6115 Pl
:= g_Player_Get(gSpectPID1
);
6116 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6121 if gSpectViewTwo
then
6123 Pl
:= g_Player_Get(gSpectPID2
);
6124 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6132 procedure g_Game_Message(Msg
: string; Time
: Word);
6134 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
6135 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
6136 MessageTime
:= Time
;
6139 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6141 punct
: Array[0..13] of String =
6142 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6148 function IsPunctuation(S
: String): Boolean;
6153 if Length(S
) <> 1 then
6155 for i
:= Low(punct
) to High(punct
) do
6156 if S
= punct
[i
] then
6162 function FilterPunctuation(S
: String): String;
6166 for i
:= Low(punct
) to High(punct
) do
6167 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6173 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6175 // remove player name
6176 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6177 // for FullWord check
6178 Text := toLowerCase1251(' ' + Text + ' ');
6179 fpText
:= FilterPunctuation(Text);
6181 for i
:= 0 to Length(gChatSounds
) - 1 do
6184 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6186 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6187 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6189 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6195 gChatSounds
[i
].Sound
.Play();
6201 g_Sound_PlayEx('SOUND_GAME_RADIO');
6204 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6213 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6217 if goodsnd
[a
].IsPlaying() then
6220 goodsnd
[Random(4)].Play();
6223 procedure g_Game_Announce_KillCombo(Param
: Integer);
6230 UID
:= Param
and $FFFF;
6235 Pl
:= g_Player_Get(UID
);
6244 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6248 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6252 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6256 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6264 if not g_Game_IsWatchedPlayer(UID
) then
6267 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6271 if killsnd
[n
].IsPlaying() then
6276 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6284 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6288 if hahasnd
[a
].IsPlaying() then
6291 hahasnd
[Random(3)].Play();
6294 procedure g_Game_StartVote(Command
, Initiator
: string);
6298 if not gVotesEnabled
then Exit
;
6299 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6300 if gVoteInProgress
or gVotePassed
then
6302 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6303 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6306 gVoteInProgress
:= True;
6307 gVotePassed
:= False;
6308 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6311 gVoteCommand
:= Command
;
6313 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6314 Need
:= Floor((NetClientCount
+1)/2.0)+1
6316 Need
:= Floor(NetClientCount
/2.0)+1;
6317 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6318 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6321 procedure g_Game_CheckVote
;
6325 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6326 if not gVoteInProgress
then Exit
;
6328 if (gTime
>= gVoteTimer
) then
6330 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6331 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6333 Need
:= Floor(NetClientCount
/2.0) + 1;
6334 if gVoteCount
>= Need
then
6336 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6337 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6338 gVotePassed
:= True;
6339 gVoteCmdTimer
:= gTime
+ 5000;
6343 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6344 MH_SEND_VoteEvent(NET_VE_FAILED
);
6346 if NetClients
<> nil then
6347 for I
:= Low(NetClients
) to High(NetClients
) do
6348 if NetClients
[i
].Used
then
6349 NetClients
[i
].Voted
:= False;
6350 gVoteInProgress
:= False;
6356 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6357 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6359 Need
:= Floor(NetClientCount
/2.0) + 1;
6360 if gVoteCount
>= Need
then
6362 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6363 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6364 gVoteInProgress
:= False;
6365 gVotePassed
:= True;
6366 gVoteCmdTimer
:= gTime
+ 5000;
6369 if NetClients
<> nil then
6370 for I
:= Low(NetClients
) to High(NetClients
) do
6371 if NetClients
[i
].Used
then
6372 NetClients
[i
].Voted
:= False;
6377 procedure g_Game_LoadMapList(FileName
: string);
6385 if not FileExists(FileName
) then Exit
;
6387 AssignFile(ListFile
, FileName
);
6389 while not EOF(ListFile
) do
6391 ReadLn(ListFile
, s
);
6394 if s
= '' then Continue
;
6396 SetLength(MapList
, Length(MapList
)+1);
6397 MapList
[High(MapList
)] := s
;
6399 CloseFile(ListFile
);
6402 procedure g_Game_SetDebugMode();
6405 // Читы (даже в своей игре):
6409 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6413 if Length(LoadingStat
.Msgs
) = 0 then
6419 begin // Переходим на следующую строку или скроллируем:
6420 if NextMsg
= Length(Msgs
) then
6422 for i
:= 0 to High(Msgs
)-1 do
6423 Msgs
[i
] := Msgs
[i
+1];
6431 Msgs
[NextMsg
-1] := Text;
6435 PBarWasHere
:= false;
6438 g_ActiveWindow
:= nil;
6440 ProcessLoading(true);
6443 procedure g_Game_StepLoading(Value
: Integer = -1);
6454 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6462 procedure g_Game_ClearLoading();
6471 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6472 if len
< 1 then len
:= 1;
6473 SetLength(Msgs
, len
);
6474 for len
:= Low(Msgs
) to High(Msgs
) do
6477 PBarWasHere
:= false;
6481 procedure Parse_Params(var pars
: TParamStrValues
);
6488 while i
<= ParamCount
do
6491 if (s
[1] = '-') and (Length(s
) > 1) then
6493 if (s
[2] = '-') and (Length(s
) > 2) then
6494 begin // Одиночный параметр
6495 SetLength(pars
, Length(pars
) + 1);
6496 with pars
[High(pars
)] do
6498 Name
:= LowerCase(s
);
6503 if (i
< ParamCount
) then
6504 begin // Параметр со значением
6506 SetLength(pars
, Length(pars
) + 1);
6507 with pars
[High(pars
)] do
6509 Name
:= LowerCase(s
);
6510 Value
:= LowerCase(ParamStr(i
));
6519 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6524 for i
:= 0 to High(pars
) do
6525 if pars
[i
].Name
= aName
then
6527 Result
:= pars
[i
].Value
;
6532 procedure g_Game_Process_Params();
6534 pars
: TParamStrValues
;
6537 LimT
, LimS
: Integer;
6548 s
:= Find_Param_Value(pars
, '--debug');
6551 g_Game_SetDebugMode();
6552 s
:= Find_Param_Value(pars
, '--netdump');
6557 // Connect when game loads
6558 ip
:= Find_Param_Value(pars
, '-connect');
6562 s
:= Find_Param_Value(pars
, '-port');
6563 if (s
= '') or not TryStrToInt(s
, Port
) then
6566 s
:= Find_Param_Value(pars
, '-pw');
6568 g_Game_StartClient(ip
, Port
, s
);
6572 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6575 gDefaultMegawadStart
:= s
;
6578 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6579 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6581 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6584 // Start map when game loads:
6585 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6586 if isWadPath(map
) then
6589 s
:= Find_Param_Value(pars
, '-gm');
6590 GMode
:= g_Game_TextToMode(s
);
6591 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6592 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6595 s
:= Find_Param_Value(pars
, '-limt');
6596 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6602 s
:= Find_Param_Value(pars
, '-lims');
6603 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6609 s
:= Find_Param_Value(pars
, '-lives');
6610 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6616 s
:= Find_Param_Value(pars
, '-opt');
6620 Opt
:= StrToIntDef(s
, 0);
6623 s
:= Find_Param_Value(pars
, '--close');
6627 // Override map to test:
6628 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6631 if e_IsValidResourceName(s
) then
6632 e_FindResource(AllMapDirs
, s
);
6633 gTestMap
:= ExpandFileName(s
);
6636 // Delete test map after play:
6637 s
:= Find_Param_Value(pars
, '--testdelete');
6640 //gMapToDelete := MapsDir + map;
6641 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6645 // Delete temporary WAD after play:
6646 s
:= Find_Param_Value(pars
, '--tempdelete');
6647 if (s
<> '') and (gTestMap
<> '') then
6649 gMapToDelete
:= gTestMap
;
6650 gTempDelete
:= True;
6653 // Number of players:
6654 s
:= Find_Param_Value(pars
, '-pl');
6656 n
:= DEFAULT_PLAYERS
6658 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6661 s
:= Find_Param_Value(pars
, '-port');
6662 if (s
= '') or not TryStrToInt(s
, Port
) then
6663 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6665 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6668 // Execute script when game loads:
6669 s
:= Find_Param_Value(pars
, '-exec');
6672 // if not isWadPath(s) then
6673 // s := GameDir + '/' + s;
6678 if IOResult
<> 0 then
6680 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6681 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6685 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6686 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6691 if IOResult
<> 0 then
6693 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6694 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6698 if Pos('#', s
) <> 1 then // script comment
6699 g_Console_Process(s
, True);
6710 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6711 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6712 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6713 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6715 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6716 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6717 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6718 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6720 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6721 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6723 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6724 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6726 {$IFDEF ENABLE_HOLMES}
6727 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6730 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6732 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6733 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6735 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6736 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6738 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6739 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6740 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6741 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
6742 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6743 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6744 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6745 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6746 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');