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_CONSOLE
], 0, False);
1474 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1475 r_PlayerModel_Initialize
;
1477 // load models from all possible wad types, in all known directories
1478 // this does a loosy job (linear search, ooph!), but meh
1479 for wext
in wadExtensions
do
1481 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1483 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1487 for s
in knownFiles
do
1489 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1497 SetLength(knownFiles
, length(knownFiles
)+1);
1498 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1500 until (FindNext(SR
) <> 0);
1506 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1508 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
);
1509 for s
in knownFiles
do
1511 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1515 gPauseMain
:= false;
1516 gPauseHolmes
:= false;
1519 {e_MouseInfo.Accel := 1.0;}
1521 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1524 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1525 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1526 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1527 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1528 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1531 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1535 gMusic
:= TMusic
.Create();
1536 gMusic
.SetByName('MUSIC_MENU');
1539 gGameSettings
.WarmupTime
:= 30;
1541 gState
:= STATE_MENU
;
1543 SetLength(gEvents
, 6);
1544 gEvents
[0].Name
:= 'ongamestart';
1545 gEvents
[1].Name
:= 'ongameend';
1546 gEvents
[2].Name
:= 'onmapstart';
1547 gEvents
[3].Name
:= 'onmapend';
1548 gEvents
[4].Name
:= 'oninter';
1549 gEvents
[5].Name
:= 'onwadend';
1551 sfsGCEnable(); // enable releasing unused volumes
1555 procedure g_Game_Free(freeTextures
: Boolean=true);
1557 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1558 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1560 g_Map_Free(freeTextures
);
1562 g_Player_RemoveAllCorpses();
1564 gGameSettings
.GameType
:= GT_NONE
;
1565 if gGameSettings
.GameMode
= GM_SINGLE
then
1566 gGameSettings
.GameMode
:= GM_DM
;
1567 gSwitchGameMode
:= gGameSettings
.GameMode
;
1570 gExitByTrigger
:= False;
1573 function IsActivePlayer(p
: TPlayer
): Boolean;
1578 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1581 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1587 if gPlayers
= nil then
1591 for a
:= Low(gPlayers
) to High(gPlayers
) do
1592 if IsActivePlayer(gPlayers
[a
]) then
1594 SetLength(ids
, Length(ids
) + 1);
1595 ids
[High(ids
)] := gPlayers
[a
].UID
;
1596 if gPlayers
[a
].UID
= Skip
then
1599 if Length(ids
) = 0 then
1604 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1607 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1613 if gPlayers
= nil then
1617 for a
:= Low(gPlayers
) to High(gPlayers
) do
1618 if IsActivePlayer(gPlayers
[a
]) then
1620 SetLength(ids
, Length(ids
) + 1);
1621 ids
[High(ids
)] := gPlayers
[a
].UID
;
1622 if gPlayers
[a
].UID
= Skip
then
1625 if Length(ids
) = 0 then
1628 Result
:= ids
[Length(ids
) - 1]
1630 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1633 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1639 if gPlayers
= nil then
1643 for a
:= Low(gPlayers
) to High(gPlayers
) do
1644 if IsActivePlayer(gPlayers
[a
]) then
1646 SetLength(ids
, Length(ids
) + 1);
1647 ids
[High(ids
)] := gPlayers
[a
].UID
;
1648 if gPlayers
[a
].UID
= Skip
then
1651 if Length(ids
) = 0 then
1653 if Length(ids
) = 1 then
1658 Result
:= ids
[Random(Length(ids
))];
1660 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1662 Result
:= ids
[Random(Length(ids
))];
1667 function GetRandomSpectMode(Current
: Byte): Byte;
1674 0: Result
:= SPECT_STATS
;
1675 1: Result
:= SPECT_MAPVIEW
;
1676 2: Result
:= SPECT_MAPVIEW
;
1677 3: Result
:= SPECT_PLAYERS
;
1678 4: Result
:= SPECT_PLAYERS
;
1679 5: Result
:= SPECT_PLAYERS
;
1680 6: Result
:= SPECT_PLAYERS
;
1682 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1686 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1692 if (plr
= nil) then exit
;
1693 if (p
= 2) then time
:= 1000 else time
:= 1;
1694 strafeDir
:= MoveButton
shr 4;
1695 MoveButton
:= MoveButton
and $0F;
1697 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1698 MoveButton
:= 1 // Нажата только "Влево"
1699 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1700 MoveButton
:= 2 // Нажата только "Вправо"
1701 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1702 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1704 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1705 if MoveButton
= 1 then
1706 plr
.PressKey(KEY_LEFT
, time
)
1707 else if MoveButton
= 2 then
1708 plr
.PressKey(KEY_RIGHT
, time
);
1710 // if we have "strafe" key, turn off old strafe mechanics
1711 if gPlayerAction
[p
, ACTION_STRAFE
] then
1713 // new strafe mechanics
1714 if (strafeDir
= 0) then
1715 strafeDir
:= MoveButton
; // start strafing
1716 // now set direction according to strafe (reversed)
1717 if (strafeDir
= 2) then
1718 plr
.SetDirection(TDirection
.D_LEFT
)
1719 else if (strafeDir
= 1) then
1720 plr
.SetDirection(TDirection
.D_RIGHT
)
1724 strafeDir
:= 0; // not strafing anymore
1725 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1726 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1727 plr
.SetDirection(TDirection
.D_LEFT
)
1728 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1729 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1730 plr
.SetDirection(TDirection
.D_RIGHT
)
1731 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1732 else if MoveButton
<> 0 then
1733 plr
.SetDirection(TDirection(MoveButton
-1))
1736 // fix movebutton state
1737 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1739 // Остальные клавиши:
1740 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1741 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1742 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1743 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1744 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1745 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1746 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1748 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1749 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1751 for i
:= WP_FIRST
to WP_LAST
do
1753 if gSelectWeapon
[p
, i
] then
1755 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1756 gSelectWeapon
[p
, i
] := False
1760 // HACK: add dynlight here
1761 if gwin_k8_enable_light_experiments
then
1763 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1765 g_playerLight
:= true;
1767 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1769 g_playerLight
:= false;
1773 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1776 // HACK: don't have a "key was pressed" function
1777 procedure InterReady();
1779 if InterReadyTime
> gTime
then Exit
;
1780 InterReadyTime
:= gTime
+ 3000;
1781 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1784 procedure g_Game_PreUpdate();
1786 // these are in separate PreUpdate functions because they can interact during Update()
1787 // and are synced over the net
1788 // we don't care that much about corpses and gibs
1789 g_Player_PreUpdate();
1790 g_Monsters_PreUpdate();
1791 g_Items_PreUpdate();
1792 g_Weapon_PreUpdate();
1795 procedure g_Game_Update();
1797 Msg
: g_gui
.TMessage
;
1803 function sendMonsPos (mon
: TMonster
): Boolean;
1805 result
:= false; // don't stop
1806 // this will also reset "need-send" flag
1807 if mon
.gncNeedSend
then
1809 MH_SEND_MonsterPos(mon
.UID
);
1811 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1813 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1815 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1817 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1821 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1823 result
:= false; // don't stop
1824 // this will also reset "need-send" flag
1825 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1829 reliableUpdate
: Boolean;
1834 // Пора выключать игру:
1835 if gExit
= EXIT_QUIT
then
1837 // Игра закончилась - обрабатываем:
1841 if gExit
= EXIT_QUIT
then
1845 // Читаем клавиатуру и джойстик, если окно активно
1846 // no need to, as we'll do it in event handler
1848 // Обновляем консоль (движение и сообщения):
1852 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1854 gExit
:= EXIT_SIMPLE
;
1859 // process master server communications
1860 g_Net_Slist_Pulse();
1863 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1864 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1865 STATE_INTERTEXT
, // Текст между уровнями
1866 STATE_INTERPIC
: // Картинка между уровнями
1868 if g_Game_IsNet
and g_Game_IsServer
then
1870 gInterTime
:= gInterTime
+ GAME_TICK
;
1871 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1872 if a
<> gServInterTime
then
1874 gServInterTime
:= a
;
1875 MH_SEND_TimeSync(gServInterTime
);
1879 if (not g_Game_IsClient
) and
1883 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1884 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1885 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1886 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1888 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1889 and (g_ActiveWindow
= nil)
1891 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1894 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1895 g_Game_StopAllSounds(True);
1897 if gMapOnce
then // Это был тест
1898 gExit
:= EXIT_SIMPLE
1900 if gNextMap
<> '' then // Переходим на следующую карту
1901 g_Game_ChangeMap(gNextMap
)
1902 else // Следующей карты нет
1904 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1906 // Выход в главное меню:
1908 g_GUI_ShowWindow('MainMenu');
1909 gMusic
.SetByName('MUSIC_MENU');
1911 gState
:= STATE_MENU
;
1914 // Финальная картинка:
1915 g_Game_ExecuteEvent('onwadend');
1917 if not gMusic
.SetByName('MUSIC_endmus') then
1918 gMusic
.SetByName('MUSIC_STDENDMUS');
1920 gState
:= STATE_ENDPIC
;
1922 g_Game_ExecuteEvent('ongameend');
1927 else if g_Game_IsClient
and
1930 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1931 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1932 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1933 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1935 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1936 and (g_ActiveWindow
= nil)
1944 if gState
= STATE_INTERTEXT
then
1945 if InterText
.counter
> 0 then
1946 InterText
.counter
:= InterText
.counter
- 1;
1949 STATE_FOLD
: // Затухание экрана
1951 if EndingGameCounter
= 0 then
1953 // Закончился уровень в Своей игре:
1954 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1956 InterReadyTime
:= -1;
1957 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1959 g_Game_ExecuteEvent('onwadend');
1960 if not gMusic
.SetByName('MUSIC_endmus') then
1961 gMusic
.SetByName('MUSIC_STDENDMUS');
1964 gMusic
.SetByName('MUSIC_ROUNDMUS');
1967 gState
:= STATE_INTERCUSTOM
;
1970 else // Закончилась последняя карта в Одиночной игре
1972 gMusic
.SetByName('MUSIC_INTERMUS');
1974 gState
:= STATE_INTERSINGLE
;
1977 g_Game_ExecuteEvent('oninter');
1980 DecMin(EndingGameCounter
, 6, 0);
1983 STATE_ENDPIC
: // Картинка окончания мегаВада
1985 if gMapOnce
then // Это был тест
1987 gExit
:= EXIT_SIMPLE
;
1993 g_Serverlist_Control(slCurrent
, slTable
);
1996 // Статистика по Tab:
1998 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
2001 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
2003 // Время += 28 миллисекунд:
2004 gTime
:= gTime
+ GAME_TICK
;
2006 // Сообщение посередине экрана:
2007 if MessageTime
= 0 then
2009 if MessageTime
> 0 then
2010 MessageTime
:= MessageTime
- 1;
2012 if (g_Game_IsServer
) then
2014 // Был задан лимит времени:
2015 if (gGameSettings
.TimeLimit
> 0) then
2016 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
2017 begin // Он прошел => конец уровня
2022 // Надо респавнить игроков в LMS:
2023 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
2024 g_Game_RestartRound(gLMSSoftSpawn
);
2026 // Проверим результат голосования, если время прошло
2027 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2029 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2031 g_Console_Process(gVoteCommand
);
2033 gVotePassed
:= False;
2036 // Замеряем время захвата флагов
2037 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2038 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2039 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2040 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2042 // Был задан лимит побед:
2043 if (gGameSettings
.GoalLimit
> 0) then
2047 if gGameSettings
.GameMode
= GM_DM
then
2048 begin // В DM ищем игрока с max фрагами
2049 for i
:= 0 to High(gPlayers
) do
2050 if gPlayers
[i
] <> nil then
2051 if gPlayers
[i
].Frags
> b
then
2052 b
:= gPlayers
[i
].Frags
;
2055 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2056 begin // В CTF/TDM выбираем команду с наибольшим счетом
2057 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
2060 // Лимит побед набран => конец уровня:
2061 if b
>= gGameSettings
.GoalLimit
then
2068 // Обрабатываем клавиши игроков:
2069 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2070 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2071 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2073 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2074 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2075 end // if not console
2078 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2080 // process weapon switch queue
2084 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2085 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2087 if not gSpectKeyPress
then
2089 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2091 // switch spect mode
2093 SPECT_NONE
: ; // not spectator
2095 SPECT_MAPVIEW
: Inc(gSpectMode
);
2096 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2098 gSpectKeyPress
:= True;
2100 if (gSpectMode
= SPECT_MAPVIEW
)
2101 and (not gSpectAuto
) then
2103 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2104 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2105 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2106 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2107 if gPlayerAction
[0, ACTION_LOOKUP
] then
2108 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2109 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2110 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2111 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2114 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2115 gSpectKeyPress
:= True;
2117 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2120 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2121 gSpectKeyPress
:= True;
2124 if (gSpectMode
= SPECT_PLAYERS
)
2125 and (not gSpectAuto
) then
2127 if gPlayerAction
[0, ACTION_LOOKUP
] then
2130 gSpectViewTwo
:= True;
2131 gSpectKeyPress
:= True;
2133 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2135 // remove second view
2136 gSpectViewTwo
:= False;
2137 gSpectKeyPress
:= True;
2139 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2141 // prev player (view 1)
2142 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2143 gSpectKeyPress
:= True;
2145 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2147 // next player (view 1)
2148 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2149 gSpectKeyPress
:= True;
2151 if gPlayerAction
[0, ACTION_WEAPPREV
] then
2153 // prev player (view 2)
2154 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2155 gSpectKeyPress
:= True;
2157 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
2159 // next player (view 2)
2160 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2161 gSpectKeyPress
:= True;
2164 if gPlayerAction
[0, ACTION_ATTACK
] then
2166 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2169 gSpectAutoNext
:= 0;
2170 gSpectViewTwo
:= False;
2171 gSpectKeyPress
:= True;
2176 gSpectMode
:= SPECT_STATS
;
2177 gSpectAuto
:= False;
2178 gSpectKeyPress
:= True;
2183 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2184 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2185 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2186 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2187 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2188 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2189 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2190 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2191 gSpectKeyPress
:= False;
2195 if gSpectMode
= SPECT_MAPVIEW
then
2197 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2199 gSpectAutoNext
:= gTime
2202 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2204 gSpectAutoNext
:= gTime
2208 if gSpectAutoNext
<= gTime
then
2210 if gSpectAutoNext
> 0 then
2212 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2216 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2217 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2218 gSpectAutoStepX
:= Random(9) - 4;
2219 gSpectAutoStepY
:= Random(9) - 4;
2220 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2221 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2222 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2223 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2224 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2225 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2229 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2234 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2235 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2236 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2242 // Обновляем все остальное:
2245 g_Triggers_Update();
2247 g_Monsters_Update();
2249 g_Player_UpdateAll();
2250 g_Player_UpdatePhysicalObjects();
2252 // server: send newly spawned monsters unconditionally
2253 if (gGameSettings
.GameType
= GT_SERVER
) then
2255 if (Length(gMonstersSpawned
) > 0) then
2257 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2258 SetLength(gMonstersSpawned
, 0);
2262 if (gSoundTriggerTime
> 8) then
2264 g_Game_UpdateTriggerSounds();
2265 gSoundTriggerTime
:= 0;
2269 Inc(gSoundTriggerTime
);
2272 if (NetMode
= NET_SERVER
) then
2274 Inc(NetTimeToUpdate
);
2275 Inc(NetTimeToReliable
);
2277 // send monster updates
2278 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2280 // send all monsters (periodic sync)
2281 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2283 for I
:= 0 to High(gPlayers
) do
2285 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2288 g_Mons_ForEach(sendMonsPos
);
2290 if reliableUpdate
then
2292 NetTimeToReliable
:= 0;
2293 NetTimeToUpdate
:= NetUpdateRate
;
2297 NetTimeToUpdate
:= 0;
2302 // send only mosters with some unexpected changes
2303 g_Mons_ForEach(sendMonsPosUnexpected
);
2306 // send unexpected platform changes
2307 g_Map_NetSendInterestingPanels();
2309 g_Net_Slist_ServerUpdate();
2311 if NetUseMaster then
2313 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2315 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2317 NetTimeToMaster := gTime + NetMasterRate;
2322 else if (NetMode
= NET_CLIENT
) then
2324 MC_SEND_PlayerPos();
2326 end; // if gameOn ...
2328 // Активно окно интерфейса - передаем клавиши ему:
2329 if g_ActiveWindow
<> nil then
2331 w
:= e_GetFirstKeyPressed();
2333 if (w
<> IK_INVALID
) then
2335 Msg
.Msg
:= MESSAGE_DIKEY
;
2337 g_ActiveWindow
.OnMessage(Msg
);
2340 // Если оно от этого не закрылось, то обновляем:
2341 if g_ActiveWindow
<> nil then
2342 g_ActiveWindow
.Update();
2344 // Нужно сменить разрешение:
2345 if gResolutionChange
then
2347 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2348 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2349 gResolutionChange
:= False;
2350 g_ActiveWindow
:= nil;
2353 // Нужно сменить язык:
2354 if gLanguageChange
then
2356 //e_WriteLog('Read language file', MSG_NOTIFY);
2357 //g_Language_Load(DataDir + gLanguage + '.txt');
2358 g_Language_Set(gLanguage
);
2362 gLanguageChange
:= False;
2366 // Горячая клавиша для вызова меню выхода из игры (F10):
2367 if e_KeyPressed(IK_F10
) and
2369 (not gConsoleShow
) and
2370 (g_ActiveWindow
= nil) then
2375 Time
:= sys_GetTicks() {div 1000};
2377 // Обработка отложенных событий:
2378 if gDelayedEvents
<> nil then
2379 for a
:= 0 to High(gDelayedEvents
) do
2380 if gDelayedEvents
[a
].Pending
and
2382 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2383 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2386 case gDelayedEvents
[a
].DEType
of
2388 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2391 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2395 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2396 if g_Game_IsNet
and g_Game_IsServer
then
2397 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2401 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2403 gDelayedEvents
[a
].Pending
:= False;
2406 // Каждую секунду обновляем счетчик обновлений:
2407 UPSCounter
:= UPSCounter
+ 1;
2408 if Time
- UPSTime
>= 1000 then
2417 g_Weapon_AddDynLights();
2418 g_Items_AddDynLights();
2422 procedure g_Game_LoadChatSounds(Resource
: string);
2425 FileName
, Snd
: string;
2427 len
, cnt
, tags
, i
, j
: Integer;
2430 FileName
:= g_ExtractWadName(Resource
);
2432 WAD
:= TWADFile
.Create();
2433 WAD
.ReadFile(FileName
);
2435 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2442 cfg
:= TConfig
.CreateMem(p
, len
);
2443 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2445 SetLength(gChatSounds
, cnt
);
2446 for i
:= 0 to Length(gChatSounds
) - 1 do
2448 gChatSounds
[i
].Sound
:= nil;
2449 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2450 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2451 if (Snd
= '') or (Tags
<= 0) then
2453 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2454 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2455 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2456 SetLength(gChatSounds
[i
].Tags
, tags
);
2457 for j
:= 0 to tags
- 1 do
2458 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2459 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2466 procedure g_Game_FreeChatSounds();
2470 for i
:= 0 to Length(gChatSounds
) - 1 do
2472 gChatSounds
[i
].Sound
.Free();
2473 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2475 SetLength(gChatSounds
, 0);
2479 procedure g_Game_LoadData();
2486 if DataLoaded
then Exit
;
2488 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2490 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2491 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2492 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2493 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2494 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2495 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2496 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2497 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2498 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2499 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2500 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2501 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2502 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2503 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2504 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2507 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2508 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2509 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2510 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2514 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2515 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2516 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2517 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2518 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
2524 hasPBarGfx
:= false;
2528 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2529 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2530 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2531 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2532 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2533 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2534 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2535 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2536 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2537 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2538 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2539 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2540 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2541 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2542 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2543 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2544 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2545 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2546 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2547 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2548 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2549 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2550 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2551 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2552 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2553 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2554 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2555 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2556 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2557 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2558 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2559 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2560 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2561 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2562 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2563 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2564 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2565 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2566 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2568 goodsnd
[0] := TPlayableSound
.Create();
2569 goodsnd
[1] := TPlayableSound
.Create();
2570 goodsnd
[2] := TPlayableSound
.Create();
2571 goodsnd
[3] := TPlayableSound
.Create();
2573 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2574 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2575 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2576 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2578 killsnd
[0] := TPlayableSound
.Create();
2579 killsnd
[1] := TPlayableSound
.Create();
2580 killsnd
[2] := TPlayableSound
.Create();
2581 killsnd
[3] := TPlayableSound
.Create();
2583 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2584 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2585 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2586 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2588 hahasnd
[0] := TPlayableSound
.Create();
2589 hahasnd
[1] := TPlayableSound
.Create();
2590 hahasnd
[2] := TPlayableSound
.Create();
2592 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2593 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2594 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2596 sound_get_flag
[0] := TPlayableSound
.Create();
2597 sound_get_flag
[1] := TPlayableSound
.Create();
2598 sound_lost_flag
[0] := TPlayableSound
.Create();
2599 sound_lost_flag
[1] := TPlayableSound
.Create();
2600 sound_ret_flag
[0] := TPlayableSound
.Create();
2601 sound_ret_flag
[1] := TPlayableSound
.Create();
2602 sound_cap_flag
[0] := TPlayableSound
.Create();
2603 sound_cap_flag
[1] := TPlayableSound
.Create();
2605 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2606 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2607 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2608 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2609 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2610 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2611 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2612 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2614 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2616 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2619 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2620 g_Weapon_LoadData();
2622 g_Monsters_LoadData();
2627 procedure g_Game_Quit();
2629 g_Game_StopAllSounds(True);
2632 r_PlayerModel_Finalize
;
2633 g_PlayerModel_FreeData();
2634 g_Texture_DeleteAll();
2635 g_Frames_DeleteAll();
2637 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2640 if NetInitDone
then g_Net_Free
;
2642 // remove map after test
2643 if gMapToDelete
<> '' then
2644 g_Game_DeleteTestMap();
2650 procedure g_Game_FreeData();
2652 if not DataLoaded
then Exit
;
2655 g_Weapon_FreeData();
2656 g_Monsters_FreeData();
2658 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2660 g_Texture_Delete('NOTEXTURE');
2661 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2662 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2663 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2664 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2665 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2666 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2667 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2668 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2669 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2670 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2671 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2672 g_Frames_DeleteByName('FRAMES_TELEPORT');
2673 g_Frames_DeleteByName('FRAMES_PUNCH');
2674 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2675 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2676 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2677 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2678 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2679 g_Sound_Delete('SOUND_GAME_TELEPORT');
2680 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2681 g_Sound_Delete('SOUND_GAME_SECRET');
2682 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2683 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2684 g_Sound_Delete('SOUND_GAME_BULK1');
2685 g_Sound_Delete('SOUND_GAME_BULK2');
2686 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2687 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2688 g_Sound_Delete('SOUND_GAME_BURNING');
2689 g_Sound_Delete('SOUND_GAME_SWITCH1');
2690 g_Sound_Delete('SOUND_GAME_SWITCH0');
2697 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2698 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2699 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2700 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2707 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2708 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2709 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2710 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2716 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2717 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2718 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2720 sound_get_flag
[0].Free();
2721 sound_get_flag
[1].Free();
2722 sound_lost_flag
[0].Free();
2723 sound_lost_flag
[1].Free();
2724 sound_ret_flag
[0].Free();
2725 sound_ret_flag
[1].Free();
2726 sound_cap_flag
[0].Free();
2727 sound_cap_flag
[1].Free();
2729 g_Sound_Delete('SOUND_CTF_GET1');
2730 g_Sound_Delete('SOUND_CTF_GET2');
2731 g_Sound_Delete('SOUND_CTF_LOST1');
2732 g_Sound_Delete('SOUND_CTF_LOST2');
2733 g_Sound_Delete('SOUND_CTF_RETURN1');
2734 g_Sound_Delete('SOUND_CTF_RETURN2');
2735 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2736 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2738 g_Game_FreeChatSounds();
2740 DataLoaded
:= False;
2743 procedure g_FatalError(Text: String);
2745 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2746 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2748 gExit
:= EXIT_SIMPLE
;
2749 if gGameOn
then EndGame
;
2752 procedure g_SimpleError(Text: String);
2754 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2755 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2758 procedure g_Game_SetupScreenSize();
2760 RES_FACTOR
= 4.0 / 3.0;
2766 // Размер экранов игроков:
2767 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2768 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2769 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
2771 gPlayerScreenSize
.Y
:= gScreenHeight
;
2773 // Размер заднего плана:
2774 if BackID
<> DWORD(-1) then
2777 if (gScreenWidth
*s
> gMapInfo
.Width
) or
2778 (gScreenHeight
*s
> gMapInfo
.Height
) then
2780 gBackSize
.X
:= gScreenWidth
;
2781 gBackSize
.Y
:= gScreenHeight
;
2785 e_GetTextureSize(BackID
, @bw
, @bh
);
2786 rf
:= Single(bw
) / Single(bh
);
2787 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
2788 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
2789 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
2790 if (s
< 1.0) then s
:= 1.0;
2791 gBackSize
.X
:= Round(bw
*s
);
2792 gBackSize
.Y
:= Round(bh
*s
);
2797 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
2799 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
2802 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2804 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2805 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2808 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2811 if gPlayer1
= nil then
2813 if g_Game_IsClient
then
2815 if NetPlrUID1
> -1 then
2816 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2820 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2821 Team
:= gPlayer1Settings
.Team
;
2823 // Создание первого игрока:
2824 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2825 gPlayer1Settings
.Color
,
2827 if gPlayer1
= nil then
2828 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2831 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2832 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2833 if g_Game_IsServer
and g_Game_IsNet
then
2834 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2835 gPlayer1
.Respawn(False, True);
2836 g_Net_Slist_ServerPlayerComes();
2841 if gPlayer2
= nil then
2843 if g_Game_IsClient
then
2845 if NetPlrUID2
> -1 then
2846 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2850 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2851 Team
:= gPlayer2Settings
.Team
;
2853 // Создание второго игрока:
2854 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2855 gPlayer2Settings
.Color
,
2857 if gPlayer2
= nil then
2858 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2861 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2862 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2863 if g_Game_IsServer
and g_Game_IsNet
then
2864 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2865 gPlayer2
.Respawn(False, True);
2866 g_Net_Slist_ServerPlayerComes();
2873 procedure g_Game_RemovePlayer();
2877 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2878 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2883 if g_Game_IsServer
then
2886 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2887 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2888 g_Player_Remove(Pl
.UID
);
2889 g_Net_Slist_ServerPlayerLeaves();
2893 gSpectLatchPID2
:= Pl
.UID
;
2901 if g_Game_IsServer
then
2904 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2905 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2906 g_Player_Remove(Pl
.UID
);
2907 g_Net_Slist_ServerPlayerLeaves();
2910 gSpectLatchPID1
:= Pl
.UID
;
2912 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2916 g_Net_Slist_ServerPlayerLeaves();
2919 procedure g_Game_Spectate();
2921 g_Game_RemovePlayer();
2922 if gPlayer1
<> nil then
2923 g_Game_RemovePlayer();
2926 procedure g_Game_SpectateCenterView();
2928 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2929 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2932 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2939 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2941 g_Game_ClearLoading();
2944 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2947 gGameSettings
.GameType
:= GT_SINGLE
;
2948 gGameSettings
.MaxLives
:= 0;
2949 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2950 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2951 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2952 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2953 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2954 gSwitchGameMode
:= GM_SINGLE
;
2956 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2957 gLMSRespawnTime
:= 0;
2958 gSpectLatchPID1
:= 0;
2959 gSpectLatchPID2
:= 0;
2961 g_Game_ExecuteEvent('ongamestart');
2963 // Установка размеров окон игроков:
2964 g_Game_SetupScreenSize();
2966 // Создание первого игрока:
2967 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2968 gPlayer1Settings
.Color
,
2969 gPlayer1Settings
.Team
, False));
2970 if gPlayer1
= nil then
2972 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2976 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2979 // Создание второго игрока, если есть:
2982 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2983 gPlayer2Settings
.Color
,
2984 gPlayer2Settings
.Team
, False));
2985 if gPlayer2
= nil then
2987 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2991 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2995 // Загрузка и запуск карты:
2996 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2998 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2999 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
3003 // Настройки игроков и ботов:
3007 for i
:= nPl
+1 to nPlayers
do
3008 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3011 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3012 TimeLimit
, GoalLimit
: Word;
3014 Options
: LongWord; nPlayers
: Byte);
3020 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
3022 g_Game_ClearLoading();
3025 gGameSettings
.GameType
:= GT_CUSTOM
;
3026 gGameSettings
.GameMode
:= GameMode
;
3027 gSwitchGameMode
:= GameMode
;
3028 gGameSettings
.TimeLimit
:= TimeLimit
;
3029 gGameSettings
.GoalLimit
:= GoalLimit
;
3030 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3031 gGameSettings
.Options
:= Options
;
3033 gCoopTotalMonstersKilled
:= 0;
3034 gCoopTotalSecretsFound
:= 0;
3035 gCoopTotalMonsters
:= 0;
3036 gCoopTotalSecrets
:= 0;
3040 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3041 gLMSRespawnTime
:= 0;
3042 gSpectLatchPID1
:= 0;
3043 gSpectLatchPID2
:= 0;
3045 g_Game_ExecuteEvent('ongamestart');
3047 // Установка размеров окон игроков:
3048 g_Game_SetupScreenSize();
3050 // Режим наблюдателя:
3051 if nPlayers
= 0 then
3058 if nPlayers
>= 1 then
3060 // Создание первого игрока:
3061 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3062 gPlayer1Settings
.Color
,
3063 gPlayer1Settings
.Team
, False));
3064 if gPlayer1
= nil then
3066 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3070 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3074 if nPlayers
>= 2 then
3076 // Создание второго игрока:
3077 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3078 gPlayer2Settings
.Color
,
3079 gPlayer2Settings
.Team
, False));
3080 if gPlayer2
= nil then
3082 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3086 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3090 // Загрузка и запуск карты:
3091 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3093 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3097 // Нет точек появления:
3098 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3099 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3100 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3101 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3102 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3104 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3108 // Настройки игроков и ботов:
3112 for i
:= nPl
+1 to nPlayers
do
3113 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3116 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3117 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3118 Options
: LongWord; nPlayers
: Byte;
3119 IPAddr
: LongWord; Port
: Word);
3122 g_Net_Slist_ServerClosed();
3124 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3126 g_Game_ClearLoading();
3129 gGameSettings
.GameType
:= GT_SERVER
;
3130 gGameSettings
.GameMode
:= GameMode
;
3131 gSwitchGameMode
:= GameMode
;
3132 gGameSettings
.TimeLimit
:= TimeLimit
;
3133 gGameSettings
.GoalLimit
:= GoalLimit
;
3134 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3135 gGameSettings
.Options
:= Options
;
3137 gCoopTotalMonstersKilled
:= 0;
3138 gCoopTotalSecretsFound
:= 0;
3139 gCoopTotalMonsters
:= 0;
3140 gCoopTotalSecrets
:= 0;
3144 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3145 gLMSRespawnTime
:= 0;
3146 gSpectLatchPID1
:= 0;
3147 gSpectLatchPID2
:= 0;
3149 g_Game_ExecuteEvent('ongamestart');
3151 // Установка размеров окна игрока
3152 g_Game_SetupScreenSize();
3154 // Режим наблюдателя:
3155 if nPlayers
= 0 then
3161 if nPlayers
>= 1 then
3163 // Создание первого игрока:
3164 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3165 gPlayer1Settings
.Color
,
3166 gPlayer1Settings
.Team
, False));
3167 if gPlayer1
= nil then
3169 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3173 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3176 if nPlayers
>= 2 then
3178 // Создание второго игрока:
3179 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3180 gPlayer2Settings
.Color
,
3181 gPlayer2Settings
.Team
, False));
3182 if gPlayer2
= nil then
3184 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3188 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3191 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3192 if NetForwardPorts
then
3193 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3196 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3198 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3202 g_Net_Slist_Set(NetMasterList
);
3204 g_Net_Slist_ServerStarted();
3206 // Загрузка и запуск карты:
3207 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3209 g_Net_Slist_ServerClosed();
3210 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3214 // Нет точек появления:
3215 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3216 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3217 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3218 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3219 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3221 g_Net_Slist_ServerClosed();
3222 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3226 // Настройки игроков и ботов:
3229 g_Net_Slist_ServerMapStarted();
3230 NetState
:= NET_STATE_GAME
;
3233 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3248 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3249 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3251 g_Game_ClearLoading();
3254 gGameSettings
.GameType
:= GT_CLIENT
;
3256 gCoopTotalMonstersKilled
:= 0;
3257 gCoopTotalSecretsFound
:= 0;
3258 gCoopTotalMonsters
:= 0;
3259 gCoopTotalSecrets
:= 0;
3263 g_Game_ExecuteEvent('ongamestart');
3265 // Установка размеров окон игроков:
3266 g_Game_SetupScreenSize();
3268 NetState
:= NET_STATE_AUTH
;
3270 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3272 // create (or update) map/resource databases
3273 g_Res_CreateDatabases(true);
3275 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3276 gLMSRespawnTime
:= 0;
3277 gSpectLatchPID1
:= 0;
3278 gSpectLatchPID2
:= 0;
3281 if not g_Net_Connect(Addr
, Port
) then
3283 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3284 NetState
:= NET_STATE_NONE
;
3288 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3290 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3295 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3296 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3297 // thank you, enet. let's ignore failures altogether then.
3298 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3300 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3302 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
3304 // ignore all download packets, they're processed by separate code
3305 enet_packet_destroy(NetEvent
.packet
);
3308 Ptr
:= NetEvent
.packet
^.data
;
3309 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3311 enet_packet_destroy(NetEvent
.packet
);
3315 InMsg
.ReadLongWord(); // skip size
3316 MID
:= InMsg
.ReadByte();
3318 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3320 NetMyID
:= InMsg
.ReadByte();
3321 NetPlrUID1
:= InMsg
.ReadWord();
3323 WadName
:= InMsg
.ReadString();
3324 Map
:= InMsg
.ReadString();
3326 gWADHash
:= InMsg
.ReadMD5();
3328 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3329 gSwitchGameMode
:= gGameSettings
.GameMode
;
3330 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
3331 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3332 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3333 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3334 T
:= InMsg
.ReadLongWord();
3336 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3337 //if newResPath = '' then
3339 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3340 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3341 if newResPath
= '' then
3343 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3344 enet_packet_destroy(NetEvent
.packet
);
3345 NetState
:= NET_STATE_NONE
;
3348 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3350 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3353 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3354 gPlayer1Settings
.Color
,
3355 gPlayer1Settings
.Team
, False));
3357 if gPlayer1
= nil then
3359 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3361 enet_packet_destroy(NetEvent
.packet
);
3362 NetState
:= NET_STATE_NONE
;
3366 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3367 gPlayer1
.UID
:= NetPlrUID1
;
3368 gPlayer1
.Reset(True);
3370 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3372 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3374 enet_packet_destroy(NetEvent
.packet
);
3375 NetState
:= NET_STATE_NONE
;
3383 enet_packet_destroy(NetEvent
.packet
);
3387 enet_packet_destroy(NetEvent
.packet
);
3391 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3394 if (NetEvent
.data
<= NET_DISC_MAX
) then
3395 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3396 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3403 ProcessLoading(true);
3405 if g_Net_UserRequestExit() then
3414 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3415 NetState
:= NET_STATE_NONE
;
3420 NetState
:= NET_STATE_GAME
;
3421 MC_SEND_FullStateRequest
;
3422 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3426 lastAsMegaWad
: Boolean = false;
3428 procedure g_Game_ChangeMap(const MapPath
: String);
3432 g_Game_ClearLoading();
3434 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3435 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3436 if gExitByTrigger
then
3439 gExitByTrigger
:= False;
3441 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3442 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3445 procedure g_Game_Restart();
3449 if g_Game_IsClient
then
3451 map
:= g_ExtractFileName(gMapInfo
.Map
);
3452 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3456 g_Game_ClearLoading();
3457 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3460 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3462 NewWAD
, ResName
: String;
3466 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3467 g_Player_RemoveAllCorpses();
3469 if (not g_Game_IsClient
) and
3470 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3471 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3473 if gSwitchGameMode
= GM_CTF
then
3474 gGameSettings
.MaxLives
:= 0;
3475 gGameSettings
.GameMode
:= gSwitchGameMode
;
3478 gSwitchGameMode
:= gGameSettings
.GameMode
;
3480 g_Player_ResetTeams();
3482 lastAsMegaWad
:= asMegawad
;
3483 if isWadPath(Map
) then
3485 NewWAD
:= g_ExtractWadName(Map
);
3486 ResName
:= g_ExtractFileName(Map
);
3487 if g_Game_IsServer
then
3489 nws
:= findDiskWad(NewWAD
);
3490 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3493 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3494 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3498 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3499 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3501 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3502 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3504 if (length(nws
) = 0) then
3506 ResName
:= ''; // failed
3511 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3512 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3513 g_Game_LoadWAD(NewWAD
);
3518 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3519 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3524 NewWAD
:= gGameSettings
.WAD
;
3530 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3532 if (ResName
<> '') and (NewWAD
<> '') then
3534 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3535 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3539 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3541 gState
:= STATE_NONE
;
3542 g_ActiveWindow
:= nil;
3546 wNeedTimeReset
:= True;
3548 if gGameSettings
.GameMode
= GM_CTF
then
3550 g_Map_ResetFlag(FLAG_RED
);
3551 g_Map_ResetFlag(FLAG_BLUE
);
3552 // CTF, а флагов нет:
3553 if not g_Map_HaveFlagPoints() then
3554 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3559 gState
:= STATE_MENU
;
3564 gPauseMain
:= false;
3565 gPauseHolmes
:= false;
3566 NetTimeToUpdate
:= 1;
3567 NetTimeToReliable
:= 0;
3568 NetTimeToMaster
:= NetMasterRate
;
3569 gSpectLatchPID1
:= 0;
3570 gSpectLatchPID2
:= 0;
3571 gMissionFailed
:= False;
3574 gCoopMonstersKilled
:= 0;
3575 gCoopSecretsFound
:= 0;
3577 gVoteInProgress
:= False;
3578 gVotePassed
:= False;
3584 if not gGameOn
then Exit
;
3586 g_Game_SpectateCenterView();
3588 if g_Game_IsServer
then
3590 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3592 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3593 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3594 gLMSSoftSpawn
:= True;
3595 if g_Game_IsNet
then
3596 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3600 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3601 gLMSRespawnTime
:= 0;
3605 if NetMode
= NET_SERVER
then
3607 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3610 g_Net_Slist_ServerMapStarted();
3612 if NetClients
<> nil then
3613 for I
:= 0 to High(NetClients
) do
3614 if NetClients
[I
].Used
then
3616 NetClients
[I
].Voted
:= False;
3617 if NetClients
[I
].RequestedFullUpdate
then
3619 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3620 NetClients
[I
].RequestedFullUpdate
:= False;
3624 g_Net_UnbanNonPermHosts();
3629 gCoopTotalMonstersKilled
:= 0;
3630 gCoopTotalSecretsFound
:= 0;
3631 gCoopTotalMonsters
:= 0;
3632 gCoopTotalSecrets
:= 0;
3636 g_Game_ExecuteEvent('onmapstart');
3639 procedure SetFirstLevel
;
3643 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3644 if MapList
= nil then
3647 SortSArray(MapList
);
3648 gNextMap
:= MapList
[Low(MapList
)];
3653 procedure g_Game_ExitLevel(const Map
: AnsiString);
3657 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3658 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3659 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3660 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3662 // Вышли в выход в Одиночной игре:
3663 if gGameSettings
.GameType
= GT_SINGLE
then
3664 gExit
:= EXIT_ENDLEVELSINGLE
3665 else // Вышли в выход в Своей игре
3667 gExit
:= EXIT_ENDLEVELCUSTOM
;
3668 if gGameSettings
.GameMode
= GM_COOP
then
3669 g_Player_RememberAll
;
3671 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3674 if gGameSettings
.GameMode
= GM_COOP
then
3677 gStatsPressed
:= True;
3678 gNextMap
:= 'MAP01';
3680 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3683 if g_Game_IsNet
then
3685 MH_SEND_GameStats();
3686 MH_SEND_CoopStats();
3692 procedure g_Game_RestartLevel();
3696 if gGameSettings
.GameMode
= GM_SINGLE
then
3701 gExit
:= EXIT_ENDLEVELCUSTOM
;
3702 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3706 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3708 gWAD
{, xwad}: String;
3711 if not g_Game_IsClient
then Exit
;
3712 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3714 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3719 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3723 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3726 g_Game_LoadWAD(NewWAD
);
3730 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3731 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3734 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3735 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3739 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3743 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3744 g_Game_LoadWAD(NewWAD);
3748 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3750 i
, n
, nb
, nr
: Integer;
3752 if not g_Game_IsServer
then Exit
;
3753 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3754 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3755 gLMSRespawnTime
:= 0;
3758 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3760 gMissionFailed
:= True;
3761 g_Game_RestartLevel
;
3765 n
:= 0; nb
:= 0; nr
:= 0;
3766 for i
:= Low(gPlayers
) to High(gPlayers
) do
3767 if (gPlayers
[i
] <> nil) and
3768 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3769 (gPlayers
[i
] is TBot
)) then
3772 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3773 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3776 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3778 // wait a second until the fuckers finally decide to join
3779 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3780 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3781 gLMSSoftSpawn
:= NoMapRestart
;
3782 if g_Game_IsNet
then
3783 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3787 g_Player_RemoveAllCorpses
;
3788 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3789 if g_Game_IsNet
then
3790 MH_SEND_GameEvent(NET_EV_LMS_START
);
3792 for i
:= Low(gPlayers
) to High(gPlayers
) do
3794 if gPlayers
[i
] = nil then continue
;
3795 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3796 // don't touch normal spectators
3797 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3799 gPlayers
[i
].FNoRespawn
:= True;
3800 gPlayers
[i
].Lives
:= 0;
3801 if g_Game_IsNet
then
3802 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3805 gPlayers
[i
].FNoRespawn
:= False;
3806 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3807 gPlayers
[i
].Respawn(False, True);
3808 if gGameSettings
.GameMode
= GM_COOP
then
3810 gPlayers
[i
].Frags
:= 0;
3811 gPlayers
[i
].RecallState
;
3813 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3814 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3815 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3816 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3819 g_Items_RestartRound();
3821 gLMSSoftSpawn
:= False;
3824 function g_Game_GetFirstMap(WAD
: String): String;
3828 MapList
:= g_Map_GetMapsList(WAD
);
3829 if MapList
= nil then
3832 SortSArray(MapList
);
3833 Result
:= MapList
[Low(MapList
)];
3835 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3841 function g_Game_GetNextMap(): String;
3848 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3849 if MapList
= nil then
3852 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3854 SortSArray(MapList
);
3856 for I
:= Low(MapList
) to High(MapList
) do
3857 if Map
= MapList
[I
] then
3863 if MapIndex
<> -255 then
3865 if MapIndex
= High(MapList
) then
3866 Result
:= MapList
[Low(MapList
)]
3868 Result
:= MapList
[MapIndex
+ 1];
3870 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3876 procedure g_Game_NextLevel();
3878 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3879 gExit
:= EXIT_ENDLEVELCUSTOM
3882 gExit
:= EXIT_ENDLEVELSINGLE
;
3886 if gNextMap
<> '' then Exit
;
3887 gNextMap
:= g_Game_GetNextMap();
3890 function g_Game_IsTestMap(): Boolean;
3892 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3895 procedure g_Game_DeleteTestMap();
3898 //MapName: AnsiString;
3906 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3907 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3908 if (a
= 0) then exit
;
3910 // Выделяем имя wad-файла и имя карты
3911 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3912 Delete(gMapToDelete
, 1, a
+5);
3913 gMapToDelete
:= UpperCase(gMapToDelete
);
3915 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3918 // Имя карты не стандартное тестовое:
3919 if MapName <> TEST_MAP_NAME then
3922 if not gTempDelete then
3924 time := g_GetFileTime(WadName);
3925 WAD := TWADFile.Create();
3928 if not WAD.ReadFile(WadName) then
3929 begin // Нет такого WAD-файла
3934 // Составляем список карт и ищем нужную:
3936 MapList := WAD.GetResourcesList('');
3938 if MapList <> nil then
3939 for a := 0 to High(MapList) do
3940 if MapList[a] = MapName then
3942 // Удаляем и сохраняем:
3943 WAD.RemoveResource('', MapName);
3944 WAD.SaveTo(WadName);
3949 g_SetFileTime(WadName, time);
3952 if gTempDelete
then DeleteFile(WadName
);
3955 procedure GameCVars(P
: SSArray
);
3958 stat
: TPlayerStatArray
;
3961 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3965 if Length(P
) > 1 then
3970 gsGameFlags
:= gsGameFlags
or Flag
3972 gsGameFlags
:= gsGameFlags
and (not Flag
);
3974 if g_Game_IsServer
then
3977 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3979 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3980 if g_Game_IsNet
then MH_SEND_GameSettings
;
3984 if LongBool(gsGameFlags
and Flag
) then
3985 g_Console_Add(_lc
[OnMsg
])
3987 g_Console_Add(_lc
[OffMsg
]);
3989 if OnMapChange
and g_Game_IsServer
then
3990 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3995 cmd
:= LowerCase(P
[0]);
3997 if cmd
= 'g_gamemode' then
3999 if (Length(P
) > 1) then
4001 a
:= g_Game_TextToMode(P
[1]);
4002 if a
= GM_SINGLE
then a
:= GM_COOP
;
4003 gsGameMode
:= g_Game_ModeToText(a
);
4004 if g_Game_IsServer
then
4006 gSwitchGameMode
:= a
;
4007 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4008 (gState
= STATE_INTERSINGLE
) then
4009 gSwitchGameMode
:= GM_SINGLE
;
4011 gGameSettings
.GameMode
:= gSwitchGameMode
;
4015 if gSwitchGameMode
= gGameSettings
.GameMode
then
4016 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4017 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4019 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4020 [g_Game_ModeToText(gGameSettings
.GameMode
),
4021 g_Game_ModeToText(gSwitchGameMode
)]));
4023 else if cmd
= 'g_friendlyfire' then
4025 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4027 else if cmd
= 'g_friendly_absorb_damage' then
4029 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4031 else if cmd
= 'g_friendly_hit_trace' then
4033 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4035 else if cmd
= 'g_friendly_hit_projectile' then
4037 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4039 else if cmd
= 'g_weaponstay' then
4041 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
4043 else if cmd
= 'g_allow_exit' then
4045 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
4047 else if cmd
= 'g_allow_monsters' then
4049 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
4051 else if cmd
= 'g_bot_vsplayers' then
4053 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4055 else if cmd
= 'g_bot_vsmonsters' then
4057 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4059 else if cmd
= 'g_dm_keys' then
4061 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4063 else if cmd
= 'g_gameflags' then
4065 if Length(P
) > 1 then
4067 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4068 if g_Game_IsServer
then
4070 gGameSettings
.Options
:= gsGameFlags
;
4071 if g_Game_IsNet
then MH_SEND_GameSettings
;
4075 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4077 else if cmd
= 'g_warmup_time' then
4079 if Length(P
) > 1 then
4081 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4082 if g_Game_IsServer
then
4084 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4085 // extend warmup if it's already going
4086 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4088 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4089 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4091 if g_Game_IsNet
then MH_SEND_GameSettings
;
4095 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4096 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4098 else if cmd
= 'g_spawn_invul' then
4100 if Length(P
) > 1 then
4102 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4103 if g_Game_IsServer
then
4105 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4106 if g_Game_IsNet
then MH_SEND_GameSettings
;
4110 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4112 else if cmd
= 'g_item_respawn_time' then
4114 if Length(P
) > 1 then
4116 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4117 if g_Game_IsServer
then
4119 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4120 if g_Game_IsNet
then MH_SEND_GameSettings
;
4124 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4125 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4127 else if cmd
= 'sv_intertime' then
4129 if (Length(P
) > 1) then
4130 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4132 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4134 else if cmd
= 'g_max_particles' then
4136 if Length(p
) = 2 then
4138 a
:= Max(0, StrToInt(p
[1]));
4141 else if Length(p
) = 1 then
4143 e_LogWritefln('%s', [g_GFX_GetMax()])
4147 e_LogWritefln('usage: %s <n>', [cmd
])
4150 else if cmd
= 'g_max_shells' then
4152 if Length(p
) = 2 then
4154 a
:= Max(0, StrToInt(p
[1]));
4157 else if Length(p
) = 1 then
4159 e_LogWritefln('%s', [g_Shells_GetMax()])
4163 e_LogWritefln('usage: %s <n>', [cmd
])
4166 else if cmd
= 'g_max_gibs' then
4168 if Length(p
) = 2 then
4170 a
:= Max(0, StrToInt(p
[1]));
4173 else if Length(p
) = 1 then
4175 e_LogWritefln('%s', [g_Gibs_GetMax()])
4179 e_LogWritefln('usage: %s <n>', [cmd
])
4182 else if cmd
= 'g_max_corpses' then
4184 if Length(p
) = 2 then
4186 a
:= Max(0, StrToInt(p
[1]));
4189 else if Length(p
) = 1 then
4191 e_LogWritefln('%s', [g_Corpses_GetMax()])
4195 e_LogWritefln('usage: %s <n>', [cmd
])
4198 else if cmd
= 'g_scorelimit' then
4200 if Length(P
) > 1 then
4202 gsGoalLimit
:= nclamp(StrToIntDef(P
[1], gsGoalLimit
), 0, $FFFF);
4204 if g_Game_IsServer
then
4207 if gGameSettings
.GameMode
= GM_DM
then
4209 stat
:= g_Player_GetStats();
4211 for a
:= 0 to High(stat
) do
4212 if stat
[a
].Frags
> b
then
4216 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4218 // if someone has a higher score, set it to that instead
4219 gsGoalLimit
:= max(gsGoalLimit
, b
);
4220 gGameSettings
.GoalLimit
:= gsGoalLimit
;
4222 if g_Game_IsNet
then MH_SEND_GameSettings
;
4226 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsGoalLimit
)]));
4228 else if cmd
= 'g_timelimit' then
4230 if Length(P
) > 1 then
4232 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4233 if g_Game_IsServer
then
4235 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4236 if g_Game_IsNet
then MH_SEND_GameSettings
;
4239 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4240 [gsTimeLimit
div 3600,
4241 (gsTimeLimit
div 60) mod 60,
4242 gsTimeLimit
mod 60]));
4244 else if cmd
= 'g_maxlives' then
4246 if Length(P
) > 1 then
4248 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4249 if g_Game_IsServer
then
4251 gGameSettings
.MaxLives
:= gsMaxLives
;
4252 if g_Game_IsNet
then MH_SEND_GameSettings
;
4256 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4260 procedure PlayerSettingsCVars(P
: SSArray
);
4265 function ParseTeam(s
: string): Byte;
4269 'red', '1': result
:= TEAM_RED
;
4270 'blue', '2': result
:= TEAM_BLUE
;
4271 else result
:= TEAM_NONE
;
4275 cmd
:= LowerCase(P
[0]);
4279 if (Length(P
) > 1) then
4281 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4282 if g_Game_IsClient
then
4283 MC_SEND_PlayerSettings
4284 else if gGameOn
and (gPlayer1
<> nil) then
4286 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4287 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4293 if (Length(P
) > 1) then
4295 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4296 if g_Game_IsClient
then
4297 MC_SEND_PlayerSettings
4298 else if gGameOn
and (gPlayer2
<> nil) then
4300 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4301 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4307 if Length(P
) > 3 then
4309 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4310 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4311 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4312 if g_Game_IsClient
then
4313 MC_SEND_PlayerSettings
4314 else if gGameOn
and (gPlayer1
<> nil) then
4316 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4317 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4323 if Length(P
) > 3 then
4325 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4326 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4327 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4328 if g_Game_IsClient
then
4329 MC_SEND_PlayerSettings
4330 else if gGameOn
and (gPlayer2
<> nil) then
4332 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4333 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4339 if (Length(P
) > 1) then
4341 gPlayer1Settings
.Model
:= P
[1];
4342 if g_Game_IsClient
then
4343 MC_SEND_PlayerSettings
4344 else if gGameOn
and (gPlayer1
<> nil) then
4346 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4347 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4348 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4354 if (Length(P
) > 1) then
4356 gPlayer2Settings
.Model
:= P
[1];
4357 if g_Game_IsClient
then
4358 MC_SEND_PlayerSettings
4359 else if gGameOn
and (gPlayer2
<> nil) then
4361 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4362 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4363 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4369 // TODO: switch teams if in game or store this separately
4370 if (Length(P
) > 1) then
4372 team
:= ParseTeam(P
[1]);
4373 if team
= TEAM_NONE
then
4374 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4375 else if not gGameOn
and not g_Game_IsNet
then
4376 gPlayer1Settings
.Team
:= team
4378 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4383 // TODO: switch teams if in game or store this separately
4384 if (Length(P
) > 1) then
4386 team
:= ParseTeam(P
[1]);
4387 if team
= TEAM_NONE
then
4388 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4389 else if not gGameOn
and not g_Game_IsNet
then
4390 gPlayer2Settings
.Team
:= team
4392 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4398 procedure PrintHeapStats();
4402 hs
:= GetFPCHeapStatus();
4403 e_LogWriteLn ('v===== heap status =====v');
4404 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4405 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4406 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4407 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4408 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4409 e_LogWriteLn ('^=======================^');
4412 procedure DebugCommands(P
: SSArray
);
4419 // Команды отладочного режима:
4420 if {gDebugMode}conIsCheatsEnabled
then
4422 cmd
:= LowerCase(P
[0]);
4423 if cmd
= 'd_window' then
4425 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4426 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4428 else if cmd
= 'd_sounds' then
4430 if (Length(P
) > 1) and
4431 ((P
[1] = '1') or (P
[1] = '0')) then
4432 g_Debug_Sounds
:= (P
[1][1] = '1');
4434 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4436 else if cmd
= 'd_frames' then
4438 if (Length(P
) > 1) and
4439 ((P
[1] = '1') or (P
[1] = '0')) then
4440 g_Debug_Frames
:= (P
[1][1] = '1');
4442 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4444 else if cmd
= 'd_winmsg' then
4446 if (Length(P
) > 1) and
4447 ((P
[1] = '1') or (P
[1] = '0')) then
4448 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4450 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4452 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4454 if (Length(P
) > 1) and
4455 ((P
[1] = '1') or (P
[1] = '0')) then
4456 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4458 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4460 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4462 if Length(P
) > 1 then
4464 '0': g_debug_BotAIOff
:= 0;
4465 '1': g_debug_BotAIOff
:= 1;
4466 '2': g_debug_BotAIOff
:= 2;
4467 '3': g_debug_BotAIOff
:= 3;
4470 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4472 else if cmd
= 'd_monster' then
4474 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4475 if Length(P
) < 2 then
4477 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4478 g_Console_Add('ID | Name');
4479 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4480 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4481 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4484 a
:= StrToIntDef(P
[1], 0);
4485 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4486 a
:= g_Mons_TypeIdByName(P
[1]);
4488 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4489 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4492 with gPlayer1
.Obj
do
4494 mon
:= g_Monsters_Create(a
,
4495 X
+ Rect
.X
+ (Rect
.Width
div 2),
4496 Y
+ Rect
.Y
+ Rect
.Height
,
4497 gPlayer1
.Direction
, True);
4499 if (Length(P
) > 2) and (mon
<> nil) then
4501 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4502 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4503 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4504 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4505 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4506 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4507 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4508 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4509 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4514 else if (cmd
= 'd_health') then
4516 if (Length(P
) > 1) and
4517 ((P
[1] = '1') or (P
[1] = '0')) then
4518 g_debug_HealthBar
:= (P
[1][1] = '1');
4520 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4522 else if (cmd
= 'd_player') then
4524 if (Length(P
) > 1) and
4525 ((P
[1] = '1') or (P
[1] = '0')) then
4526 g_debug_Player
:= (P
[1][1] = '1');
4528 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4530 else if (cmd
= 'd_mem') then
4536 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4540 procedure GameCheats(P
: SSArray
);
4546 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4548 g_Console_Add('not available');
4554 g_Console_Add('where is the player?!');
4557 cmd
:= LowerCase(P
[0]);
4561 plr
.GodMode
:= not plr
.GodMode
;
4562 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4565 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4566 if cmd
= 'give' then
4568 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4569 for f
:= 1 to High(P
) do
4571 cmd
:= LowerCase(P
[f
]);
4572 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4573 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4574 if cmd
= 'exit' then
4576 if gTriggers
<> nil then
4578 for a
:= 0 to High(gTriggers
) do
4580 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4582 g_Console_Add('player left the map');
4583 gExitByTrigger
:= True;
4584 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4585 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4593 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4594 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4595 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4596 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4597 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4599 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4600 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4602 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4603 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;
4605 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4606 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4608 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4609 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4611 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4612 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4614 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4615 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4616 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4618 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4619 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4620 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4621 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;
4622 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4623 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4625 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;
4626 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;
4627 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;
4628 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;
4629 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;
4630 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;
4632 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4633 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;
4635 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;
4636 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;
4638 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4640 if cmd
= 'ammo' then
4642 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4643 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4644 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4645 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4646 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4647 g_Console_Add('player got some ammo');
4651 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4652 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4654 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4655 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4657 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4658 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4660 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4661 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4663 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4665 if cmd
= 'weapons' then
4667 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4668 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4669 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4670 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4671 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4672 plr
.GiveItem(ITEM_WEAPON_BFG
);
4673 g_Console_Add('player got weapons');
4677 if cmd
= 'keys' then
4679 plr
.GiveItem(ITEM_KEY_RED
);
4680 plr
.GiveItem(ITEM_KEY_GREEN
);
4681 plr
.GiveItem(ITEM_KEY_BLUE
);
4682 g_Console_Add('player got all keys');
4686 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4691 if cmd
= 'open' then
4693 g_Console_Add('player activated sesame');
4694 g_Triggers_OpenAll();
4701 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4705 if cmd
= 'noclip' then
4708 g_Console_Add('wall hardeness adjusted');
4712 if cmd
= 'notarget' then
4714 plr
.NoTarget
:= not plr
.NoTarget
;
4715 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4719 if cmd
= 'noreload' then
4721 plr
.NoReload
:= not plr
.NoReload
;
4722 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4726 if cmd
= 'speedy' then
4728 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4729 g_Console_Add('speed adjusted');
4733 if cmd
= 'jumpy' then
4735 VEL_JUMP
:= 30-VEL_JUMP
;
4736 g_Console_Add('jump height adjusted');
4740 if cmd
= 'automap' then
4742 gShowMap
:= not gShowMap
;
4743 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4747 if cmd
= 'aimline' then
4749 gAimLine
:= not gAimLine
;
4750 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4755 procedure GameCommands(P
: SSArray
);
4761 pl
: pTNetClient
= nil;
4769 cmd
:= LowerCase(P
[0]);
4771 if cmd
= 'pause' then
4773 if (g_ActiveWindow
= nil) then
4774 g_Game_Pause(not gPauseMain
);
4776 else if cmd
= 'endgame' then
4777 gExit
:= EXIT_SIMPLE
4778 else if cmd
= 'restart' then
4780 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4782 if g_Game_IsClient
then
4784 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4789 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4791 else if cmd
= 'kick' then
4793 if g_Game_IsServer
then
4795 if Length(P
) < 2 then
4797 g_Console_Add('kick <name>');
4802 g_Console_Add('kick <name>');
4806 if g_Game_IsNet
then
4807 pl
:= g_Net_Client_ByName(P
[1]);
4810 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4811 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4812 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4813 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4814 g_Net_Slist_ServerPlayerLeaves();
4815 end else if gPlayers
<> nil then
4816 for a
:= Low(gPlayers
) to High(gPlayers
) do
4817 if gPlayers
[a
] <> nil then
4818 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4820 // Не отключать основных игроков в сингле
4821 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4823 gPlayers
[a
].Lives
:= 0;
4824 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4825 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4826 g_Player_Remove(gPlayers
[a
].UID
);
4827 g_Net_Slist_ServerPlayerLeaves();
4828 // Если не перемешать, при добавлении новых ботов появятся старые
4832 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4834 else if cmd
= 'kick_id' then
4836 if g_Game_IsServer
and g_Game_IsNet
then
4838 if Length(P
) < 2 then
4840 g_Console_Add('kick_id <client ID>');
4845 g_Console_Add('kick_id <client ID>');
4849 a
:= StrToIntDef(P
[1], 0);
4850 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4852 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4854 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4855 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
4856 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4857 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4858 g_Net_Slist_ServerPlayerLeaves();
4862 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4864 else if cmd
= 'kick_pid' then
4866 if g_Game_IsServer
and g_Game_IsNet
then
4868 if Length(P
) < 2 then
4870 g_Console_Add('kick_pid <player ID>');
4875 g_Console_Add('kick_pid <player ID>');
4879 a
:= StrToIntDef(P
[1], 0);
4880 pl
:= g_Net_Client_ByPlayer(a
);
4881 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4883 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4884 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
4885 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4886 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4887 g_Net_Slist_ServerPlayerLeaves();
4890 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4892 else if cmd
= 'ban' then
4894 if g_Game_IsServer
and g_Game_IsNet
then
4896 if Length(P
) < 2 then
4898 g_Console_Add('ban <name>');
4903 g_Console_Add('ban <name>');
4907 pl
:= g_Net_Client_ByName(P
[1]);
4910 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4911 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4912 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4913 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4914 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4915 g_Net_Slist_ServerPlayerLeaves();
4917 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4919 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4921 else if cmd
= 'ban_id' then
4923 if g_Game_IsServer
and g_Game_IsNet
then
4925 if Length(P
) < 2 then
4927 g_Console_Add('ban_id <client ID>');
4932 g_Console_Add('ban_id <client ID>');
4936 a
:= StrToIntDef(P
[1], 0);
4937 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4938 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4940 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4941 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
4942 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
4943 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4944 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4945 g_Net_Slist_ServerPlayerLeaves();
4948 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4950 else if cmd
= 'ban_pid' then
4952 if g_Game_IsServer
and g_Game_IsNet
then
4954 if Length(P
) < 2 then
4956 g_Console_Add('ban_pid <player ID>');
4961 g_Console_Add('ban_pid <player ID>');
4965 a
:= StrToIntDef(P
[1], 0);
4966 pl
:= g_Net_Client_ByPlayer(a
);
4967 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4969 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4970 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4971 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
4972 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4973 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4974 g_Net_Slist_ServerPlayerLeaves();
4977 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4979 else if cmd
= 'permban' then
4981 if g_Game_IsServer
and g_Game_IsNet
then
4983 if Length(P
) < 2 then
4985 g_Console_Add('permban <name>');
4990 g_Console_Add('permban <name>');
4994 pl
:= g_Net_Client_ByName(P
[1]);
4997 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4998 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4999 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5000 g_Net_SaveBanList();
5001 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5002 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5003 g_Net_Slist_ServerPlayerLeaves();
5005 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5007 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5009 else if cmd
= 'permban_id' then
5011 if g_Game_IsServer
and g_Game_IsNet
then
5013 if Length(P
) < 2 then
5015 g_Console_Add('permban_id <client ID>');
5020 g_Console_Add('permban_id <client ID>');
5024 a
:= StrToIntDef(P
[1], 0);
5025 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5026 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5028 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5029 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5030 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5031 g_Net_SaveBanList();
5032 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5033 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5034 g_Net_Slist_ServerPlayerLeaves();
5037 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5039 else if cmd
= 'permban_pid' then
5041 if g_Game_IsServer
and g_Game_IsNet
then
5043 if Length(P
) < 2 then
5045 g_Console_Add('permban_pid <player ID>');
5050 g_Console_Add('permban_pid <player ID>');
5054 a
:= StrToIntDef(P
[1], 0);
5055 pl
:= g_Net_Client_ByPlayer(a
);
5056 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5058 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5059 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5060 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5061 g_Net_SaveBanList();
5062 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5063 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5064 g_Net_Slist_ServerPlayerLeaves();
5067 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5069 else if cmd
= 'permban_ip' then
5071 if g_Game_IsServer
and g_Game_IsNet
then
5073 if Length(P
) < 2 then
5075 g_Console_Add('permban_ip <IP address>');
5080 g_Console_Add('permban_ip <IP address>');
5084 g_Net_BanHost(P
[1]);
5085 g_Net_SaveBanList();
5086 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5088 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5090 else if cmd
= 'unban' then
5092 if g_Game_IsServer
and g_Game_IsNet
then
5094 if Length(P
) < 2 then
5096 g_Console_Add('unban <IP Address>');
5101 g_Console_Add('unban <IP Address>');
5105 if g_Net_UnbanHost(P
[1]) then
5107 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5108 g_Net_SaveBanList();
5110 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5112 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5114 else if cmd
= 'clientlist' then
5116 if g_Game_IsServer
and g_Game_IsNet
then
5119 if NetClients
<> nil then
5120 for a
:= Low(NetClients
) to High(NetClients
) do
5121 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5123 plr
:= g_Player_Get(NetClients
[a
].Player
);
5124 if plr
= nil then continue
;
5126 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5127 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5130 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5132 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5134 else if cmd
= 'connect' then
5136 if (NetMode
= NET_NONE
) then
5138 if Length(P
) < 2 then
5140 g_Console_Add('connect <IP> [port] [password]');
5145 g_Console_Add('connect <IP> [port] [password]');
5149 if Length(P
) > 2 then
5150 prt
:= StrToIntDef(P
[2], 25666)
5154 if Length(P
) > 3 then
5159 g_Game_StartClient(P
[1], prt
, pw
);
5162 else if cmd
= 'disconnect' then
5164 if (NetMode
= NET_CLIENT
) then
5167 else if cmd
= 'reconnect' then
5169 if (NetMode
= NET_SERVER
) then
5172 if (NetMode
= NET_CLIENT
) then
5175 gExit
:= EXIT_SIMPLE
;
5179 //TODO: Use last successful password to reconnect, instead of ''
5180 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5182 else if (cmd
= 'addbot') or
5183 (cmd
= 'bot_add') then
5185 if Length(P
) > 2 then
5186 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5187 else if Length(P
) > 1 then
5188 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5190 g_Bot_Add(TEAM_NONE
, 2);
5192 else if cmd
= 'bot_addlist' then
5194 if Length(P
) > 1 then
5196 if Length(P
) = 2 then
5197 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5198 else if Length(P
) = 3 then
5199 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5201 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5204 else if cmd
= 'bot_removeall' then
5206 else if cmd
= 'chat' then
5208 if g_Game_IsNet
then
5210 if Length(P
) > 1 then
5212 for a
:= 1 to High(P
) do
5213 chstr
:= chstr
+ P
[a
] + ' ';
5215 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5217 if Length(chstr
) < 1 then
5219 g_Console_Add('chat <text>');
5223 chstr
:= b_Text_Format(chstr
);
5224 if g_Game_IsClient
then
5225 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5227 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5230 g_Console_Add('chat <text>');
5232 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5234 else if cmd
= 'teamchat' then
5236 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5238 if Length(P
) > 1 then
5240 for a
:= 1 to High(P
) do
5241 chstr
:= chstr
+ P
[a
] + ' ';
5243 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5245 if Length(chstr
) < 1 then
5247 g_Console_Add('teamchat <text>');
5251 chstr
:= b_Text_Format(chstr
);
5252 if g_Game_IsClient
then
5253 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5255 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5256 gPlayer1Settings
.Team
);
5259 g_Console_Add('teamchat <text>');
5261 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5263 else if cmd
= 'game' then
5265 if gGameSettings
.GameType
<> GT_NONE
then
5267 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5270 if Length(P
) = 1 then
5272 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5275 // game not started yet, load fist map from some wad
5277 s
:= addWadExtension(P
[1]);
5278 found
:= e_FindResource(AllMapDirs
, s
);
5282 P
[1] := ExpandFileName(P
[1]);
5283 // if map not choosed then set first map
5284 if Length(P
) < 3 then
5287 P
[2] := g_Game_GetFirstMap(P
[1]);
5290 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5292 if g_Map_Exist(s
) then
5296 with gGameSettings
do
5298 Options
:= gsGameFlags
;
5299 GameMode
:= g_Game_TextToMode(gsGameMode
);
5300 if gSwitchGameMode
<> GM_NONE
then
5301 GameMode
:= gSwitchGameMode
;
5302 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5303 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5305 if Length(P
) >= 4 then
5306 b
:= StrToIntDef(P
[3], 1);
5307 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5308 GoalLimit
, MaxLives
, Options
, b
);
5313 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5315 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5317 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5319 else if cmd
= 'host' then
5321 if gGameSettings
.GameType
<> GT_NONE
then
5323 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5326 if Length(P
) < 4 then
5328 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5331 if not StrToIp(P
[1], listen
) then
5333 prt
:= StrToIntDef(P
[2], 25666);
5335 s
:= addWadExtension(P
[3]);
5336 found
:= e_FindResource(AllMapDirs
, s
);
5340 // get first map in wad, if not specified
5341 if Length(P
) < 5 then
5344 P
[4] := g_Game_GetFirstMap(P
[1]);
5346 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5347 if g_Map_Exist(s
) then
5351 with gGameSettings
do
5353 Options
:= gsGameFlags
;
5354 GameMode
:= g_Game_TextToMode(gsGameMode
);
5355 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5356 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5357 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5359 if Length(P
) >= 6 then
5360 b
:= StrToIntDef(P
[5], 0);
5361 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
5367 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5369 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5374 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5377 else if cmd
= 'map' then
5379 if Length(P
) = 1 then
5381 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5383 g_Console_Add(cmd
+ ' <MAP>');
5384 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5388 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5393 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5395 if Length(P
) < 3 then
5397 // first param is map or wad
5398 s
:= UpperCase(P
[1]);
5399 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5401 gExitByTrigger
:= False;
5404 // already in game, finish current map
5406 gExit
:= EXIT_ENDLEVELCUSTOM
;
5410 // intermission, so change map immediately
5417 found
:= e_FindResource(AllMapDirs
, s
);
5419 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5422 // no such map, found wad
5425 P
[1] := ExpandFileName(pw
);
5426 P
[2] := g_Game_GetFirstMap(P
[1]);
5427 s
:= P
[1] + ':\' + P
[2];
5428 if g_Map_Exist(s
) then
5430 gExitByTrigger
:= False;
5433 // already in game, finish current map
5435 gExit
:= EXIT_ENDLEVELCUSTOM
5439 // intermission, so change map immediately
5446 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5448 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5453 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5459 s
:= addWadExtension(P
[1]);
5460 found
:= e_FindResource(AllMapDirs
, s
);
5464 P
[2] := UpperCase(P
[2]);
5465 s
:= P
[1] + ':\' + P
[2];
5466 if g_Map_Exist(s
) then
5468 gExitByTrigger
:= False;
5472 gExit
:= EXIT_ENDLEVELCUSTOM
5481 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5486 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5492 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5496 else if cmd
= 'nextmap' then
5498 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5500 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5505 if Length(P
) = 1 then
5507 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5509 g_Console_Add(cmd
+ ' <MAP>');
5510 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5515 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5521 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5523 if Length(P
) < 3 then
5525 // first param is map or wad
5526 s
:= UpperCase(P
[1]);
5527 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5530 gExitByTrigger
:= False;
5536 // no such map, found wad
5537 pw
:= addWadExtension(P
[1]);
5538 found
:= e_FindResource(MapDirs
, pw
);
5540 found
:= e_FindResource(WadDirs
, pw
);
5542 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5545 // map not specified, select first map
5547 P
[2] := g_Game_GetFirstMap(P
[1]);
5548 s
:= P
[1] + ':\' + P
[2];
5549 if g_Map_Exist(s
) then
5551 gExitByTrigger
:= False;
5558 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5560 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5565 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5571 // specified two params wad + map
5572 pw
:= addWadExtension(P
[1]);
5573 found
:= e_FindResource(MapDirs
, pw
);
5575 found
:= e_FindResource(MapDirs
, pw
);
5579 P
[2] := UpperCase(P
[2]);
5580 s
:= P
[1] + ':\' + P
[2];
5581 if g_Map_Exist(s
) then
5583 gExitByTrigger
:= False;
5589 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5594 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5600 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5605 if gNextMap
= '' then
5606 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5608 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5612 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5616 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5620 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5622 gExitByTrigger
:= False;
5623 // next map not specified, try to find trigger EXIT
5624 if (gNextMap
= '') and (gTriggers
<> nil) then
5626 for a
:= 0 to High(gTriggers
) do
5628 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5630 gExitByTrigger
:= True;
5631 //gNextMap := gTriggers[a].Data.MapName;
5632 gNextMap
:= gTriggers
[a
].tgcMap
;
5637 if gNextMap
= '' then
5638 gNextMap
:= g_Game_GetNextMap();
5639 if not isWadPath(gNextMap
) then
5640 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5643 if g_Map_Exist(s
) then
5644 gExit
:= EXIT_ENDLEVELCUSTOM
5646 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5650 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5654 else if (cmd
= 'event') then
5656 if (Length(P
) <= 1) then
5658 for a
:= 0 to High(gEvents
) do
5659 if gEvents
[a
].Command
= '' then
5660 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5662 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5665 if (Length(P
) = 2) then
5667 for a
:= 0 to High(gEvents
) do
5668 if gEvents
[a
].Name
= P
[1] then
5669 if gEvents
[a
].Command
= '' then
5670 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5672 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5675 for a
:= 0 to High(gEvents
) do
5676 if gEvents
[a
].Name
= P
[1] then
5678 gEvents
[a
].Command
:= '';
5679 for b
:= 2 to High(P
) do
5680 if Pos(' ', P
[b
]) = 0 then
5681 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5683 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5684 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5688 else if cmd
= 'suicide' then
5692 if g_Game_IsClient
then
5693 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5696 if gPlayer1
<> nil then
5697 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5698 if gPlayer2
<> nil then
5699 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5703 else if cmd
= 'screenshot' then
5707 else if cmd
= 'weapon' then
5709 if Length(p
) = 2 then
5711 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
5712 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5713 gSelectWeapon
[0, a
] := True
5716 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5718 if Length(p
) = 2 then
5720 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
5721 b
:= ord(cmd
[2]) - ord('1');
5722 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5723 gSelectWeapon
[b
, a
] := True
5726 // Команды Своей игры:
5727 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5729 if cmd
= 'bot_addred' then
5731 if Length(P
) > 1 then
5732 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5734 g_Bot_Add(TEAM_RED
, 2);
5736 else if cmd
= 'bot_addblue' then
5738 if Length(P
) > 1 then
5739 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5741 g_Bot_Add(TEAM_BLUE
, 2);
5743 else if cmd
= 'spectate' then
5749 else if cmd
= 'say' then
5751 if g_Game_IsServer
and g_Game_IsNet
then
5753 if Length(P
) > 1 then
5756 for a
:= 1 to High(P
) do
5757 chstr
:= chstr
+ P
[a
] + ' ';
5759 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5761 if Length(chstr
) < 1 then
5763 g_Console_Add('say <text>');
5767 chstr
:= b_Text_Format(chstr
);
5768 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5770 else g_Console_Add('say <text>');
5772 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5774 else if cmd
= 'tell' then
5776 if g_Game_IsServer
and g_Game_IsNet
then
5778 if (Length(P
) > 2) and (P
[1] <> '') then
5781 for a
:= 2 to High(P
) do
5782 chstr
:= chstr
+ P
[a
] + ' ';
5784 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5786 if Length(chstr
) < 1 then
5788 g_Console_Add('tell <playername> <text>');
5792 pl
:= g_Net_Client_ByName(P
[1]);
5794 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5796 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5798 else g_Console_Add('tell <playername> <text>');
5800 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5802 else if cmd
= 'centerprint' then
5804 if (Length(P
) > 2) and (P
[1] <> '') then
5807 for a
:= 2 to High(P
) do
5808 chstr
:= chstr
+ P
[a
] + ' ';
5810 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5812 if Length(chstr
) < 1 then
5814 g_Console_Add('centerprint <timeout> <text>');
5818 a
:= StrToIntDef(P
[1], 100);
5819 chstr
:= b_Text_Format(chstr
);
5820 g_Game_Message(chstr
, a
);
5821 if g_Game_IsNet
and g_Game_IsServer
then
5822 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
5824 else g_Console_Add('centerprint <timeout> <text>');
5826 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5828 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5830 // Дополнительное время:
5831 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5833 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5834 [gGameSettings
.TimeLimit
div 3600,
5835 (gGameSettings
.TimeLimit
div 60) mod 60,
5836 gGameSettings
.TimeLimit
mod 60]));
5837 if g_Game_IsNet
then MH_SEND_GameSettings
;
5839 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5841 if (Length(P
) <= 1) then
5842 g_Console_Add('rcon_password <password>')
5844 MC_SEND_RCONPassword(P
[1]);
5846 else if cmd
= 'rcon' then
5848 if g_Game_IsClient
then
5850 if Length(P
) > 1 then
5853 for a
:= 1 to High(P
) do
5854 chstr
:= chstr
+ P
[a
] + ' ';
5856 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5858 if Length(chstr
) < 1 then
5860 g_Console_Add('rcon <command>');
5864 MC_SEND_RCONCommand(chstr
);
5866 else g_Console_Add('rcon <command>');
5869 else if cmd
= 'ready' then
5871 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5872 gLMSRespawnTime
:= gTime
+ 100;
5874 else if (cmd
= 'callvote') and g_Game_IsNet
then
5876 if Length(P
) > 1 then
5879 for a
:= 1 to High(P
) do begin
5880 if a
> 1 then chstr
:= chstr
+ ' ';
5881 chstr
:= chstr
+ P
[a
];
5884 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5886 if Length(chstr
) < 1 then
5888 g_Console_Add('callvote <command>');
5892 if g_Game_IsClient
then
5893 MC_SEND_Vote(True, chstr
)
5895 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5896 g_Console_Process('vote', True);
5899 g_Console_Add('callvote <command>');
5901 else if (cmd
= 'vote') and g_Game_IsNet
then
5903 if g_Game_IsClient
then
5905 else if gVoteInProgress
then
5907 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5908 a
:= Floor((NetClientCount
+1)/2.0) + 1
5910 a
:= Floor(NetClientCount
/2.0) + 1;
5915 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5916 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5922 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5923 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5931 procedure SystemCommands(P
: SSArray
);
5935 cmd
:= LowerCase(P
[0]);
5944 gRC_Width
:= Max(1, gRC_Width
);
5945 gRC_Height
:= Max(1, gRC_Height
);
5946 gBPP
:= Max(1, gBPP
);
5947 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
5948 e_LogWriteln('resolution changed')
5950 e_LogWriteln('resolution not changed');
5951 sys_EnableVSync(gVSync
);
5955 if Length(p
) = 2 then
5957 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
5959 gFrameTime
:= 1000 div gMaxFPS
5963 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
5967 if Length(p
) = 2 then
5969 gAskLanguage
:= true;
5970 gLanguage
:= LANGUAGE_ENGLISH
;
5971 case LowerCase(p
[1]) of
5974 gAskLanguage
:= false;
5975 gLanguage
:= LANGUAGE_ENGLISH
;
5979 gAskLanguage
:= false;
5980 gLanguage
:= LANGUAGE_RUSSIAN
;
5984 gAskLanguage
:= true;
5985 gLanguage
:= LANGUAGE_ENGLISH
;
5988 g_Language_Set(gLanguage
);
5992 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
5998 procedure g_TakeScreenShot(Filename
: string = '');
5999 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
6001 if e_NoGraphics
then Exit
;
6003 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6005 if Filename
= '' then
6008 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6009 Filename
:= 'screenshot-' + date
;
6012 name
:= e_CatPath(dir
, Filename
+ '.png');
6013 s
:= createDiskFile(name
);
6015 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
6017 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6019 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6024 g_Console_Add('oh shit, i can''t create screenshot!')
6028 procedure g_Game_InGameMenu(Show
: Boolean);
6030 if (g_ActiveWindow
= nil) and Show
then
6032 if gGameSettings
.GameType
= GT_SINGLE
then
6033 g_GUI_ShowWindow('GameSingleMenu')
6036 if g_Game_IsClient
then
6037 g_GUI_ShowWindow('GameClientMenu')
6039 if g_Game_IsNet
then
6040 g_GUI_ShowWindow('GameServerMenu')
6042 g_GUI_ShowWindow('GameCustomMenu');
6044 g_Sound_PlayEx('MENU_OPEN');
6046 // Пауза при меню только в одиночной игре:
6047 if (not g_Game_IsNet
) then
6051 if (g_ActiveWindow
<> nil) and (not Show
) then
6053 // Пауза при меню только в одиночной игре:
6054 if (not g_Game_IsNet
) then
6055 g_Game_Pause(False);
6059 procedure g_Game_Pause (Enable
: Boolean);
6063 if not gGameOn
then exit
;
6065 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6068 gPauseMain
:= Enable
;
6070 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6073 procedure g_Game_HolmesPause (Enable
: Boolean);
6077 if not gGameOn
then exit
;
6078 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6081 gPauseHolmes
:= Enable
;
6083 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6086 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6091 if gTriggers
<> nil then
6092 for i
:= 0 to High(gTriggers
) do
6093 with gTriggers
[i
] do
6094 if (TriggerType
= TRIGGER_SOUND
) and
6096 Sound
.IsPlaying() then
6098 Sound
.Pause(Enable
);
6102 if gPlayers
<> nil then
6103 for i
:= 0 to High(gPlayers
) do
6104 if gPlayers
[i
] <> nil then
6105 gPlayers
[i
].PauseSounds(Enable
);
6108 if gMusic
<> nil then
6109 gMusic
.Pause(Enable
);
6112 procedure g_Game_StopAllSounds(all
: Boolean);
6116 if gTriggers
<> nil then
6117 for i
:= 0 to High(gTriggers
) do
6118 with gTriggers
[i
] do
6119 if (TriggerType
= TRIGGER_SOUND
) and
6123 if gMusic
<> nil then
6130 procedure g_Game_UpdateTriggerSounds
;
6133 if gTriggers
<> nil then
6134 for i
:= 0 to High(gTriggers
) do
6135 with gTriggers
[i
] do
6136 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6137 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6140 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6143 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6148 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6153 if gSpectMode
<> SPECT_PLAYERS
then
6155 if gSpectPID1
= UID
then
6160 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6167 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6172 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6177 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6182 if gSpectMode
<> SPECT_PLAYERS
then
6184 Pl
:= g_Player_Get(gSpectPID1
);
6185 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6190 if gSpectViewTwo
then
6192 Pl
:= g_Player_Get(gSpectPID2
);
6193 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6201 procedure g_Game_Message(Msg
: string; Time
: Word);
6203 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
6204 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
6205 MessageTime
:= Time
;
6208 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6210 punct
: Array[0..13] of String =
6211 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6217 function IsPunctuation(S
: String): Boolean;
6222 if Length(S
) <> 1 then
6224 for i
:= Low(punct
) to High(punct
) do
6225 if S
= punct
[i
] then
6231 function FilterPunctuation(S
: String): String;
6235 for i
:= Low(punct
) to High(punct
) do
6236 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6242 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6244 // remove player name
6245 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6246 // for FullWord check
6247 Text := toLowerCase1251(' ' + Text + ' ');
6248 fpText
:= FilterPunctuation(Text);
6250 for i
:= 0 to Length(gChatSounds
) - 1 do
6253 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6255 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6256 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6258 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6264 gChatSounds
[i
].Sound
.Play();
6270 g_Sound_PlayEx('SOUND_GAME_RADIO');
6273 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6282 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6286 if goodsnd
[a
].IsPlaying() then
6289 goodsnd
[Random(4)].Play();
6292 procedure g_Game_Announce_KillCombo(Param
: Integer);
6299 UID
:= Param
and $FFFF;
6304 Pl
:= g_Player_Get(UID
);
6313 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6317 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6321 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6325 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6333 if not g_Game_IsWatchedPlayer(UID
) then
6336 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6340 if killsnd
[n
].IsPlaying() then
6345 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6353 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6357 if hahasnd
[a
].IsPlaying() then
6360 hahasnd
[Random(3)].Play();
6363 procedure g_Game_StartVote(Command
, Initiator
: string);
6367 if not gVotesEnabled
then Exit
;
6368 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6369 if gVoteInProgress
or gVotePassed
then
6371 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6372 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6375 gVoteInProgress
:= True;
6376 gVotePassed
:= False;
6377 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6380 gVoteCommand
:= Command
;
6382 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6383 Need
:= Floor((NetClientCount
+1)/2.0)+1
6385 Need
:= Floor(NetClientCount
/2.0)+1;
6386 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6387 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6390 procedure g_Game_CheckVote
;
6394 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6395 if not gVoteInProgress
then Exit
;
6397 if (gTime
>= gVoteTimer
) then
6399 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6400 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6402 Need
:= Floor(NetClientCount
/2.0) + 1;
6403 if gVoteCount
>= Need
then
6405 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6406 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6407 gVotePassed
:= True;
6408 gVoteCmdTimer
:= gTime
+ 5000;
6412 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6413 MH_SEND_VoteEvent(NET_VE_FAILED
);
6415 if NetClients
<> nil then
6416 for I
:= Low(NetClients
) to High(NetClients
) do
6417 if NetClients
[i
].Used
then
6418 NetClients
[i
].Voted
:= False;
6419 gVoteInProgress
:= False;
6425 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6426 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6428 Need
:= Floor(NetClientCount
/2.0) + 1;
6429 if gVoteCount
>= Need
then
6431 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6432 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6433 gVoteInProgress
:= False;
6434 gVotePassed
:= True;
6435 gVoteCmdTimer
:= gTime
+ 5000;
6438 if NetClients
<> nil then
6439 for I
:= Low(NetClients
) to High(NetClients
) do
6440 if NetClients
[i
].Used
then
6441 NetClients
[i
].Voted
:= False;
6446 procedure g_Game_LoadMapList(FileName
: string);
6454 if not FileExists(FileName
) then Exit
;
6456 AssignFile(ListFile
, FileName
);
6458 while not EOF(ListFile
) do
6460 ReadLn(ListFile
, s
);
6463 if s
= '' then Continue
;
6465 SetLength(MapList
, Length(MapList
)+1);
6466 MapList
[High(MapList
)] := s
;
6468 CloseFile(ListFile
);
6471 procedure g_Game_SetDebugMode();
6474 // Читы (даже в своей игре):
6478 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6482 if Length(LoadingStat
.Msgs
) = 0 then
6488 begin // Переходим на следующую строку или скроллируем:
6489 if NextMsg
= Length(Msgs
) then
6491 for i
:= 0 to High(Msgs
)-1 do
6492 Msgs
[i
] := Msgs
[i
+1];
6500 Msgs
[NextMsg
-1] := Text;
6504 PBarWasHere
:= false;
6507 g_ActiveWindow
:= nil;
6509 ProcessLoading(true);
6512 procedure g_Game_StepLoading(Value
: Integer = -1);
6523 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6531 procedure g_Game_ClearLoading();
6540 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6541 if len
< 1 then len
:= 1;
6542 SetLength(Msgs
, len
);
6543 for len
:= Low(Msgs
) to High(Msgs
) do
6546 PBarWasHere
:= false;
6550 procedure Parse_Params(var pars
: TParamStrValues
);
6557 while i
<= ParamCount
do
6560 if (s
[1] = '-') and (Length(s
) > 1) then
6562 if (s
[2] = '-') and (Length(s
) > 2) then
6563 begin // Одиночный параметр
6564 SetLength(pars
, Length(pars
) + 1);
6565 with pars
[High(pars
)] do
6567 Name
:= LowerCase(s
);
6572 if (i
< ParamCount
) then
6573 begin // Параметр со значением
6575 SetLength(pars
, Length(pars
) + 1);
6576 with pars
[High(pars
)] do
6578 Name
:= LowerCase(s
);
6579 Value
:= LowerCase(ParamStr(i
));
6588 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6593 for i
:= 0 to High(pars
) do
6594 if pars
[i
].Name
= aName
then
6596 Result
:= pars
[i
].Value
;
6601 procedure g_Game_Process_Params();
6603 pars
: TParamStrValues
;
6606 LimT
, LimS
: Integer;
6617 s
:= Find_Param_Value(pars
, '--debug');
6620 g_Game_SetDebugMode();
6621 s
:= Find_Param_Value(pars
, '--netdump');
6626 // Connect when game loads
6627 ip
:= Find_Param_Value(pars
, '-connect');
6631 s
:= Find_Param_Value(pars
, '-port');
6632 if (s
= '') or not TryStrToInt(s
, Port
) then
6635 s
:= Find_Param_Value(pars
, '-pw');
6637 g_Game_StartClient(ip
, Port
, s
);
6641 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6644 gDefaultMegawadStart
:= s
;
6647 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6648 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6650 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6653 // Start map when game loads:
6654 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6655 if isWadPath(map
) then
6658 s
:= Find_Param_Value(pars
, '-gm');
6659 GMode
:= g_Game_TextToMode(s
);
6660 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6661 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6664 s
:= Find_Param_Value(pars
, '-limt');
6665 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6671 s
:= Find_Param_Value(pars
, '-lims');
6672 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6678 s
:= Find_Param_Value(pars
, '-lives');
6679 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6685 s
:= Find_Param_Value(pars
, '-opt');
6689 Opt
:= StrToIntDef(s
, 0);
6692 s
:= Find_Param_Value(pars
, '--close');
6696 // Override map to test:
6697 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6700 if e_IsValidResourceName(s
) then
6701 e_FindResource(AllMapDirs
, s
);
6702 gTestMap
:= ExpandFileName(s
);
6705 // Delete test map after play:
6706 s
:= Find_Param_Value(pars
, '--testdelete');
6709 //gMapToDelete := MapsDir + map;
6710 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6714 // Delete temporary WAD after play:
6715 s
:= Find_Param_Value(pars
, '--tempdelete');
6716 if (s
<> '') and (gTestMap
<> '') then
6718 gMapToDelete
:= gTestMap
;
6719 gTempDelete
:= True;
6722 // Number of players:
6723 s
:= Find_Param_Value(pars
, '-pl');
6725 n
:= DEFAULT_PLAYERS
6727 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6730 s
:= Find_Param_Value(pars
, '-port');
6731 if (s
= '') or not TryStrToInt(s
, Port
) then
6732 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6734 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6737 // Execute script when game loads:
6738 s
:= Find_Param_Value(pars
, '-exec');
6741 // if not isWadPath(s) then
6742 // s := GameDir + '/' + s;
6747 if IOResult
<> 0 then
6749 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6750 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6754 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6755 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6760 if IOResult
<> 0 then
6762 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6763 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6767 if Pos('#', s
) <> 1 then // script comment
6768 g_Console_Process(s
, True);
6779 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6780 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6781 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6782 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6784 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6785 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6786 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6787 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6789 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6790 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6792 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6793 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6795 {$IFDEF ENABLE_HOLMES}
6796 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6799 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6801 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6802 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6804 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6805 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6807 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6808 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6809 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6810 conRegVar('r_showscore', @gShowGoals
, 'show score', 'show score');
6811 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6812 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6813 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6814 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6815 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');