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
65 // ones below are sent only to the server
67 WeaponPreferences
: Array[WP_FIRST
..WP_LAST
+1] of Byte;
84 function g_Game_IsNet(): Boolean;
85 function g_Game_IsServer(): Boolean;
86 function g_Game_IsClient(): Boolean;
87 procedure g_Game_Init();
88 procedure g_Game_Free (freeTextures
: Boolean=true);
89 procedure g_Game_LoadData();
90 procedure g_Game_FreeData();
91 procedure g_Game_Update();
92 procedure g_Game_PreUpdate();
93 procedure g_Game_Quit();
94 procedure g_Game_SetupScreenSize();
95 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
96 function g_Game_ModeToText(Mode
: Byte): string;
97 function g_Game_TextToMode(Mode
: string): Byte;
98 procedure g_Game_ExecuteEvent(Name
: String);
99 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
100 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
101 procedure g_Game_RemovePlayer();
102 procedure g_Game_Spectate();
103 procedure g_Game_SpectateCenterView();
104 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
105 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
106 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
107 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
108 procedure g_Game_Restart();
109 procedure g_Game_RestartLevel();
110 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
111 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
112 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
113 procedure g_Game_ChangeMap(const MapPath
: String);
114 procedure g_Game_ExitLevel(const Map
: AnsiString);
115 function g_Game_GetFirstMap(WAD
: String): String;
116 function g_Game_GetNextMap(): String;
117 procedure g_Game_NextLevel();
118 procedure g_Game_Pause(Enable
: Boolean);
119 procedure g_Game_HolmesPause(Enable
: Boolean);
120 procedure g_Game_InGameMenu(Show
: Boolean);
121 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
122 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
123 procedure g_Game_Message(Msg
: String; Time
: Word);
124 procedure g_Game_LoadMapList(FileName
: String);
125 procedure g_Game_PauseAllSounds(Enable
: Boolean);
126 procedure g_Game_StopAllSounds(all
: Boolean);
127 procedure g_Game_UpdateTriggerSounds();
128 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
129 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
130 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
131 procedure g_Game_Announce_KillCombo(Param
: Integer);
132 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
133 procedure g_Game_StartVote(Command
, Initiator
: string);
134 procedure g_Game_CheckVote
;
135 procedure g_TakeScreenShot(Filename
: string = '');
136 procedure g_FatalError(Text: String);
137 procedure g_SimpleError(Text: String);
138 function g_Game_IsTestMap(): Boolean;
139 procedure g_Game_DeleteTestMap();
140 procedure GameCVars(P
: SSArray
);
141 procedure PlayerSettingsCVars(P
: SSArray
);
142 procedure SystemCommands(P
: SSArray
);
143 procedure GameCommands(P
: SSArray
);
144 procedure GameCheats(P
: SSArray
);
145 procedure DebugCommands(P
: SSArray
);
146 procedure g_Game_Process_Params
;
147 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
148 procedure g_Game_StepLoading(Value
: Integer = -1);
149 procedure g_Game_ClearLoading();
150 procedure g_Game_SetDebugMode();
152 function IsActivePlayer(p
: TPlayer
): Boolean;
153 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
154 procedure SortGameStat(var stat
: TPlayerStatArray
);
156 procedure KeyPress (K
: Word);
157 procedure CharPress (C
: AnsiChar);
159 { procedure SetWinPause(Enable: Boolean); }
164 LOADING_SHOW_STEP
= 100;
165 LOADING_INTERLINE
= 20;
180 MESSAGE_DIKEY
= WM_USER
+ 1;
185 EXIT_ENDLEVELSINGLE
= 4;
186 EXIT_ENDLEVELCUSTOM
= 5;
188 GAME_OPTION_RESERVED
= 1;
189 GAME_OPTION_TEAMDAMAGE
= 2;
190 GAME_OPTION_ALLOWEXIT
= 4;
191 GAME_OPTION_WEAPONSTAY
= 8;
192 GAME_OPTION_MONSTERS
= 16;
193 GAME_OPTION_BOTVSPLAYER
= 32;
194 GAME_OPTION_BOTVSMONSTER
= 64;
195 GAME_OPTION_DMKEYS
= 128;
196 GAME_OPTION_TEAMHITTRACE
= 256;
197 GAME_OPTION_TEAMHITPROJECTILE
= 512;
198 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
199 GAME_OPTION_ALLOWDROPFLAG
= 2048;
200 GAME_OPTION_THROWFLAG
= 4096;
205 STATE_INTERCUSTOM
= 3;
206 STATE_INTERSINGLE
= 4;
212 LMS_RESPAWN_NONE
= 0;
213 LMS_RESPAWN_WARMUP
= 1;
214 LMS_RESPAWN_FINAL
= 2;
231 CONFIG_FILENAME
= 'Doom2DF.cfg';
233 TEST_MAP_NAME
= '$$$_TEST_$$$';
235 STD_PLAYER_MODEL
= 'Doomer';
243 STATFILE_VERSION
= $03;
247 gGameSettings
: TGameSettings
;
248 gPlayer1Settings
: TPlayerSettings
;
249 gPlayer2Settings
: TPlayerSettings
;
251 gPlayerScreenSize
: TDFPoint
;
252 gPlayer1ScreenCoord
: TDFPoint
;
253 gPlayer2ScreenCoord
: TDFPoint
;
254 gPlayer1
: TPlayer
= nil;
255 gPlayer2
: TPlayer
= nil;
256 gPlayerDrawn
: TPlayer
= nil;
258 gLerpFactor
: Single = 1.0;
259 gSwitchGameMode
: Byte = GM_DM
;
260 gHearPoint1
, gHearPoint2
: THearPoint
;
261 gSoundEffectsDF
: Boolean = False;
262 gSoundTriggerTime
: Word = 0;
263 gAnnouncer
: Integer = ANNOUNCE_NONE
;
264 goodsnd
: array[0..3] of TPlayableSound
;
265 killsnd
: array[0..3] of TPlayableSound
;
266 hahasnd
: array[0..2] of TPlayableSound
;
267 sound_get_flag
: array[0..1] of TPlayableSound
;
268 sound_lost_flag
: array[0..1] of TPlayableSound
;
269 sound_ret_flag
: array[0..1] of TPlayableSound
;
270 sound_cap_flag
: array[0..1] of TPlayableSound
;
271 gBodyKillEvent
: Integer = -1;
272 gDefInterTime
: ShortInt = -1;
273 gInterEndTime
: LongWord = 0;
274 gInterTime
: LongWord = 0;
275 gServInterTime
: Byte = 0;
276 gGameStartTime
: LongWord = 0;
277 gTotalMonsters
: Integer = 0;
278 gPauseMain
: Boolean = false;
279 gPauseHolmes
: Boolean = false;
280 gShowTime
: Boolean = False;
281 gShowFPS
: Boolean = False;
282 gShowScore
: Boolean = True;
283 gShowStat
: Boolean = True;
284 gShowPIDs
: Boolean = False;
285 gShowKillMsg
: Boolean = True;
286 gShowLives
: Boolean = True;
287 gShowPing
: Boolean = False;
288 gShowMap
: Boolean = False;
290 gState
: Byte = STATE_NONE
;
292 sWidth
, sHeight
: Word;
293 gSpectMode
: Byte = SPECT_NONE
;
294 gSpectHUD
: Boolean = True;
295 gSpectKeyPress
: Boolean = False;
296 gSpectX
: Integer = 0;
297 gSpectY
: Integer = 0;
298 gSpectStep
: Byte = 8;
299 gSpectViewTwo
: Boolean = False;
300 gSpectPID1
: Integer = -1;
301 gSpectPID2
: Integer = -1;
302 gSpectAuto
: Boolean = False;
303 gSpectAutoNext
: LongWord;
304 gSpectAutoStepX
: Integer;
305 gSpectAutoStepY
: Integer;
306 gMusic
: TMusic
= nil;
307 gLoadGameMode
: Boolean;
308 gCheats
: Boolean = False;
309 gMapOnce
: Boolean = False;
310 gMapToDelete
: String;
311 gTempDelete
: Boolean = False;
312 gLastMap
: Boolean = False;
315 gResolutionChange
: Boolean = False;
316 gRC_Width
, gRC_Height
: Integer;
317 gRC_FullScreen
, gRC_Maximized
: Boolean;
318 gLanguageChange
: Boolean = False;
319 gDebugMode
: Boolean = False;
320 g_debug_Sounds
: Boolean = False;
321 g_debug_Frames
: Boolean = False;
322 g_debug_WinMsgs
: Boolean = False;
323 g_debug_MonsterOff
: Boolean = False;
324 g_debug_BotAIOff
: Byte = 0;
325 g_debug_HealthBar
: Boolean = False;
326 g_Debug_Player
: Boolean = False;
327 gCoopMonstersKilled
: Word = 0;
328 gCoopSecretsFound
: Word = 0;
329 gCoopTotalMonstersKilled
: Word = 0;
330 gCoopTotalSecretsFound
: Word = 0;
331 gCoopTotalMonsters
: Word = 0;
332 gCoopTotalSecrets
: Word = 0;
333 gStatsOff
: Boolean = False;
334 gStatsPressed
: Boolean = False;
335 gExitByTrigger
: Boolean = False;
336 gNextMap
: String = '';
337 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
338 gLMSRespawnTime
: Cardinal = 0;
339 gLMSSoftSpawn
: Boolean = False;
340 gMissionFailed
: Boolean = False;
341 gVoteInProgress
: Boolean = False;
342 gVotePassed
: Boolean = False;
343 gVoteCommand
: string = '';
344 gVoteTimer
: Cardinal = 0;
345 gVoteCmdTimer
: Cardinal = 0;
346 gVoteCount
: Integer = 0;
347 gVoteTimeout
: Cardinal = 30;
348 gVoted
: Boolean = False;
349 gVotesEnabled
: Boolean = True;
350 gEvents
: Array of TGameEvent
;
351 gDelayedEvents
: Array of TDelayedEvent
;
352 gUseChatSounds
: Boolean = True;
353 gChatSounds
: Array of TChatSound
;
354 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
355 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
356 gInterReadyCount
: Integer = 0;
357 gMaxBots
: Integer = 127;
359 g_dbg_ignore_bounds
: Boolean = false;
360 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
361 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
363 // move button values:
364 // bits 0-1: l/r state:
365 // 0: neither left, nor right pressed
368 // bits 4-5: l/r state when strafe was pressed
369 P1MoveButton
: Byte = 0;
370 P2MoveButton
: Byte = 0;
372 g_profile_frame_update
: Boolean = false;
373 g_profile_frame_draw
: Boolean = false;
374 g_profile_collision
: Boolean = false;
375 g_profile_los
: Boolean = false;
376 g_profile_history_size
: Integer = 1000;
378 g_rlayer_back
: Boolean = true;
379 g_rlayer_step
: Boolean = true;
380 g_rlayer_wall
: Boolean = true;
381 g_rlayer_door
: Boolean = true;
382 g_rlayer_acid1
: Boolean = true;
383 g_rlayer_acid2
: Boolean = true;
384 g_rlayer_water
: Boolean = true;
385 g_rlayer_fore
: Boolean = true;
387 wNeedTimeReset
: Boolean = false;
389 procedure g_ResetDynlights ();
390 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
391 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
393 function conIsCheatsEnabled (): Boolean; inline;
394 function gPause (): Boolean; inline;
396 type (* private state *)
397 TEndCustomGameStat
= record
398 PlayerStat
: TPlayerStatArray
;
402 Map
, MapName
: String;
405 TEndSingleGameStat
= record
406 PlayerStat
: Array [0..1] of record
412 TotalSecrets
: Integer;
415 TLoadingStat
= record
419 Msgs
: Array of String;
421 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
425 x
, y
, radius
: Integer;
428 exploRadius
: Integer;
431 var (* private state *)
432 CustomStat
: TEndCustomGameStat
;
433 StatShotDone
: Boolean;
434 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
435 SingleStat
: TEndSingleGameStat
;
437 LoadingStat
: TLoadingStat
;
440 EndingGameCounter
: Byte;
442 g_playerLight
: Boolean;
443 g_dynLights
: array of TDynLight
= nil;
444 g_dynLightCount
: Integer = 0;
449 {$IFDEF ENABLE_HOLMES}
452 e_res
, g_textures
, g_window
, g_menu
,
453 e_input
, e_log
, g_console
, r_console
, g_items
, g_map
, g_panel
,
454 g_playermodel
, g_gfx
, g_options
, Math
,
455 g_triggers
, g_monsters
, e_sound
, CONFIG
,
456 g_language
, g_net
, g_phys
,
457 ENet
, e_msg
, g_netmsg
, g_netmaster
,
458 sfs
, wadreader
, g_system
, r_playermodel
;
461 charbuff
: packed array [0..15] of AnsiChar = (
462 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
465 function Translit (const S
: AnsiString): AnsiString;
470 for i
:= 1 to Length(Result
) do
473 #
$C9: Result
[i
] := 'Q';
474 #
$D6: Result
[i
] := 'W';
475 #
$D3: Result
[i
] := 'E';
476 #
$CA: Result
[i
] := 'R';
477 #
$C5: Result
[i
] := 'T';
478 #
$CD: Result
[i
] := 'Y';
479 #
$C3: Result
[i
] := 'U';
480 #
$D8: Result
[i
] := 'I';
481 #
$D9: Result
[i
] := 'O';
482 #
$C7: Result
[i
] := 'P';
483 #
$D5: Result
[i
] := '['; //Chr(219);
484 #
$DA: Result
[i
] := ']'; //Chr(221);
485 #
$D4: Result
[i
] := 'A';
486 #
$DB: Result
[i
] := 'S';
487 #
$C2: Result
[i
] := 'D';
488 #
$C0: Result
[i
] := 'F';
489 #
$CF: Result
[i
] := 'G';
490 #
$D0: Result
[i
] := 'H';
491 #
$CE: Result
[i
] := 'J';
492 #
$CB: Result
[i
] := 'K';
493 #
$C4: Result
[i
] := 'L';
494 #
$C6: Result
[i
] := ';'; //Chr(186);
495 #
$DD: Result
[i
] := #39; //Chr(222);
496 #
$DF: Result
[i
] := 'Z';
497 #
$D7: Result
[i
] := 'X';
498 #
$D1: Result
[i
] := 'C';
499 #
$CC: Result
[i
] := 'V';
500 #
$C8: Result
[i
] := 'B';
501 #
$D2: Result
[i
] := 'N';
502 #
$DC: Result
[i
] := 'M';
503 #
$C1: Result
[i
] := ','; //Chr(188);
504 #
$DE: Result
[i
] := '.'; //Chr(190);
510 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
515 ls2
:= Translit(CheatRus
[ct
]);
516 if length(ls1
) = 0 then ls1
:= '~';
517 if length(ls2
) = 0 then ls2
:= '~';
519 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
520 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
521 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
522 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
524 if ct = I_GAME_CHEAT_JETPACK then
526 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
527 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
528 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
529 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
530 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
531 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
547 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
548 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
549 or g_Game_IsNet then Exit;
551 if not gGameOn
then exit
;
552 if not conIsCheatsEnabled
then exit
;
554 s
:= 'SOUND_GAME_RADIO';
557 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
559 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
560 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
564 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
566 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
567 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
571 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
573 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
574 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
578 if CheckCheat(I_GAME_CHEAT_DEATH
) then
580 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
581 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
582 s
:= 'SOUND_MONSTER_HAHA';
586 if CheckCheat(I_GAME_CHEAT_DOORS
) then
588 g_Triggers_OpenAll();
592 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
594 if gTriggers
<> nil then
595 for a
:= 0 to High(gTriggers
) do
596 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
598 gExitByTrigger
:= True;
599 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
600 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
606 s2
:= Copy(charbuff
, 15, 2);
607 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
609 if g_Map_Exist(gGameSettings
.WAD
+ ':\MAP' + s2
) then
617 if CheckCheat(I_GAME_CHEAT_FLY
) then
623 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
625 VEL_JUMP
:= 30-VEL_JUMP
;
629 if CheckCheat(I_GAME_CHEAT_SPEED
) then
631 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
635 if CheckCheat(I_GAME_CHEAT_SUIT
) then
637 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
638 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
642 if CheckCheat(I_GAME_CHEAT_AIR
) then
644 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
645 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
649 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
651 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
652 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
656 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
658 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
659 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
663 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
665 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
666 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
670 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
672 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
673 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
677 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
679 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
680 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
683 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
685 gAimLine
:= not gAimLine
;
688 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
690 gShowMap
:= not gShowMap
;
700 procedure KeyPress (K
: Word);
710 if (g_ActiveWindow
<> nil) then
712 Msg
.Msg
:= WM_KEYDOWN
;
713 Msg
.WParam
:= VK_ESCAPE
;
714 g_ActiveWindow
.OnMessage(Msg
);
715 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
717 else if (gState
<> STATE_FOLD
) then
719 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
721 g_Game_InGameMenu(True);
723 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
725 if (gState
<> STATE_MENU
) then
727 if (NetMode
<> NET_NONE
) then
729 g_Game_StopAllSounds(True);
731 gState
:= STATE_MENU
;
735 g_GUI_ShowWindow('MainMenu');
736 g_Sound_PlayEx('MENU_OPEN');
741 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
742 begin // <F2> .. <F6> � <F12>
743 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
745 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
746 if (not g_Game_IsNet
) then g_Game_Pause(True);
748 IK_F2
: g_Menu_Show_SaveMenu();
749 IK_F3
: g_Menu_Show_LoadMenu();
750 IK_F4
: g_Menu_Show_GameSetGame();
751 IK_F5
: g_Menu_Show_OptionsVideo();
752 IK_F6
: g_Menu_Show_OptionsSound();
753 IK_F7
: g_Menu_Show_EndGameMenu();
754 IK_F10
: g_Menu_Show_QuitGameMenu();
761 gJustChatted
:= False;
762 if gConsoleShow
or gChatShow
then
764 g_Console_Control(K
);
766 else if (g_ActiveWindow
<> nil) then
768 Msg
.Msg
:= WM_KEYDOWN
;
770 g_ActiveWindow
.OnMessage(Msg
);
772 else if (gState
= STATE_MENU
) then
774 g_GUI_ShowWindow('MainMenu');
775 g_Sound_PlayEx('MENU_OPEN');
782 procedure CharPress (C
: AnsiChar);
787 if gConsoleShow
or gChatShow
then
791 else if (g_ActiveWindow
<> nil) then
794 Msg
.WParam
:= Ord(C
);
795 g_ActiveWindow
.OnMessage(Msg
);
799 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
800 charbuff
[15] := upcase1251(C
);
806 // ////////////////////////////////////////////////////////////////////////// //
807 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
809 procedure g_ResetDynlights ();
813 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
815 for idx
:= 0 to g_dynLightCount
-1 do
817 if g_dynLights
[idx
].exploCount
= -666 then
824 Inc(g_dynLights
[idx
].exploCount
);
825 if (g_dynLights
[idx
].exploCount
< 10) then
827 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
828 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
829 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
830 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
835 g_dynLightCount
:= lnum
;
838 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
840 if not gwin_has_stencil
then exit
;
841 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
842 g_dynLights
[g_dynLightCount
].x
:= x
;
843 g_dynLights
[g_dynLightCount
].y
:= y
;
844 g_dynLights
[g_dynLightCount
].radius
:= radius
;
845 g_dynLights
[g_dynLightCount
].r
:= r
;
846 g_dynLights
[g_dynLightCount
].g
:= g
;
847 g_dynLights
[g_dynLightCount
].b
:= b
;
848 g_dynLights
[g_dynLightCount
].a
:= a
;
849 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
850 Inc(g_dynLightCount
);
853 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
855 if not gwin_has_stencil
then exit
;
856 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
857 g_dynLights
[g_dynLightCount
].x
:= x
;
858 g_dynLights
[g_dynLightCount
].y
:= y
;
859 g_dynLights
[g_dynLightCount
].radius
:= 0;
860 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
861 g_dynLights
[g_dynLightCount
].r
:= r
;
862 g_dynLights
[g_dynLightCount
].g
:= g
;
863 g_dynLights
[g_dynLightCount
].b
:= b
;
864 g_dynLights
[g_dynLightCount
].a
:= 0;
865 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
866 Inc(g_dynLightCount
);
869 // ////////////////////////////////////////////////////////////////////////// //
870 function conIsCheatsEnabled (): Boolean; inline;
873 if g_Game_IsNet
then exit
;
874 if not gDebugMode
then
876 //if not gCheats then exit;
877 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
878 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
883 // ////////////////////////////////////////////////////////////////////////// //
885 TParamStrValue
= record
890 TParamStrValues
= Array of TParamStrValue
;
893 INTER_ACTION_TEXT
= 1;
894 INTER_ACTION_PIC
= 2;
895 INTER_ACTION_MUSIC
= 3;
900 DataLoaded
: Boolean = False;
902 MessageLineLength
: Integer = 80;
903 MapList
: SSArray
= nil;
904 MapIndex
: Integer = -1;
905 InterReadyTime
: Integer = -1;
906 StatDate
: string = '';
912 text: Array of ShortString;
913 anim
: Array of ShortString;
914 pic
: Array of ShortString;
915 mus
: Array of ShortString;
917 triggers
: Array of record
919 actions
: Array of record
920 action
, p1
, p2
: Integer;
923 cur_trigger
: Integer;
936 function Compare(a
, b
: TPlayerStat
): Integer;
938 if a
.Spectator
then Result
:= 1
939 else if b
.Spectator
then Result
:= -1
940 else if a
.Frags
< b
.Frags
then Result
:= 1
941 else if a
.Frags
> b
.Frags
then Result
:= -1
942 else if a
.Deaths
< b
.Deaths
then Result
:= -1
943 else if a
.Deaths
> b
.Deaths
then Result
:= 1
944 else if a
.Kills
< b
.Kills
then Result
:= -1
948 procedure SortGameStat(var stat
: TPlayerStatArray
);
953 if stat
= nil then Exit
;
955 for I
:= High(stat
) downto Low(stat
) do
956 for J
:= Low(stat
) to High(stat
) - 1 do
957 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
960 stat
[J
] := stat
[J
+ 1];
965 // saves a shitty CSV containing the game stats passed to it
966 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
969 dir
, fname
, map
, mode
, etime
: String;
973 dir
:= e_GetWriteableDir(StatsDirs
);
974 // stats are placed in stats/yy/mm/dd/*.csv
975 fname
:= e_CatPath(dir
, Path
);
976 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
977 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
978 AssignFile(s
, fname
);
980 SetTextCodePage(s
, CP_UTF8
);
982 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
983 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
984 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
985 mode
:= g_Game_ModeToText(Stat
.GameMode
);
986 etime
:= Format('%d:%.2d:%.2d', [
987 Stat
.GameTime
div 1000 div 3600,
988 (Stat
.GameTime
div 1000 div 60) mod 60,
989 Stat
.GameTime
div 1000 mod 60
991 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
992 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
998 gGameSettings
.TimeLimit
,
999 gGameSettings
.ScoreLimit
,
1000 gGameSettings
.Options
,
1002 Length(Stat
.PlayerStat
)
1004 // line 2: game specific shit
1005 // if it's a team game: red score, blue score
1006 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1007 // otherwise nothing
1008 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
1010 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
1011 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
1013 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
1014 // lines 3-...: team, player name, frags, deaths
1015 WriteLn(s
, 'team,name,frags,deaths');
1016 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
1017 with Stat
.PlayerStat
[I
] do
1018 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
1020 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
1023 g_Console_Add('could not create gamestats file "' + fname
+ '"');
1028 procedure ClearDebugCvars();
1030 g_debug_Sounds
:= False;
1031 g_debug_Frames
:= False;
1032 g_debug_WinMsgs
:= False;
1033 g_debug_MonsterOff
:= False;
1034 g_debug_BotAIOff
:= 0;
1035 g_debug_HealthBar
:= False;
1036 g_Debug_Player
:= False;
1039 function g_Game_ModeToText(Mode
: Byte): string;
1043 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
1044 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
1045 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
1046 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
1047 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
1051 function g_Game_TextToMode(Mode
: string): Byte;
1054 Mode
:= UpperCase(Mode
);
1055 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
1060 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
1065 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
1070 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
1075 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
1077 Result
:= GM_SINGLE
;
1082 function g_Game_IsNet(): Boolean;
1084 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
1087 function g_Game_IsServer(): Boolean;
1089 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
1092 function g_Game_IsClient(): Boolean;
1094 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
1097 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
1104 Result
.name
:= ExtractFileName(WAD
);
1105 Result
.description
:= '';
1106 Result
.author
:= '';
1108 w
:= TWADFile
.Create();
1111 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1117 cfg
:= TConfig
.CreateMem(p
, len
);
1118 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
1119 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
1120 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
1121 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
1127 procedure g_Game_FreeWAD();
1131 for a
:= 0 to High(MegaWAD
.res
.pic
) do
1132 if MegaWAD
.res
.pic
[a
] <> '' then
1133 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
1135 for a
:= 0 to High(MegaWAD
.res
.mus
) do
1136 if MegaWAD
.res
.mus
[a
] <> '' then
1137 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
1139 MegaWAD
.res
.pic
:= nil;
1140 MegaWAD
.res
.text := nil;
1141 MegaWAD
.res
.anim
:= nil;
1142 MegaWAD
.res
.mus
:= nil;
1143 MegaWAD
.triggers
:= nil;
1145 g_Texture_Delete('TEXTURE_endpic');
1146 g_Sound_Delete('MUSIC_endmus');
1148 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
1149 gGameSettings
.WAD
:= '';
1152 procedure g_Game_LoadWAD(WAD
: string);
1161 gGameSettings
.WAD
:= WAD
;
1162 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
1165 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
1167 w
:= TWADFile
.Create();
1170 if not w
.GetResource('INTERSCRIPT', p
, len
) then
1176 cfg
:= TConfig
.CreateMem(p
, len
);
1181 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
1182 if s = '' then Break;
1185 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
1186 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
1188 g_Texture_CreateWADEx(s, s);
1194 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
1195 if s = '' then Break;
1198 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
1199 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
1201 g_Music_CreateWADEx(s, s);
1204 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
1205 if MegaWAD
.endpic
<> '' then
1207 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
1208 g_Texture_CreateWADEx('TEXTURE_endpic', s
, gTextureFilter
);
1210 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1211 if MegaWAD
.endmus
<> '' then
1213 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
1214 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
1222 {procedure start_trigger(t: string);
1226 function next_trigger(): Boolean;
1230 procedure DisableCheats();
1236 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
1237 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
1238 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
1239 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
1241 {$IF DEFINED(D2F_DEBUG)}
1242 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
1243 gAimLine
:= g_dbg_aimline_on
;
1247 procedure g_Game_ExecuteEvent(Name
: String);
1253 if gEvents
= nil then
1255 for a
:= 0 to High(gEvents
) do
1256 if gEvents
[a
].Name
= Name
then
1258 if gEvents
[a
].Command
<> '' then
1259 g_Console_Process(gEvents
[a
].Command
, True);
1264 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
1269 if gDelayedEvents
<> nil then
1270 for a
:= 0 to High(gDelayedEvents
) do
1271 if not gDelayedEvents
[a
].Pending
then
1278 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
1279 n
:= High(gDelayedEvents
);
1281 gDelayedEvents
[n
].Pending
:= True;
1282 gDelayedEvents
[n
].DEType
:= DEType
;
1283 gDelayedEvents
[n
].DENum
:= Num
;
1284 gDelayedEvents
[n
].DEStr
:= Str
;
1285 if DEType
= DE_GLOBEVENT
then
1286 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
1288 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
1292 procedure EndGame();
1298 if g_Game_IsNet
and g_Game_IsServer
then
1299 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
1302 gPauseMain
:= false;
1303 gPauseHolmes
:= false;
1306 g_Game_StopAllSounds(False);
1311 EndingGameCounter
:= 0;
1312 g_ActiveWindow
:= nil;
1314 gLMSRespawn
:= LMS_RESPAWN_NONE
;
1315 gLMSRespawnTime
:= 0;
1318 EXIT_SIMPLE
: // Выход через меню или конец теста
1323 begin // Это был тест
1327 begin // Выход в главное меню
1328 gMusic
.SetByName('MUSIC_MENU');
1330 if gState
<> STATE_SLIST
then
1332 g_GUI_ShowWindow('MainMenu');
1333 gState
:= STATE_MENU
;
1336 // Обновляем список серверов
1337 slReturnPressed
:= True;
1338 if g_Net_Slist_Fetch(slCurrent
) then
1340 if slCurrent
= nil then
1341 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
1344 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
1345 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1348 g_Game_ExecuteEvent('ongameend');
1352 EXIT_RESTART
: // Начать уровень сначала
1354 if not g_Game_IsClient
then g_Game_Restart();
1357 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1359 // Статистика Своей игры:
1360 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1362 CustomStat
.GameTime
:= gTime
;
1363 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1364 CustomStat
.MapName
:= gMapInfo
.Name
;
1365 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1366 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1367 CustomStat
.TeamStat
:= gTeamStat
;
1369 CustomStat
.PlayerStat
:= nil;
1371 // Статистика игроков:
1372 if gPlayers
<> nil then
1374 for a
:= 0 to High(gPlayers
) do
1375 if gPlayers
[a
] <> nil then
1377 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1378 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1381 Name
:= gPlayers
[a
].Name
;
1382 Frags
:= gPlayers
[a
].Frags
;
1383 Deaths
:= gPlayers
[a
].Death
;
1384 Kills
:= gPlayers
[a
].Kills
;
1385 Team
:= gPlayers
[a
].Team
;
1386 Color
:= gPlayers
[a
].Model
.Color
;
1387 Spectator
:= gPlayers
[a
].FSpectator
;
1391 SortGameStat(CustomStat
.PlayerStat
);
1393 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1396 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1397 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1398 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1399 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1401 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1404 StatShotDone
:= False;
1407 g_Game_ExecuteEvent('onmapend');
1408 if not g_Game_IsClient
then g_Player_ResetReady
;
1409 gInterReadyCount
:= 0;
1411 // Затухающий экран:
1412 EndingGameCounter
:= 255;
1413 gState
:= STATE_FOLD
;
1415 if gDefInterTime
< 0 then
1416 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1418 gInterEndTime
:= gDefInterTime
* 1000;
1421 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1423 // Статистика Одиночной игры:
1424 SingleStat
.GameTime
:= gTime
;
1425 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1426 SingleStat
.TotalSecrets
:= gSecretsCount
;
1427 // Статистика первого игрока:
1428 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1429 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1430 // Статистика второго игрока (если есть):
1431 if SingleStat
.TwoPlayers
then
1433 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1434 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1437 g_Game_ExecuteEvent('onmapend');
1440 if gNextMap
<> '' then
1442 gMusic
.SetByName('MUSIC_INTERMUS');
1444 gState
:= STATE_INTERSINGLE
;
1447 g_Game_ExecuteEvent('oninter');
1449 else // Больше нет карт
1451 // Затухающий экран:
1452 EndingGameCounter
:= 255;
1453 gState
:= STATE_FOLD
;
1458 // Окончание обработано:
1459 if gExit
<> EXIT_QUIT
then
1463 procedure g_Game_Init();
1466 knownFiles
: array of AnsiString = nil;
1468 wext
, s
: AnsiString;
1473 gTempDelete
:= False;
1475 sfsGCDisable(); // temporary disable removing of temporary volumes
1478 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE', gTextureFilter
);
1479 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER', gTextureFilter
);
1480 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN', gTextureFilter
);
1481 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU', gTextureFilter
);
1483 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1484 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1485 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1487 g_Game_ClearLoading();
1488 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1489 g_Game_SetLoadingText('', 0, False);
1491 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1495 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1496 r_PlayerModel_Initialize
;
1498 // load models from all possible wad types, in all known directories
1499 // this does a loosy job (linear search, ooph!), but meh
1500 for wext
in wadExtensions
do
1502 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1504 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1508 for s
in knownFiles
do
1510 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1518 SetLength(knownFiles
, length(knownFiles
)+1);
1519 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1521 until (FindNext(SR
) <> 0);
1527 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1529 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
);
1530 for s
in knownFiles
do
1532 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1536 gPauseMain
:= false;
1537 gPauseHolmes
:= false;
1540 {e_MouseInfo.Accel := 1.0;}
1542 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1545 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1546 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1547 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1548 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1549 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1552 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1556 gMusic
:= TMusic
.Create();
1557 gMusic
.SetByName('MUSIC_MENU');
1560 gGameSettings
.WarmupTime
:= 30;
1562 gState
:= STATE_MENU
;
1564 SetLength(gEvents
, 6);
1565 gEvents
[0].Name
:= 'ongamestart';
1566 gEvents
[1].Name
:= 'ongameend';
1567 gEvents
[2].Name
:= 'onmapstart';
1568 gEvents
[3].Name
:= 'onmapend';
1569 gEvents
[4].Name
:= 'oninter';
1570 gEvents
[5].Name
:= 'onwadend';
1572 sfsGCEnable(); // enable releasing unused volumes
1576 procedure g_Game_Free(freeTextures
: Boolean=true);
1578 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1579 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1581 g_Map_Free(freeTextures
);
1583 g_Player_RemoveAllCorpses();
1585 gGameSettings
.GameType
:= GT_NONE
;
1586 if gGameSettings
.GameMode
= GM_SINGLE
then
1587 gGameSettings
.GameMode
:= GM_DM
;
1588 gSwitchGameMode
:= gGameSettings
.GameMode
;
1591 gExitByTrigger
:= False;
1594 function IsActivePlayer(p
: TPlayer
): Boolean;
1599 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1602 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1608 if gPlayers
= nil then
1612 for a
:= Low(gPlayers
) to High(gPlayers
) do
1613 if IsActivePlayer(gPlayers
[a
]) then
1615 SetLength(ids
, Length(ids
) + 1);
1616 ids
[High(ids
)] := gPlayers
[a
].UID
;
1617 if gPlayers
[a
].UID
= Skip
then
1620 if Length(ids
) = 0 then
1625 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1628 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1634 if gPlayers
= nil then
1638 for a
:= Low(gPlayers
) to High(gPlayers
) do
1639 if IsActivePlayer(gPlayers
[a
]) then
1641 SetLength(ids
, Length(ids
) + 1);
1642 ids
[High(ids
)] := gPlayers
[a
].UID
;
1643 if gPlayers
[a
].UID
= Skip
then
1646 if Length(ids
) = 0 then
1649 Result
:= ids
[Length(ids
) - 1]
1651 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1654 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1660 if gPlayers
= nil then
1664 for a
:= Low(gPlayers
) to High(gPlayers
) do
1665 if IsActivePlayer(gPlayers
[a
]) then
1667 SetLength(ids
, Length(ids
) + 1);
1668 ids
[High(ids
)] := gPlayers
[a
].UID
;
1669 if gPlayers
[a
].UID
= Skip
then
1672 if Length(ids
) = 0 then
1674 if Length(ids
) = 1 then
1679 Result
:= ids
[Random(Length(ids
))];
1681 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1683 Result
:= ids
[Random(Length(ids
))];
1688 function GetRandomSpectMode(Current
: Byte): Byte;
1695 0: Result
:= SPECT_STATS
;
1696 1: Result
:= SPECT_MAPVIEW
;
1697 2: Result
:= SPECT_MAPVIEW
;
1698 3: Result
:= SPECT_PLAYERS
;
1699 4: Result
:= SPECT_PLAYERS
;
1700 5: Result
:= SPECT_PLAYERS
;
1701 6: Result
:= SPECT_PLAYERS
;
1703 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1707 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1713 if (plr
= nil) then exit
;
1714 if (p
= 2) then time
:= 1000 else time
:= 1;
1715 strafeDir
:= MoveButton
shr 4;
1716 MoveButton
:= MoveButton
and $0F;
1718 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1719 MoveButton
:= 1 // Нажата только "Влево"
1720 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1721 MoveButton
:= 2 // Нажата только "Вправо"
1722 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1723 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1725 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1726 if MoveButton
= 1 then
1727 plr
.PressKey(KEY_LEFT
, time
)
1728 else if MoveButton
= 2 then
1729 plr
.PressKey(KEY_RIGHT
, time
);
1731 // if we have "strafe" key, turn off old strafe mechanics
1732 if gPlayerAction
[p
, ACTION_STRAFE
] then
1734 // new strafe mechanics
1735 if (strafeDir
= 0) then
1736 strafeDir
:= MoveButton
; // start strafing
1737 // now set direction according to strafe (reversed)
1738 if (strafeDir
= 2) then
1739 plr
.SetDirection(TDirection
.D_LEFT
)
1740 else if (strafeDir
= 1) then
1741 plr
.SetDirection(TDirection
.D_RIGHT
)
1745 strafeDir
:= 0; // not strafing anymore
1746 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1747 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1748 plr
.SetDirection(TDirection
.D_LEFT
)
1749 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1750 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1751 plr
.SetDirection(TDirection
.D_RIGHT
)
1752 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1753 else if MoveButton
<> 0 then
1754 plr
.SetDirection(TDirection(MoveButton
-1))
1757 // fix movebutton state
1758 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1760 // Остальные клавиши:
1761 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1762 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1763 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1764 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1765 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1767 for i
:= WP_FACT
to WP_LACT
do
1769 if gWeaponAction
[p
, i
] then
1771 plr
.ProcessWeaponAction(i
);
1772 gWeaponAction
[p
, i
] := False
1776 for i
:= WP_FIRST
to WP_LAST
do
1778 if gSelectWeapon
[p
, i
] then
1780 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1781 gSelectWeapon
[p
, i
] := False
1785 // HACK: add dynlight here
1786 if gwin_k8_enable_light_experiments
then
1788 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1790 g_playerLight
:= true;
1792 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1794 g_playerLight
:= false;
1798 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1801 // HACK: don't have a "key was pressed" function
1802 procedure InterReady();
1804 if InterReadyTime
> gTime
then Exit
;
1805 InterReadyTime
:= gTime
+ 3000;
1806 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1809 procedure g_Game_PreUpdate();
1811 // these are in separate PreUpdate functions because they can interact during Update()
1812 // and are synced over the net
1813 // we don't care that much about corpses and gibs
1814 g_Player_PreUpdate();
1815 g_Monsters_PreUpdate();
1816 g_Items_PreUpdate();
1817 g_Weapon_PreUpdate();
1820 procedure g_Game_Update();
1822 Msg
: g_gui
.TMessage
;
1828 function sendMonsPos (mon
: TMonster
): Boolean;
1830 result
:= false; // don't stop
1831 // this will also reset "need-send" flag
1832 if mon
.gncNeedSend
then
1834 MH_SEND_MonsterPos(mon
.UID
);
1836 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1838 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1840 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1842 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1846 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1848 result
:= false; // don't stop
1849 // this will also reset "need-send" flag
1850 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1853 function sendItemPos (it
: PItem
): Boolean;
1855 result
:= false; // don't stop
1858 MH_SEND_ItemPos(it
.myId
);
1859 it
.needSend
:= False;
1864 reliableUpdate
: Boolean;
1869 // Пора выключать игру:
1870 if gExit
= EXIT_QUIT
then
1872 // Игра закончилась - обрабатываем:
1876 if gExit
= EXIT_QUIT
then
1880 // Читаем клавиатуру и джойстик, если окно активно
1881 // no need to, as we'll do it in event handler
1883 // Обновляем консоль (движение и сообщения):
1887 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1889 gExit
:= EXIT_SIMPLE
;
1894 // process master server communications
1895 g_Net_Slist_Pulse();
1898 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1899 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1900 STATE_INTERTEXT
, // Текст между уровнями
1901 STATE_INTERPIC
: // Картинка между уровнями
1903 if g_Game_IsNet
and g_Game_IsServer
then
1905 gInterTime
:= gInterTime
+ GAME_TICK
;
1906 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1907 if a
<> gServInterTime
then
1909 gServInterTime
:= a
;
1910 MH_SEND_TimeSync(gServInterTime
);
1914 if (not g_Game_IsClient
) and
1918 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1919 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1920 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1921 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1923 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1924 and (g_ActiveWindow
= nil)
1926 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1929 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1930 g_Game_StopAllSounds(True);
1932 if gMapOnce
then // Это был тест
1933 gExit
:= EXIT_SIMPLE
1935 if gNextMap
<> '' then // Переходим на следующую карту
1936 g_Game_ChangeMap(gNextMap
)
1937 else // Следующей карты нет
1939 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1941 // Выход в главное меню:
1943 g_GUI_ShowWindow('MainMenu');
1944 gMusic
.SetByName('MUSIC_MENU');
1946 gState
:= STATE_MENU
;
1949 // Финальная картинка:
1950 g_Game_ExecuteEvent('onwadend');
1952 if not gMusic
.SetByName('MUSIC_endmus') then
1953 gMusic
.SetByName('MUSIC_STDENDMUS');
1955 gState
:= STATE_ENDPIC
;
1957 g_Game_ExecuteEvent('ongameend');
1962 else if g_Game_IsClient
and
1965 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1966 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1967 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1968 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1970 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1971 and (g_ActiveWindow
= nil)
1979 if gState
= STATE_INTERTEXT
then
1980 if InterText
.counter
> 0 then
1981 InterText
.counter
:= InterText
.counter
- 1;
1984 STATE_FOLD
: // Затухание экрана
1986 if EndingGameCounter
= 0 then
1988 // Закончился уровень в Своей игре:
1989 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1991 gState
:= STATE_INTERCUSTOM
;
1992 InterReadyTime
:= -1;
1993 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1995 g_Game_ExecuteEvent('onwadend');
1996 if not gMusic
.SetByName('MUSIC_endmus') then
1997 gMusic
.SetByName('MUSIC_STDENDMUS');
2000 gMusic
.SetByName('MUSIC_ROUNDMUS');
2004 else // Закончилась последняя карта в Одиночной игре
2006 gMusic
.SetByName('MUSIC_INTERMUS');
2008 gState
:= STATE_INTERSINGLE
;
2011 g_Game_ExecuteEvent('oninter');
2014 DecMin(EndingGameCounter
, 6, 0);
2017 STATE_ENDPIC
: // Картинка окончания мегаВада
2019 if gMapOnce
then // Это был тест
2021 gExit
:= EXIT_SIMPLE
;
2027 g_Serverlist_Control(slCurrent
, slTable
);
2030 // Статистика по Tab:
2032 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
2035 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
2037 // Время += 28 миллисекунд:
2038 gTime
:= gTime
+ GAME_TICK
;
2040 // Сообщение посередине экрана:
2041 if MessageTime
= 0 then
2043 if MessageTime
> 0 then
2044 MessageTime
:= MessageTime
- 1;
2046 if (g_Game_IsServer
) then
2048 // Был задан лимит времени:
2049 if (gGameSettings
.TimeLimit
> 0) then
2050 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
2051 begin // Он прошел => конец уровня
2056 // Надо респавнить игроков в LMS:
2057 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
2058 g_Game_RestartRound(gLMSSoftSpawn
);
2060 // Проверим результат голосования, если время прошло
2061 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2063 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2065 g_Console_Process(gVoteCommand
);
2067 gVotePassed
:= False;
2070 // Замеряем время захвата флагов
2071 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2072 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2073 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2074 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2076 // Был задан лимит побед:
2077 if (gGameSettings
.ScoreLimit
> 0) then
2081 if gGameSettings
.GameMode
= GM_DM
then
2082 begin // В DM ищем игрока с max фрагами
2083 for i
:= 0 to High(gPlayers
) do
2084 if gPlayers
[i
] <> nil then
2085 if gPlayers
[i
].Frags
> b
then
2086 b
:= gPlayers
[i
].Frags
;
2089 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2090 begin // В CTF/TDM выбираем команду с наибольшим счетом
2091 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2094 // Лимит побед набран => конец уровня:
2095 if b
>= gGameSettings
.ScoreLimit
then
2102 // Обрабатываем клавиши игроков:
2103 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2104 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2105 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2107 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2108 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2109 end // if not console
2112 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2114 // process weapon switch queue
2118 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2119 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2121 if not gSpectKeyPress
then
2123 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2125 // switch spect mode
2127 SPECT_NONE
: ; // not spectator
2129 SPECT_MAPVIEW
: Inc(gSpectMode
);
2130 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2132 gSpectKeyPress
:= True;
2134 if (gSpectMode
= SPECT_MAPVIEW
)
2135 and (not gSpectAuto
) then
2137 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2138 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2139 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2140 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2141 if gPlayerAction
[0, ACTION_LOOKUP
] then
2142 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2143 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2144 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2145 if gWeaponAction
[0, WP_PREV
] then
2148 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2149 gWeaponAction
[0, WP_PREV
] := False;
2151 if gWeaponAction
[0, WP_NEXT
] then
2154 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2155 gWeaponAction
[0, WP_NEXT
] := False;
2158 if (gSpectMode
= SPECT_PLAYERS
)
2159 and (not gSpectAuto
) then
2161 if gPlayerAction
[0, ACTION_LOOKUP
] then
2164 gSpectViewTwo
:= True;
2165 gSpectKeyPress
:= True;
2167 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2169 // remove second view
2170 gSpectViewTwo
:= False;
2171 gSpectKeyPress
:= True;
2173 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2175 // prev player (view 1)
2176 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2177 gSpectKeyPress
:= True;
2179 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2181 // next player (view 1)
2182 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2183 gSpectKeyPress
:= True;
2185 if gWeaponAction
[0, WP_PREV
] then
2187 // prev player (view 2)
2188 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2189 gWeaponAction
[0, WP_PREV
] := False;
2191 if gWeaponAction
[0, WP_NEXT
] then
2193 // next player (view 2)
2194 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2195 gWeaponAction
[0, WP_NEXT
] := False;
2198 if gPlayerAction
[0, ACTION_ATTACK
] then
2200 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2203 gSpectAutoNext
:= 0;
2204 gSpectViewTwo
:= False;
2205 gSpectKeyPress
:= True;
2210 gSpectMode
:= SPECT_STATS
;
2211 gSpectAuto
:= False;
2212 gSpectKeyPress
:= True;
2217 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2218 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2219 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2220 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2221 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2222 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2223 gSpectKeyPress
:= False;
2227 if gSpectMode
= SPECT_MAPVIEW
then
2229 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2231 gSpectAutoNext
:= gTime
2234 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2236 gSpectAutoNext
:= gTime
2240 if gSpectAutoNext
<= gTime
then
2242 if gSpectAutoNext
> 0 then
2244 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2248 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2249 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2250 gSpectAutoStepX
:= Random(9) - 4;
2251 gSpectAutoStepY
:= Random(9) - 4;
2252 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2253 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2254 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2255 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2256 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2257 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2261 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2266 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2267 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2268 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2274 // Обновляем все остальное:
2277 g_Triggers_Update();
2279 g_Monsters_Update();
2281 g_Player_UpdateAll();
2282 g_Player_UpdatePhysicalObjects();
2284 // server: send newly spawned monsters unconditionally
2285 if (gGameSettings
.GameType
= GT_SERVER
) then
2287 if (Length(gMonstersSpawned
) > 0) then
2289 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2290 SetLength(gMonstersSpawned
, 0);
2294 if (gSoundTriggerTime
> 8) then
2296 g_Game_UpdateTriggerSounds();
2297 gSoundTriggerTime
:= 0;
2301 Inc(gSoundTriggerTime
);
2304 if (NetMode
= NET_SERVER
) then
2306 Inc(NetTimeToUpdate
);
2307 Inc(NetTimeToReliable
);
2309 // send monster updates
2310 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2312 // send all monsters (periodic sync)
2313 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2315 for I
:= 0 to High(gPlayers
) do
2317 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2320 g_Mons_ForEach(sendMonsPos
);
2322 // update flags that aren't stationary
2323 if gGameSettings
.GameMode
= GM_CTF
then
2324 for I
:= FLAG_RED
to FLAG_BLUE
do
2325 if gFlags
[I
].NeedSend
then
2327 gFlags
[I
].NeedSend
:= False;
2331 // update items that aren't stationary
2332 g_Items_ForEachAlive(sendItemPos
);
2334 if reliableUpdate
then
2336 NetTimeToReliable
:= 0;
2337 NetTimeToUpdate
:= NetUpdateRate
;
2341 NetTimeToUpdate
:= 0;
2346 // send only mosters with some unexpected changes
2347 g_Mons_ForEach(sendMonsPosUnexpected
);
2350 // send unexpected platform changes
2351 g_Map_NetSendInterestingPanels();
2353 g_Net_Slist_ServerUpdate();
2355 if NetUseMaster then
2357 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2359 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2361 NetTimeToMaster := gTime + NetMasterRate;
2366 else if (NetMode
= NET_CLIENT
) then
2368 MC_SEND_PlayerPos();
2370 end; // if gameOn ...
2372 // Активно окно интерфейса - передаем клавиши ему:
2373 if g_ActiveWindow
<> nil then
2375 w
:= e_GetFirstKeyPressed();
2377 if (w
<> IK_INVALID
) then
2379 Msg
.Msg
:= MESSAGE_DIKEY
;
2381 g_ActiveWindow
.OnMessage(Msg
);
2384 // Если оно от этого не закрылось, то обновляем:
2385 if g_ActiveWindow
<> nil then
2386 g_ActiveWindow
.Update();
2388 // Нужно сменить разрешение:
2389 if gResolutionChange
then
2391 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2392 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2393 gResolutionChange
:= False;
2394 g_ActiveWindow
:= nil;
2397 // Нужно сменить язык:
2398 if gLanguageChange
then
2400 //e_WriteLog('Read language file', MSG_NOTIFY);
2401 //g_Language_Load(DataDir + gLanguage + '.txt');
2402 g_Language_Set(gLanguage
);
2406 gLanguageChange
:= False;
2410 // Горячая клавиша для вызова меню выхода из игры (F10):
2411 if e_KeyPressed(IK_F10
) and
2413 (not gConsoleShow
) and
2414 (g_ActiveWindow
= nil) then
2419 Time
:= sys_GetTicks() {div 1000};
2421 // Обработка отложенных событий:
2422 if gDelayedEvents
<> nil then
2423 for a
:= 0 to High(gDelayedEvents
) do
2424 if gDelayedEvents
[a
].Pending
and
2426 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2427 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2430 case gDelayedEvents
[a
].DEType
of
2432 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2435 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2439 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2440 if g_Game_IsNet
and g_Game_IsServer
then
2441 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2445 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2447 gDelayedEvents
[a
].Pending
:= False;
2450 // Каждую секунду обновляем счетчик обновлений:
2451 UPSCounter
:= UPSCounter
+ 1;
2452 if Time
- UPSTime
>= 1000 then
2461 g_Weapon_AddDynLights();
2462 g_Items_AddDynLights();
2466 procedure g_Game_LoadChatSounds(Resource
: string);
2469 FileName
, Snd
: string;
2471 len
, cnt
, tags
, i
, j
: Integer;
2474 FileName
:= g_ExtractWadName(Resource
);
2476 WAD
:= TWADFile
.Create();
2477 WAD
.ReadFile(FileName
);
2479 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2486 cfg
:= TConfig
.CreateMem(p
, len
);
2487 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2489 SetLength(gChatSounds
, cnt
);
2490 for i
:= 0 to Length(gChatSounds
) - 1 do
2492 gChatSounds
[i
].Sound
:= nil;
2493 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2494 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2495 if (Snd
= '') or (Tags
<= 0) then
2497 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2498 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2499 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2500 SetLength(gChatSounds
[i
].Tags
, tags
);
2501 for j
:= 0 to tags
- 1 do
2502 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2503 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2510 procedure g_Game_FreeChatSounds();
2514 for i
:= 0 to Length(gChatSounds
) - 1 do
2516 gChatSounds
[i
].Sound
.Free();
2517 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2519 SetLength(gChatSounds
, 0);
2523 procedure g_Game_LoadData();
2530 if DataLoaded
then Exit
;
2532 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2534 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2535 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2536 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2537 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2538 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2539 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2540 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2541 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2542 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2543 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2544 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2545 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2546 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2547 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2548 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2551 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2552 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2553 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2554 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2558 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2559 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2560 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2561 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2562 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
2568 hasPBarGfx
:= false;
2572 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2573 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2574 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2575 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2576 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2577 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2578 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2579 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2580 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2581 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2582 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2583 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2584 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2585 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2586 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2587 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2588 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2589 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2590 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2591 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2592 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2593 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2594 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2595 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2596 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2597 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2598 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2599 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2600 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2601 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2602 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2603 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2604 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2605 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2606 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2607 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2608 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2609 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2610 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2612 goodsnd
[0] := TPlayableSound
.Create();
2613 goodsnd
[1] := TPlayableSound
.Create();
2614 goodsnd
[2] := TPlayableSound
.Create();
2615 goodsnd
[3] := TPlayableSound
.Create();
2617 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2618 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2619 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2620 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2622 killsnd
[0] := TPlayableSound
.Create();
2623 killsnd
[1] := TPlayableSound
.Create();
2624 killsnd
[2] := TPlayableSound
.Create();
2625 killsnd
[3] := TPlayableSound
.Create();
2627 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2628 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2629 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2630 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2632 hahasnd
[0] := TPlayableSound
.Create();
2633 hahasnd
[1] := TPlayableSound
.Create();
2634 hahasnd
[2] := TPlayableSound
.Create();
2636 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2637 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2638 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2640 sound_get_flag
[0] := TPlayableSound
.Create();
2641 sound_get_flag
[1] := TPlayableSound
.Create();
2642 sound_lost_flag
[0] := TPlayableSound
.Create();
2643 sound_lost_flag
[1] := TPlayableSound
.Create();
2644 sound_ret_flag
[0] := TPlayableSound
.Create();
2645 sound_ret_flag
[1] := TPlayableSound
.Create();
2646 sound_cap_flag
[0] := TPlayableSound
.Create();
2647 sound_cap_flag
[1] := TPlayableSound
.Create();
2649 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2650 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2651 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2652 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2653 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2654 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2655 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2656 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2658 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2660 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2663 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2664 g_Weapon_LoadData();
2666 g_Monsters_LoadData();
2671 procedure g_Game_Quit();
2673 g_Game_StopAllSounds(True);
2676 r_PlayerModel_Finalize
;
2677 g_PlayerModel_FreeData();
2678 g_Texture_DeleteAll();
2679 g_Frames_DeleteAll();
2681 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2684 if NetInitDone
then g_Net_Free
;
2686 // remove map after test
2687 if gMapToDelete
<> '' then
2688 g_Game_DeleteTestMap();
2694 procedure g_Game_FreeData();
2696 if not DataLoaded
then Exit
;
2699 g_Weapon_FreeData();
2700 g_Monsters_FreeData();
2702 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2704 g_Texture_Delete('NOTEXTURE');
2705 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2706 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2707 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2708 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2709 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2710 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2711 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2712 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2713 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2714 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2715 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2716 g_Frames_DeleteByName('FRAMES_TELEPORT');
2717 g_Frames_DeleteByName('FRAMES_PUNCH');
2718 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2719 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2720 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2721 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2722 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2723 g_Sound_Delete('SOUND_GAME_TELEPORT');
2724 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2725 g_Sound_Delete('SOUND_GAME_SECRET');
2726 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2727 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2728 g_Sound_Delete('SOUND_GAME_BULK1');
2729 g_Sound_Delete('SOUND_GAME_BULK2');
2730 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2731 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2732 g_Sound_Delete('SOUND_GAME_BURNING');
2733 g_Sound_Delete('SOUND_GAME_SWITCH1');
2734 g_Sound_Delete('SOUND_GAME_SWITCH0');
2741 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2742 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2743 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2744 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2751 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2752 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2753 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2754 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2760 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2761 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2762 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2764 sound_get_flag
[0].Free();
2765 sound_get_flag
[1].Free();
2766 sound_lost_flag
[0].Free();
2767 sound_lost_flag
[1].Free();
2768 sound_ret_flag
[0].Free();
2769 sound_ret_flag
[1].Free();
2770 sound_cap_flag
[0].Free();
2771 sound_cap_flag
[1].Free();
2773 g_Sound_Delete('SOUND_CTF_GET1');
2774 g_Sound_Delete('SOUND_CTF_GET2');
2775 g_Sound_Delete('SOUND_CTF_LOST1');
2776 g_Sound_Delete('SOUND_CTF_LOST2');
2777 g_Sound_Delete('SOUND_CTF_RETURN1');
2778 g_Sound_Delete('SOUND_CTF_RETURN2');
2779 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2780 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2782 g_Game_FreeChatSounds();
2784 DataLoaded
:= False;
2787 procedure g_FatalError(Text: String);
2789 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2790 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2792 gExit
:= EXIT_SIMPLE
;
2793 if gGameOn
then EndGame
;
2796 procedure g_SimpleError(Text: String);
2798 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2799 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2802 procedure g_Game_SetupScreenSize();
2804 RES_FACTOR
= 4.0 / 3.0;
2810 // Размер экранов игроков:
2811 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2812 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2813 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
2815 gPlayerScreenSize
.Y
:= gScreenHeight
;
2817 // Размер заднего плана:
2818 if BackID
<> DWORD(-1) then
2821 if (gScreenWidth
*s
> gMapInfo
.Width
) or
2822 (gScreenHeight
*s
> gMapInfo
.Height
) then
2824 gBackSize
.X
:= gScreenWidth
;
2825 gBackSize
.Y
:= gScreenHeight
;
2829 e_GetTextureSize(BackID
, @bw
, @bh
);
2830 rf
:= Single(bw
) / Single(bh
);
2831 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
2832 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
2833 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
2834 if (s
< 1.0) then s
:= 1.0;
2835 gBackSize
.X
:= Round(bw
*s
);
2836 gBackSize
.Y
:= Round(bh
*s
);
2841 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
2843 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
2846 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2848 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2849 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2852 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2855 if gPlayer1
= nil then
2857 if g_Game_IsClient
then
2859 if NetPlrUID1
> -1 then
2860 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2864 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2865 Team
:= gPlayer1Settings
.Team
;
2867 // Создание первого игрока:
2868 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2869 gPlayer1Settings
.Color
,
2871 if gPlayer1
= nil then
2872 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2875 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2876 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2877 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2878 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2879 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2880 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2881 if g_Game_IsServer
and g_Game_IsNet
then
2882 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2883 gPlayer1
.Respawn(False, True);
2884 g_Net_Slist_ServerPlayerComes();
2889 if gPlayer2
= nil then
2891 if g_Game_IsClient
then
2893 if NetPlrUID2
> -1 then
2894 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2898 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2899 Team
:= gPlayer2Settings
.Team
;
2901 // Создание второго игрока:
2902 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2903 gPlayer2Settings
.Color
,
2905 if gPlayer2
= nil then
2906 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2909 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2910 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2911 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2912 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2913 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2914 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2915 if g_Game_IsServer
and g_Game_IsNet
then
2916 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2917 gPlayer2
.Respawn(False, True);
2918 g_Net_Slist_ServerPlayerComes();
2925 procedure g_Game_RemovePlayer();
2929 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2930 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2935 if g_Game_IsServer
then
2938 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2939 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2940 g_Player_Remove(Pl
.UID
);
2941 g_Net_Slist_ServerPlayerLeaves();
2945 gSpectLatchPID2
:= Pl
.UID
;
2953 if g_Game_IsServer
then
2956 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2957 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2958 g_Player_Remove(Pl
.UID
);
2959 g_Net_Slist_ServerPlayerLeaves();
2962 gSpectLatchPID1
:= Pl
.UID
;
2964 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2968 g_Net_Slist_ServerPlayerLeaves();
2971 procedure g_Game_Spectate();
2973 g_Game_RemovePlayer();
2974 if gPlayer1
<> nil then
2975 g_Game_RemovePlayer();
2978 procedure g_Game_SpectateCenterView();
2980 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2981 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2984 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2991 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2993 g_Game_ClearLoading();
2996 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2999 gGameSettings
.GameType
:= GT_SINGLE
;
3000 gGameSettings
.MaxLives
:= 0;
3001 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3002 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3003 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3004 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
3005 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
3006 gSwitchGameMode
:= GM_SINGLE
;
3008 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3009 gLMSRespawnTime
:= 0;
3010 gSpectLatchPID1
:= 0;
3011 gSpectLatchPID2
:= 0;
3013 g_Game_ExecuteEvent('ongamestart');
3015 // Установка размеров окон игроков:
3016 g_Game_SetupScreenSize();
3018 // Создание первого игрока:
3019 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3020 gPlayer1Settings
.Color
,
3021 gPlayer1Settings
.Team
, False));
3022 if gPlayer1
= nil then
3024 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3028 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3029 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3030 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3031 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3032 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3035 // Создание второго игрока, если есть:
3038 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3039 gPlayer2Settings
.Color
,
3040 gPlayer2Settings
.Team
, False));
3041 if gPlayer2
= nil then
3043 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3047 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3048 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3049 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3050 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3051 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3055 // Загрузка и запуск карты:
3056 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
3058 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
3059 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
3063 // Настройки игроков и ботов:
3067 for i
:= nPl
+1 to nPlayers
do
3068 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3071 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3072 TimeLimit
, ScoreLimit
: Word;
3074 Options
: LongWord; nPlayers
: Byte);
3080 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
3082 g_Game_ClearLoading();
3085 gGameSettings
.GameType
:= GT_CUSTOM
;
3086 gGameSettings
.GameMode
:= GameMode
;
3087 gSwitchGameMode
:= GameMode
;
3088 gGameSettings
.TimeLimit
:= TimeLimit
;
3089 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3090 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3091 gGameSettings
.Options
:= Options
;
3093 gCoopTotalMonstersKilled
:= 0;
3094 gCoopTotalSecretsFound
:= 0;
3095 gCoopTotalMonsters
:= 0;
3096 gCoopTotalSecrets
:= 0;
3100 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3101 gLMSRespawnTime
:= 0;
3102 gSpectLatchPID1
:= 0;
3103 gSpectLatchPID2
:= 0;
3105 g_Game_ExecuteEvent('ongamestart');
3107 // Установка размеров окон игроков:
3108 g_Game_SetupScreenSize();
3110 // Режим наблюдателя:
3111 if nPlayers
= 0 then
3118 if nPlayers
>= 1 then
3120 // Создание первого игрока:
3121 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3122 gPlayer1Settings
.Color
,
3123 gPlayer1Settings
.Team
, False));
3124 if gPlayer1
= nil then
3126 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3130 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3131 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3132 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3133 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3134 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3138 if nPlayers
>= 2 then
3140 // Создание второго игрока:
3141 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3142 gPlayer2Settings
.Color
,
3143 gPlayer2Settings
.Team
, False));
3144 if gPlayer2
= nil then
3146 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3150 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3151 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3152 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3153 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3154 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3158 // Загрузка и запуск карты:
3159 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3161 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3165 // Нет точек появления:
3166 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3167 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3168 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3169 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3170 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3172 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3176 // Настройки игроков и ботов:
3180 for i
:= nPl
+1 to nPlayers
do
3181 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3184 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3185 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3186 Options
: LongWord; nPlayers
: Byte;
3187 IPAddr
: LongWord; Port
: Word);
3190 g_Net_Slist_ServerClosed();
3192 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3194 g_Game_ClearLoading();
3199 gGameSettings
.GameType
:= GT_SERVER
;
3200 gGameSettings
.GameMode
:= GameMode
;
3201 gSwitchGameMode
:= GameMode
;
3202 gGameSettings
.TimeLimit
:= TimeLimit
;
3203 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3204 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3205 gGameSettings
.Options
:= Options
;
3207 gCoopTotalMonstersKilled
:= 0;
3208 gCoopTotalSecretsFound
:= 0;
3209 gCoopTotalMonsters
:= 0;
3210 gCoopTotalSecrets
:= 0;
3214 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3215 gLMSRespawnTime
:= 0;
3216 gSpectLatchPID1
:= 0;
3217 gSpectLatchPID2
:= 0;
3219 g_Game_ExecuteEvent('ongamestart');
3221 // Установка размеров окна игрока
3222 g_Game_SetupScreenSize();
3224 // Режим наблюдателя:
3225 if nPlayers
= 0 then
3231 if nPlayers
>= 1 then
3233 // Создание первого игрока:
3234 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3235 gPlayer1Settings
.Color
,
3236 gPlayer1Settings
.Team
, False));
3237 if gPlayer1
= nil then
3239 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3243 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3244 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3245 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3246 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3247 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3250 if nPlayers
>= 2 then
3252 // Создание второго игрока:
3253 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3254 gPlayer2Settings
.Color
,
3255 gPlayer2Settings
.Team
, False));
3256 if gPlayer2
= nil then
3258 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3262 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3263 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3264 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3265 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3266 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3269 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3270 if NetForwardPorts
then
3271 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3274 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3276 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3280 g_Net_Slist_Set(NetMasterList
);
3282 g_Net_Slist_ServerStarted();
3284 // Загрузка и запуск карты:
3285 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3287 g_Net_Slist_ServerClosed();
3288 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3292 // Нет точек появления:
3293 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3294 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3295 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3296 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3297 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3299 g_Net_Slist_ServerClosed();
3300 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3304 // Настройки игроков и ботов:
3307 g_Net_Slist_ServerMapStarted();
3308 NetState
:= NET_STATE_GAME
;
3311 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3326 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3327 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3329 g_Game_ClearLoading();
3334 gGameSettings
.GameType
:= GT_CLIENT
;
3336 gCoopTotalMonstersKilled
:= 0;
3337 gCoopTotalSecretsFound
:= 0;
3338 gCoopTotalMonsters
:= 0;
3339 gCoopTotalSecrets
:= 0;
3343 g_Game_ExecuteEvent('ongamestart');
3345 // Установка размеров окон игроков:
3346 g_Game_SetupScreenSize();
3348 NetState
:= NET_STATE_AUTH
;
3350 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3352 // create (or update) map/resource databases
3353 g_Res_CreateDatabases(true);
3355 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3356 gLMSRespawnTime
:= 0;
3357 gSpectLatchPID1
:= 0;
3358 gSpectLatchPID2
:= 0;
3361 if not g_Net_Connect(Addr
, Port
) then
3363 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3364 NetState
:= NET_STATE_NONE
;
3368 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3370 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3375 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3376 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3377 // thank you, enet. let's ignore failures altogether then.
3378 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3380 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3382 Ptr
:= NetEvent
.packet
^.data
;
3383 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3385 enet_packet_destroy(NetEvent
.packet
);
3389 InMsg
.ReadLongWord(); // skip size
3390 MID
:= InMsg
.ReadByte();
3392 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3394 NetMyID
:= InMsg
.ReadByte();
3395 NetPlrUID1
:= InMsg
.ReadWord();
3397 WadName
:= InMsg
.ReadString();
3398 Map
:= InMsg
.ReadString();
3400 gWADHash
:= InMsg
.ReadMD5();
3402 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3403 gSwitchGameMode
:= gGameSettings
.GameMode
;
3404 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3405 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3406 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3407 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3408 T
:= InMsg
.ReadLongWord();
3410 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3411 //if newResPath = '' then
3413 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3414 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3415 if newResPath
= '' then
3417 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3418 enet_packet_destroy(NetEvent
.packet
);
3419 NetState
:= NET_STATE_NONE
;
3422 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3424 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3427 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3428 gPlayer1Settings
.Color
,
3429 gPlayer1Settings
.Team
, False));
3431 if gPlayer1
= nil then
3433 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3435 enet_packet_destroy(NetEvent
.packet
);
3436 NetState
:= NET_STATE_NONE
;
3440 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3441 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3442 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3443 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3444 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3445 gPlayer1
.UID
:= NetPlrUID1
;
3446 gPlayer1
.Reset(True);
3448 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3450 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3452 enet_packet_destroy(NetEvent
.packet
);
3453 NetState
:= NET_STATE_NONE
;
3461 enet_packet_destroy(NetEvent
.packet
);
3465 enet_packet_destroy(NetEvent
.packet
);
3469 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3472 if (NetEvent
.data
<= NET_DISC_MAX
) then
3473 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3474 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3481 ProcessLoading(True);
3482 if g_Net_UserRequestExit() then
3491 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3492 NetState
:= NET_STATE_NONE
;
3497 NetState
:= NET_STATE_GAME
;
3498 MC_SEND_FullStateRequest
;
3499 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3503 lastAsMegaWad
: Boolean = false;
3505 procedure g_Game_ChangeMap(const MapPath
: String);
3509 g_Game_ClearLoading();
3511 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3512 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3513 if gExitByTrigger
then
3516 gExitByTrigger
:= False;
3518 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3519 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3522 procedure g_Game_Restart();
3526 if g_Game_IsClient
then
3528 map
:= g_ExtractFileName(gMapInfo
.Map
);
3529 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3533 g_Game_ClearLoading();
3534 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3537 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3539 NewWAD
, ResName
: String;
3543 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3544 g_Player_RemoveAllCorpses();
3546 if (not g_Game_IsClient
) and
3547 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3548 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3550 if gSwitchGameMode
= GM_CTF
then
3551 gGameSettings
.MaxLives
:= 0;
3552 gGameSettings
.GameMode
:= gSwitchGameMode
;
3555 gSwitchGameMode
:= gGameSettings
.GameMode
;
3557 g_Player_ResetTeams();
3559 lastAsMegaWad
:= asMegawad
;
3560 if isWadPath(Map
) then
3562 NewWAD
:= g_ExtractWadName(Map
);
3563 ResName
:= g_ExtractFileName(Map
);
3564 if g_Game_IsServer
then
3566 nws
:= findDiskWad(NewWAD
);
3567 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3570 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3571 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3575 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3576 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3578 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3579 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3581 if (length(nws
) = 0) then
3583 ResName
:= ''; // failed
3588 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3589 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3590 g_Game_LoadWAD(NewWAD
);
3595 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3596 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3601 NewWAD
:= gGameSettings
.WAD
;
3607 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3609 if (ResName
<> '') and (NewWAD
<> '') then
3611 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3612 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3616 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3618 gState
:= STATE_NONE
;
3619 g_ActiveWindow
:= nil;
3623 wNeedTimeReset
:= True;
3625 if gGameSettings
.GameMode
= GM_CTF
then
3627 g_Map_ResetFlag(FLAG_RED
);
3628 g_Map_ResetFlag(FLAG_BLUE
);
3629 // CTF, а флагов нет:
3630 if not g_Map_HaveFlagPoints() then
3631 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3636 gState
:= STATE_MENU
;
3641 gPauseMain
:= false;
3642 gPauseHolmes
:= false;
3643 NetTimeToUpdate
:= 1;
3644 NetTimeToReliable
:= 0;
3645 NetTimeToMaster
:= NetMasterRate
;
3646 gSpectLatchPID1
:= 0;
3647 gSpectLatchPID2
:= 0;
3648 gMissionFailed
:= False;
3651 gCoopMonstersKilled
:= 0;
3652 gCoopSecretsFound
:= 0;
3654 gVoteInProgress
:= False;
3655 gVotePassed
:= False;
3661 if not gGameOn
then Exit
;
3663 g_Game_SpectateCenterView();
3665 if g_Game_IsServer
then
3667 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3669 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3670 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3671 gLMSSoftSpawn
:= True;
3672 if g_Game_IsNet
then
3673 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3677 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3678 gLMSRespawnTime
:= 0;
3682 if NetMode
= NET_SERVER
then
3684 // reset full state flags
3685 if NetClients
<> nil then
3686 for I
:= 0 to High(NetClients
) do
3687 NetClients
[I
].FullUpdateSent
:= False;
3689 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3692 g_Net_Slist_ServerMapStarted();
3694 if NetClients
<> nil then
3695 for I
:= 0 to High(NetClients
) do
3696 if NetClients
[I
].Used
then
3698 NetClients
[I
].Voted
:= False;
3699 if NetClients
[I
].RequestedFullUpdate
then
3701 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3702 NetClients
[I
].RequestedFullUpdate
:= False;
3706 g_Net_UnbanNonPermHosts();
3711 gCoopTotalMonstersKilled
:= 0;
3712 gCoopTotalSecretsFound
:= 0;
3713 gCoopTotalMonsters
:= 0;
3714 gCoopTotalSecrets
:= 0;
3718 g_Game_ExecuteEvent('onmapstart');
3721 procedure SetFirstLevel
;
3725 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3726 if MapList
= nil then
3729 SortSArray(MapList
);
3730 gNextMap
:= MapList
[Low(MapList
)];
3735 procedure g_Game_ExitLevel(const Map
: AnsiString);
3739 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3740 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3741 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3742 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3744 // Вышли в выход в Одиночной игре:
3745 if gGameSettings
.GameType
= GT_SINGLE
then
3746 gExit
:= EXIT_ENDLEVELSINGLE
3747 else // Вышли в выход в Своей игре
3749 gExit
:= EXIT_ENDLEVELCUSTOM
;
3750 if gGameSettings
.GameMode
= GM_COOP
then
3751 g_Player_RememberAll
;
3753 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3756 if gGameSettings
.GameMode
= GM_COOP
then
3759 gStatsPressed
:= True;
3760 gNextMap
:= 'MAP01';
3762 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3765 if g_Game_IsNet
then
3767 MH_SEND_GameStats();
3768 MH_SEND_CoopStats();
3774 procedure g_Game_RestartLevel();
3778 if gGameSettings
.GameMode
= GM_SINGLE
then
3783 gExit
:= EXIT_ENDLEVELCUSTOM
;
3784 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3788 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3790 gWAD
{, xwad}: String;
3793 if not g_Game_IsClient
then Exit
;
3794 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3796 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3801 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3805 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3808 g_Game_LoadWAD(NewWAD
);
3812 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3813 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3816 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3817 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3821 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3825 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3826 g_Game_LoadWAD(NewWAD);
3830 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3832 i
, n
, nb
, nr
: Integer;
3834 if not g_Game_IsServer
then Exit
;
3835 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3836 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3837 gLMSRespawnTime
:= 0;
3840 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3842 gMissionFailed
:= True;
3843 g_Game_RestartLevel
;
3847 n
:= 0; nb
:= 0; nr
:= 0;
3848 for i
:= Low(gPlayers
) to High(gPlayers
) do
3849 if (gPlayers
[i
] <> nil) and
3850 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3851 (gPlayers
[i
] is TBot
)) then
3854 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3855 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3858 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3860 // wait a second until the fuckers finally decide to join
3861 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3862 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3863 gLMSSoftSpawn
:= NoMapRestart
;
3864 if g_Game_IsNet
then
3865 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3869 g_Player_RemoveAllCorpses
;
3870 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3871 if g_Game_IsNet
then
3872 MH_SEND_GameEvent(NET_EV_LMS_START
);
3874 for i
:= Low(gPlayers
) to High(gPlayers
) do
3876 if gPlayers
[i
] = nil then continue
;
3877 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3878 // don't touch normal spectators
3879 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3881 gPlayers
[i
].FNoRespawn
:= True;
3882 gPlayers
[i
].Lives
:= 0;
3883 if g_Game_IsNet
then
3884 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3887 gPlayers
[i
].FNoRespawn
:= False;
3888 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3889 gPlayers
[i
].Respawn(False, True);
3890 if gGameSettings
.GameMode
= GM_COOP
then
3892 gPlayers
[i
].Frags
:= 0;
3893 gPlayers
[i
].RecallState
;
3895 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3896 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3897 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3898 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3901 g_Items_RestartRound();
3903 gLMSSoftSpawn
:= False;
3906 function g_Game_GetFirstMap(WAD
: String): String;
3910 MapList
:= g_Map_GetMapsList(WAD
);
3911 if MapList
= nil then
3914 SortSArray(MapList
);
3915 Result
:= MapList
[Low(MapList
)];
3917 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3923 function g_Game_GetNextMap(): String;
3930 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3931 if MapList
= nil then
3934 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3936 SortSArray(MapList
);
3938 for I
:= Low(MapList
) to High(MapList
) do
3939 if Map
= MapList
[I
] then
3945 if MapIndex
<> -255 then
3947 if MapIndex
= High(MapList
) then
3948 Result
:= MapList
[Low(MapList
)]
3950 Result
:= MapList
[MapIndex
+ 1];
3952 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3958 procedure g_Game_NextLevel();
3960 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3961 gExit
:= EXIT_ENDLEVELCUSTOM
3964 gExit
:= EXIT_ENDLEVELSINGLE
;
3968 if gNextMap
<> '' then Exit
;
3969 gNextMap
:= g_Game_GetNextMap();
3972 function g_Game_IsTestMap(): Boolean;
3974 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3977 procedure g_Game_DeleteTestMap();
3980 //MapName: AnsiString;
3988 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3989 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3990 if (a
= 0) then exit
;
3992 // Выделяем имя wad-файла и имя карты
3993 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3994 Delete(gMapToDelete
, 1, a
+5);
3995 gMapToDelete
:= UpperCase(gMapToDelete
);
3997 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
4000 // Имя карты не стандартное тестовое:
4001 if MapName <> TEST_MAP_NAME then
4004 if not gTempDelete then
4006 time := g_GetFileTime(WadName);
4007 WAD := TWADFile.Create();
4010 if not WAD.ReadFile(WadName) then
4011 begin // Нет такого WAD-файла
4016 // Составляем список карт и ищем нужную:
4018 MapList := WAD.GetResourcesList('');
4020 if MapList <> nil then
4021 for a := 0 to High(MapList) do
4022 if MapList[a] = MapName then
4024 // Удаляем и сохраняем:
4025 WAD.RemoveResource('', MapName);
4026 WAD.SaveTo(WadName);
4031 g_SetFileTime(WadName, time);
4034 if gTempDelete
then DeleteFile(WadName
);
4037 procedure GameCVars(P
: SSArray
);
4040 stat
: TPlayerStatArray
;
4043 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
4047 if Length(P
) > 1 then
4052 gsGameFlags
:= gsGameFlags
or Flag
4054 gsGameFlags
:= gsGameFlags
and (not Flag
);
4056 if g_Game_IsServer
then
4059 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
4061 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
4062 if g_Game_IsNet
then MH_SEND_GameSettings
;
4066 if LongBool(gsGameFlags
and Flag
) then
4067 g_Console_Add(_lc
[OnMsg
])
4069 g_Console_Add(_lc
[OffMsg
]);
4071 if OnMapChange
and g_Game_IsServer
then
4072 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4077 cmd
:= LowerCase(P
[0]);
4079 if cmd
= 'g_gamemode' then
4081 if (Length(P
) > 1) then
4083 a
:= g_Game_TextToMode(P
[1]);
4084 if a
= GM_SINGLE
then a
:= GM_COOP
;
4085 gsGameMode
:= g_Game_ModeToText(a
);
4086 if g_Game_IsServer
then
4088 gSwitchGameMode
:= a
;
4089 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4090 (gState
= STATE_INTERSINGLE
) then
4091 gSwitchGameMode
:= GM_SINGLE
;
4093 gGameSettings
.GameMode
:= gSwitchGameMode
;
4097 if gSwitchGameMode
= gGameSettings
.GameMode
then
4098 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4099 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4101 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4102 [g_Game_ModeToText(gGameSettings
.GameMode
),
4103 g_Game_ModeToText(gSwitchGameMode
)]));
4105 else if cmd
= 'g_friendlyfire' then
4107 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4109 else if cmd
= 'g_friendly_absorb_damage' then
4111 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
4113 else if cmd
= 'g_friendly_hit_trace' then
4115 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
4117 else if cmd
= 'g_friendly_hit_projectile' then
4119 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
4121 else if cmd
= 'g_weaponstay' then
4123 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
4125 else if cmd
= 'g_allow_exit' then
4127 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
4129 else if cmd
= 'g_allow_monsters' then
4131 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
4133 else if cmd
= 'g_allow_dropflag' then
4135 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
4137 else if cmd
= 'g_throw_flag' then
4139 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
4141 else if cmd
= 'g_bot_vsplayers' then
4143 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4145 else if cmd
= 'g_bot_vsmonsters' then
4147 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4149 else if cmd
= 'g_dm_keys' then
4151 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4153 else if cmd
= 'g_gameflags' then
4155 if Length(P
) > 1 then
4157 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4158 if g_Game_IsServer
then
4160 gGameSettings
.Options
:= gsGameFlags
;
4161 if g_Game_IsNet
then MH_SEND_GameSettings
;
4165 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4167 else if cmd
= 'g_warmup_time' then
4169 if Length(P
) > 1 then
4171 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4172 if g_Game_IsServer
then
4174 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4175 // extend warmup if it's already going
4176 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4178 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4179 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4181 if g_Game_IsNet
then MH_SEND_GameSettings
;
4185 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4186 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4188 else if cmd
= 'g_spawn_invul' then
4190 if Length(P
) > 1 then
4192 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4193 if g_Game_IsServer
then
4195 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4196 if g_Game_IsNet
then MH_SEND_GameSettings
;
4200 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4202 else if cmd
= 'g_item_respawn_time' then
4204 if Length(P
) > 1 then
4206 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4207 if g_Game_IsServer
then
4209 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4210 if g_Game_IsNet
then MH_SEND_GameSettings
;
4214 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4215 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4217 else if cmd
= 'sv_intertime' then
4219 if (Length(P
) > 1) then
4220 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4222 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4224 else if cmd
= 'g_max_particles' then
4226 if Length(p
) = 2 then
4228 a
:= Max(0, StrToIntDef(p
[1], 0));
4231 else if Length(p
) = 1 then
4233 e_LogWritefln('%s', [g_GFX_GetMax()])
4237 e_LogWritefln('usage: %s <n>', [cmd
])
4240 else if cmd
= 'g_max_shells' then
4242 if Length(p
) = 2 then
4244 a
:= Max(0, StrToIntDef(p
[1], 0));
4247 else if Length(p
) = 1 then
4249 e_LogWritefln('%s', [g_Shells_GetMax()])
4253 e_LogWritefln('usage: %s <n>', [cmd
])
4256 else if cmd
= 'g_max_gibs' then
4258 if Length(p
) = 2 then
4260 a
:= Max(0, StrToIntDef(p
[1], 0));
4263 else if Length(p
) = 1 then
4265 e_LogWritefln('%s', [g_Gibs_GetMax()])
4269 e_LogWritefln('usage: %s <n>', [cmd
])
4272 else if cmd
= 'g_max_corpses' then
4274 if Length(p
) = 2 then
4276 a
:= Max(0, StrToIntDef(p
[1], 0));
4279 else if Length(p
) = 1 then
4281 e_LogWritefln('%s', [g_Corpses_GetMax()])
4285 e_LogWritefln('usage: %s <n>', [cmd
])
4288 else if cmd
= 'g_force_model' then
4290 if Length(p
) = 2 then
4292 a
:= StrToIntDef(p
[1], 0);
4293 g_Force_Model_Set(a
);
4294 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4296 for a
:= Low(gPlayers
) to High(gPlayers
) do
4298 if (gPlayers
[a
] <> nil) then
4300 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4302 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4304 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4308 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4310 for a
:= Low(gPlayers
) to High(gPlayers
) do
4312 if (gPlayers
[a
] <> nil) then
4314 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4316 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4318 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4324 else if cmd
= 'g_force_model_name' then
4326 if (Length(P
) > 1) then
4328 cmd
:= b_Text_Unformat(P
[1]);
4329 g_Forced_Model_SetName(cmd
);
4330 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4332 for a
:= Low(gPlayers
) to High(gPlayers
) do
4334 if (gPlayers
[a
] <> nil) then
4336 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4338 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4340 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4346 else if cmd
= 'g_scorelimit' then
4348 if Length(P
) > 1 then
4350 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4352 if g_Game_IsServer
then
4355 if gGameSettings
.GameMode
= GM_DM
then
4357 stat
:= g_Player_GetStats();
4359 for a
:= 0 to High(stat
) do
4360 if stat
[a
].Frags
> b
then
4364 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4366 // if someone has a higher score, set it to that instead
4367 gsScoreLimit
:= max(gsScoreLimit
, b
);
4368 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4370 if g_Game_IsNet
then MH_SEND_GameSettings
;
4374 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4376 else if cmd
= 'g_timelimit' then
4378 if Length(P
) > 1 then
4380 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4381 if g_Game_IsServer
then
4383 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4384 if g_Game_IsNet
then MH_SEND_GameSettings
;
4387 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4388 [gsTimeLimit
div 3600,
4389 (gsTimeLimit
div 60) mod 60,
4390 gsTimeLimit
mod 60]));
4392 else if cmd
= 'g_max_bots' then
4394 if Length(P
) > 1 then
4395 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4396 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4398 else if cmd
= 'g_maxlives' then
4400 if Length(P
) > 1 then
4402 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4403 if g_Game_IsServer
then
4405 gGameSettings
.MaxLives
:= gsMaxLives
;
4406 if g_Game_IsNet
then MH_SEND_GameSettings
;
4410 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4414 procedure PlayerSettingsCVars(P
: SSArray
);
4419 function ParseTeam(s
: string): Byte;
4423 'red', '1': result
:= TEAM_RED
;
4424 'blue', '2': result
:= TEAM_BLUE
;
4425 else result
:= TEAM_NONE
;
4429 cmd
:= LowerCase(P
[0]);
4433 if (Length(P
) > 1) then
4435 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4436 if g_Game_IsClient
then
4437 MC_SEND_PlayerSettings
4438 else if gGameOn
and (gPlayer1
<> nil) then
4440 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4441 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4447 if (Length(P
) > 1) then
4449 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4450 if g_Game_IsClient
then
4451 MC_SEND_PlayerSettings
4452 else if gGameOn
and (gPlayer2
<> nil) then
4454 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4455 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4461 if Length(P
) > 3 then
4463 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4464 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4465 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4466 if g_Game_IsClient
then
4467 MC_SEND_PlayerSettings
4468 else if gGameOn
and (gPlayer1
<> nil) then
4470 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4471 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4477 if Length(P
) > 3 then
4479 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4480 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4481 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4482 if g_Game_IsClient
then
4483 MC_SEND_PlayerSettings
4484 else if gGameOn
and (gPlayer2
<> nil) then
4486 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4487 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4493 if (Length(P
) > 1) then
4495 gPlayer1Settings
.Model
:= P
[1];
4496 if g_Game_IsClient
then
4497 MC_SEND_PlayerSettings
4498 else if gGameOn
and (gPlayer1
<> nil) then
4500 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4501 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4502 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4508 if (Length(P
) > 1) then
4510 gPlayer2Settings
.Model
:= P
[1];
4511 if g_Game_IsClient
then
4512 MC_SEND_PlayerSettings
4513 else if gGameOn
and (gPlayer2
<> nil) then
4515 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4516 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4517 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4523 // TODO: switch teams if in game or store this separately
4524 if (Length(P
) > 1) then
4526 team
:= ParseTeam(P
[1]);
4527 if team
= TEAM_NONE
then
4528 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4529 else if not gGameOn
and not g_Game_IsNet
then
4530 gPlayer1Settings
.Team
:= team
4532 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4537 // TODO: switch teams if in game or store this separately
4538 if (Length(P
) > 1) then
4540 team
:= ParseTeam(P
[1]);
4541 if team
= TEAM_NONE
then
4542 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4543 else if not gGameOn
and not g_Game_IsNet
then
4544 gPlayer2Settings
.Team
:= team
4546 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4551 if (Length(P
) = 2) then
4552 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4556 if (Length(P
) = 2) then
4557 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4561 if (Length(P
) = 2) then
4562 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4566 if (Length(P
) = 2) then
4567 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4571 if (Length(P
) = 2) then
4572 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4576 if (Length(P
) = 2) then
4577 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4579 'p1_priority_kastet':
4581 if (Length(P
) = 2) then
4582 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4584 'p2_priority_kastet':
4586 if (Length(P
) = 2) then
4587 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4591 if (Length(P
) = 2) then
4592 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4596 if (Length(P
) = 2) then
4597 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4599 'p1_priority_pistol':
4601 if (Length(P
) = 2) then
4602 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4604 'p2_priority_pistol':
4606 if (Length(P
) = 2) then
4607 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4609 'p1_priority_shotgun1':
4611 if (Length(P
) = 2) then
4612 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4614 'p2_priority_shotgun1':
4616 if (Length(P
) = 2) then
4617 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4619 'p1_priority_shotgun2':
4621 if (Length(P
) = 2) then
4622 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4624 'p2_priority_shotgun2':
4626 if (Length(P
) = 2) then
4627 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4629 'p1_priority_chaingun':
4631 if (Length(P
) = 2) then
4632 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4634 'p2_priority_chaingun':
4636 if (Length(P
) = 2) then
4637 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4639 'p1_priority_rocketlauncher':
4641 if (Length(P
) = 2) then
4642 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4644 'p2_priority_rocketlauncher':
4646 if (Length(P
) = 2) then
4647 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4649 'p1_priority_plasma':
4651 if (Length(P
) = 2) then
4652 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4654 'p2_priority_plasma':
4656 if (Length(P
) = 2) then
4657 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4661 if (Length(P
) = 2) then
4662 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4666 if (Length(P
) = 2) then
4667 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4669 'p1_priority_super':
4671 if (Length(P
) = 2) then
4672 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4674 'p2_priority_super':
4676 if (Length(P
) = 2) then
4677 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4679 'p1_priority_flamethrower':
4681 if (Length(P
) = 2) then
4682 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4684 'p2_priority_flamethrower':
4686 if (Length(P
) = 2) then
4687 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4689 'p1_priority_berserk':
4691 if (Length(P
) = 2) then
4692 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4694 'p2_priority_berserk':
4696 if (Length(P
) = 2) then
4697 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4702 procedure PrintHeapStats();
4706 hs
:= GetFPCHeapStatus();
4707 e_LogWriteLn ('v===== heap status =====v');
4708 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4709 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4710 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4711 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4712 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4713 e_LogWriteLn ('^=======================^');
4716 procedure DebugCommands(P
: SSArray
);
4723 // Команды отладочного режима:
4724 if {gDebugMode}conIsCheatsEnabled
then
4726 cmd
:= LowerCase(P
[0]);
4727 if cmd
= 'd_window' then
4729 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4730 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4732 else if cmd
= 'd_sounds' then
4734 if (Length(P
) > 1) and
4735 ((P
[1] = '1') or (P
[1] = '0')) then
4736 g_Debug_Sounds
:= (P
[1][1] = '1');
4738 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4740 else if cmd
= 'd_frames' then
4742 if (Length(P
) > 1) and
4743 ((P
[1] = '1') or (P
[1] = '0')) then
4744 g_Debug_Frames
:= (P
[1][1] = '1');
4746 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4748 else if cmd
= 'd_winmsg' then
4750 if (Length(P
) > 1) and
4751 ((P
[1] = '1') or (P
[1] = '0')) then
4752 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4754 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4756 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4758 if (Length(P
) > 1) and
4759 ((P
[1] = '1') or (P
[1] = '0')) then
4760 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4762 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4764 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4766 if Length(P
) > 1 then
4768 '0': g_debug_BotAIOff
:= 0;
4769 '1': g_debug_BotAIOff
:= 1;
4770 '2': g_debug_BotAIOff
:= 2;
4771 '3': g_debug_BotAIOff
:= 3;
4774 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4776 else if cmd
= 'd_monster' then
4778 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4779 if Length(P
) < 2 then
4781 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4782 g_Console_Add('ID | Name');
4783 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4784 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4785 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4788 a
:= StrToIntDef(P
[1], 0);
4789 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4790 a
:= g_Mons_TypeIdByName(P
[1]);
4792 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4793 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4796 with gPlayer1
.Obj
do
4798 mon
:= g_Monsters_Create(a
,
4799 X
+ Rect
.X
+ (Rect
.Width
div 2),
4800 Y
+ Rect
.Y
+ Rect
.Height
,
4801 gPlayer1
.Direction
, True);
4803 if (Length(P
) > 2) and (mon
<> nil) then
4805 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4806 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4807 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4808 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4809 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4810 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4811 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4812 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4813 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4818 else if (cmd
= 'd_health') then
4820 if (Length(P
) > 1) and
4821 ((P
[1] = '1') or (P
[1] = '0')) then
4822 g_debug_HealthBar
:= (P
[1][1] = '1');
4824 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4826 else if (cmd
= 'd_player') then
4828 if (Length(P
) > 1) and
4829 ((P
[1] = '1') or (P
[1] = '0')) then
4830 g_debug_Player
:= (P
[1][1] = '1');
4832 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4834 else if (cmd
= 'd_mem') then
4840 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4844 procedure GameCheats(P
: SSArray
);
4850 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4852 g_Console_Add('not available');
4858 g_Console_Add('where is the player?!');
4861 cmd
:= LowerCase(P
[0]);
4865 plr
.GodMode
:= not plr
.GodMode
;
4866 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4869 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4870 if cmd
= 'give' then
4872 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4873 for f
:= 1 to High(P
) do
4875 cmd
:= LowerCase(P
[f
]);
4876 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4877 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4878 if cmd
= 'exit' then
4880 if gTriggers
<> nil then
4882 for a
:= 0 to High(gTriggers
) do
4884 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4886 g_Console_Add('player left the map');
4887 gExitByTrigger
:= True;
4888 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4889 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4897 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4898 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4899 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4900 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4901 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4903 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4904 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4906 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4907 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;
4909 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4910 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4912 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4913 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4915 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4916 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4918 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4919 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4920 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4922 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4923 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4924 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4925 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;
4926 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4927 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4929 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;
4930 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;
4931 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;
4932 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;
4933 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;
4934 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;
4936 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4937 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;
4939 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;
4940 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;
4942 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4944 if cmd
= 'ammo' then
4946 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4947 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4948 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4949 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4950 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4951 g_Console_Add('player got some ammo');
4955 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4956 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4958 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4959 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4961 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4962 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4964 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4965 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4967 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4969 if cmd
= 'weapons' then
4971 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4972 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4973 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4974 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4975 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4976 plr
.GiveItem(ITEM_WEAPON_BFG
);
4977 g_Console_Add('player got weapons');
4981 if cmd
= 'keys' then
4983 plr
.GiveItem(ITEM_KEY_RED
);
4984 plr
.GiveItem(ITEM_KEY_GREEN
);
4985 plr
.GiveItem(ITEM_KEY_BLUE
);
4986 g_Console_Add('player got all keys');
4990 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4995 if cmd
= 'open' then
4997 g_Console_Add('player activated sesame');
4998 g_Triggers_OpenAll();
5005 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
5009 if cmd
= 'noclip' then
5012 g_Console_Add('wall hardeness adjusted');
5016 if cmd
= 'notarget' then
5018 plr
.NoTarget
:= not plr
.NoTarget
;
5019 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
5023 if cmd
= 'noreload' then
5025 plr
.NoReload
:= not plr
.NoReload
;
5026 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
5030 if cmd
= 'speedy' then
5032 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
5033 g_Console_Add('speed adjusted');
5037 if cmd
= 'jumpy' then
5039 VEL_JUMP
:= 30-VEL_JUMP
;
5040 g_Console_Add('jump height adjusted');
5044 if cmd
= 'automap' then
5046 gShowMap
:= not gShowMap
;
5047 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
5051 if cmd
= 'aimline' then
5053 gAimLine
:= not gAimLine
;
5054 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
5059 procedure GameCommands(P
: SSArray
);
5065 pl
: pTNetClient
= nil;
5073 cmd
:= LowerCase(P
[0]);
5075 if cmd
= 'pause' then
5077 if (g_ActiveWindow
= nil) then
5078 g_Game_Pause(not gPauseMain
);
5080 else if cmd
= 'endgame' then
5081 gExit
:= EXIT_SIMPLE
5082 else if cmd
= 'restart' then
5084 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5086 if g_Game_IsClient
then
5088 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5093 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5095 else if cmd
= 'kick' then
5097 if g_Game_IsServer
then
5099 if Length(P
) < 2 then
5101 g_Console_Add('kick <name>');
5106 g_Console_Add('kick <name>');
5110 if g_Game_IsNet
then
5111 pl
:= g_Net_Client_ByName(P
[1]);
5114 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5115 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5116 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5117 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5118 g_Net_Slist_ServerPlayerLeaves();
5119 end else if gPlayers
<> nil then
5120 for a
:= Low(gPlayers
) to High(gPlayers
) do
5121 if gPlayers
[a
] <> nil then
5122 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5124 // Не отключать основных игроков в сингле
5125 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5127 gPlayers
[a
].Lives
:= 0;
5128 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5129 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5130 g_Player_Remove(gPlayers
[a
].UID
);
5131 g_Net_Slist_ServerPlayerLeaves();
5132 // Если не перемешать, при добавлении новых ботов появятся старые
5136 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5138 else if cmd
= 'kick_id' then
5140 if g_Game_IsServer
and g_Game_IsNet
then
5142 if Length(P
) < 2 then
5144 g_Console_Add('kick_id <client ID>');
5149 g_Console_Add('kick_id <client ID>');
5153 a
:= StrToIntDef(P
[1], 0);
5154 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5156 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5158 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5159 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
5160 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5161 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5162 g_Net_Slist_ServerPlayerLeaves();
5166 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5168 else if cmd
= 'kick_pid' then
5170 if g_Game_IsServer
and g_Game_IsNet
then
5172 if Length(P
) < 2 then
5174 g_Console_Add('kick_pid <player ID>');
5179 g_Console_Add('kick_pid <player ID>');
5183 a
:= StrToIntDef(P
[1], 0);
5184 pl
:= g_Net_Client_ByPlayer(a
);
5185 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5187 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5188 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5189 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5190 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5191 g_Net_Slist_ServerPlayerLeaves();
5194 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5196 else if cmd
= 'ban' then
5198 if g_Game_IsServer
and g_Game_IsNet
then
5200 if Length(P
) < 2 then
5202 g_Console_Add('ban <name>');
5207 g_Console_Add('ban <name>');
5211 pl
:= g_Net_Client_ByName(P
[1]);
5214 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5215 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5216 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5217 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5218 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5219 g_Net_Slist_ServerPlayerLeaves();
5221 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5223 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5225 else if cmd
= 'ban_id' then
5227 if g_Game_IsServer
and g_Game_IsNet
then
5229 if Length(P
) < 2 then
5231 g_Console_Add('ban_id <client ID>');
5236 g_Console_Add('ban_id <client ID>');
5240 a
:= StrToIntDef(P
[1], 0);
5241 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5242 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5244 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5245 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5246 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5247 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5248 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5249 g_Net_Slist_ServerPlayerLeaves();
5252 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5254 else if cmd
= 'ban_pid' then
5256 if g_Game_IsServer
and g_Game_IsNet
then
5258 if Length(P
) < 2 then
5260 g_Console_Add('ban_pid <player ID>');
5265 g_Console_Add('ban_pid <player ID>');
5269 a
:= StrToIntDef(P
[1], 0);
5270 pl
:= g_Net_Client_ByPlayer(a
);
5271 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5273 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5274 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5275 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5276 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5277 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5278 g_Net_Slist_ServerPlayerLeaves();
5281 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5283 else if cmd
= 'permban' then
5285 if g_Game_IsServer
and g_Game_IsNet
then
5287 if Length(P
) < 2 then
5289 g_Console_Add('permban <name>');
5294 g_Console_Add('permban <name>');
5298 pl
:= g_Net_Client_ByName(P
[1]);
5301 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5302 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5303 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5304 g_Net_SaveBanList();
5305 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5306 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5307 g_Net_Slist_ServerPlayerLeaves();
5309 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5311 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5313 else if cmd
= 'permban_id' then
5315 if g_Game_IsServer
and g_Game_IsNet
then
5317 if Length(P
) < 2 then
5319 g_Console_Add('permban_id <client ID>');
5324 g_Console_Add('permban_id <client ID>');
5328 a
:= StrToIntDef(P
[1], 0);
5329 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5330 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5332 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5333 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5334 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5335 g_Net_SaveBanList();
5336 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5337 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5338 g_Net_Slist_ServerPlayerLeaves();
5341 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5343 else if cmd
= 'permban_pid' then
5345 if g_Game_IsServer
and g_Game_IsNet
then
5347 if Length(P
) < 2 then
5349 g_Console_Add('permban_pid <player ID>');
5354 g_Console_Add('permban_pid <player ID>');
5358 a
:= StrToIntDef(P
[1], 0);
5359 pl
:= g_Net_Client_ByPlayer(a
);
5360 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5362 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5363 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5364 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5365 g_Net_SaveBanList();
5366 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5367 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5368 g_Net_Slist_ServerPlayerLeaves();
5371 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5373 else if cmd
= 'permban_ip' then
5375 if g_Game_IsServer
and g_Game_IsNet
then
5377 if Length(P
) < 2 then
5379 g_Console_Add('permban_ip <IP address>');
5384 g_Console_Add('permban_ip <IP address>');
5388 g_Net_BanHost(P
[1]);
5389 g_Net_SaveBanList();
5390 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5392 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5394 else if cmd
= 'unban' then
5396 if g_Game_IsServer
and g_Game_IsNet
then
5398 if Length(P
) < 2 then
5400 g_Console_Add('unban <IP Address>');
5405 g_Console_Add('unban <IP Address>');
5409 if g_Net_UnbanHost(P
[1]) then
5411 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5412 g_Net_SaveBanList();
5414 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5416 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5418 else if cmd
= 'clientlist' then
5420 if g_Game_IsServer
and g_Game_IsNet
then
5423 if NetClients
<> nil then
5424 for a
:= Low(NetClients
) to High(NetClients
) do
5425 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5427 plr
:= g_Player_Get(NetClients
[a
].Player
);
5428 if plr
= nil then continue
;
5430 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5431 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5434 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5436 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5438 else if cmd
= 'connect' then
5440 if (NetMode
= NET_NONE
) then
5442 if Length(P
) < 2 then
5444 g_Console_Add('connect <IP> [port] [password]');
5449 g_Console_Add('connect <IP> [port] [password]');
5453 if Length(P
) > 2 then
5454 prt
:= StrToIntDef(P
[2], 25666)
5458 if Length(P
) > 3 then
5463 g_Game_StartClient(P
[1], prt
, pw
);
5466 else if cmd
= 'disconnect' then
5468 if (NetMode
= NET_CLIENT
) then
5471 else if cmd
= 'reconnect' then
5473 if (NetMode
= NET_SERVER
) then
5476 if (NetMode
= NET_CLIENT
) then
5479 gExit
:= EXIT_SIMPLE
;
5483 //TODO: Use last successful password to reconnect, instead of ''
5484 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5486 else if (cmd
= 'addbot') or
5487 (cmd
= 'bot_add') then
5489 if Length(P
) > 2 then
5490 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5491 else if Length(P
) > 1 then
5492 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5494 g_Bot_Add(TEAM_NONE
, 2);
5496 else if cmd
= 'bot_addlist' then
5498 if Length(P
) > 1 then
5500 if Length(P
) = 2 then
5501 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5502 else if Length(P
) = 3 then
5503 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5505 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5508 else if cmd
= 'bot_removeall' then
5510 else if cmd
= 'chat' then
5512 if g_Game_IsNet
then
5514 if Length(P
) > 1 then
5516 for a
:= 1 to High(P
) do
5517 chstr
:= chstr
+ P
[a
] + ' ';
5519 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5521 if Length(chstr
) < 1 then
5523 g_Console_Add('chat <text>');
5527 chstr
:= b_Text_Format(chstr
);
5528 if g_Game_IsClient
then
5529 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5531 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5534 g_Console_Add('chat <text>');
5536 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5538 else if cmd
= 'teamchat' then
5540 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5542 if Length(P
) > 1 then
5544 for a
:= 1 to High(P
) do
5545 chstr
:= chstr
+ P
[a
] + ' ';
5547 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5549 if Length(chstr
) < 1 then
5551 g_Console_Add('teamchat <text>');
5555 chstr
:= b_Text_Format(chstr
);
5556 if g_Game_IsClient
then
5557 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5559 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5560 gPlayer1Settings
.Team
);
5563 g_Console_Add('teamchat <text>');
5565 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5567 else if (cmd
= 'an') or (cmd
= 'announce') then
5569 if g_Game_IsNet
then
5571 if Length(P
) > 1 then
5573 for a
:= 1 to High(P
) do
5574 chstr
:= chstr
+ P
[a
] + ' ';
5576 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5578 if Length(chstr
) < 1 then
5580 g_Console_Add('announce <text>');
5584 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5585 if g_Game_IsClient
then
5586 MC_SEND_RCONCommand(chstr
)
5588 g_Console_Process(chstr
, True);
5591 g_Console_Add('announce <text>');
5593 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5595 else if cmd
= 'game' then
5597 if gGameSettings
.GameType
<> GT_NONE
then
5599 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5602 if Length(P
) = 1 then
5604 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5607 // game not started yet, load fist map from some wad
5609 s
:= addWadExtension(P
[1]);
5610 found
:= e_FindResource(AllMapDirs
, s
);
5614 P
[1] := ExpandFileName(P
[1]);
5615 // if map not choosed then set first map
5616 if Length(P
) < 3 then
5619 P
[2] := g_Game_GetFirstMap(P
[1]);
5622 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5624 if g_Map_Exist(s
) then
5628 with gGameSettings
do
5630 Options
:= gsGameFlags
;
5631 GameMode
:= g_Game_TextToMode(gsGameMode
);
5632 if gSwitchGameMode
<> GM_NONE
then
5633 GameMode
:= gSwitchGameMode
;
5634 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5635 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5637 if Length(P
) >= 4 then
5638 b
:= StrToIntDef(P
[3], 1);
5639 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5640 ScoreLimit
, MaxLives
, Options
, b
);
5645 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5647 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5649 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5651 else if cmd
= 'host' then
5653 if gGameSettings
.GameType
<> GT_NONE
then
5655 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5658 if Length(P
) < 4 then
5660 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5663 if not StrToIp(P
[1], listen
) then
5665 prt
:= StrToIntDef(P
[2], 25666);
5667 s
:= addWadExtension(P
[3]);
5668 found
:= e_FindResource(AllMapDirs
, s
);
5672 // get first map in wad, if not specified
5673 if Length(P
) < 5 then
5676 P
[4] := g_Game_GetFirstMap(P
[1]);
5678 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5679 if g_Map_Exist(s
) then
5683 with gGameSettings
do
5685 Options
:= gsGameFlags
;
5686 GameMode
:= g_Game_TextToMode(gsGameMode
);
5687 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5688 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5689 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5691 if Length(P
) >= 6 then
5692 b
:= StrToIntDef(P
[5], 0);
5693 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5699 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5701 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5706 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5709 else if cmd
= 'map' then
5711 if Length(P
) = 1 then
5713 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5715 g_Console_Add(cmd
+ ' <MAP>');
5716 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5720 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5725 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5727 if Length(P
) < 3 then
5729 // first param is map or wad
5730 s
:= UpperCase(P
[1]);
5731 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5733 gExitByTrigger
:= False;
5736 // already in game, finish current map
5738 gExit
:= EXIT_ENDLEVELCUSTOM
;
5742 // intermission, so change map immediately
5749 found
:= e_FindResource(AllMapDirs
, s
);
5751 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5754 // no such map, found wad
5757 P
[1] := ExpandFileName(pw
);
5758 P
[2] := g_Game_GetFirstMap(P
[1]);
5759 s
:= P
[1] + ':\' + P
[2];
5760 if g_Map_Exist(s
) then
5762 gExitByTrigger
:= False;
5765 // already in game, finish current map
5767 gExit
:= EXIT_ENDLEVELCUSTOM
5771 // intermission, so change map immediately
5778 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5780 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5785 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5791 s
:= addWadExtension(P
[1]);
5792 found
:= e_FindResource(AllMapDirs
, s
);
5796 P
[2] := UpperCase(P
[2]);
5797 s
:= P
[1] + ':\' + P
[2];
5798 if g_Map_Exist(s
) then
5800 gExitByTrigger
:= False;
5804 gExit
:= EXIT_ENDLEVELCUSTOM
5813 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5818 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5824 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5828 else if cmd
= 'nextmap' then
5830 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5832 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5837 if Length(P
) = 1 then
5839 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5841 g_Console_Add(cmd
+ ' <MAP>');
5842 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5847 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5853 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5855 if Length(P
) < 3 then
5857 // first param is map or wad
5858 s
:= UpperCase(P
[1]);
5859 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5862 gExitByTrigger
:= False;
5868 // no such map, found wad
5869 pw
:= addWadExtension(P
[1]);
5870 found
:= e_FindResource(MapDirs
, pw
);
5872 found
:= e_FindResource(WadDirs
, pw
);
5874 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5877 // map not specified, select first map
5879 P
[2] := g_Game_GetFirstMap(P
[1]);
5880 s
:= P
[1] + ':\' + P
[2];
5881 if g_Map_Exist(s
) then
5883 gExitByTrigger
:= False;
5890 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5892 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5897 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5903 // specified two params wad + map
5904 pw
:= addWadExtension(P
[1]);
5905 found
:= e_FindResource(MapDirs
, pw
);
5907 found
:= e_FindResource(MapDirs
, pw
);
5911 P
[2] := UpperCase(P
[2]);
5912 s
:= P
[1] + ':\' + P
[2];
5913 if g_Map_Exist(s
) then
5915 gExitByTrigger
:= False;
5921 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5926 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5932 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5937 if gNextMap
= '' then
5938 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5940 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5944 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5948 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5952 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5954 gExitByTrigger
:= False;
5955 // next map not specified, try to find trigger EXIT
5956 if (gNextMap
= '') and (gTriggers
<> nil) then
5958 for a
:= 0 to High(gTriggers
) do
5960 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5962 gExitByTrigger
:= True;
5963 //gNextMap := gTriggers[a].Data.MapName;
5964 gNextMap
:= gTriggers
[a
].tgcMap
;
5969 if gNextMap
= '' then
5970 gNextMap
:= g_Game_GetNextMap();
5971 if not isWadPath(gNextMap
) then
5972 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5975 if g_Map_Exist(s
) then
5976 gExit
:= EXIT_ENDLEVELCUSTOM
5978 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5982 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5986 else if (cmd
= 'event') then
5988 if (Length(P
) <= 1) then
5990 for a
:= 0 to High(gEvents
) do
5991 if gEvents
[a
].Command
= '' then
5992 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5994 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5997 if (Length(P
) = 2) then
5999 for a
:= 0 to High(gEvents
) do
6000 if gEvents
[a
].Name
= P
[1] then
6001 if gEvents
[a
].Command
= '' then
6002 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6004 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6007 for a
:= 0 to High(gEvents
) do
6008 if gEvents
[a
].Name
= P
[1] then
6010 gEvents
[a
].Command
:= '';
6011 for b
:= 2 to High(P
) do
6012 if Pos(' ', P
[b
]) = 0 then
6013 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6015 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6016 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6020 else if cmd
= 'suicide' then
6024 if g_Game_IsClient
then
6025 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6028 if gPlayer1
<> nil then
6029 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6030 if gPlayer2
<> nil then
6031 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6035 else if cmd
= 'screenshot' then
6039 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
6041 a
:= 1 - (ord(cmd
[5]) - ord('n'));
6043 gWeaponAction
[0, WP_PREV
] := True;
6045 gWeaponAction
[0, WP_NEXT
] := True;
6047 else if cmd
= 'weapon' then
6049 if Length(p
) = 2 then
6051 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
6052 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6053 gSelectWeapon
[0, a
] := True
6056 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
6057 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
6059 a
:= 1 - (ord(cmd
[8]) - ord('n'));
6060 b
:= ord(cmd
[2]) - ord('1');
6062 gWeaponAction
[b
, WP_PREV
] := True;
6064 gWeaponAction
[b
, WP_NEXT
] := True;
6066 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
6068 if Length(p
) = 2 then
6070 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
6071 b
:= ord(cmd
[2]) - ord('1');
6072 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6073 gSelectWeapon
[b
, a
] := True
6076 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
6078 b
:= ord(cmd
[2]) - ord('1');
6080 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
6082 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
6084 else if (cmd
= 'dropflag') then
6086 if g_Game_IsServer
then
6088 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
6089 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
6092 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6094 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
6096 b
:= ord(cmd
[2]) - ord('1');
6097 if g_Game_IsServer
then
6099 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
6100 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
6103 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6105 // Команды Своей игры:
6106 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6108 if cmd
= 'bot_addred' then
6110 if Length(P
) > 1 then
6111 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6113 g_Bot_Add(TEAM_RED
, 2);
6115 else if cmd
= 'bot_addblue' then
6117 if Length(P
) > 1 then
6118 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6120 g_Bot_Add(TEAM_BLUE
, 2);
6122 else if cmd
= 'spectate' then
6128 else if cmd
= 'say' then
6130 if g_Game_IsServer
and g_Game_IsNet
then
6132 if Length(P
) > 1 then
6135 for a
:= 1 to High(P
) do
6136 chstr
:= chstr
+ P
[a
] + ' ';
6138 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6140 if Length(chstr
) < 1 then
6142 g_Console_Add('say <text>');
6146 chstr
:= b_Text_Format(chstr
);
6147 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6149 else g_Console_Add('say <text>');
6151 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6153 else if cmd
= 'tell' then
6155 if g_Game_IsServer
and g_Game_IsNet
then
6157 if (Length(P
) > 2) and (P
[1] <> '') then
6160 for a
:= 2 to High(P
) do
6161 chstr
:= chstr
+ P
[a
] + ' ';
6163 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6165 if Length(chstr
) < 1 then
6167 g_Console_Add('tell <playername> <text>');
6171 pl
:= g_Net_Client_ByName(P
[1]);
6173 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6175 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6177 else g_Console_Add('tell <playername> <text>');
6179 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6181 else if cmd
= 'centerprint' then
6183 if (Length(P
) > 2) and (P
[1] <> '') then
6186 for a
:= 2 to High(P
) do
6187 chstr
:= chstr
+ P
[a
] + ' ';
6189 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6191 if Length(chstr
) < 1 then
6193 g_Console_Add('centerprint <timeout> <text>');
6197 a
:= StrToIntDef(P
[1], 100);
6198 chstr
:= b_Text_Format(chstr
);
6199 g_Game_Message(chstr
, a
);
6200 if g_Game_IsNet
and g_Game_IsServer
then
6201 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6203 else g_Console_Add('centerprint <timeout> <text>');
6205 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6207 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6209 // Дополнительное время:
6210 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6212 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6213 [gGameSettings
.TimeLimit
div 3600,
6214 (gGameSettings
.TimeLimit
div 60) mod 60,
6215 gGameSettings
.TimeLimit
mod 60]));
6216 if g_Game_IsNet
then MH_SEND_GameSettings
;
6218 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6220 if (Length(P
) <= 1) then
6221 g_Console_Add('rcon_password <password>')
6223 MC_SEND_RCONPassword(P
[1]);
6225 else if cmd
= 'rcon' then
6227 if g_Game_IsClient
then
6229 if Length(P
) > 1 then
6232 for a
:= 1 to High(P
) do
6233 chstr
:= chstr
+ P
[a
] + ' ';
6235 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6237 if Length(chstr
) < 1 then
6239 g_Console_Add('rcon <command>');
6243 MC_SEND_RCONCommand(chstr
);
6245 else g_Console_Add('rcon <command>');
6248 else if cmd
= 'ready' then
6250 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6251 gLMSRespawnTime
:= gTime
+ 100;
6253 else if (cmd
= 'callvote') and g_Game_IsNet
then
6255 if Length(P
) > 1 then
6258 for a
:= 1 to High(P
) do begin
6259 if a
> 1 then chstr
:= chstr
+ ' ';
6260 chstr
:= chstr
+ P
[a
];
6263 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6265 if Length(chstr
) < 1 then
6267 g_Console_Add('callvote <command>');
6271 if g_Game_IsClient
then
6272 MC_SEND_Vote(True, chstr
)
6274 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6275 g_Console_Process('vote', True);
6278 g_Console_Add('callvote <command>');
6280 else if (cmd
= 'vote') and g_Game_IsNet
then
6282 if g_Game_IsClient
then
6284 else if gVoteInProgress
then
6286 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6287 a
:= Floor((NetClientCount
+1)/2.0) + 1
6289 a
:= Floor(NetClientCount
/2.0) + 1;
6294 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6295 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6301 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6302 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6310 procedure SystemCommands(P
: SSArray
);
6314 cmd
:= LowerCase(P
[0]);
6323 gRC_Width
:= Max(1, gRC_Width
);
6324 gRC_Height
:= Max(1, gRC_Height
);
6325 gBPP
:= Max(1, gBPP
);
6326 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
6327 e_LogWriteln('resolution changed')
6329 e_LogWriteln('resolution not changed');
6330 sys_EnableVSync(gVSync
);
6334 if Length(p
) = 2 then
6336 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6338 gFrameTime
:= 1000 div gMaxFPS
6342 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6346 if Length(p
) = 2 then
6348 gAskLanguage
:= true;
6349 gLanguage
:= LANGUAGE_ENGLISH
;
6350 case LowerCase(p
[1]) of
6353 gAskLanguage
:= false;
6354 gLanguage
:= LANGUAGE_ENGLISH
;
6358 gAskLanguage
:= false;
6359 gLanguage
:= LANGUAGE_RUSSIAN
;
6363 gAskLanguage
:= true;
6364 gLanguage
:= LANGUAGE_ENGLISH
;
6367 g_Language_Set(gLanguage
);
6371 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6377 procedure g_TakeScreenShot(Filename
: string = '');
6378 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
6380 if e_NoGraphics
then Exit
;
6382 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6384 if Filename
= '' then
6387 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6388 Filename
:= 'screenshot-' + date
;
6391 name
:= e_CatPath(dir
, Filename
+ '.png');
6392 s
:= createDiskFile(name
);
6394 e_MakeScreenshot(s
, gWinSizeX
, gWinSizeY
);
6396 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6398 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6403 g_Console_Add('oh shit, i can''t create screenshot!')
6407 procedure g_Game_InGameMenu(Show
: Boolean);
6409 if (g_ActiveWindow
= nil) and Show
then
6411 if gGameSettings
.GameType
= GT_SINGLE
then
6412 g_GUI_ShowWindow('GameSingleMenu')
6415 if g_Game_IsClient
then
6416 g_GUI_ShowWindow('GameClientMenu')
6418 if g_Game_IsNet
then
6419 g_GUI_ShowWindow('GameServerMenu')
6421 g_GUI_ShowWindow('GameCustomMenu');
6423 g_Sound_PlayEx('MENU_OPEN');
6425 // Пауза при меню только в одиночной игре:
6426 if (not g_Game_IsNet
) then
6430 if (g_ActiveWindow
<> nil) and (not Show
) then
6432 // Пауза при меню только в одиночной игре:
6433 if (not g_Game_IsNet
) then
6434 g_Game_Pause(False);
6438 procedure g_Game_Pause (Enable
: Boolean);
6442 if not gGameOn
then exit
;
6444 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6447 gPauseMain
:= Enable
;
6449 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6452 procedure g_Game_HolmesPause (Enable
: Boolean);
6456 if not gGameOn
then exit
;
6457 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6460 gPauseHolmes
:= Enable
;
6462 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6465 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6470 if gTriggers
<> nil then
6471 for i
:= 0 to High(gTriggers
) do
6472 with gTriggers
[i
] do
6473 if (TriggerType
= TRIGGER_SOUND
) and
6475 Sound
.IsPlaying() then
6477 Sound
.Pause(Enable
);
6481 if gPlayers
<> nil then
6482 for i
:= 0 to High(gPlayers
) do
6483 if gPlayers
[i
] <> nil then
6484 gPlayers
[i
].PauseSounds(Enable
);
6487 if gMusic
<> nil then
6488 gMusic
.Pause(Enable
);
6491 procedure g_Game_StopAllSounds(all
: Boolean);
6495 if gTriggers
<> nil then
6496 for i
:= 0 to High(gTriggers
) do
6497 with gTriggers
[i
] do
6498 if (TriggerType
= TRIGGER_SOUND
) and
6502 if gMusic
<> nil then
6509 procedure g_Game_UpdateTriggerSounds
;
6512 if gTriggers
<> nil then
6513 for i
:= 0 to High(gTriggers
) do
6514 with gTriggers
[i
] do
6515 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6516 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6519 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6522 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6527 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6532 if gSpectMode
<> SPECT_PLAYERS
then
6534 if gSpectPID1
= UID
then
6539 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6546 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6551 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6556 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6561 if gSpectMode
<> SPECT_PLAYERS
then
6563 Pl
:= g_Player_Get(gSpectPID1
);
6564 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6569 if gSpectViewTwo
then
6571 Pl
:= g_Player_Get(gSpectPID2
);
6572 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6580 procedure g_Game_Message(Msg
: string; Time
: Word);
6582 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
6583 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
6584 MessageTime
:= Time
;
6587 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6589 punct
: Array[0..13] of String =
6590 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6596 function IsPunctuation(S
: String): Boolean;
6601 if Length(S
) <> 1 then
6603 for i
:= Low(punct
) to High(punct
) do
6604 if S
= punct
[i
] then
6610 function FilterPunctuation(S
: String): String;
6614 for i
:= Low(punct
) to High(punct
) do
6615 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6621 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6623 // remove player name
6624 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6625 // for FullWord check
6626 Text := toLowerCase1251(' ' + Text + ' ');
6627 fpText
:= FilterPunctuation(Text);
6629 for i
:= 0 to Length(gChatSounds
) - 1 do
6632 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6634 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6635 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6637 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6643 gChatSounds
[i
].Sound
.Play();
6649 g_Sound_PlayEx('SOUND_GAME_RADIO');
6652 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6661 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6665 if goodsnd
[a
].IsPlaying() then
6668 goodsnd
[Random(4)].Play();
6671 procedure g_Game_Announce_KillCombo(Param
: Integer);
6678 UID
:= Param
and $FFFF;
6683 Pl
:= g_Player_Get(UID
);
6692 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6696 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6700 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6704 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6712 if not g_Game_IsWatchedPlayer(UID
) then
6715 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6719 if killsnd
[n
].IsPlaying() then
6724 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6732 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6736 if hahasnd
[a
].IsPlaying() then
6739 hahasnd
[Random(3)].Play();
6742 procedure g_Game_StartVote(Command
, Initiator
: string);
6746 if not gVotesEnabled
then Exit
;
6747 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6748 if gVoteInProgress
or gVotePassed
then
6750 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6751 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6754 gVoteInProgress
:= True;
6755 gVotePassed
:= False;
6756 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6759 gVoteCommand
:= Command
;
6761 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6762 Need
:= Floor((NetClientCount
+1)/2.0)+1
6764 Need
:= Floor(NetClientCount
/2.0)+1;
6765 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6766 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6769 procedure g_Game_CheckVote
;
6773 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6774 if not gVoteInProgress
then Exit
;
6776 if (gTime
>= gVoteTimer
) then
6778 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6779 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6781 Need
:= Floor(NetClientCount
/2.0) + 1;
6782 if gVoteCount
>= Need
then
6784 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6785 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6786 gVotePassed
:= True;
6787 gVoteCmdTimer
:= gTime
+ 5000;
6791 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6792 MH_SEND_VoteEvent(NET_VE_FAILED
);
6794 if NetClients
<> nil then
6795 for I
:= Low(NetClients
) to High(NetClients
) do
6796 if NetClients
[i
].Used
then
6797 NetClients
[i
].Voted
:= False;
6798 gVoteInProgress
:= False;
6804 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6805 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6807 Need
:= Floor(NetClientCount
/2.0) + 1;
6808 if gVoteCount
>= Need
then
6810 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6811 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6812 gVoteInProgress
:= False;
6813 gVotePassed
:= True;
6814 gVoteCmdTimer
:= gTime
+ 5000;
6817 if NetClients
<> nil then
6818 for I
:= Low(NetClients
) to High(NetClients
) do
6819 if NetClients
[i
].Used
then
6820 NetClients
[i
].Voted
:= False;
6825 procedure g_Game_LoadMapList(FileName
: string);
6833 if not FileExists(FileName
) then Exit
;
6835 AssignFile(ListFile
, FileName
);
6837 while not EOF(ListFile
) do
6839 ReadLn(ListFile
, s
);
6842 if s
= '' then Continue
;
6844 SetLength(MapList
, Length(MapList
)+1);
6845 MapList
[High(MapList
)] := s
;
6847 CloseFile(ListFile
);
6850 procedure g_Game_SetDebugMode();
6853 // Читы (даже в своей игре):
6857 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6861 if Length(LoadingStat
.Msgs
) = 0 then
6867 begin // Переходим на следующую строку или скроллируем:
6868 if NextMsg
= Length(Msgs
) then
6870 for i
:= 0 to High(Msgs
)-1 do
6871 Msgs
[i
] := Msgs
[i
+1];
6879 Msgs
[NextMsg
-1] := Text;
6883 PBarWasHere
:= false;
6886 g_ActiveWindow
:= nil;
6887 ProcessLoading(True);
6890 procedure g_Game_StepLoading(Value
: Integer = -1);
6902 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6905 ProcessLoading(False);
6910 procedure g_Game_ClearLoading();
6919 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6920 if len
< 1 then len
:= 1;
6921 SetLength(Msgs
, len
);
6922 for len
:= Low(Msgs
) to High(Msgs
) do
6925 PBarWasHere
:= false;
6929 procedure Parse_Params(var pars
: TParamStrValues
);
6936 while i
<= ParamCount
do
6939 if (Length(s
) > 1) and (s
[1] = '-') then
6941 if (Length(s
) > 2) and (s
[2] = '-') then
6942 begin // Одиночный параметр
6943 SetLength(pars
, Length(pars
) + 1);
6944 with pars
[High(pars
)] do
6946 Name
:= LowerCase(s
);
6951 if (i
< ParamCount
) then
6952 begin // Параметр со значением
6954 SetLength(pars
, Length(pars
) + 1);
6955 with pars
[High(pars
)] do
6957 Name
:= LowerCase(s
);
6958 Value
:= LowerCase(ParamStr(i
));
6967 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6972 for i
:= 0 to High(pars
) do
6973 if pars
[i
].Name
= aName
then
6975 Result
:= pars
[i
].Value
;
6980 procedure g_Game_Process_Params();
6982 pars
: TParamStrValues
;
6985 LimT
, LimS
: Integer;
6996 s
:= Find_Param_Value(pars
, '--debug');
6999 g_Game_SetDebugMode();
7000 s
:= Find_Param_Value(pars
, '--netdump');
7005 // Connect when game loads
7006 ip
:= Find_Param_Value(pars
, '-connect');
7010 s
:= Find_Param_Value(pars
, '-port');
7011 if (s
= '') or not TryStrToInt(s
, Port
) then
7014 s
:= Find_Param_Value(pars
, '-pw');
7016 g_Game_StartClient(ip
, Port
, s
);
7020 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
7023 gDefaultMegawadStart
:= s
;
7026 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
7027 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
7029 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
7032 // Start map when game loads:
7033 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
7034 if isWadPath(map
) then
7037 s
:= Find_Param_Value(pars
, '-gm');
7038 GMode
:= g_Game_TextToMode(s
);
7039 if GMode
= GM_NONE
then GMode
:= GM_DM
;
7040 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
7043 s
:= Find_Param_Value(pars
, '-limt');
7044 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
7050 s
:= Find_Param_Value(pars
, '-lims');
7051 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
7057 s
:= Find_Param_Value(pars
, '-lives');
7058 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
7064 s
:= Find_Param_Value(pars
, '-opt');
7068 Opt
:= StrToIntDef(s
, 0);
7071 s
:= Find_Param_Value(pars
, '--close');
7075 // Override map to test:
7076 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
7079 if e_IsValidResourceName(s
) then
7080 e_FindResource(AllMapDirs
, s
);
7081 gTestMap
:= ExpandFileName(s
);
7084 // Delete test map after play:
7085 s
:= Find_Param_Value(pars
, '--testdelete');
7088 //gMapToDelete := MapsDir + map;
7089 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
7093 // Delete temporary WAD after play:
7094 s
:= Find_Param_Value(pars
, '--tempdelete');
7095 if (s
<> '') and (gTestMap
<> '') then
7097 gMapToDelete
:= gTestMap
;
7098 gTempDelete
:= True;
7101 // Number of players:
7102 s
:= Find_Param_Value(pars
, '-pl');
7104 n
:= DEFAULT_PLAYERS
7106 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
7109 s
:= Find_Param_Value(pars
, '-port');
7110 if (s
= '') or not TryStrToInt(s
, Port
) then
7111 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
7113 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
7116 // Execute script when game loads:
7117 s
:= Find_Param_Value(pars
, '-exec');
7120 // if not isWadPath(s) then
7121 // s := GameDir + '/' + s;
7126 if IOResult
<> 0 then
7128 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7129 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7133 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
7134 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7139 if IOResult
<> 0 then
7141 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7142 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7146 if Pos('#', s
) <> 1 then // script comment
7147 g_Console_Process(s
, True);
7158 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7159 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7160 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7161 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7163 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7164 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7165 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7166 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7168 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7169 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7171 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7172 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7174 {$IFDEF ENABLE_HOLMES}
7175 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7178 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7180 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7181 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7183 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7184 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7186 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
7187 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
7188 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
7189 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
7190 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7191 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7192 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7193 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7194 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');