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 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
91 function g_Game_ModeToText(Mode
: Byte): string;
92 function g_Game_TextToMode(Mode
: string): Byte;
93 procedure g_Game_ExecuteEvent(Name
: String);
94 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
95 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
96 procedure g_Game_RemovePlayer();
97 procedure g_Game_Spectate();
98 procedure g_Game_SpectateCenterView();
99 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
100 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
101 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
102 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
103 procedure g_Game_Restart();
104 procedure g_Game_RestartLevel();
105 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
106 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
107 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
108 procedure g_Game_ChangeMap(const MapPath
: String);
109 procedure g_Game_ExitLevel(const Map
: AnsiString);
110 function g_Game_GetFirstMap(WAD
: String): String;
111 function g_Game_GetNextMap(): String;
112 procedure g_Game_NextLevel();
113 procedure g_Game_Pause(Enable
: Boolean);
114 procedure g_Game_HolmesPause(Enable
: Boolean);
115 procedure g_Game_InGameMenu(Show
: Boolean);
116 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
117 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
118 procedure g_Game_Message(Msg
: String; Time
: Word);
119 procedure g_Game_LoadMapList(FileName
: String);
120 procedure g_Game_PauseAllSounds(Enable
: Boolean);
121 procedure g_Game_StopAllSounds(all
: Boolean);
122 procedure g_Game_UpdateTriggerSounds();
123 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
124 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
125 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
126 procedure g_Game_Announce_KillCombo(Param
: Integer);
127 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
128 procedure g_Game_StartVote(Command
, Initiator
: string);
129 procedure g_Game_CheckVote
;
130 procedure g_TakeScreenShot(Filename
: string = '');
131 procedure g_FatalError(Text: String);
132 procedure g_SimpleError(Text: String);
133 function g_Game_IsTestMap(): Boolean;
134 procedure g_Game_DeleteTestMap();
135 procedure GameCVars(P
: SSArray
);
136 procedure PlayerSettingsCVars(P
: SSArray
);
137 procedure SystemCommands(P
: SSArray
);
138 procedure GameCommands(P
: SSArray
);
139 procedure GameCheats(P
: SSArray
);
140 procedure DebugCommands(P
: SSArray
);
141 procedure g_Game_Process_Params
;
142 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
143 procedure g_Game_StepLoading(Value
: Integer = -1);
144 procedure g_Game_ClearLoading();
145 procedure g_Game_SetDebugMode();
147 function IsActivePlayer(p
: TPlayer
): Boolean;
148 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
149 procedure SortGameStat(var stat
: TPlayerStatArray
);
151 procedure KeyPress (K
: Word);
152 procedure CharPress (C
: AnsiChar);
154 { procedure SetWinPause(Enable: Boolean); }
159 LOADING_SHOW_STEP
= 100;
160 LOADING_INTERLINE
= 20;
175 MESSAGE_DIKEY
= WM_USER
+ 1;
180 EXIT_ENDLEVELSINGLE
= 4;
181 EXIT_ENDLEVELCUSTOM
= 5;
183 GAME_OPTION_RESERVED
= 1;
184 GAME_OPTION_TEAMDAMAGE
= 2;
185 GAME_OPTION_ALLOWEXIT
= 4;
186 GAME_OPTION_WEAPONSTAY
= 8;
187 GAME_OPTION_MONSTERS
= 16;
188 GAME_OPTION_BOTVSPLAYER
= 32;
189 GAME_OPTION_BOTVSMONSTER
= 64;
190 GAME_OPTION_DMKEYS
= 128;
191 GAME_OPTION_TEAMHITTRACE
= 256;
192 GAME_OPTION_TEAMHITPROJECTILE
= 512;
193 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
198 STATE_INTERCUSTOM
= 3;
199 STATE_INTERSINGLE
= 4;
205 LMS_RESPAWN_NONE
= 0;
206 LMS_RESPAWN_WARMUP
= 1;
207 LMS_RESPAWN_FINAL
= 2;
224 CONFIG_FILENAME
= 'Doom2DF.cfg';
226 TEST_MAP_NAME
= '$$$_TEST_$$$';
228 STD_PLAYER_MODEL
= 'Doomer';
236 STATFILE_VERSION
= $03;
240 gGameSettings
: TGameSettings
;
241 gPlayer1Settings
: TPlayerSettings
;
242 gPlayer2Settings
: TPlayerSettings
;
244 gPlayerScreenSize
: TDFPoint
;
245 gPlayer1ScreenCoord
: TDFPoint
;
246 gPlayer2ScreenCoord
: TDFPoint
;
247 gPlayer1
: TPlayer
= nil;
248 gPlayer2
: TPlayer
= nil;
249 gPlayerDrawn
: TPlayer
= nil;
251 gLerpFactor
: Single = 1.0;
252 gSwitchGameMode
: Byte = GM_DM
;
253 gHearPoint1
, gHearPoint2
: THearPoint
;
254 gSoundEffectsDF
: Boolean = False;
255 gSoundTriggerTime
: Word = 0;
256 gAnnouncer
: Integer = ANNOUNCE_NONE
;
257 goodsnd
: array[0..3] of TPlayableSound
;
258 killsnd
: array[0..3] of TPlayableSound
;
259 hahasnd
: array[0..2] of TPlayableSound
;
260 sound_get_flag
: array[0..1] of TPlayableSound
;
261 sound_lost_flag
: array[0..1] of TPlayableSound
;
262 sound_ret_flag
: array[0..1] of TPlayableSound
;
263 sound_cap_flag
: array[0..1] of TPlayableSound
;
264 gBodyKillEvent
: Integer = -1;
265 gDefInterTime
: ShortInt = -1;
266 gInterEndTime
: LongWord = 0;
267 gInterTime
: LongWord = 0;
268 gServInterTime
: Byte = 0;
269 gGameStartTime
: LongWord = 0;
270 gTotalMonsters
: Integer = 0;
271 gPauseMain
: Boolean = false;
272 gPauseHolmes
: Boolean = false;
273 gShowTime
: Boolean = False;
274 gShowFPS
: Boolean = False;
275 gShowGoals
: Boolean = True;
276 gShowStat
: Boolean = True;
277 gShowPIDs
: Boolean = False;
278 gShowKillMsg
: Boolean = True;
279 gShowLives
: Boolean = True;
280 gShowPing
: Boolean = False;
281 gShowMap
: Boolean = False;
283 gState
: Byte = STATE_NONE
;
285 sWidth
, sHeight
: Word;
286 gSpectMode
: Byte = SPECT_NONE
;
287 gSpectHUD
: Boolean = True;
288 gSpectKeyPress
: Boolean = False;
289 gSpectX
: Integer = 0;
290 gSpectY
: Integer = 0;
291 gSpectStep
: Byte = 8;
292 gSpectViewTwo
: Boolean = False;
293 gSpectPID1
: Integer = -1;
294 gSpectPID2
: Integer = -1;
295 gSpectAuto
: Boolean = False;
296 gSpectAutoNext
: LongWord;
297 gSpectAutoStepX
: Integer;
298 gSpectAutoStepY
: Integer;
299 gMusic
: TMusic
= nil;
300 gLoadGameMode
: Boolean;
301 gCheats
: Boolean = False;
302 gMapOnce
: Boolean = False;
303 gMapToDelete
: String;
304 gTempDelete
: Boolean = False;
305 gLastMap
: Boolean = False;
308 gResolutionChange
: Boolean = False;
309 gRC_Width
, gRC_Height
: Integer;
310 gRC_FullScreen
, gRC_Maximized
: Boolean;
311 gLanguageChange
: Boolean = False;
312 gDebugMode
: Boolean = False;
313 g_debug_Sounds
: Boolean = False;
314 g_debug_Frames
: Boolean = False;
315 g_debug_WinMsgs
: Boolean = False;
316 g_debug_MonsterOff
: Boolean = False;
317 g_debug_BotAIOff
: Byte = 0;
318 g_debug_HealthBar
: Boolean = False;
319 g_Debug_Player
: Boolean = False;
320 gCoopMonstersKilled
: Word = 0;
321 gCoopSecretsFound
: Word = 0;
322 gCoopTotalMonstersKilled
: Word = 0;
323 gCoopTotalSecretsFound
: Word = 0;
324 gCoopTotalMonsters
: Word = 0;
325 gCoopTotalSecrets
: Word = 0;
326 gStatsOff
: Boolean = False;
327 gStatsPressed
: Boolean = False;
328 gExitByTrigger
: Boolean = False;
329 gNextMap
: String = '';
330 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
331 gLMSRespawnTime
: Cardinal = 0;
332 gLMSSoftSpawn
: Boolean = False;
333 gMissionFailed
: Boolean = False;
334 gVoteInProgress
: Boolean = False;
335 gVotePassed
: Boolean = False;
336 gVoteCommand
: string = '';
337 gVoteTimer
: Cardinal = 0;
338 gVoteCmdTimer
: Cardinal = 0;
339 gVoteCount
: Integer = 0;
340 gVoteTimeout
: Cardinal = 30;
341 gVoted
: Boolean = False;
342 gVotesEnabled
: Boolean = True;
343 gEvents
: Array of TGameEvent
;
344 gDelayedEvents
: Array of TDelayedEvent
;
345 gUseChatSounds
: Boolean = True;
346 gChatSounds
: Array of TChatSound
;
347 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
348 gInterReadyCount
: Integer = 0;
350 g_dbg_ignore_bounds
: Boolean = false;
351 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
352 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
354 // move button values:
355 // bits 0-1: l/r state:
356 // 0: neither left, nor right pressed
359 // bits 4-5: l/r state when strafe was pressed
360 P1MoveButton
: Byte = 0;
361 P2MoveButton
: Byte = 0;
363 g_profile_frame_update
: Boolean = false;
364 g_profile_frame_draw
: Boolean = false;
365 g_profile_collision
: Boolean = false;
366 g_profile_los
: Boolean = false;
367 g_profile_history_size
: Integer = 1000;
369 g_rlayer_back
: Boolean = true;
370 g_rlayer_step
: Boolean = true;
371 g_rlayer_wall
: Boolean = true;
372 g_rlayer_door
: Boolean = true;
373 g_rlayer_acid1
: Boolean = true;
374 g_rlayer_acid2
: Boolean = true;
375 g_rlayer_water
: Boolean = true;
376 g_rlayer_fore
: Boolean = true;
378 wNeedTimeReset
: Boolean = false;
380 procedure g_ResetDynlights ();
381 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
382 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
384 function conIsCheatsEnabled (): Boolean; inline;
385 function gPause (): Boolean; inline;
387 type (* private state *)
388 TEndCustomGameStat
= record
389 PlayerStat
: TPlayerStatArray
;
393 Map
, MapName
: String;
396 TEndSingleGameStat
= record
397 PlayerStat
: Array [0..1] of record
403 TotalSecrets
: Integer;
406 TLoadingStat
= record
410 Msgs
: Array of String;
412 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
416 x
, y
, radius
: Integer;
419 exploRadius
: Integer;
422 var (* private state *)
423 CustomStat
: TEndCustomGameStat
;
424 StatShotDone
: Boolean;
425 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
426 SingleStat
: TEndSingleGameStat
;
428 LoadingStat
: TLoadingStat
;
431 EndingGameCounter
: Byte;
433 g_playerLight
: Boolean;
434 g_dynLights
: array of TDynLight
= nil;
435 g_dynLightCount
: Integer = 0;
440 {$IFDEF ENABLE_HOLMES}
443 e_res
, g_textures
, g_window
, g_menu
,
444 e_input
, e_log
, g_console
, r_console
, g_items
, g_map
, g_panel
,
445 g_playermodel
, g_gfx
, g_options
, Math
,
446 g_triggers
, g_monsters
, e_sound
, CONFIG
,
447 g_language
, g_net
, g_phys
,
448 ENet
, e_msg
, g_netmsg
, g_netmaster
,
449 sfs
, wadreader
, g_system
, r_playermodel
;
452 charbuff
: packed array [0..15] of AnsiChar = (
453 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
456 function Translit (const S
: AnsiString): AnsiString;
461 for i
:= 1 to Length(Result
) do
464 #
$C9: Result
[i
] := 'Q';
465 #
$D6: Result
[i
] := 'W';
466 #
$D3: Result
[i
] := 'E';
467 #
$CA: Result
[i
] := 'R';
468 #
$C5: Result
[i
] := 'T';
469 #
$CD: Result
[i
] := 'Y';
470 #
$C3: Result
[i
] := 'U';
471 #
$D8: Result
[i
] := 'I';
472 #
$D9: Result
[i
] := 'O';
473 #
$C7: Result
[i
] := 'P';
474 #
$D5: Result
[i
] := '['; //Chr(219);
475 #
$DA: Result
[i
] := ']'; //Chr(221);
476 #
$D4: Result
[i
] := 'A';
477 #
$DB: Result
[i
] := 'S';
478 #
$C2: Result
[i
] := 'D';
479 #
$C0: Result
[i
] := 'F';
480 #
$CF: Result
[i
] := 'G';
481 #
$D0: Result
[i
] := 'H';
482 #
$CE: Result
[i
] := 'J';
483 #
$CB: Result
[i
] := 'K';
484 #
$C4: Result
[i
] := 'L';
485 #
$C6: Result
[i
] := ';'; //Chr(186);
486 #
$DD: Result
[i
] := #39; //Chr(222);
487 #
$DF: Result
[i
] := 'Z';
488 #
$D7: Result
[i
] := 'X';
489 #
$D1: Result
[i
] := 'C';
490 #
$CC: Result
[i
] := 'V';
491 #
$C8: Result
[i
] := 'B';
492 #
$D2: Result
[i
] := 'N';
493 #
$DC: Result
[i
] := 'M';
494 #
$C1: Result
[i
] := ','; //Chr(188);
495 #
$DE: Result
[i
] := '.'; //Chr(190);
501 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
506 ls2
:= Translit(CheatRus
[ct
]);
507 if length(ls1
) = 0 then ls1
:= '~';
508 if length(ls2
) = 0 then ls2
:= '~';
510 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
511 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
512 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
513 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
515 if ct = I_GAME_CHEAT_JETPACK then
517 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
518 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
519 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
520 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
521 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
522 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
538 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
539 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
540 or g_Game_IsNet then Exit;
542 if not gGameOn
then exit
;
543 if not conIsCheatsEnabled
then exit
;
545 s
:= 'SOUND_GAME_RADIO';
548 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
550 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
551 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
555 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
557 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
558 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
562 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
564 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
565 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
569 if CheckCheat(I_GAME_CHEAT_DEATH
) then
571 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
572 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
573 s
:= 'SOUND_MONSTER_HAHA';
577 if CheckCheat(I_GAME_CHEAT_DOORS
) then
579 g_Triggers_OpenAll();
583 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
585 if gTriggers
<> nil then
586 for a
:= 0 to High(gTriggers
) do
587 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
589 gExitByTrigger
:= True;
590 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
591 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
597 s2
:= Copy(charbuff
, 15, 2);
598 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
600 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
608 if CheckCheat(I_GAME_CHEAT_FLY
) then
614 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
616 VEL_JUMP
:= 30-VEL_JUMP
;
620 if CheckCheat(I_GAME_CHEAT_SPEED
) then
622 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
626 if CheckCheat(I_GAME_CHEAT_SUIT
) then
628 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
629 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
633 if CheckCheat(I_GAME_CHEAT_AIR
) then
635 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
636 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
640 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
642 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
643 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
647 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
649 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
650 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
654 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
656 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
657 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
661 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
663 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
664 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
668 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
670 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
671 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
674 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
676 gAimLine
:= not gAimLine
;
679 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
681 gShowMap
:= not gShowMap
;
691 procedure KeyPress (K
: Word);
701 if (g_ActiveWindow
<> nil) then
703 Msg
.Msg
:= WM_KEYDOWN
;
704 Msg
.WParam
:= VK_ESCAPE
;
705 g_ActiveWindow
.OnMessage(Msg
);
706 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
708 else if (gState
<> STATE_FOLD
) then
710 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
712 g_Game_InGameMenu(True);
714 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
716 if (gState
<> STATE_MENU
) then
718 if (NetMode
<> NET_NONE
) then
720 g_Game_StopAllSounds(True);
722 gState
:= STATE_MENU
;
726 g_GUI_ShowWindow('MainMenu');
727 g_Sound_PlayEx('MENU_OPEN');
732 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
733 begin // <F2> .. <F6> � <F12>
734 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
736 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
737 if (not g_Game_IsNet
) then g_Game_Pause(True);
739 IK_F2
: g_Menu_Show_SaveMenu();
740 IK_F3
: g_Menu_Show_LoadMenu();
741 IK_F4
: g_Menu_Show_GameSetGame();
742 IK_F5
: g_Menu_Show_OptionsVideo();
743 IK_F6
: g_Menu_Show_OptionsSound();
744 IK_F7
: g_Menu_Show_EndGameMenu();
745 IK_F10
: g_Menu_Show_QuitGameMenu();
752 gJustChatted
:= False;
753 if gConsoleShow
or gChatShow
then
755 g_Console_Control(K
);
757 else if (g_ActiveWindow
<> nil) then
759 Msg
.Msg
:= WM_KEYDOWN
;
761 g_ActiveWindow
.OnMessage(Msg
);
763 else if (gState
= STATE_MENU
) then
765 g_GUI_ShowWindow('MainMenu');
766 g_Sound_PlayEx('MENU_OPEN');
773 procedure CharPress (C
: AnsiChar);
778 if gConsoleShow
or gChatShow
then
782 else if (g_ActiveWindow
<> nil) then
785 Msg
.WParam
:= Ord(C
);
786 g_ActiveWindow
.OnMessage(Msg
);
790 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
791 charbuff
[15] := upcase1251(C
);
797 // ////////////////////////////////////////////////////////////////////////// //
798 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
800 procedure g_ResetDynlights ();
804 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
806 for idx
:= 0 to g_dynLightCount
-1 do
808 if g_dynLights
[idx
].exploCount
= -666 then
815 Inc(g_dynLights
[idx
].exploCount
);
816 if (g_dynLights
[idx
].exploCount
< 10) then
818 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
819 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
820 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
821 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
826 g_dynLightCount
:= lnum
;
829 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
831 if not gwin_has_stencil
then exit
;
832 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
833 g_dynLights
[g_dynLightCount
].x
:= x
;
834 g_dynLights
[g_dynLightCount
].y
:= y
;
835 g_dynLights
[g_dynLightCount
].radius
:= radius
;
836 g_dynLights
[g_dynLightCount
].r
:= r
;
837 g_dynLights
[g_dynLightCount
].g
:= g
;
838 g_dynLights
[g_dynLightCount
].b
:= b
;
839 g_dynLights
[g_dynLightCount
].a
:= a
;
840 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
841 Inc(g_dynLightCount
);
844 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
846 if not gwin_has_stencil
then exit
;
847 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
848 g_dynLights
[g_dynLightCount
].x
:= x
;
849 g_dynLights
[g_dynLightCount
].y
:= y
;
850 g_dynLights
[g_dynLightCount
].radius
:= 0;
851 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
852 g_dynLights
[g_dynLightCount
].r
:= r
;
853 g_dynLights
[g_dynLightCount
].g
:= g
;
854 g_dynLights
[g_dynLightCount
].b
:= b
;
855 g_dynLights
[g_dynLightCount
].a
:= 0;
856 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
857 Inc(g_dynLightCount
);
860 // ////////////////////////////////////////////////////////////////////////// //
861 function conIsCheatsEnabled (): Boolean; inline;
864 if g_Game_IsNet
then exit
;
865 if not gDebugMode
then
867 //if not gCheats then exit;
868 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
869 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
874 // ////////////////////////////////////////////////////////////////////////// //
876 TParamStrValue
= record
881 TParamStrValues
= Array of TParamStrValue
;
884 INTER_ACTION_TEXT
= 1;
885 INTER_ACTION_PIC
= 2;
886 INTER_ACTION_MUSIC
= 3;
891 DataLoaded
: Boolean = False;
893 MessageLineLength
: Integer = 80;
894 MapList
: SSArray
= nil;
895 MapIndex
: Integer = -1;
896 InterReadyTime
: Integer = -1;
897 StatDate
: string = '';
903 text: Array of ShortString;
904 anim
: Array of ShortString;
905 pic
: Array of ShortString;
906 mus
: Array of ShortString;
908 triggers
: Array of record
910 actions
: Array of record
911 action
, p1
, p2
: Integer;
914 cur_trigger
: Integer;
927 function Compare(a
, b
: TPlayerStat
): Integer;
929 if a
.Spectator
then Result
:= 1
930 else if b
.Spectator
then Result
:= -1
931 else if a
.Frags
< b
.Frags
then Result
:= 1
932 else if a
.Frags
> b
.Frags
then Result
:= -1
933 else if a
.Deaths
< b
.Deaths
then Result
:= -1
934 else if a
.Deaths
> b
.Deaths
then Result
:= 1
935 else if a
.Kills
< b
.Kills
then Result
:= -1
939 procedure SortGameStat(var stat
: TPlayerStatArray
);
944 if stat
= nil then Exit
;
946 for I
:= High(stat
) downto Low(stat
) do
947 for J
:= Low(stat
) to High(stat
) - 1 do
948 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
951 stat
[J
] := stat
[J
+ 1];
956 // saves a shitty CSV containing the game stats passed to it
957 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
960 dir
, fname
, map
, mode
, etime
: String;
964 dir
:= e_GetWriteableDir(StatsDirs
);
965 // stats are placed in stats/yy/mm/dd/*.csv
966 fname
:= e_CatPath(dir
, Path
);
967 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
968 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
969 AssignFile(s
, fname
);
972 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
973 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
974 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
975 mode
:= g_Game_ModeToText(Stat
.GameMode
);
976 etime
:= Format('%d:%.2d:%.2d', [
977 Stat
.GameTime
div 1000 div 3600,
978 (Stat
.GameTime
div 1000 div 60) mod 60,
979 Stat
.GameTime
div 1000 mod 60
981 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
982 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
988 gGameSettings
.TimeLimit
,
989 gGameSettings
.GoalLimit
,
990 gGameSettings
.Options
,
992 Length(Stat
.PlayerStat
)
994 // line 2: game specific shit
995 // if it's a team game: red score, blue score
996 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
998 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1000 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Goals
, Stat
.TeamStat
[TEAM_BLUE
].Goals
]))
1001 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1003 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1004 // lines 3-...: team, player name, frags, deaths
1005 WriteLn(s
, 'team,name,frags,deaths');
1006 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1007 with Stat
.PlayerStat
[I
] do
1008 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1010 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1013 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1018 function g_Game_ModeToText(Mode
: Byte): string;
1022 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1023 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1024 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1025 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1026 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1030 function g_Game_TextToMode(Mode
: string): Byte;
1033 Mode
:= UpperCase(Mode
);
1034 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1039 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1044 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1049 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1054 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1056 Result
:= GM_SINGLE
;
1061 function g_Game_IsNet(): Boolean;
1063 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1066 function g_Game_IsServer(): Boolean;
1068 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1071 function g_Game_IsClient(): Boolean;
1073 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1076 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1083 Result
.name
:= ExtractFileName(WAD
);
1084 Result
.description
:= '';
1085 Result
.author
:= '';
1087 w
:= TWADFile
.Create();
1090 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1096 cfg
:= TConfig
.CreateMem(p
, len
);
1097 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1098 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1099 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1100 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1106 procedure g_Game_FreeWAD();
1110 for a
:= 0 to High(MegaWAD
.res
.pic
) do
1111 if MegaWAD
.res
.pic
[a
] <> '' then
1112 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
1114 for a
:= 0 to High(MegaWAD
.res
.mus
) do
1115 if MegaWAD
.res
.mus
[a
] <> '' then
1116 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
1118 MegaWAD
.res
.pic
:= nil;
1119 MegaWAD
.res
.text := nil;
1120 MegaWAD
.res
.anim
:= nil;
1121 MegaWAD
.res
.mus
:= nil;
1122 MegaWAD
.triggers
:= nil;
1124 g_Texture_Delete('TEXTURE_endpic');
1125 g_Sound_Delete('MUSIC_endmus');
1127 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1128 gGameSettings
.WAD
:= '';
1131 procedure g_Game_LoadWAD(WAD
: string);
1140 gGameSettings
.WAD
:= WAD
;
1141 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1144 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1146 w
:= TWADFile
.Create();
1149 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1155 cfg
:= TConfig
.CreateMem(p
, len
);
1160 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
1161 if s = '' then Break;
1164 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
1165 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
1167 g_Texture_CreateWADEx(s, s);
1173 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
1174 if s = '' then Break;
1177 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
1178 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
1180 g_Music_CreateWADEx(s, s);
1183 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1184 if MegaWAD
.endpic
<> '' then
1186 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1187 g_Texture_CreateWADEx('TEXTURE_endpic', s
, gTextureFilter
);
1189 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1190 if MegaWAD
.endmus
<> '' then
1192 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1193 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1201 {procedure start_trigger(t: string);
1205 function next_trigger(): Boolean;
1209 procedure DisableCheats();
1215 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1216 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1217 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1218 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1220 {$IF DEFINED(D2F_DEBUG)}
1221 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1222 gAimLine
:= g_dbg_aimline_on
;
1226 procedure g_Game_ExecuteEvent(Name
: String);
1232 if gEvents
= nil then
1234 for a
:= 0 to High(gEvents
) do
1235 if gEvents
[a
].Name
= Name
then
1237 if gEvents
[a
].Command
<> '' then
1238 g_Console_Process(gEvents
[a
].Command
, True);
1243 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1248 if gDelayedEvents
<> nil then
1249 for a
:= 0 to High(gDelayedEvents
) do
1250 if not gDelayedEvents
[a
].Pending
then
1257 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1258 n
:= High(gDelayedEvents
);
1260 gDelayedEvents
[n
].Pending
:= True;
1261 gDelayedEvents
[n
].DEType
:= DEType
;
1262 gDelayedEvents
[n
].DENum
:= Num
;
1263 gDelayedEvents
[n
].DEStr
:= Str
;
1264 if DEType
= DE_GLOBEVENT
then
1265 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
1267 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1271 procedure EndGame();
1277 if g_Game_IsNet
and g_Game_IsServer
then
1278 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1281 gPauseMain
:= false;
1282 gPauseHolmes
:= false;
1285 g_Game_StopAllSounds(False);
1290 EndingGameCounter
:= 0;
1291 g_ActiveWindow
:= nil;
1293 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1294 gLMSRespawnTime
:= 0;
1297 EXIT_SIMPLE
: // Выход через меню или конец теста
1302 begin // Это был тест
1306 begin // Выход в главное меню
1307 gMusic
.SetByName('MUSIC_MENU');
1309 if gState
<> STATE_SLIST
then
1311 g_GUI_ShowWindow('MainMenu');
1312 gState
:= STATE_MENU
;
1315 // Обновляем список серверов
1316 slReturnPressed
:= True;
1317 if g_Net_Slist_Fetch(slCurrent
) then
1319 if slCurrent
= nil then
1320 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1323 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1324 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1327 g_Game_ExecuteEvent('ongameend');
1331 EXIT_RESTART
: // Начать уровень сначала
1333 if not g_Game_IsClient
then g_Game_Restart();
1336 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1338 // Статистика Своей игры:
1339 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1341 CustomStat
.GameTime
:= gTime
;
1342 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1343 CustomStat
.MapName
:= gMapInfo
.Name
;
1344 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1345 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1346 CustomStat
.TeamStat
:= gTeamStat
;
1348 CustomStat
.PlayerStat
:= nil;
1350 // Статистика игроков:
1351 if gPlayers
<> nil then
1353 for a
:= 0 to High(gPlayers
) do
1354 if gPlayers
[a
] <> nil then
1356 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1357 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1360 Name
:= gPlayers
[a
].Name
;
1361 Frags
:= gPlayers
[a
].Frags
;
1362 Deaths
:= gPlayers
[a
].Death
;
1363 Kills
:= gPlayers
[a
].Kills
;
1364 Team
:= gPlayers
[a
].Team
;
1365 Color
:= gPlayers
[a
].Model
.Color
;
1366 Spectator
:= gPlayers
[a
].FSpectator
;
1370 SortGameStat(CustomStat
.PlayerStat
);
1372 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1375 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1376 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1377 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1378 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1380 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1383 StatShotDone
:= False;
1386 g_Game_ExecuteEvent('onmapend');
1387 if not g_Game_IsClient
then g_Player_ResetReady
;
1388 gInterReadyCount
:= 0;
1390 // Затухающий экран:
1391 EndingGameCounter
:= 255;
1392 gState
:= STATE_FOLD
;
1394 if gDefInterTime
< 0 then
1395 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1397 gInterEndTime
:= gDefInterTime
* 1000;
1400 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1402 // Статистика Одиночной игры:
1403 SingleStat
.GameTime
:= gTime
;
1404 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1405 SingleStat
.TotalSecrets
:= gSecretsCount
;
1406 // Статистика первого игрока:
1407 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1408 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1409 // Статистика второго игрока (если есть):
1410 if SingleStat
.TwoPlayers
then
1412 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1413 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1416 g_Game_ExecuteEvent('onmapend');
1419 if gNextMap
<> '' then
1421 gMusic
.SetByName('MUSIC_INTERMUS');
1423 gState
:= STATE_INTERSINGLE
;
1426 g_Game_ExecuteEvent('oninter');
1428 else // Больше нет карт
1430 // Затухающий экран:
1431 EndingGameCounter
:= 255;
1432 gState
:= STATE_FOLD
;
1437 // Окончание обработано:
1438 if gExit
<> EXIT_QUIT
then
1442 procedure g_Game_Init();
1445 knownFiles
: array of AnsiString = nil;
1447 wext
, s
: AnsiString;
1452 gTempDelete
:= False;
1454 sfsGCDisable(); // temporary disable removing of temporary volumes
1457 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE', gTextureFilter
);
1458 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER', gTextureFilter
);
1459 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN', gTextureFilter
);
1460 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU', gTextureFilter
);
1462 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1463 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1464 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1466 g_Game_ClearLoading();
1467 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1468 g_Game_SetLoadingText('', 0, False);
1470 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1471 // load models from all possible wad types, in all known directories
1472 // this does a loosy job (linear search, ooph!), but meh
1473 for wext
in wadExtensions
do
1475 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1477 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1481 for s
in knownFiles
do
1483 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1491 SetLength(knownFiles
, length(knownFiles
)+1);
1492 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1494 until (FindNext(SR
) <> 0);
1500 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1502 if (length(knownFiles
) = 1) then e_LogWriteln('1 player model found.', TMsgType
.Notify
) else e_LogWritefln('%d player models found.', [Integer(length(knownFiles
))], TMsgType
.Notify
);
1503 for s
in knownFiles
do
1505 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1509 gPauseMain
:= false;
1510 gPauseHolmes
:= false;
1513 {e_MouseInfo.Accel := 1.0;}
1515 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1518 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1519 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1520 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1521 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1522 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1524 gMusic
:= TMusic
.Create();
1525 gMusic
.SetByName('MUSIC_MENU');
1528 gGameSettings
.WarmupTime
:= 30;
1530 gState
:= STATE_MENU
;
1532 SetLength(gEvents
, 6);
1533 gEvents
[0].Name
:= 'ongamestart';
1534 gEvents
[1].Name
:= 'ongameend';
1535 gEvents
[2].Name
:= 'onmapstart';
1536 gEvents
[3].Name
:= 'onmapend';
1537 gEvents
[4].Name
:= 'oninter';
1538 gEvents
[5].Name
:= 'onwadend';
1540 sfsGCEnable(); // enable releasing unused volumes
1544 procedure g_Game_Free(freeTextures
: Boolean=true);
1546 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1547 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1549 g_Map_Free(freeTextures
);
1551 g_Player_RemoveAllCorpses();
1553 gGameSettings
.GameType
:= GT_NONE
;
1554 if gGameSettings
.GameMode
= GM_SINGLE
then
1555 gGameSettings
.GameMode
:= GM_DM
;
1556 gSwitchGameMode
:= gGameSettings
.GameMode
;
1559 gExitByTrigger
:= False;
1562 function IsActivePlayer(p
: TPlayer
): Boolean;
1567 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1570 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1576 if gPlayers
= nil then
1580 for a
:= Low(gPlayers
) to High(gPlayers
) do
1581 if IsActivePlayer(gPlayers
[a
]) then
1583 SetLength(ids
, Length(ids
) + 1);
1584 ids
[High(ids
)] := gPlayers
[a
].UID
;
1585 if gPlayers
[a
].UID
= Skip
then
1588 if Length(ids
) = 0 then
1593 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1596 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1602 if gPlayers
= nil then
1606 for a
:= Low(gPlayers
) to High(gPlayers
) do
1607 if IsActivePlayer(gPlayers
[a
]) then
1609 SetLength(ids
, Length(ids
) + 1);
1610 ids
[High(ids
)] := gPlayers
[a
].UID
;
1611 if gPlayers
[a
].UID
= Skip
then
1614 if Length(ids
) = 0 then
1617 Result
:= ids
[Length(ids
) - 1]
1619 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1622 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1628 if gPlayers
= nil then
1632 for a
:= Low(gPlayers
) to High(gPlayers
) do
1633 if IsActivePlayer(gPlayers
[a
]) then
1635 SetLength(ids
, Length(ids
) + 1);
1636 ids
[High(ids
)] := gPlayers
[a
].UID
;
1637 if gPlayers
[a
].UID
= Skip
then
1640 if Length(ids
) = 0 then
1642 if Length(ids
) = 1 then
1647 Result
:= ids
[Random(Length(ids
))];
1649 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1651 Result
:= ids
[Random(Length(ids
))];
1656 function GetRandomSpectMode(Current
: Byte): Byte;
1663 0: Result
:= SPECT_STATS
;
1664 1: Result
:= SPECT_MAPVIEW
;
1665 2: Result
:= SPECT_MAPVIEW
;
1666 3: Result
:= SPECT_PLAYERS
;
1667 4: Result
:= SPECT_PLAYERS
;
1668 5: Result
:= SPECT_PLAYERS
;
1669 6: Result
:= SPECT_PLAYERS
;
1671 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1675 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1681 if (plr
= nil) then exit
;
1682 if (p
= 2) then time
:= 1000 else time
:= 1;
1683 strafeDir
:= MoveButton
shr 4;
1684 MoveButton
:= MoveButton
and $0F;
1686 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1687 MoveButton
:= 1 // Нажата только "Влево"
1688 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1689 MoveButton
:= 2 // Нажата только "Вправо"
1690 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1691 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1693 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1694 if MoveButton
= 1 then
1695 plr
.PressKey(KEY_LEFT
, time
)
1696 else if MoveButton
= 2 then
1697 plr
.PressKey(KEY_RIGHT
, time
);
1699 // if we have "strafe" key, turn off old strafe mechanics
1700 if gPlayerAction
[p
, ACTION_STRAFE
] then
1702 // new strafe mechanics
1703 if (strafeDir
= 0) then
1704 strafeDir
:= MoveButton
; // start strafing
1705 // now set direction according to strafe (reversed)
1706 if (strafeDir
= 2) then
1707 plr
.SetDirection(TDirection
.D_LEFT
)
1708 else if (strafeDir
= 1) then
1709 plr
.SetDirection(TDirection
.D_RIGHT
)
1713 strafeDir
:= 0; // not strafing anymore
1714 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1715 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1716 plr
.SetDirection(TDirection
.D_LEFT
)
1717 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1718 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1719 plr
.SetDirection(TDirection
.D_RIGHT
)
1720 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1721 else if MoveButton
<> 0 then
1722 plr
.SetDirection(TDirection(MoveButton
-1))
1725 // fix movebutton state
1726 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1728 // Остальные клавиши:
1729 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1730 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1731 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1732 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1733 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1734 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1735 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1737 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1738 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1740 for i
:= WP_FIRST
to WP_LAST
do
1742 if gSelectWeapon
[p
, i
] then
1744 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1745 gSelectWeapon
[p
, i
] := False
1749 // HACK: add dynlight here
1750 if gwin_k8_enable_light_experiments
then
1752 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1754 g_playerLight
:= true;
1756 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1758 g_playerLight
:= false;
1762 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1765 // HACK: don't have a "key was pressed" function
1766 procedure InterReady();
1768 if InterReadyTime
> gTime
then Exit
;
1769 InterReadyTime
:= gTime
+ 3000;
1770 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1773 procedure g_Game_PreUpdate();
1775 // these are in separate PreUpdate functions because they can interact during Update()
1776 // and are synced over the net
1777 // we don't care that much about corpses and gibs
1778 g_Player_PreUpdate();
1779 g_Monsters_PreUpdate();
1780 g_Items_PreUpdate();
1781 g_Weapon_PreUpdate();
1784 procedure g_Game_Update();
1786 Msg
: g_gui
.TMessage
;
1792 function sendMonsPos (mon
: TMonster
): Boolean;
1794 result
:= false; // don't stop
1795 // this will also reset "need-send" flag
1796 if mon
.gncNeedSend
then
1798 MH_SEND_MonsterPos(mon
.UID
);
1800 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1802 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1804 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1806 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1810 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1812 result
:= false; // don't stop
1813 // this will also reset "need-send" flag
1814 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1818 reliableUpdate
: Boolean;
1823 // Пора выключать игру:
1824 if gExit
= EXIT_QUIT
then
1826 // Игра закончилась - обрабатываем:
1830 if gExit
= EXIT_QUIT
then
1834 // Читаем клавиатуру и джойстик, если окно активно
1835 // no need to, as we'll do it in event handler
1837 // Обновляем консоль (движение и сообщения):
1841 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1843 gExit
:= EXIT_SIMPLE
;
1848 // process master server communications
1849 g_Net_Slist_Pulse();
1852 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1853 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1854 STATE_INTERTEXT
, // Текст между уровнями
1855 STATE_INTERPIC
: // Картинка между уровнями
1857 if g_Game_IsNet
and g_Game_IsServer
then
1859 gInterTime
:= gInterTime
+ GAME_TICK
;
1860 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1861 if a
<> gServInterTime
then
1863 gServInterTime
:= a
;
1864 MH_SEND_TimeSync(gServInterTime
);
1868 if (not g_Game_IsClient
) and
1872 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1873 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1874 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1875 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1877 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1878 and (g_ActiveWindow
= nil)
1880 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1883 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1884 g_Game_StopAllSounds(True);
1886 if gMapOnce
then // Это был тест
1887 gExit
:= EXIT_SIMPLE
1889 if gNextMap
<> '' then // Переходим на следующую карту
1890 g_Game_ChangeMap(gNextMap
)
1891 else // Следующей карты нет
1893 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1895 // Выход в главное меню:
1897 g_GUI_ShowWindow('MainMenu');
1898 gMusic
.SetByName('MUSIC_MENU');
1900 gState
:= STATE_MENU
;
1903 // Финальная картинка:
1904 g_Game_ExecuteEvent('onwadend');
1906 if not gMusic
.SetByName('MUSIC_endmus') then
1907 gMusic
.SetByName('MUSIC_STDENDMUS');
1909 gState
:= STATE_ENDPIC
;
1911 g_Game_ExecuteEvent('ongameend');
1916 else if g_Game_IsClient
and
1919 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1920 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1921 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1922 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1924 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1925 and (g_ActiveWindow
= nil)
1933 if gState
= STATE_INTERTEXT
then
1934 if InterText
.counter
> 0 then
1935 InterText
.counter
:= InterText
.counter
- 1;
1938 STATE_FOLD
: // Затухание экрана
1940 if EndingGameCounter
= 0 then
1942 // Закончился уровень в Своей игре:
1943 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1945 InterReadyTime
:= -1;
1946 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1948 g_Game_ExecuteEvent('onwadend');
1949 if not gMusic
.SetByName('MUSIC_endmus') then
1950 gMusic
.SetByName('MUSIC_STDENDMUS');
1953 gMusic
.SetByName('MUSIC_ROUNDMUS');
1956 gState
:= STATE_INTERCUSTOM
;
1959 else // Закончилась последняя карта в Одиночной игре
1961 gMusic
.SetByName('MUSIC_INTERMUS');
1963 gState
:= STATE_INTERSINGLE
;
1966 g_Game_ExecuteEvent('oninter');
1969 DecMin(EndingGameCounter
, 6, 0);
1972 STATE_ENDPIC
: // Картинка окончания мегаВада
1974 if gMapOnce
then // Это был тест
1976 gExit
:= EXIT_SIMPLE
;
1982 g_Serverlist_Control(slCurrent
, slTable
);
1985 // Статистика по Tab:
1987 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1990 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1992 // Время += 28 миллисекунд:
1993 gTime
:= gTime
+ GAME_TICK
;
1995 // Сообщение посередине экрана:
1996 if MessageTime
= 0 then
1998 if MessageTime
> 0 then
1999 MessageTime
:= MessageTime
- 1;
2001 if (g_Game_IsServer
) then
2003 // Был задан лимит времени:
2004 if (gGameSettings
.TimeLimit
> 0) then
2005 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
2006 begin // Он прошел => конец уровня
2011 // Надо респавнить игроков в LMS:
2012 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
2013 g_Game_RestartRound(gLMSSoftSpawn
);
2015 // Проверим результат голосования, если время прошло
2016 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2018 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2020 g_Console_Process(gVoteCommand
);
2022 gVotePassed
:= False;
2025 // Замеряем время захвата флагов
2026 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2027 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2028 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2029 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2031 // Был задан лимит побед:
2032 if (gGameSettings
.GoalLimit
> 0) then
2036 if gGameSettings
.GameMode
= GM_DM
then
2037 begin // В DM ищем игрока с max фрагами
2038 for i
:= 0 to High(gPlayers
) do
2039 if gPlayers
[i
] <> nil then
2040 if gPlayers
[i
].Frags
> b
then
2041 b
:= gPlayers
[i
].Frags
;
2044 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2045 begin // В CTF/TDM выбираем команду с наибольшим счетом
2046 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
2049 // Лимит побед набран => конец уровня:
2050 if b
>= gGameSettings
.GoalLimit
then
2057 // Обрабатываем клавиши игроков:
2058 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2059 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2060 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2062 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2063 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2064 end // if not console
2067 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2069 // process weapon switch queue
2073 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2074 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2076 if not gSpectKeyPress
then
2078 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2080 // switch spect mode
2082 SPECT_NONE
: ; // not spectator
2084 SPECT_MAPVIEW
: Inc(gSpectMode
);
2085 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2087 gSpectKeyPress
:= True;
2089 if (gSpectMode
= SPECT_MAPVIEW
)
2090 and (not gSpectAuto
) then
2092 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2093 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2094 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2095 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2096 if gPlayerAction
[0, ACTION_LOOKUP
] then
2097 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2098 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2099 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2100 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2103 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2104 gSpectKeyPress
:= True;
2106 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2109 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2110 gSpectKeyPress
:= True;
2113 if (gSpectMode
= SPECT_PLAYERS
)
2114 and (not gSpectAuto
) then
2116 if gPlayerAction
[0, ACTION_LOOKUP
] then
2119 gSpectViewTwo
:= True;
2120 gSpectKeyPress
:= True;
2122 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2124 // remove second view
2125 gSpectViewTwo
:= False;
2126 gSpectKeyPress
:= True;
2128 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2130 // prev player (view 1)
2131 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2132 gSpectKeyPress
:= True;
2134 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2136 // next player (view 1)
2137 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2138 gSpectKeyPress
:= True;
2140 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2142 // prev player (view 2)
2143 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2144 gSpectKeyPress
:= True;
2146 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2148 // next player (view 2)
2149 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2150 gSpectKeyPress
:= True;
2153 if gPlayerAction
[0, ACTION_ATTACK
] then
2155 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2158 gSpectAutoNext
:= 0;
2159 gSpectViewTwo
:= False;
2160 gSpectKeyPress
:= True;
2165 gSpectMode
:= SPECT_STATS
;
2166 gSpectAuto
:= False;
2167 gSpectKeyPress
:= True;
2172 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2173 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2174 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2175 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2176 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2177 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2178 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2179 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2180 gSpectKeyPress
:= False;
2184 if gSpectMode
= SPECT_MAPVIEW
then
2186 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2188 gSpectAutoNext
:= gTime
2191 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2193 gSpectAutoNext
:= gTime
2197 if gSpectAutoNext
<= gTime
then
2199 if gSpectAutoNext
> 0 then
2201 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2205 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2206 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2207 gSpectAutoStepX
:= Random(9) - 4;
2208 gSpectAutoStepY
:= Random(9) - 4;
2209 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2210 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2211 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2212 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2213 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2214 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2218 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2223 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2224 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2225 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2231 // Обновляем все остальное:
2234 g_Triggers_Update();
2236 g_Monsters_Update();
2238 g_Player_UpdateAll();
2239 g_Player_UpdatePhysicalObjects();
2241 // server: send newly spawned monsters unconditionally
2242 if (gGameSettings
.GameType
= GT_SERVER
) then
2244 if (Length(gMonstersSpawned
) > 0) then
2246 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2247 SetLength(gMonstersSpawned
, 0);
2251 if (gSoundTriggerTime
> 8) then
2253 g_Game_UpdateTriggerSounds();
2254 gSoundTriggerTime
:= 0;
2258 Inc(gSoundTriggerTime
);
2261 if (NetMode
= NET_SERVER
) then
2263 Inc(NetTimeToUpdate
);
2264 Inc(NetTimeToReliable
);
2266 // send monster updates
2267 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2269 // send all monsters (periodic sync)
2270 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2272 for I
:= 0 to High(gPlayers
) do
2274 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2277 g_Mons_ForEach(sendMonsPos
);
2279 if reliableUpdate
then
2281 NetTimeToReliable
:= 0;
2282 NetTimeToUpdate
:= NetUpdateRate
;
2286 NetTimeToUpdate
:= 0;
2291 // send only mosters with some unexpected changes
2292 g_Mons_ForEach(sendMonsPosUnexpected
);
2295 // send unexpected platform changes
2296 g_Map_NetSendInterestingPanels();
2298 g_Net_Slist_ServerUpdate();
2300 if NetUseMaster then
2302 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2304 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2306 NetTimeToMaster := gTime + NetMasterRate;
2311 else if (NetMode
= NET_CLIENT
) then
2313 MC_SEND_PlayerPos();
2315 end; // if gameOn ...
2317 // Активно окно интерфейса - передаем клавиши ему:
2318 if g_ActiveWindow
<> nil then
2320 w
:= e_GetFirstKeyPressed();
2322 if (w
<> IK_INVALID
) then
2324 Msg
.Msg
:= MESSAGE_DIKEY
;
2326 g_ActiveWindow
.OnMessage(Msg
);
2329 // Если оно от этого не закрылось, то обновляем:
2330 if g_ActiveWindow
<> nil then
2331 g_ActiveWindow
.Update();
2333 // Нужно сменить разрешение:
2334 if gResolutionChange
then
2336 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2337 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2338 gResolutionChange
:= False;
2339 g_ActiveWindow
:= nil;
2342 // Нужно сменить язык:
2343 if gLanguageChange
then
2345 //e_WriteLog('Read language file', MSG_NOTIFY);
2346 //g_Language_Load(DataDir + gLanguage + '.txt');
2347 g_Language_Set(gLanguage
);
2351 gLanguageChange
:= False;
2355 // Горячая клавиша для вызова меню выхода из игры (F10):
2356 if e_KeyPressed(IK_F10
) and
2358 (not gConsoleShow
) and
2359 (g_ActiveWindow
= nil) then
2364 Time
:= sys_GetTicks() {div 1000};
2366 // Обработка отложенных событий:
2367 if gDelayedEvents
<> nil then
2368 for a
:= 0 to High(gDelayedEvents
) do
2369 if gDelayedEvents
[a
].Pending
and
2371 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2372 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2375 case gDelayedEvents
[a
].DEType
of
2377 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2380 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2384 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2385 if g_Game_IsNet
and g_Game_IsServer
then
2386 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2390 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2392 gDelayedEvents
[a
].Pending
:= False;
2395 // Каждую секунду обновляем счетчик обновлений:
2396 UPSCounter
:= UPSCounter
+ 1;
2397 if Time
- UPSTime
>= 1000 then
2406 g_Weapon_AddDynLights();
2407 g_Items_AddDynLights();
2411 procedure g_Game_LoadChatSounds(Resource
: string);
2414 FileName
, Snd
: string;
2416 len
, cnt
, tags
, i
, j
: Integer;
2419 FileName
:= g_ExtractWadName(Resource
);
2421 WAD
:= TWADFile
.Create();
2422 WAD
.ReadFile(FileName
);
2424 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2431 cfg
:= TConfig
.CreateMem(p
, len
);
2432 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2434 SetLength(gChatSounds
, cnt
);
2435 for i
:= 0 to Length(gChatSounds
) - 1 do
2437 gChatSounds
[i
].Sound
:= nil;
2438 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2439 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2440 if (Snd
= '') or (Tags
<= 0) then
2442 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2443 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2444 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2445 SetLength(gChatSounds
[i
].Tags
, tags
);
2446 for j
:= 0 to tags
- 1 do
2447 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2448 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2455 procedure g_Game_FreeChatSounds();
2459 for i
:= 0 to Length(gChatSounds
) - 1 do
2461 gChatSounds
[i
].Sound
.Free();
2462 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2464 SetLength(gChatSounds
, 0);
2468 procedure g_Game_LoadData();
2475 if DataLoaded
then Exit
;
2477 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2479 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2480 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2481 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2482 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2483 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2484 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2485 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2486 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2487 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2488 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2489 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2490 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2491 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2492 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2493 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2496 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2497 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2498 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2499 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2503 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2504 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2505 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2506 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2507 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
2513 hasPBarGfx
:= false;
2517 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2518 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2519 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2520 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2521 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2522 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2523 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2524 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2525 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2526 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2527 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2528 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2529 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2530 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2531 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2532 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2533 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2534 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2535 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2536 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2537 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2538 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2539 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2540 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2541 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2542 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2543 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2544 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2545 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2546 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2547 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2548 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2549 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2550 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2551 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2552 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2553 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2554 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2555 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2557 goodsnd
[0] := TPlayableSound
.Create();
2558 goodsnd
[1] := TPlayableSound
.Create();
2559 goodsnd
[2] := TPlayableSound
.Create();
2560 goodsnd
[3] := TPlayableSound
.Create();
2562 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2563 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2564 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2565 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2567 killsnd
[0] := TPlayableSound
.Create();
2568 killsnd
[1] := TPlayableSound
.Create();
2569 killsnd
[2] := TPlayableSound
.Create();
2570 killsnd
[3] := TPlayableSound
.Create();
2572 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2573 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2574 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2575 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2577 hahasnd
[0] := TPlayableSound
.Create();
2578 hahasnd
[1] := TPlayableSound
.Create();
2579 hahasnd
[2] := TPlayableSound
.Create();
2581 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2582 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2583 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2585 sound_get_flag
[0] := TPlayableSound
.Create();
2586 sound_get_flag
[1] := TPlayableSound
.Create();
2587 sound_lost_flag
[0] := TPlayableSound
.Create();
2588 sound_lost_flag
[1] := TPlayableSound
.Create();
2589 sound_ret_flag
[0] := TPlayableSound
.Create();
2590 sound_ret_flag
[1] := TPlayableSound
.Create();
2591 sound_cap_flag
[0] := TPlayableSound
.Create();
2592 sound_cap_flag
[1] := TPlayableSound
.Create();
2594 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2595 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2596 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2597 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2598 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2599 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2600 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2601 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2603 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2605 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2608 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2609 g_Weapon_LoadData();
2611 g_Monsters_LoadData();
2616 procedure g_Game_Quit();
2618 g_Game_StopAllSounds(True);
2621 g_PlayerModel_FreeData();
2622 g_Texture_DeleteAll();
2623 g_Frames_DeleteAll();
2625 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2628 if NetInitDone
then g_Net_Free
;
2630 // remove map after test
2631 if gMapToDelete
<> '' then
2632 g_Game_DeleteTestMap();
2638 procedure g_Game_FreeData();
2640 if not DataLoaded
then Exit
;
2643 g_Weapon_FreeData();
2644 g_Monsters_FreeData();
2646 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2648 g_Texture_Delete('NOTEXTURE');
2649 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2650 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2651 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2652 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2653 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2654 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2655 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2656 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2657 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2658 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2659 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2660 g_Frames_DeleteByName('FRAMES_TELEPORT');
2661 g_Frames_DeleteByName('FRAMES_PUNCH');
2662 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2663 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2664 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2665 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2666 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2667 g_Sound_Delete('SOUND_GAME_TELEPORT');
2668 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2669 g_Sound_Delete('SOUND_GAME_SECRET');
2670 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2671 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2672 g_Sound_Delete('SOUND_GAME_BULK1');
2673 g_Sound_Delete('SOUND_GAME_BULK2');
2674 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2675 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2676 g_Sound_Delete('SOUND_GAME_BURNING');
2677 g_Sound_Delete('SOUND_GAME_SWITCH1');
2678 g_Sound_Delete('SOUND_GAME_SWITCH0');
2685 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2686 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2687 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2688 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2695 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2696 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2697 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2698 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2704 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2705 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2706 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2708 sound_get_flag
[0].Free();
2709 sound_get_flag
[1].Free();
2710 sound_lost_flag
[0].Free();
2711 sound_lost_flag
[1].Free();
2712 sound_ret_flag
[0].Free();
2713 sound_ret_flag
[1].Free();
2714 sound_cap_flag
[0].Free();
2715 sound_cap_flag
[1].Free();
2717 g_Sound_Delete('SOUND_CTF_GET1');
2718 g_Sound_Delete('SOUND_CTF_GET2');
2719 g_Sound_Delete('SOUND_CTF_LOST1');
2720 g_Sound_Delete('SOUND_CTF_LOST2');
2721 g_Sound_Delete('SOUND_CTF_RETURN1');
2722 g_Sound_Delete('SOUND_CTF_RETURN2');
2723 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2724 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2726 g_Game_FreeChatSounds();
2728 DataLoaded
:= False;
2731 procedure g_FatalError(Text: String);
2733 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2734 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2736 gExit
:= EXIT_SIMPLE
;
2737 if gGameOn
then EndGame
;
2740 procedure g_SimpleError(Text: String);
2742 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2743 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2746 procedure g_Game_SetupScreenSize();
2748 RES_FACTOR
= 4.0 / 3.0;
2754 // Размер экранов игроков:
2755 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2756 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2757 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
2759 gPlayerScreenSize
.Y
:= gScreenHeight
;
2761 // Размер заднего плана:
2762 if BackID
<> DWORD(-1) then
2765 if (gScreenWidth
*s
> gMapInfo
.Width
) or
2766 (gScreenHeight
*s
> gMapInfo
.Height
) then
2768 gBackSize
.X
:= gScreenWidth
;
2769 gBackSize
.Y
:= gScreenHeight
;
2773 e_GetTextureSize(BackID
, @bw
, @bh
);
2774 rf
:= Single(bw
) / Single(bh
);
2775 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
2776 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
2777 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
2778 if (s
< 1.0) then s
:= 1.0;
2779 gBackSize
.X
:= Round(bw
*s
);
2780 gBackSize
.Y
:= Round(bh
*s
);
2785 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
2787 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
2790 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2792 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2793 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2796 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2799 if gPlayer1
= nil then
2801 if g_Game_IsClient
then
2803 if NetPlrUID1
> -1 then
2804 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2808 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2809 Team
:= gPlayer1Settings
.Team
;
2811 // Создание первого игрока:
2812 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2813 gPlayer1Settings
.Color
,
2815 if gPlayer1
= nil then
2816 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2819 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2820 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2821 if g_Game_IsServer
and g_Game_IsNet
then
2822 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2823 gPlayer1
.Respawn(False, True);
2824 g_Net_Slist_ServerPlayerComes();
2829 if gPlayer2
= nil then
2831 if g_Game_IsClient
then
2833 if NetPlrUID2
> -1 then
2834 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2838 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2839 Team
:= gPlayer2Settings
.Team
;
2841 // Создание второго игрока:
2842 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2843 gPlayer2Settings
.Color
,
2845 if gPlayer2
= nil then
2846 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2849 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2850 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2851 if g_Game_IsServer
and g_Game_IsNet
then
2852 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2853 gPlayer2
.Respawn(False, True);
2854 g_Net_Slist_ServerPlayerComes();
2861 procedure g_Game_RemovePlayer();
2865 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2866 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2871 if g_Game_IsServer
then
2874 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2875 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2876 g_Player_Remove(Pl
.UID
);
2877 g_Net_Slist_ServerPlayerLeaves();
2881 gSpectLatchPID2
:= Pl
.UID
;
2889 if g_Game_IsServer
then
2892 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2893 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2894 g_Player_Remove(Pl
.UID
);
2895 g_Net_Slist_ServerPlayerLeaves();
2898 gSpectLatchPID1
:= Pl
.UID
;
2900 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2904 g_Net_Slist_ServerPlayerLeaves();
2907 procedure g_Game_Spectate();
2909 g_Game_RemovePlayer();
2910 if gPlayer1
<> nil then
2911 g_Game_RemovePlayer();
2914 procedure g_Game_SpectateCenterView();
2916 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2917 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2920 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2927 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2929 g_Game_ClearLoading();
2932 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2935 gGameSettings
.GameType
:= GT_SINGLE
;
2936 gGameSettings
.MaxLives
:= 0;
2937 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2938 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2939 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2940 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2941 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2942 gSwitchGameMode
:= GM_SINGLE
;
2944 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2945 gLMSRespawnTime
:= 0;
2946 gSpectLatchPID1
:= 0;
2947 gSpectLatchPID2
:= 0;
2949 g_Game_ExecuteEvent('ongamestart');
2951 // Установка размеров окон игроков:
2952 g_Game_SetupScreenSize();
2954 // Создание первого игрока:
2955 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2956 gPlayer1Settings
.Color
,
2957 gPlayer1Settings
.Team
, False));
2958 if gPlayer1
= nil then
2960 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2964 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2967 // Создание второго игрока, если есть:
2970 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2971 gPlayer2Settings
.Color
,
2972 gPlayer2Settings
.Team
, False));
2973 if gPlayer2
= nil then
2975 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2979 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2983 // Загрузка и запуск карты:
2984 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2986 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2987 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2991 // Настройки игроков и ботов:
2995 for i
:= nPl
+1 to nPlayers
do
2996 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2999 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3000 TimeLimit
, GoalLimit
: Word;
3002 Options
: LongWord; nPlayers
: Byte);
3008 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
3010 g_Game_ClearLoading();
3013 gGameSettings
.GameType
:= GT_CUSTOM
;
3014 gGameSettings
.GameMode
:= GameMode
;
3015 gSwitchGameMode
:= GameMode
;
3016 gGameSettings
.TimeLimit
:= TimeLimit
;
3017 gGameSettings
.GoalLimit
:= GoalLimit
;
3018 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3019 gGameSettings
.Options
:= Options
;
3021 gCoopTotalMonstersKilled
:= 0;
3022 gCoopTotalSecretsFound
:= 0;
3023 gCoopTotalMonsters
:= 0;
3024 gCoopTotalSecrets
:= 0;
3028 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3029 gLMSRespawnTime
:= 0;
3030 gSpectLatchPID1
:= 0;
3031 gSpectLatchPID2
:= 0;
3033 g_Game_ExecuteEvent('ongamestart');
3035 // Установка размеров окон игроков:
3036 g_Game_SetupScreenSize();
3038 // Режим наблюдателя:
3039 if nPlayers
= 0 then
3046 if nPlayers
>= 1 then
3048 // Создание первого игрока:
3049 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3050 gPlayer1Settings
.Color
,
3051 gPlayer1Settings
.Team
, False));
3052 if gPlayer1
= nil then
3054 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3058 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3062 if nPlayers
>= 2 then
3064 // Создание второго игрока:
3065 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3066 gPlayer2Settings
.Color
,
3067 gPlayer2Settings
.Team
, False));
3068 if gPlayer2
= nil then
3070 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3074 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3078 // Загрузка и запуск карты:
3079 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3081 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3085 // Нет точек появления:
3086 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3087 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3088 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3089 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3090 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3092 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3096 // Настройки игроков и ботов:
3100 for i
:= nPl
+1 to nPlayers
do
3101 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3104 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3105 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3106 Options
: LongWord; nPlayers
: Byte;
3107 IPAddr
: LongWord; Port
: Word);
3110 g_Net_Slist_ServerClosed();
3112 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3114 g_Game_ClearLoading();
3117 gGameSettings
.GameType
:= GT_SERVER
;
3118 gGameSettings
.GameMode
:= GameMode
;
3119 gSwitchGameMode
:= GameMode
;
3120 gGameSettings
.TimeLimit
:= TimeLimit
;
3121 gGameSettings
.GoalLimit
:= GoalLimit
;
3122 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3123 gGameSettings
.Options
:= Options
;
3125 gCoopTotalMonstersKilled
:= 0;
3126 gCoopTotalSecretsFound
:= 0;
3127 gCoopTotalMonsters
:= 0;
3128 gCoopTotalSecrets
:= 0;
3132 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3133 gLMSRespawnTime
:= 0;
3134 gSpectLatchPID1
:= 0;
3135 gSpectLatchPID2
:= 0;
3137 g_Game_ExecuteEvent('ongamestart');
3139 // Установка размеров окна игрока
3140 g_Game_SetupScreenSize();
3142 // Режим наблюдателя:
3143 if nPlayers
= 0 then
3149 if nPlayers
>= 1 then
3151 // Создание первого игрока:
3152 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3153 gPlayer1Settings
.Color
,
3154 gPlayer1Settings
.Team
, False));
3155 if gPlayer1
= nil then
3157 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3161 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3164 if nPlayers
>= 2 then
3166 // Создание второго игрока:
3167 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3168 gPlayer2Settings
.Color
,
3169 gPlayer2Settings
.Team
, False));
3170 if gPlayer2
= nil then
3172 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3176 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3179 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3180 if NetForwardPorts
then
3181 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3184 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3186 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3190 g_Net_Slist_Set(NetMasterList
);
3192 g_Net_Slist_ServerStarted();
3194 // Загрузка и запуск карты:
3195 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3197 g_Net_Slist_ServerClosed();
3198 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3202 // Нет точек появления:
3203 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3204 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3205 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3206 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3207 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3209 g_Net_Slist_ServerClosed();
3210 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3214 // Настройки игроков и ботов:
3217 g_Net_Slist_ServerMapStarted();
3218 NetState
:= NET_STATE_GAME
;
3221 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3236 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3237 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3239 g_Game_ClearLoading();
3242 gGameSettings
.GameType
:= GT_CLIENT
;
3244 gCoopTotalMonstersKilled
:= 0;
3245 gCoopTotalSecretsFound
:= 0;
3246 gCoopTotalMonsters
:= 0;
3247 gCoopTotalSecrets
:= 0;
3251 g_Game_ExecuteEvent('ongamestart');
3253 // Установка размеров окон игроков:
3254 g_Game_SetupScreenSize();
3256 NetState
:= NET_STATE_AUTH
;
3258 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3260 // create (or update) map/resource databases
3261 g_Res_CreateDatabases(true);
3263 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3264 gLMSRespawnTime
:= 0;
3265 gSpectLatchPID1
:= 0;
3266 gSpectLatchPID2
:= 0;
3269 if not g_Net_Connect(Addr
, Port
) then
3271 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3272 NetState
:= NET_STATE_NONE
;
3276 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3278 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3283 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3284 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3285 // thank you, enet. let's ignore failures altogether then.
3286 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3288 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3290 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
3292 // ignore all download packets, they're processed by separate code
3293 enet_packet_destroy(NetEvent
.packet
);
3296 Ptr
:= NetEvent
.packet
^.data
;
3297 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3299 enet_packet_destroy(NetEvent
.packet
);
3303 InMsg
.ReadLongWord(); // skip size
3304 MID
:= InMsg
.ReadByte();
3306 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3308 NetMyID
:= InMsg
.ReadByte();
3309 NetPlrUID1
:= InMsg
.ReadWord();
3311 WadName
:= InMsg
.ReadString();
3312 Map
:= InMsg
.ReadString();
3314 gWADHash
:= InMsg
.ReadMD5();
3316 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3317 gSwitchGameMode
:= gGameSettings
.GameMode
;
3318 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
3319 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3320 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3321 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3322 T
:= InMsg
.ReadLongWord();
3324 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3325 //if newResPath = '' then
3327 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3328 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3329 if newResPath
= '' then
3331 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3332 enet_packet_destroy(NetEvent
.packet
);
3333 NetState
:= NET_STATE_NONE
;
3336 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3338 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3341 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3342 gPlayer1Settings
.Color
,
3343 gPlayer1Settings
.Team
, False));
3345 if gPlayer1
= nil then
3347 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3349 enet_packet_destroy(NetEvent
.packet
);
3350 NetState
:= NET_STATE_NONE
;
3354 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3355 gPlayer1
.UID
:= NetPlrUID1
;
3356 gPlayer1
.Reset(True);
3358 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3360 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3362 enet_packet_destroy(NetEvent
.packet
);
3363 NetState
:= NET_STATE_NONE
;
3371 enet_packet_destroy(NetEvent
.packet
);
3375 enet_packet_destroy(NetEvent
.packet
);
3379 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3382 if (NetEvent
.data
<= NET_DISC_MAX
) then
3383 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3384 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3391 ProcessLoading(true);
3393 if g_Net_UserRequestExit() then
3402 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3403 NetState
:= NET_STATE_NONE
;
3408 NetState
:= NET_STATE_GAME
;
3409 MC_SEND_FullStateRequest
;
3410 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3414 lastAsMegaWad
: Boolean = false;
3416 procedure g_Game_ChangeMap(const MapPath
: String);
3420 g_Game_ClearLoading();
3422 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3423 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3424 if gExitByTrigger
then
3427 gExitByTrigger
:= False;
3429 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3430 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3433 procedure g_Game_Restart();
3437 if g_Game_IsClient
then
3439 map
:= g_ExtractFileName(gMapInfo
.Map
);
3440 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3444 g_Game_ClearLoading();
3445 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3448 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3450 NewWAD
, ResName
: String;
3454 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3455 g_Player_RemoveAllCorpses();
3457 if (not g_Game_IsClient
) and
3458 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3459 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3461 if gSwitchGameMode
= GM_CTF
then
3462 gGameSettings
.MaxLives
:= 0;
3463 gGameSettings
.GameMode
:= gSwitchGameMode
;
3466 gSwitchGameMode
:= gGameSettings
.GameMode
;
3468 g_Player_ResetTeams();
3470 lastAsMegaWad
:= asMegawad
;
3471 if isWadPath(Map
) then
3473 NewWAD
:= g_ExtractWadName(Map
);
3474 ResName
:= g_ExtractFileName(Map
);
3475 if g_Game_IsServer
then
3477 nws
:= findDiskWad(NewWAD
);
3478 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3481 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3482 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3486 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3487 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3489 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3490 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3492 if (length(nws
) = 0) then
3494 ResName
:= ''; // failed
3499 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3500 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3501 g_Game_LoadWAD(NewWAD
);
3506 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3507 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3512 NewWAD
:= gGameSettings
.WAD
;
3518 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3520 if (ResName
<> '') and (NewWAD
<> '') then
3522 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3523 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3527 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3529 gState
:= STATE_NONE
;
3530 g_ActiveWindow
:= nil;
3534 wNeedTimeReset
:= True;
3536 if gGameSettings
.GameMode
= GM_CTF
then
3538 g_Map_ResetFlag(FLAG_RED
);
3539 g_Map_ResetFlag(FLAG_BLUE
);
3540 // CTF, а флагов нет:
3541 if not g_Map_HaveFlagPoints() then
3542 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3547 gState
:= STATE_MENU
;
3552 gPauseMain
:= false;
3553 gPauseHolmes
:= false;
3554 NetTimeToUpdate
:= 1;
3555 NetTimeToReliable
:= 0;
3556 NetTimeToMaster
:= NetMasterRate
;
3557 gSpectLatchPID1
:= 0;
3558 gSpectLatchPID2
:= 0;
3559 gMissionFailed
:= False;
3562 gCoopMonstersKilled
:= 0;
3563 gCoopSecretsFound
:= 0;
3565 gVoteInProgress
:= False;
3566 gVotePassed
:= False;
3572 if not gGameOn
then Exit
;
3574 g_Game_SpectateCenterView();
3576 if g_Game_IsServer
then
3578 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3580 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3581 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3582 gLMSSoftSpawn
:= True;
3583 if g_Game_IsNet
then
3584 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3588 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3589 gLMSRespawnTime
:= 0;
3593 if NetMode
= NET_SERVER
then
3595 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3598 g_Net_Slist_ServerMapStarted();
3600 if NetClients
<> nil then
3601 for I
:= 0 to High(NetClients
) do
3602 if NetClients
[I
].Used
then
3604 NetClients
[I
].Voted
:= False;
3605 if NetClients
[I
].RequestedFullUpdate
then
3607 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3608 NetClients
[I
].RequestedFullUpdate
:= False;
3612 g_Net_UnbanNonPermHosts();
3617 gCoopTotalMonstersKilled
:= 0;
3618 gCoopTotalSecretsFound
:= 0;
3619 gCoopTotalMonsters
:= 0;
3620 gCoopTotalSecrets
:= 0;
3624 g_Game_ExecuteEvent('onmapstart');
3627 procedure SetFirstLevel
;
3631 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3632 if MapList
= nil then
3635 SortSArray(MapList
);
3636 gNextMap
:= MapList
[Low(MapList
)];
3641 procedure g_Game_ExitLevel(const Map
: AnsiString);
3645 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3646 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3647 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3648 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3650 // Вышли в выход в Одиночной игре:
3651 if gGameSettings
.GameType
= GT_SINGLE
then
3652 gExit
:= EXIT_ENDLEVELSINGLE
3653 else // Вышли в выход в Своей игре
3655 gExit
:= EXIT_ENDLEVELCUSTOM
;
3656 if gGameSettings
.GameMode
= GM_COOP
then
3657 g_Player_RememberAll
;
3659 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3662 if gGameSettings
.GameMode
= GM_COOP
then
3665 gStatsPressed
:= True;
3666 gNextMap
:= 'MAP01';
3668 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3671 if g_Game_IsNet
then
3673 MH_SEND_GameStats();
3674 MH_SEND_CoopStats();
3680 procedure g_Game_RestartLevel();
3684 if gGameSettings
.GameMode
= GM_SINGLE
then
3689 gExit
:= EXIT_ENDLEVELCUSTOM
;
3690 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3694 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3696 gWAD
{, xwad}: String;
3699 if not g_Game_IsClient
then Exit
;
3700 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3702 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3707 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3711 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3714 g_Game_LoadWAD(NewWAD
);
3718 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3719 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3722 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3723 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3727 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3731 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3732 g_Game_LoadWAD(NewWAD);
3736 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3738 i
, n
, nb
, nr
: Integer;
3740 if not g_Game_IsServer
then Exit
;
3741 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3742 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3743 gLMSRespawnTime
:= 0;
3746 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3748 gMissionFailed
:= True;
3749 g_Game_RestartLevel
;
3753 n
:= 0; nb
:= 0; nr
:= 0;
3754 for i
:= Low(gPlayers
) to High(gPlayers
) do
3755 if (gPlayers
[i
] <> nil) and
3756 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3757 (gPlayers
[i
] is TBot
)) then
3760 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3761 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3764 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3766 // wait a second until the fuckers finally decide to join
3767 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3768 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3769 gLMSSoftSpawn
:= NoMapRestart
;
3770 if g_Game_IsNet
then
3771 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3775 g_Player_RemoveAllCorpses
;
3776 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3777 if g_Game_IsNet
then
3778 MH_SEND_GameEvent(NET_EV_LMS_START
);
3780 for i
:= Low(gPlayers
) to High(gPlayers
) do
3782 if gPlayers
[i
] = nil then continue
;
3783 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3784 // don't touch normal spectators
3785 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3787 gPlayers
[i
].FNoRespawn
:= True;
3788 gPlayers
[i
].Lives
:= 0;
3789 if g_Game_IsNet
then
3790 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3793 gPlayers
[i
].FNoRespawn
:= False;
3794 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3795 gPlayers
[i
].Respawn(False, True);
3796 if gGameSettings
.GameMode
= GM_COOP
then
3798 gPlayers
[i
].Frags
:= 0;
3799 gPlayers
[i
].RecallState
;
3801 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3802 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3803 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3804 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3807 g_Items_RestartRound();
3809 gLMSSoftSpawn
:= False;
3812 function g_Game_GetFirstMap(WAD
: String): String;
3816 MapList
:= g_Map_GetMapsList(WAD
);
3817 if MapList
= nil then
3820 SortSArray(MapList
);
3821 Result
:= MapList
[Low(MapList
)];
3823 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3829 function g_Game_GetNextMap(): String;
3836 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3837 if MapList
= nil then
3840 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3842 SortSArray(MapList
);
3844 for I
:= Low(MapList
) to High(MapList
) do
3845 if Map
= MapList
[I
] then
3851 if MapIndex
<> -255 then
3853 if MapIndex
= High(MapList
) then
3854 Result
:= MapList
[Low(MapList
)]
3856 Result
:= MapList
[MapIndex
+ 1];
3858 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3864 procedure g_Game_NextLevel();
3866 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3867 gExit
:= EXIT_ENDLEVELCUSTOM
3870 gExit
:= EXIT_ENDLEVELSINGLE
;
3874 if gNextMap
<> '' then Exit
;
3875 gNextMap
:= g_Game_GetNextMap();
3878 function g_Game_IsTestMap(): Boolean;
3880 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3883 procedure g_Game_DeleteTestMap();
3886 //MapName: AnsiString;
3894 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3895 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3896 if (a
= 0) then exit
;
3898 // Выделяем имя wad-файла и имя карты
3899 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3900 Delete(gMapToDelete
, 1, a
+5);
3901 gMapToDelete
:= UpperCase(gMapToDelete
);
3903 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3906 // Имя карты не стандартное тестовое:
3907 if MapName <> TEST_MAP_NAME then
3910 if not gTempDelete then
3912 time := g_GetFileTime(WadName);
3913 WAD := TWADFile.Create();
3916 if not WAD.ReadFile(WadName) then
3917 begin // Нет такого WAD-файла
3922 // Составляем список карт и ищем нужную:
3924 MapList := WAD.GetResourcesList('');
3926 if MapList <> nil then
3927 for a := 0 to High(MapList) do
3928 if MapList[a] = MapName then
3930 // Удаляем и сохраняем:
3931 WAD.RemoveResource('', MapName);
3932 WAD.SaveTo(WadName);
3937 g_SetFileTime(WadName, time);
3940 if gTempDelete
then DeleteFile(WadName
);
3943 procedure GameCVars(P
: SSArray
);
3946 stat
: TPlayerStatArray
;
3949 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3953 if Length(P
) > 1 then
3958 gsGameFlags
:= gsGameFlags
or Flag
3960 gsGameFlags
:= gsGameFlags
and (not Flag
);
3962 if g_Game_IsServer
then
3965 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3967 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3968 if g_Game_IsNet
then MH_SEND_GameSettings
;
3972 if LongBool(gsGameFlags
and Flag
) then
3973 g_Console_Add(_lc
[OnMsg
])
3975 g_Console_Add(_lc
[OffMsg
]);
3977 if OnMapChange
and g_Game_IsServer
then
3978 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3983 cmd
:= LowerCase(P
[0]);
3985 if cmd
= 'g_gamemode' then
3987 if (Length(P
) > 1) then
3989 a
:= g_Game_TextToMode(P
[1]);
3990 if a
= GM_SINGLE
then a
:= GM_COOP
;
3991 gsGameMode
:= g_Game_ModeToText(a
);
3992 if g_Game_IsServer
then
3994 gSwitchGameMode
:= a
;
3995 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3996 (gState
= STATE_INTERSINGLE
) then
3997 gSwitchGameMode
:= GM_SINGLE
;
3999 gGameSettings
.GameMode
:= gSwitchGameMode
;
4003 if gSwitchGameMode
= gGameSettings
.GameMode
then
4004 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4005 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4007 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4008 [g_Game_ModeToText(gGameSettings
.GameMode
),
4009 g_Game_ModeToText(gSwitchGameMode
)]));
4011 else if cmd
= 'g_friendlyfire' then
4013 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4015 else if cmd
= 'g_friendly_absorb_damage' then
4017 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4019 else if cmd
= 'g_friendly_hit_trace' then
4021 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4023 else if cmd
= 'g_friendly_hit_projectile' then
4025 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4027 else if cmd
= 'g_weaponstay' then
4029 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
4031 else if cmd
= 'g_allow_exit' then
4033 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
4035 else if cmd
= 'g_allow_monsters' then
4037 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
4039 else if cmd
= 'g_bot_vsplayers' then
4041 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4043 else if cmd
= 'g_bot_vsmonsters' then
4045 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4047 else if cmd
= 'g_dm_keys' then
4049 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4051 else if cmd
= 'g_gameflags' then
4053 if Length(P
) > 1 then
4055 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4056 if g_Game_IsServer
then
4058 gGameSettings
.Options
:= gsGameFlags
;
4059 if g_Game_IsNet
then MH_SEND_GameSettings
;
4063 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4065 else if cmd
= 'g_warmup_time' then
4067 if Length(P
) > 1 then
4069 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4070 if g_Game_IsServer
then
4072 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4073 // extend warmup if it's already going
4074 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4076 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4077 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4079 if g_Game_IsNet
then MH_SEND_GameSettings
;
4083 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4084 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4086 else if cmd
= 'g_spawn_invul' then
4088 if Length(P
) > 1 then
4090 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4091 if g_Game_IsServer
then
4093 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4094 if g_Game_IsNet
then MH_SEND_GameSettings
;
4098 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4100 else if cmd
= 'g_item_respawn_time' then
4102 if Length(P
) > 1 then
4104 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4105 if g_Game_IsServer
then
4107 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4108 if g_Game_IsNet
then MH_SEND_GameSettings
;
4112 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4113 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4115 else if cmd
= 'sv_intertime' then
4117 if (Length(P
) > 1) then
4118 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4120 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4122 else if cmd
= 'g_max_particles' 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_GFX_GetMax()])
4135 e_LogWritefln('usage: %s <n>', [cmd
])
4138 else if cmd
= 'g_max_shells' then
4140 if Length(p
) = 2 then
4142 a
:= Max(0, StrToInt(p
[1]));
4145 else if Length(p
) = 1 then
4147 e_LogWritefln('%s', [g_Shells_GetMax()])
4151 e_LogWritefln('usage: %s <n>', [cmd
])
4154 else if cmd
= 'g_max_gibs' then
4156 if Length(p
) = 2 then
4158 a
:= Max(0, StrToInt(p
[1]));
4161 else if Length(p
) = 1 then
4163 e_LogWritefln('%s', [g_Gibs_GetMax()])
4167 e_LogWritefln('usage: %s <n>', [cmd
])
4170 else if cmd
= 'g_max_corpses' then
4172 if Length(p
) = 2 then
4174 a
:= Max(0, StrToInt(p
[1]));
4177 else if Length(p
) = 1 then
4179 e_LogWritefln('%s', [g_Corpses_GetMax()])
4183 e_LogWritefln('usage: %s <n>', [cmd
])
4186 else if cmd
= 'g_scorelimit' then
4188 if Length(P
) > 1 then
4190 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
4192 if g_Game_IsServer
then
4195 if gGameSettings
.GameMode
= GM_DM
then
4197 stat
:= g_Player_GetStats();
4199 for a
:= 0 to High(stat
) do
4200 if stat
[a
].Frags
> b
then
4204 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4206 // if someone has a higher score, set it to that instead
4207 gsGoalLimit
:= max(gsGoalLimit
, b
);
4208 gGameSettings
.GoalLimit
:= gsGoalLimit
;
4210 if g_Game_IsNet
then MH_SEND_GameSettings
;
4214 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
4216 else if cmd
= 'g_timelimit' then
4218 if Length(P
) > 1 then
4220 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4221 if g_Game_IsServer
then
4223 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4224 if g_Game_IsNet
then MH_SEND_GameSettings
;
4227 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4228 [gsTimeLimit
div 3600,
4229 (gsTimeLimit
div 60) mod 60,
4230 gsTimeLimit
mod 60]));
4232 else if cmd
= 'g_maxlives' then
4234 if Length(P
) > 1 then
4236 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4237 if g_Game_IsServer
then
4239 gGameSettings
.MaxLives
:= gsMaxLives
;
4240 if g_Game_IsNet
then MH_SEND_GameSettings
;
4244 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4248 procedure PlayerSettingsCVars(P
: SSArray
);
4253 function ParseTeam(s
: string): Byte;
4257 'red', '1': result
:= TEAM_RED
;
4258 'blue', '2': result
:= TEAM_BLUE
;
4259 else result
:= TEAM_NONE
;
4263 cmd
:= LowerCase(P
[0]);
4267 if (Length(P
) > 1) then
4269 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4270 if g_Game_IsClient
then
4271 MC_SEND_PlayerSettings
4272 else if gGameOn
and (gPlayer1
<> nil) then
4274 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4275 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4281 if (Length(P
) > 1) then
4283 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4284 if g_Game_IsClient
then
4285 MC_SEND_PlayerSettings
4286 else if gGameOn
and (gPlayer2
<> nil) then
4288 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4289 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4295 if Length(P
) > 3 then
4297 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4298 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4299 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4300 if g_Game_IsClient
then
4301 MC_SEND_PlayerSettings
4302 else if gGameOn
and (gPlayer1
<> nil) then
4304 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4305 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4311 if Length(P
) > 3 then
4313 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4314 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4315 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4316 if g_Game_IsClient
then
4317 MC_SEND_PlayerSettings
4318 else if gGameOn
and (gPlayer2
<> nil) then
4320 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4321 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4327 if (Length(P
) > 1) then
4329 gPlayer1Settings
.Model
:= P
[1];
4330 if g_Game_IsClient
then
4331 MC_SEND_PlayerSettings
4332 else if gGameOn
and (gPlayer1
<> nil) then
4334 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4335 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4336 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4342 if (Length(P
) > 1) then
4344 gPlayer2Settings
.Model
:= P
[1];
4345 if g_Game_IsClient
then
4346 MC_SEND_PlayerSettings
4347 else if gGameOn
and (gPlayer2
<> nil) then
4349 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4350 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4351 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4357 // TODO: switch teams if in game or store this separately
4358 if (Length(P
) > 1) then
4360 team
:= ParseTeam(P
[1]);
4361 if team
= TEAM_NONE
then
4362 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4363 else if not gGameOn
and not g_Game_IsNet
then
4364 gPlayer1Settings
.Team
:= team
4366 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4371 // TODO: switch teams if in game or store this separately
4372 if (Length(P
) > 1) then
4374 team
:= ParseTeam(P
[1]);
4375 if team
= TEAM_NONE
then
4376 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4377 else if not gGameOn
and not g_Game_IsNet
then
4378 gPlayer2Settings
.Team
:= team
4380 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4386 procedure PrintHeapStats();
4390 hs
:= GetFPCHeapStatus();
4391 e_LogWriteLn ('v===== heap status =====v');
4392 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4393 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4394 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4395 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4396 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4397 e_LogWriteLn ('^=======================^');
4400 procedure DebugCommands(P
: SSArray
);
4407 // Команды отладочного режима:
4408 if {gDebugMode}conIsCheatsEnabled
then
4410 cmd
:= LowerCase(P
[0]);
4411 if cmd
= 'd_window' then
4413 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4414 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4416 else if cmd
= 'd_sounds' then
4418 if (Length(P
) > 1) and
4419 ((P
[1] = '1') or (P
[1] = '0')) then
4420 g_Debug_Sounds
:= (P
[1][1] = '1');
4422 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4424 else if cmd
= 'd_frames' then
4426 if (Length(P
) > 1) and
4427 ((P
[1] = '1') or (P
[1] = '0')) then
4428 g_Debug_Frames
:= (P
[1][1] = '1');
4430 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4432 else if cmd
= 'd_winmsg' then
4434 if (Length(P
) > 1) and
4435 ((P
[1] = '1') or (P
[1] = '0')) then
4436 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4438 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4440 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4442 if (Length(P
) > 1) and
4443 ((P
[1] = '1') or (P
[1] = '0')) then
4444 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4446 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4448 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4450 if Length(P
) > 1 then
4452 '0': g_debug_BotAIOff
:= 0;
4453 '1': g_debug_BotAIOff
:= 1;
4454 '2': g_debug_BotAIOff
:= 2;
4455 '3': g_debug_BotAIOff
:= 3;
4458 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4460 else if cmd
= 'd_monster' then
4462 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4463 if Length(P
) < 2 then
4465 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4466 g_Console_Add('ID | Name');
4467 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4468 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4469 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4472 a
:= StrToIntDef(P
[1], 0);
4473 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4474 a
:= g_Mons_TypeIdByName(P
[1]);
4476 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4477 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4480 with gPlayer1
.Obj
do
4482 mon
:= g_Monsters_Create(a
,
4483 X
+ Rect
.X
+ (Rect
.Width
div 2),
4484 Y
+ Rect
.Y
+ Rect
.Height
,
4485 gPlayer1
.Direction
, True);
4487 if (Length(P
) > 2) and (mon
<> nil) then
4489 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4490 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4491 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4492 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4493 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4494 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4495 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4496 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4497 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4502 else if (cmd
= 'd_health') then
4504 if (Length(P
) > 1) and
4505 ((P
[1] = '1') or (P
[1] = '0')) then
4506 g_debug_HealthBar
:= (P
[1][1] = '1');
4508 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4510 else if (cmd
= 'd_player') then
4512 if (Length(P
) > 1) and
4513 ((P
[1] = '1') or (P
[1] = '0')) then
4514 g_debug_Player
:= (P
[1][1] = '1');
4516 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4518 else if (cmd
= 'd_mem') then
4524 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4528 procedure GameCheats(P
: SSArray
);
4534 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4536 g_Console_Add('not available');
4542 g_Console_Add('where is the player?!');
4545 cmd
:= LowerCase(P
[0]);
4549 plr
.GodMode
:= not plr
.GodMode
;
4550 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4553 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4554 if cmd
= 'give' then
4556 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4557 for f
:= 1 to High(P
) do
4559 cmd
:= LowerCase(P
[f
]);
4560 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4561 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4562 if cmd
= 'exit' then
4564 if gTriggers
<> nil then
4566 for a
:= 0 to High(gTriggers
) do
4568 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4570 g_Console_Add('player left the map');
4571 gExitByTrigger
:= True;
4572 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4573 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4581 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4582 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4583 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4584 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4585 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4587 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4588 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4590 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4591 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;
4593 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4594 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4596 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4597 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4599 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4600 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4602 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4603 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4604 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4606 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4607 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4608 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4609 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;
4610 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4611 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4613 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;
4614 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;
4615 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;
4616 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;
4617 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;
4618 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;
4620 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4621 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;
4623 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;
4624 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;
4626 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4628 if cmd
= 'ammo' then
4630 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4631 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4632 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4633 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4634 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4635 g_Console_Add('player got some ammo');
4639 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4640 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4642 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4643 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4645 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4646 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4648 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4649 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4651 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4653 if cmd
= 'weapons' then
4655 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4656 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4657 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4658 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4659 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4660 plr
.GiveItem(ITEM_WEAPON_BFG
);
4661 g_Console_Add('player got weapons');
4665 if cmd
= 'keys' then
4667 plr
.GiveItem(ITEM_KEY_RED
);
4668 plr
.GiveItem(ITEM_KEY_GREEN
);
4669 plr
.GiveItem(ITEM_KEY_BLUE
);
4670 g_Console_Add('player got all keys');
4674 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4679 if cmd
= 'open' then
4681 g_Console_Add('player activated sesame');
4682 g_Triggers_OpenAll();
4689 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4693 if cmd
= 'noclip' then
4696 g_Console_Add('wall hardeness adjusted');
4700 if cmd
= 'notarget' then
4702 plr
.NoTarget
:= not plr
.NoTarget
;
4703 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4707 if cmd
= 'noreload' then
4709 plr
.NoReload
:= not plr
.NoReload
;
4710 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4714 if cmd
= 'speedy' then
4716 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4717 g_Console_Add('speed adjusted');
4721 if cmd
= 'jumpy' then
4723 VEL_JUMP
:= 30-VEL_JUMP
;
4724 g_Console_Add('jump height adjusted');
4728 if cmd
= 'automap' then
4730 gShowMap
:= not gShowMap
;
4731 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4735 if cmd
= 'aimline' then
4737 gAimLine
:= not gAimLine
;
4738 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4743 procedure GameCommands(P
: SSArray
);
4749 pl
: pTNetClient
= nil;
4757 cmd
:= LowerCase(P
[0]);
4759 if cmd
= 'pause' then
4761 if (g_ActiveWindow
= nil) then
4762 g_Game_Pause(not gPauseMain
);
4764 else if cmd
= 'endgame' then
4765 gExit
:= EXIT_SIMPLE
4766 else if cmd
= 'restart' then
4768 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4770 if g_Game_IsClient
then
4772 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4777 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4779 else if cmd
= 'kick' then
4781 if g_Game_IsServer
then
4783 if Length(P
) < 2 then
4785 g_Console_Add('kick <name>');
4790 g_Console_Add('kick <name>');
4794 if g_Game_IsNet
then
4795 pl
:= g_Net_Client_ByName(P
[1]);
4798 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4799 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4800 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4801 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4802 g_Net_Slist_ServerPlayerLeaves();
4803 end else if gPlayers
<> nil then
4804 for a
:= Low(gPlayers
) to High(gPlayers
) do
4805 if gPlayers
[a
] <> nil then
4806 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4808 // Не отключать основных игроков в сингле
4809 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4811 gPlayers
[a
].Lives
:= 0;
4812 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4813 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4814 g_Player_Remove(gPlayers
[a
].UID
);
4815 g_Net_Slist_ServerPlayerLeaves();
4816 // Если не перемешать, при добавлении новых ботов появятся старые
4820 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4822 else if cmd
= 'kick_id' then
4824 if g_Game_IsServer
and g_Game_IsNet
then
4826 if Length(P
) < 2 then
4828 g_Console_Add('kick_id <client ID>');
4833 g_Console_Add('kick_id <client ID>');
4837 a
:= StrToIntDef(P
[1], 0);
4838 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4840 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4842 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4843 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
4844 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4845 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4846 g_Net_Slist_ServerPlayerLeaves();
4850 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4852 else if cmd
= 'kick_pid' then
4854 if g_Game_IsServer
and g_Game_IsNet
then
4856 if Length(P
) < 2 then
4858 g_Console_Add('kick_pid <player ID>');
4863 g_Console_Add('kick_pid <player ID>');
4867 a
:= StrToIntDef(P
[1], 0);
4868 pl
:= g_Net_Client_ByPlayer(a
);
4869 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4871 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4872 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4873 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4874 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4875 g_Net_Slist_ServerPlayerLeaves();
4878 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4880 else if cmd
= 'ban' then
4882 if g_Game_IsServer
and g_Game_IsNet
then
4884 if Length(P
) < 2 then
4886 g_Console_Add('ban <name>');
4891 g_Console_Add('ban <name>');
4895 pl
:= g_Net_Client_ByName(P
[1]);
4898 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4899 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4900 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4901 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4902 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4903 g_Net_Slist_ServerPlayerLeaves();
4905 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4907 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4909 else if cmd
= 'ban_id' then
4911 if g_Game_IsServer
and g_Game_IsNet
then
4913 if Length(P
) < 2 then
4915 g_Console_Add('ban_id <client ID>');
4920 g_Console_Add('ban_id <client ID>');
4924 a
:= StrToIntDef(P
[1], 0);
4925 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4926 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4928 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4929 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
4930 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
4931 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4932 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4933 g_Net_Slist_ServerPlayerLeaves();
4936 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4938 else if cmd
= 'ban_pid' then
4940 if g_Game_IsServer
and g_Game_IsNet
then
4942 if Length(P
) < 2 then
4944 g_Console_Add('ban_pid <player ID>');
4949 g_Console_Add('ban_pid <player ID>');
4953 a
:= StrToIntDef(P
[1], 0);
4954 pl
:= g_Net_Client_ByPlayer(a
);
4955 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4957 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4958 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4959 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4960 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4961 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4962 g_Net_Slist_ServerPlayerLeaves();
4965 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4967 else if cmd
= 'permban' then
4969 if g_Game_IsServer
and g_Game_IsNet
then
4971 if Length(P
) < 2 then
4973 g_Console_Add('permban <name>');
4978 g_Console_Add('permban <name>');
4982 pl
:= g_Net_Client_ByName(P
[1]);
4985 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4986 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4987 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
4988 g_Net_SaveBanList();
4989 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4990 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4991 g_Net_Slist_ServerPlayerLeaves();
4993 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4995 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4997 else if cmd
= 'permban_id' then
4999 if g_Game_IsServer
and g_Game_IsNet
then
5001 if Length(P
) < 2 then
5003 g_Console_Add('permban_id <client ID>');
5008 g_Console_Add('permban_id <client ID>');
5012 a
:= StrToIntDef(P
[1], 0);
5013 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5014 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5016 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5017 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5018 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5019 g_Net_SaveBanList();
5020 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5021 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5022 g_Net_Slist_ServerPlayerLeaves();
5025 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5027 else if cmd
= 'permban_pid' then
5029 if g_Game_IsServer
and g_Game_IsNet
then
5031 if Length(P
) < 2 then
5033 g_Console_Add('permban_pid <player ID>');
5038 g_Console_Add('permban_pid <player ID>');
5042 a
:= StrToIntDef(P
[1], 0);
5043 pl
:= g_Net_Client_ByPlayer(a
);
5044 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5046 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5047 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5048 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5049 g_Net_SaveBanList();
5050 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5051 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5052 g_Net_Slist_ServerPlayerLeaves();
5055 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5057 else if cmd
= 'permban_ip' then
5059 if g_Game_IsServer
and g_Game_IsNet
then
5061 if Length(P
) < 2 then
5063 g_Console_Add('permban_ip <IP address>');
5068 g_Console_Add('permban_ip <IP address>');
5072 g_Net_BanHost(P
[1]);
5073 g_Net_SaveBanList();
5074 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5076 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5078 else if cmd
= 'unban' then
5080 if g_Game_IsServer
and g_Game_IsNet
then
5082 if Length(P
) < 2 then
5084 g_Console_Add('unban <IP Address>');
5089 g_Console_Add('unban <IP Address>');
5093 if g_Net_UnbanHost(P
[1]) then
5095 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5096 g_Net_SaveBanList();
5098 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5100 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5102 else if cmd
= 'clientlist' then
5104 if g_Game_IsServer
and g_Game_IsNet
then
5107 if NetClients
<> nil then
5108 for a
:= Low(NetClients
) to High(NetClients
) do
5109 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5111 plr
:= g_Player_Get(NetClients
[a
].Player
);
5112 if plr
= nil then continue
;
5114 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5115 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5118 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5120 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5122 else if cmd
= 'connect' then
5124 if (NetMode
= NET_NONE
) then
5126 if Length(P
) < 2 then
5128 g_Console_Add('connect <IP> [port] [password]');
5133 g_Console_Add('connect <IP> [port] [password]');
5137 if Length(P
) > 2 then
5138 prt
:= StrToIntDef(P
[2], 25666)
5142 if Length(P
) > 3 then
5147 g_Game_StartClient(P
[1], prt
, pw
);
5150 else if cmd
= 'disconnect' then
5152 if (NetMode
= NET_CLIENT
) then
5155 else if cmd
= 'reconnect' then
5157 if (NetMode
= NET_SERVER
) then
5160 if (NetMode
= NET_CLIENT
) then
5163 gExit
:= EXIT_SIMPLE
;
5167 //TODO: Use last successful password to reconnect, instead of ''
5168 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5170 else if (cmd
= 'addbot') or
5171 (cmd
= 'bot_add') then
5173 if Length(P
) > 2 then
5174 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5175 else if Length(P
) > 1 then
5176 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5178 g_Bot_Add(TEAM_NONE
, 2);
5180 else if cmd
= 'bot_addlist' then
5182 if Length(P
) > 1 then
5184 if Length(P
) = 2 then
5185 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5186 else if Length(P
) = 3 then
5187 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5189 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5192 else if cmd
= 'bot_removeall' then
5194 else if cmd
= 'chat' then
5196 if g_Game_IsNet
then
5198 if Length(P
) > 1 then
5200 for a
:= 1 to High(P
) do
5201 chstr
:= chstr
+ P
[a
] + ' ';
5203 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5205 if Length(chstr
) < 1 then
5207 g_Console_Add('chat <text>');
5211 chstr
:= b_Text_Format(chstr
);
5212 if g_Game_IsClient
then
5213 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5215 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5218 g_Console_Add('chat <text>');
5220 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5222 else if cmd
= 'teamchat' then
5224 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5226 if Length(P
) > 1 then
5228 for a
:= 1 to High(P
) do
5229 chstr
:= chstr
+ P
[a
] + ' ';
5231 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5233 if Length(chstr
) < 1 then
5235 g_Console_Add('teamchat <text>');
5239 chstr
:= b_Text_Format(chstr
);
5240 if g_Game_IsClient
then
5241 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5243 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5244 gPlayer1Settings
.Team
);
5247 g_Console_Add('teamchat <text>');
5249 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5251 else if cmd
= 'game' then
5253 if gGameSettings
.GameType
<> GT_NONE
then
5255 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5258 if Length(P
) = 1 then
5260 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5263 // game not started yet, load fist map from some wad
5265 s
:= addWadExtension(P
[1]);
5266 found
:= e_FindResource(AllMapDirs
, s
);
5270 P
[1] := ExpandFileName(P
[1]);
5271 // if map not choosed then set first map
5272 if Length(P
) < 3 then
5275 P
[2] := g_Game_GetFirstMap(P
[1]);
5278 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5280 if g_Map_Exist(s
) then
5284 with gGameSettings
do
5286 Options
:= gsGameFlags
;
5287 GameMode
:= g_Game_TextToMode(gsGameMode
);
5288 if gSwitchGameMode
<> GM_NONE
then
5289 GameMode
:= gSwitchGameMode
;
5290 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5291 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5293 if Length(P
) >= 4 then
5294 b
:= StrToIntDef(P
[3], 1);
5295 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5296 GoalLimit
, MaxLives
, Options
, b
);
5301 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5303 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5305 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5307 else if cmd
= 'host' then
5309 if gGameSettings
.GameType
<> GT_NONE
then
5311 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5314 if Length(P
) < 4 then
5316 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5319 if not StrToIp(P
[1], listen
) then
5321 prt
:= StrToIntDef(P
[2], 25666);
5323 s
:= addWadExtension(P
[3]);
5324 found
:= e_FindResource(AllMapDirs
, s
);
5328 // get first map in wad, if not specified
5329 if Length(P
) < 5 then
5332 P
[4] := g_Game_GetFirstMap(P
[1]);
5334 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5335 if g_Map_Exist(s
) then
5339 with gGameSettings
do
5341 Options
:= gsGameFlags
;
5342 GameMode
:= g_Game_TextToMode(gsGameMode
);
5343 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5344 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5345 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5347 if Length(P
) >= 6 then
5348 b
:= StrToIntDef(P
[5], 0);
5349 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
5355 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5357 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5362 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5365 else if cmd
= 'map' then
5367 if Length(P
) = 1 then
5369 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5371 g_Console_Add(cmd
+ ' <MAP>');
5372 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5376 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5381 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5383 if Length(P
) < 3 then
5385 // first param is map or wad
5386 s
:= UpperCase(P
[1]);
5387 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5389 gExitByTrigger
:= False;
5392 // already in game, finish current map
5394 gExit
:= EXIT_ENDLEVELCUSTOM
;
5398 // intermission, so change map immediately
5405 found
:= e_FindResource(AllMapDirs
, s
);
5407 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5410 // no such map, found wad
5413 P
[1] := ExpandFileName(pw
);
5414 P
[2] := g_Game_GetFirstMap(P
[1]);
5415 s
:= P
[1] + ':\' + P
[2];
5416 if g_Map_Exist(s
) then
5418 gExitByTrigger
:= False;
5421 // already in game, finish current map
5423 gExit
:= EXIT_ENDLEVELCUSTOM
5427 // intermission, so change map immediately
5434 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5436 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5441 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5447 s
:= addWadExtension(P
[1]);
5448 found
:= e_FindResource(AllMapDirs
, s
);
5452 P
[2] := UpperCase(P
[2]);
5453 s
:= P
[1] + ':\' + P
[2];
5454 if g_Map_Exist(s
) then
5456 gExitByTrigger
:= False;
5460 gExit
:= EXIT_ENDLEVELCUSTOM
5469 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5474 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5480 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5484 else if cmd
= 'nextmap' then
5486 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5488 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5493 if Length(P
) = 1 then
5495 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5497 g_Console_Add(cmd
+ ' <MAP>');
5498 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5503 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5509 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5511 if Length(P
) < 3 then
5513 // first param is map or wad
5514 s
:= UpperCase(P
[1]);
5515 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5518 gExitByTrigger
:= False;
5524 // no such map, found wad
5525 pw
:= addWadExtension(P
[1]);
5526 found
:= e_FindResource(MapDirs
, pw
);
5528 found
:= e_FindResource(WadDirs
, pw
);
5530 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5533 // map not specified, select first map
5535 P
[2] := g_Game_GetFirstMap(P
[1]);
5536 s
:= P
[1] + ':\' + P
[2];
5537 if g_Map_Exist(s
) then
5539 gExitByTrigger
:= False;
5546 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5548 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5553 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5559 // specified two params wad + map
5560 pw
:= addWadExtension(P
[1]);
5561 found
:= e_FindResource(MapDirs
, pw
);
5563 found
:= e_FindResource(MapDirs
, pw
);
5567 P
[2] := UpperCase(P
[2]);
5568 s
:= P
[1] + ':\' + P
[2];
5569 if g_Map_Exist(s
) then
5571 gExitByTrigger
:= False;
5577 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5582 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5588 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5593 if gNextMap
= '' then
5594 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5596 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5600 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5604 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5608 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5610 gExitByTrigger
:= False;
5611 // next map not specified, try to find trigger EXIT
5612 if (gNextMap
= '') and (gTriggers
<> nil) then
5614 for a
:= 0 to High(gTriggers
) do
5616 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5618 gExitByTrigger
:= True;
5619 //gNextMap := gTriggers[a].Data.MapName;
5620 gNextMap
:= gTriggers
[a
].tgcMap
;
5625 if gNextMap
= '' then
5626 gNextMap
:= g_Game_GetNextMap();
5627 if not isWadPath(gNextMap
) then
5628 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5631 if g_Map_Exist(s
) then
5632 gExit
:= EXIT_ENDLEVELCUSTOM
5634 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5638 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5642 else if (cmd
= 'event') then
5644 if (Length(P
) <= 1) then
5646 for a
:= 0 to High(gEvents
) do
5647 if gEvents
[a
].Command
= '' then
5648 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5650 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5653 if (Length(P
) = 2) then
5655 for a
:= 0 to High(gEvents
) do
5656 if gEvents
[a
].Name
= P
[1] then
5657 if gEvents
[a
].Command
= '' then
5658 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5660 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5663 for a
:= 0 to High(gEvents
) do
5664 if gEvents
[a
].Name
= P
[1] then
5666 gEvents
[a
].Command
:= '';
5667 for b
:= 2 to High(P
) do
5668 if Pos(' ', P
[b
]) = 0 then
5669 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5671 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5672 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5676 else if cmd
= 'suicide' then
5680 if g_Game_IsClient
then
5681 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5684 if gPlayer1
<> nil then
5685 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5686 if gPlayer2
<> nil then
5687 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5691 else if cmd
= 'screenshot' then
5695 else if cmd
= 'weapon' then
5697 if Length(p
) = 2 then
5699 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
5700 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5701 gSelectWeapon
[0, a
] := True
5704 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5706 if Length(p
) = 2 then
5708 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
5709 b
:= ord(cmd
[2]) - ord('1');
5710 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5711 gSelectWeapon
[b
, a
] := True
5714 // Команды Своей игры:
5715 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5717 if cmd
= 'bot_addred' then
5719 if Length(P
) > 1 then
5720 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5722 g_Bot_Add(TEAM_RED
, 2);
5724 else if cmd
= 'bot_addblue' then
5726 if Length(P
) > 1 then
5727 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5729 g_Bot_Add(TEAM_BLUE
, 2);
5731 else if cmd
= 'spectate' then
5737 else if cmd
= 'say' then
5739 if g_Game_IsServer
and g_Game_IsNet
then
5741 if Length(P
) > 1 then
5744 for a
:= 1 to High(P
) do
5745 chstr
:= chstr
+ P
[a
] + ' ';
5747 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5749 if Length(chstr
) < 1 then
5751 g_Console_Add('say <text>');
5755 chstr
:= b_Text_Format(chstr
);
5756 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5758 else g_Console_Add('say <text>');
5760 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5762 else if cmd
= 'tell' then
5764 if g_Game_IsServer
and g_Game_IsNet
then
5766 if (Length(P
) > 2) and (P
[1] <> '') then
5769 for a
:= 2 to High(P
) do
5770 chstr
:= chstr
+ P
[a
] + ' ';
5772 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5774 if Length(chstr
) < 1 then
5776 g_Console_Add('tell <playername> <text>');
5780 pl
:= g_Net_Client_ByName(P
[1]);
5782 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5784 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5786 else g_Console_Add('tell <playername> <text>');
5788 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5790 else if cmd
= 'centerprint' then
5792 if (Length(P
) > 2) and (P
[1] <> '') then
5795 for a
:= 2 to High(P
) do
5796 chstr
:= chstr
+ P
[a
] + ' ';
5798 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5800 if Length(chstr
) < 1 then
5802 g_Console_Add('centerprint <timeout> <text>');
5806 a
:= StrToIntDef(P
[1], 100);
5807 chstr
:= b_Text_Format(chstr
);
5808 g_Game_Message(chstr
, a
);
5809 if g_Game_IsNet
and g_Game_IsServer
then
5810 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
5812 else g_Console_Add('centerprint <timeout> <text>');
5814 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5816 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5818 // Дополнительное время:
5819 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5821 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5822 [gGameSettings
.TimeLimit
div 3600,
5823 (gGameSettings
.TimeLimit
div 60) mod 60,
5824 gGameSettings
.TimeLimit
mod 60]));
5825 if g_Game_IsNet
then MH_SEND_GameSettings
;
5827 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5829 if (Length(P
) <= 1) then
5830 g_Console_Add('rcon_password <password>')
5832 MC_SEND_RCONPassword(P
[1]);
5834 else if cmd
= 'rcon' then
5836 if g_Game_IsClient
then
5838 if Length(P
) > 1 then
5841 for a
:= 1 to High(P
) do
5842 chstr
:= chstr
+ P
[a
] + ' ';
5844 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5846 if Length(chstr
) < 1 then
5848 g_Console_Add('rcon <command>');
5852 MC_SEND_RCONCommand(chstr
);
5854 else g_Console_Add('rcon <command>');
5857 else if cmd
= 'ready' then
5859 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5860 gLMSRespawnTime
:= gTime
+ 100;
5862 else if (cmd
= 'callvote') and g_Game_IsNet
then
5864 if Length(P
) > 1 then
5867 for a
:= 1 to High(P
) do begin
5868 if a
> 1 then chstr
:= chstr
+ ' ';
5869 chstr
:= chstr
+ P
[a
];
5872 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5874 if Length(chstr
) < 1 then
5876 g_Console_Add('callvote <command>');
5880 if g_Game_IsClient
then
5881 MC_SEND_Vote(True, chstr
)
5883 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5884 g_Console_Process('vote', True);
5887 g_Console_Add('callvote <command>');
5889 else if (cmd
= 'vote') and g_Game_IsNet
then
5891 if g_Game_IsClient
then
5893 else if gVoteInProgress
then
5895 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5896 a
:= Floor((NetClientCount
+1)/2.0) + 1
5898 a
:= Floor(NetClientCount
/2.0) + 1;
5903 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5904 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5910 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5911 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5919 procedure SystemCommands(P
: SSArray
);
5923 cmd
:= LowerCase(P
[0]);
5932 gRC_Width
:= Max(1, gRC_Width
);
5933 gRC_Height
:= Max(1, gRC_Height
);
5934 gBPP
:= Max(1, gBPP
);
5935 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
5936 e_LogWriteln('resolution changed')
5938 e_LogWriteln('resolution not changed');
5939 sys_EnableVSync(gVSync
);
5943 if Length(p
) = 2 then
5945 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
5947 gFrameTime
:= 1000 div gMaxFPS
5951 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
5955 if Length(p
) = 2 then
5957 gAskLanguage
:= true;
5958 gLanguage
:= LANGUAGE_ENGLISH
;
5959 case LowerCase(p
[1]) of
5962 gAskLanguage
:= false;
5963 gLanguage
:= LANGUAGE_ENGLISH
;
5967 gAskLanguage
:= false;
5968 gLanguage
:= LANGUAGE_RUSSIAN
;
5972 gAskLanguage
:= true;
5973 gLanguage
:= LANGUAGE_ENGLISH
;
5976 g_Language_Set(gLanguage
);
5980 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
5986 procedure g_TakeScreenShot(Filename
: string = '');
5987 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
5989 if e_NoGraphics
then Exit
;
5991 dir
:= e_GetWriteableDir(ScreenshotDirs
);
5993 if Filename
= '' then
5996 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
5997 Filename
:= 'screenshot-' + date
;
6000 name
:= e_CatPath(dir
, Filename
+ '.png');
6001 s
:= createDiskFile(name
);
6003 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
6005 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6007 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6012 g_Console_Add('oh shit, i can''t create screenshot!')
6016 procedure g_Game_InGameMenu(Show
: Boolean);
6018 if (g_ActiveWindow
= nil) and Show
then
6020 if gGameSettings
.GameType
= GT_SINGLE
then
6021 g_GUI_ShowWindow('GameSingleMenu')
6024 if g_Game_IsClient
then
6025 g_GUI_ShowWindow('GameClientMenu')
6027 if g_Game_IsNet
then
6028 g_GUI_ShowWindow('GameServerMenu')
6030 g_GUI_ShowWindow('GameCustomMenu');
6032 g_Sound_PlayEx('MENU_OPEN');
6034 // Пауза при меню только в одиночной игре:
6035 if (not g_Game_IsNet
) then
6039 if (g_ActiveWindow
<> nil) and (not Show
) then
6041 // Пауза при меню только в одиночной игре:
6042 if (not g_Game_IsNet
) then
6043 g_Game_Pause(False);
6047 procedure g_Game_Pause (Enable
: Boolean);
6051 if not gGameOn
then exit
;
6053 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6056 gPauseMain
:= Enable
;
6058 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6061 procedure g_Game_HolmesPause (Enable
: Boolean);
6065 if not gGameOn
then exit
;
6066 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6069 gPauseHolmes
:= Enable
;
6071 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6074 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6079 if gTriggers
<> nil then
6080 for i
:= 0 to High(gTriggers
) do
6081 with gTriggers
[i
] do
6082 if (TriggerType
= TRIGGER_SOUND
) and
6084 Sound
.IsPlaying() then
6086 Sound
.Pause(Enable
);
6090 if gPlayers
<> nil then
6091 for i
:= 0 to High(gPlayers
) do
6092 if gPlayers
[i
] <> nil then
6093 gPlayers
[i
].PauseSounds(Enable
);
6096 if gMusic
<> nil then
6097 gMusic
.Pause(Enable
);
6100 procedure g_Game_StopAllSounds(all
: Boolean);
6104 if gTriggers
<> nil then
6105 for i
:= 0 to High(gTriggers
) do
6106 with gTriggers
[i
] do
6107 if (TriggerType
= TRIGGER_SOUND
) and
6111 if gMusic
<> nil then
6118 procedure g_Game_UpdateTriggerSounds
;
6121 if gTriggers
<> nil then
6122 for i
:= 0 to High(gTriggers
) do
6123 with gTriggers
[i
] do
6124 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6125 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6128 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6131 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6136 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6141 if gSpectMode
<> SPECT_PLAYERS
then
6143 if gSpectPID1
= UID
then
6148 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6155 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6160 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6165 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6170 if gSpectMode
<> SPECT_PLAYERS
then
6172 Pl
:= g_Player_Get(gSpectPID1
);
6173 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6178 if gSpectViewTwo
then
6180 Pl
:= g_Player_Get(gSpectPID2
);
6181 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6189 procedure g_Game_Message(Msg
: string; Time
: Word);
6191 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
6192 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
6193 MessageTime
:= Time
;
6196 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6198 punct
: Array[0..13] of String =
6199 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6205 function IsPunctuation(S
: String): Boolean;
6210 if Length(S
) <> 1 then
6212 for i
:= Low(punct
) to High(punct
) do
6213 if S
= punct
[i
] then
6219 function FilterPunctuation(S
: String): String;
6223 for i
:= Low(punct
) to High(punct
) do
6224 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6230 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6232 // remove player name
6233 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6234 // for FullWord check
6235 Text := toLowerCase1251(' ' + Text + ' ');
6236 fpText
:= FilterPunctuation(Text);
6238 for i
:= 0 to Length(gChatSounds
) - 1 do
6241 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6243 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6244 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6246 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6252 gChatSounds
[i
].Sound
.Play();
6258 g_Sound_PlayEx('SOUND_GAME_RADIO');
6261 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6270 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6274 if goodsnd
[a
].IsPlaying() then
6277 goodsnd
[Random(4)].Play();
6280 procedure g_Game_Announce_KillCombo(Param
: Integer);
6287 UID
:= Param
and $FFFF;
6292 Pl
:= g_Player_Get(UID
);
6301 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6305 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6309 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6313 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6321 if not g_Game_IsWatchedPlayer(UID
) then
6324 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6328 if killsnd
[n
].IsPlaying() then
6333 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6341 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6345 if hahasnd
[a
].IsPlaying() then
6348 hahasnd
[Random(3)].Play();
6351 procedure g_Game_StartVote(Command
, Initiator
: string);
6355 if not gVotesEnabled
then Exit
;
6356 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6357 if gVoteInProgress
or gVotePassed
then
6359 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6360 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6363 gVoteInProgress
:= True;
6364 gVotePassed
:= False;
6365 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6368 gVoteCommand
:= Command
;
6370 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6371 Need
:= Floor((NetClientCount
+1)/2.0)+1
6373 Need
:= Floor(NetClientCount
/2.0)+1;
6374 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6375 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6378 procedure g_Game_CheckVote
;
6382 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6383 if not gVoteInProgress
then Exit
;
6385 if (gTime
>= gVoteTimer
) then
6387 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6388 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6390 Need
:= Floor(NetClientCount
/2.0) + 1;
6391 if gVoteCount
>= Need
then
6393 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6394 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6395 gVotePassed
:= True;
6396 gVoteCmdTimer
:= gTime
+ 5000;
6400 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6401 MH_SEND_VoteEvent(NET_VE_FAILED
);
6403 if NetClients
<> nil then
6404 for I
:= Low(NetClients
) to High(NetClients
) do
6405 if NetClients
[i
].Used
then
6406 NetClients
[i
].Voted
:= False;
6407 gVoteInProgress
:= False;
6413 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6414 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6416 Need
:= Floor(NetClientCount
/2.0) + 1;
6417 if gVoteCount
>= Need
then
6419 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6420 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6421 gVoteInProgress
:= False;
6422 gVotePassed
:= True;
6423 gVoteCmdTimer
:= gTime
+ 5000;
6426 if NetClients
<> nil then
6427 for I
:= Low(NetClients
) to High(NetClients
) do
6428 if NetClients
[i
].Used
then
6429 NetClients
[i
].Voted
:= False;
6434 procedure g_Game_LoadMapList(FileName
: string);
6442 if not FileExists(FileName
) then Exit
;
6444 AssignFile(ListFile
, FileName
);
6446 while not EOF(ListFile
) do
6448 ReadLn(ListFile
, s
);
6451 if s
= '' then Continue
;
6453 SetLength(MapList
, Length(MapList
)+1);
6454 MapList
[High(MapList
)] := s
;
6456 CloseFile(ListFile
);
6459 procedure g_Game_SetDebugMode();
6462 // Читы (даже в своей игре):
6466 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6470 if Length(LoadingStat
.Msgs
) = 0 then
6476 begin // Переходим на следующую строку или скроллируем:
6477 if NextMsg
= Length(Msgs
) then
6479 for i
:= 0 to High(Msgs
)-1 do
6480 Msgs
[i
] := Msgs
[i
+1];
6488 Msgs
[NextMsg
-1] := Text;
6492 PBarWasHere
:= false;
6495 g_ActiveWindow
:= nil;
6497 ProcessLoading(true);
6500 procedure g_Game_StepLoading(Value
: Integer = -1);
6511 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6519 procedure g_Game_ClearLoading();
6528 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6529 if len
< 1 then len
:= 1;
6530 SetLength(Msgs
, len
);
6531 for len
:= Low(Msgs
) to High(Msgs
) do
6534 PBarWasHere
:= false;
6538 procedure Parse_Params(var pars
: TParamStrValues
);
6545 while i
<= ParamCount
do
6548 if (s
[1] = '-') and (Length(s
) > 1) then
6550 if (s
[2] = '-') and (Length(s
) > 2) then
6551 begin // Одиночный параметр
6552 SetLength(pars
, Length(pars
) + 1);
6553 with pars
[High(pars
)] do
6555 Name
:= LowerCase(s
);
6560 if (i
< ParamCount
) then
6561 begin // Параметр со значением
6563 SetLength(pars
, Length(pars
) + 1);
6564 with pars
[High(pars
)] do
6566 Name
:= LowerCase(s
);
6567 Value
:= LowerCase(ParamStr(i
));
6576 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6581 for i
:= 0 to High(pars
) do
6582 if pars
[i
].Name
= aName
then
6584 Result
:= pars
[i
].Value
;
6589 procedure g_Game_Process_Params();
6591 pars
: TParamStrValues
;
6594 LimT
, LimS
: Integer;
6605 s
:= Find_Param_Value(pars
, '--debug');
6608 g_Game_SetDebugMode();
6609 s
:= Find_Param_Value(pars
, '--netdump');
6614 // Connect when game loads
6615 ip
:= Find_Param_Value(pars
, '-connect');
6619 s
:= Find_Param_Value(pars
, '-port');
6620 if (s
= '') or not TryStrToInt(s
, Port
) then
6623 s
:= Find_Param_Value(pars
, '-pw');
6625 g_Game_StartClient(ip
, Port
, s
);
6629 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6632 gDefaultMegawadStart
:= s
;
6635 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6636 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6638 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6641 // Start map when game loads:
6642 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6643 if isWadPath(map
) then
6646 s
:= Find_Param_Value(pars
, '-gm');
6647 GMode
:= g_Game_TextToMode(s
);
6648 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6649 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6652 s
:= Find_Param_Value(pars
, '-limt');
6653 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6659 s
:= Find_Param_Value(pars
, '-lims');
6660 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6666 s
:= Find_Param_Value(pars
, '-lives');
6667 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6673 s
:= Find_Param_Value(pars
, '-opt');
6677 Opt
:= StrToIntDef(s
, 0);
6680 s
:= Find_Param_Value(pars
, '--close');
6684 // Override map to test:
6685 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6688 if e_IsValidResourceName(s
) then
6689 e_FindResource(AllMapDirs
, s
);
6690 gTestMap
:= ExpandFileName(s
);
6693 // Delete test map after play:
6694 s
:= Find_Param_Value(pars
, '--testdelete');
6697 //gMapToDelete := MapsDir + map;
6698 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6702 // Delete temporary WAD after play:
6703 s
:= Find_Param_Value(pars
, '--tempdelete');
6704 if (s
<> '') and (gTestMap
<> '') then
6706 gMapToDelete
:= gTestMap
;
6707 gTempDelete
:= True;
6710 // Number of players:
6711 s
:= Find_Param_Value(pars
, '-pl');
6713 n
:= DEFAULT_PLAYERS
6715 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6718 s
:= Find_Param_Value(pars
, '-port');
6719 if (s
= '') or not TryStrToInt(s
, Port
) then
6720 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6722 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6725 // Execute script when game loads:
6726 s
:= Find_Param_Value(pars
, '-exec');
6729 // if not isWadPath(s) then
6730 // s := GameDir + '/' + s;
6735 if IOResult
<> 0 then
6737 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6738 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6742 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6743 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6748 if IOResult
<> 0 then
6750 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6751 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6755 if Pos('#', s
) <> 1 then // script comment
6756 g_Console_Process(s
, True);
6767 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6768 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6769 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6770 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6772 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6773 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6774 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6775 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6777 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6778 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6780 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6781 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6783 {$IFDEF ENABLE_HOLMES}
6784 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6787 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6789 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6790 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6792 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6793 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6795 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6796 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6797 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6798 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
6799 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6800 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6801 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6802 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6803 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');