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_MODELS
], 0, False);
1492 // load models from all possible wad types, in all known directories
1493 // this does a loosy job (linear search, ooph!), but meh
1494 for wext
in wadExtensions
do
1496 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1498 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1502 for s
in knownFiles
do
1504 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1512 SetLength(knownFiles
, length(knownFiles
)+1);
1513 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1515 until (FindNext(SR
) <> 0);
1521 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1523 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
);
1524 for s
in knownFiles
do
1526 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1530 gPauseMain
:= false;
1531 gPauseHolmes
:= false;
1534 {e_MouseInfo.Accel := 1.0;}
1536 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1539 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1540 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1541 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1542 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1543 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1545 gMusic
:= TMusic
.Create();
1546 gMusic
.SetByName('MUSIC_MENU');
1549 gGameSettings
.WarmupTime
:= 30;
1551 gState
:= STATE_MENU
;
1553 SetLength(gEvents
, 6);
1554 gEvents
[0].Name
:= 'ongamestart';
1555 gEvents
[1].Name
:= 'ongameend';
1556 gEvents
[2].Name
:= 'onmapstart';
1557 gEvents
[3].Name
:= 'onmapend';
1558 gEvents
[4].Name
:= 'oninter';
1559 gEvents
[5].Name
:= 'onwadend';
1561 sfsGCEnable(); // enable releasing unused volumes
1565 procedure g_Game_Free(freeTextures
: Boolean=true);
1567 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1568 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1570 g_Map_Free(freeTextures
);
1572 g_Player_RemoveAllCorpses();
1574 gGameSettings
.GameType
:= GT_NONE
;
1575 if gGameSettings
.GameMode
= GM_SINGLE
then
1576 gGameSettings
.GameMode
:= GM_DM
;
1577 gSwitchGameMode
:= gGameSettings
.GameMode
;
1580 gExitByTrigger
:= False;
1583 function IsActivePlayer(p
: TPlayer
): Boolean;
1588 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1591 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1597 if gPlayers
= nil then
1601 for a
:= Low(gPlayers
) to High(gPlayers
) do
1602 if IsActivePlayer(gPlayers
[a
]) then
1604 SetLength(ids
, Length(ids
) + 1);
1605 ids
[High(ids
)] := gPlayers
[a
].UID
;
1606 if gPlayers
[a
].UID
= Skip
then
1609 if Length(ids
) = 0 then
1614 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1617 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1623 if gPlayers
= nil then
1627 for a
:= Low(gPlayers
) to High(gPlayers
) do
1628 if IsActivePlayer(gPlayers
[a
]) then
1630 SetLength(ids
, Length(ids
) + 1);
1631 ids
[High(ids
)] := gPlayers
[a
].UID
;
1632 if gPlayers
[a
].UID
= Skip
then
1635 if Length(ids
) = 0 then
1638 Result
:= ids
[Length(ids
) - 1]
1640 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1643 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1649 if gPlayers
= nil then
1653 for a
:= Low(gPlayers
) to High(gPlayers
) do
1654 if IsActivePlayer(gPlayers
[a
]) then
1656 SetLength(ids
, Length(ids
) + 1);
1657 ids
[High(ids
)] := gPlayers
[a
].UID
;
1658 if gPlayers
[a
].UID
= Skip
then
1661 if Length(ids
) = 0 then
1663 if Length(ids
) = 1 then
1668 Result
:= ids
[Random(Length(ids
))];
1670 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1672 Result
:= ids
[Random(Length(ids
))];
1677 function GetRandomSpectMode(Current
: Byte): Byte;
1684 0: Result
:= SPECT_STATS
;
1685 1: Result
:= SPECT_MAPVIEW
;
1686 2: Result
:= SPECT_MAPVIEW
;
1687 3: Result
:= SPECT_PLAYERS
;
1688 4: Result
:= SPECT_PLAYERS
;
1689 5: Result
:= SPECT_PLAYERS
;
1690 6: Result
:= SPECT_PLAYERS
;
1692 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1696 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1702 if (plr
= nil) then exit
;
1703 if (p
= 2) then time
:= 1000 else time
:= 1;
1704 strafeDir
:= MoveButton
shr 4;
1705 MoveButton
:= MoveButton
and $0F;
1707 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1708 MoveButton
:= 1 // Нажата только "Влево"
1709 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1710 MoveButton
:= 2 // Нажата только "Вправо"
1711 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1712 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1714 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1715 if MoveButton
= 1 then
1716 plr
.PressKey(KEY_LEFT
, time
)
1717 else if MoveButton
= 2 then
1718 plr
.PressKey(KEY_RIGHT
, time
);
1720 // if we have "strafe" key, turn off old strafe mechanics
1721 if gPlayerAction
[p
, ACTION_STRAFE
] then
1723 // new strafe mechanics
1724 if (strafeDir
= 0) then
1725 strafeDir
:= MoveButton
; // start strafing
1726 // now set direction according to strafe (reversed)
1727 if (strafeDir
= 2) then
1728 plr
.SetDirection(TDirection
.D_LEFT
)
1729 else if (strafeDir
= 1) then
1730 plr
.SetDirection(TDirection
.D_RIGHT
)
1734 strafeDir
:= 0; // not strafing anymore
1735 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1736 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1737 plr
.SetDirection(TDirection
.D_LEFT
)
1738 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1739 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1740 plr
.SetDirection(TDirection
.D_RIGHT
)
1741 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1742 else if MoveButton
<> 0 then
1743 plr
.SetDirection(TDirection(MoveButton
-1))
1746 // fix movebutton state
1747 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1749 // Остальные клавиши:
1750 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1751 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1752 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1753 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1754 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1756 for i
:= WP_FACT
to WP_LACT
do
1758 if gWeaponAction
[p
, i
] then
1760 plr
.ProcessWeaponAction(i
);
1761 gWeaponAction
[p
, i
] := False
1765 for i
:= WP_FIRST
to WP_LAST
do
1767 if gSelectWeapon
[p
, i
] then
1769 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1770 gSelectWeapon
[p
, i
] := False
1774 // HACK: add dynlight here
1775 if gwin_k8_enable_light_experiments
then
1777 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1779 g_playerLight
:= true;
1781 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1783 g_playerLight
:= false;
1787 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1790 // HACK: don't have a "key was pressed" function
1791 procedure InterReady();
1793 if InterReadyTime
> gTime
then Exit
;
1794 InterReadyTime
:= gTime
+ 3000;
1795 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1798 procedure g_Game_PreUpdate();
1800 // these are in separate PreUpdate functions because they can interact during Update()
1801 // and are synced over the net
1802 // we don't care that much about corpses and gibs
1803 g_Player_PreUpdate();
1804 g_Monsters_PreUpdate();
1805 g_Items_PreUpdate();
1806 g_Weapon_PreUpdate();
1809 procedure g_Game_Update();
1811 Msg
: g_gui
.TMessage
;
1817 function sendMonsPos (mon
: TMonster
): Boolean;
1819 result
:= false; // don't stop
1820 // this will also reset "need-send" flag
1821 if mon
.gncNeedSend
then
1823 MH_SEND_MonsterPos(mon
.UID
);
1825 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1827 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1829 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1831 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1835 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1837 result
:= false; // don't stop
1838 // this will also reset "need-send" flag
1839 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1842 function sendItemPos (it
: PItem
): Boolean;
1844 result
:= false; // don't stop
1847 MH_SEND_ItemPos(it
.myId
);
1848 it
.needSend
:= False;
1853 reliableUpdate
: Boolean;
1858 // Пора выключать игру:
1859 if gExit
= EXIT_QUIT
then
1861 // Игра закончилась - обрабатываем:
1865 if gExit
= EXIT_QUIT
then
1869 // Читаем клавиатуру и джойстик, если окно активно
1870 // no need to, as we'll do it in event handler
1872 // Обновляем консоль (движение и сообщения):
1876 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1878 gExit
:= EXIT_SIMPLE
;
1883 // process master server communications
1884 g_Net_Slist_Pulse();
1887 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1888 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1889 STATE_INTERTEXT
, // Текст между уровнями
1890 STATE_INTERPIC
: // Картинка между уровнями
1892 if g_Game_IsNet
and g_Game_IsServer
then
1894 gInterTime
:= gInterTime
+ GAME_TICK
;
1895 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1896 if a
<> gServInterTime
then
1898 gServInterTime
:= a
;
1899 MH_SEND_TimeSync(gServInterTime
);
1903 if (not g_Game_IsClient
) and
1907 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1908 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1909 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1910 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1912 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1913 and (g_ActiveWindow
= nil)
1915 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1918 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1919 g_Game_StopAllSounds(True);
1921 if gMapOnce
then // Это был тест
1922 gExit
:= EXIT_SIMPLE
1924 if gNextMap
<> '' then // Переходим на следующую карту
1925 g_Game_ChangeMap(gNextMap
)
1926 else // Следующей карты нет
1928 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1930 // Выход в главное меню:
1932 g_GUI_ShowWindow('MainMenu');
1933 gMusic
.SetByName('MUSIC_MENU');
1935 gState
:= STATE_MENU
;
1938 // Финальная картинка:
1939 g_Game_ExecuteEvent('onwadend');
1941 if not gMusic
.SetByName('MUSIC_endmus') then
1942 gMusic
.SetByName('MUSIC_STDENDMUS');
1944 gState
:= STATE_ENDPIC
;
1946 g_Game_ExecuteEvent('ongameend');
1951 else if g_Game_IsClient
and
1954 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1955 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1956 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1957 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1959 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1960 and (g_ActiveWindow
= nil)
1968 if gState
= STATE_INTERTEXT
then
1969 if InterText
.counter
> 0 then
1970 InterText
.counter
:= InterText
.counter
- 1;
1973 STATE_FOLD
: // Затухание экрана
1975 if EndingGameCounter
= 0 then
1977 // Закончился уровень в Своей игре:
1978 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1980 gState
:= STATE_INTERCUSTOM
;
1981 InterReadyTime
:= -1;
1982 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1984 g_Game_ExecuteEvent('onwadend');
1985 if not gMusic
.SetByName('MUSIC_endmus') then
1986 gMusic
.SetByName('MUSIC_STDENDMUS');
1989 gMusic
.SetByName('MUSIC_ROUNDMUS');
1993 else // Закончилась последняя карта в Одиночной игре
1995 gMusic
.SetByName('MUSIC_INTERMUS');
1997 gState
:= STATE_INTERSINGLE
;
2000 g_Game_ExecuteEvent('oninter');
2003 DecMin(EndingGameCounter
, 6, 0);
2006 STATE_ENDPIC
: // Картинка окончания мегаВада
2008 if gMapOnce
then // Это был тест
2010 gExit
:= EXIT_SIMPLE
;
2016 g_Serverlist_Control(slCurrent
, slTable
);
2019 // Статистика по Tab:
2021 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
2024 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
2026 // Время += 28 миллисекунд:
2027 gTime
:= gTime
+ GAME_TICK
;
2029 // Сообщение посередине экрана:
2030 if MessageTime
= 0 then
2032 if MessageTime
> 0 then
2033 MessageTime
:= MessageTime
- 1;
2035 if (g_Game_IsServer
) then
2037 // Был задан лимит времени:
2038 if (gGameSettings
.TimeLimit
> 0) then
2039 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
2040 begin // Он прошел => конец уровня
2045 // Надо респавнить игроков в LMS:
2046 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
2047 g_Game_RestartRound(gLMSSoftSpawn
);
2049 // Проверим результат голосования, если время прошло
2050 if gVoteInProgress
and (gVoteTimer
< gTime
) then
2052 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
2054 g_Console_Process(gVoteCommand
);
2056 gVotePassed
:= False;
2059 // Замеряем время захвата флагов
2060 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2061 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
2062 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2063 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
2065 // Был задан лимит побед:
2066 if (gGameSettings
.ScoreLimit
> 0) then
2070 if gGameSettings
.GameMode
= GM_DM
then
2071 begin // В DM ищем игрока с max фрагами
2072 for i
:= 0 to High(gPlayers
) do
2073 if gPlayers
[i
] <> nil then
2074 if gPlayers
[i
].Frags
> b
then
2075 b
:= gPlayers
[i
].Frags
;
2078 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
2079 begin // В CTF/TDM выбираем команду с наибольшим счетом
2080 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
2083 // Лимит побед набран => конец уровня:
2084 if b
>= gGameSettings
.ScoreLimit
then
2091 // Обрабатываем клавиши игроков:
2092 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
2093 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
2094 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2096 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
2097 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
2098 end // if not console
2101 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
2103 // process weapon switch queue
2107 if (gPlayer1
= nil) and (gPlayer2
= nil) and
2108 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
2110 if not gSpectKeyPress
then
2112 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
2114 // switch spect mode
2116 SPECT_NONE
: ; // not spectator
2118 SPECT_MAPVIEW
: Inc(gSpectMode
);
2119 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
2121 gSpectKeyPress
:= True;
2123 if (gSpectMode
= SPECT_MAPVIEW
)
2124 and (not gSpectAuto
) then
2126 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2127 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
2128 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2129 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
2130 if gPlayerAction
[0, ACTION_LOOKUP
] then
2131 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
2132 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2133 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
2134 if gWeaponAction
[0, WP_PREV
] then
2137 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
2138 gWeaponAction
[0, WP_PREV
] := False;
2140 if gWeaponAction
[0, WP_NEXT
] then
2143 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
2144 gWeaponAction
[0, WP_NEXT
] := False;
2147 if (gSpectMode
= SPECT_PLAYERS
)
2148 and (not gSpectAuto
) then
2150 if gPlayerAction
[0, ACTION_LOOKUP
] then
2153 gSpectViewTwo
:= True;
2154 gSpectKeyPress
:= True;
2156 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
2158 // remove second view
2159 gSpectViewTwo
:= False;
2160 gSpectKeyPress
:= True;
2162 if gPlayerAction
[0, ACTION_MOVELEFT
] then
2164 // prev player (view 1)
2165 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
2166 gSpectKeyPress
:= True;
2168 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
2170 // next player (view 1)
2171 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
2172 gSpectKeyPress
:= True;
2174 if gWeaponAction
[0, WP_PREV
] then
2176 // prev player (view 2)
2177 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
2178 gWeaponAction
[0, WP_PREV
] := False;
2180 if gWeaponAction
[0, WP_NEXT
] then
2182 // next player (view 2)
2183 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
2184 gWeaponAction
[0, WP_NEXT
] := False;
2187 if gPlayerAction
[0, ACTION_ATTACK
] then
2189 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
2192 gSpectAutoNext
:= 0;
2193 gSpectViewTwo
:= False;
2194 gSpectKeyPress
:= True;
2199 gSpectMode
:= SPECT_STATS
;
2200 gSpectAuto
:= False;
2201 gSpectKeyPress
:= True;
2206 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2207 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2208 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2209 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2210 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2211 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
2212 gSpectKeyPress
:= False;
2216 if gSpectMode
= SPECT_MAPVIEW
then
2218 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2220 gSpectAutoNext
:= gTime
2223 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2225 gSpectAutoNext
:= gTime
2229 if gSpectAutoNext
<= gTime
then
2231 if gSpectAutoNext
> 0 then
2233 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2237 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2238 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2239 gSpectAutoStepX
:= Random(9) - 4;
2240 gSpectAutoStepY
:= Random(9) - 4;
2241 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2242 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2243 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2244 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2245 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2246 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2250 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2255 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2256 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2257 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2263 // Обновляем все остальное:
2266 g_Triggers_Update();
2268 g_Monsters_Update();
2270 g_Player_UpdateAll();
2271 g_Player_UpdatePhysicalObjects();
2273 // server: send newly spawned monsters unconditionally
2274 if (gGameSettings
.GameType
= GT_SERVER
) then
2276 if (Length(gMonstersSpawned
) > 0) then
2278 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2279 SetLength(gMonstersSpawned
, 0);
2283 if (gSoundTriggerTime
> 8) then
2285 g_Game_UpdateTriggerSounds();
2286 gSoundTriggerTime
:= 0;
2290 Inc(gSoundTriggerTime
);
2293 if (NetMode
= NET_SERVER
) then
2295 Inc(NetTimeToUpdate
);
2296 Inc(NetTimeToReliable
);
2298 // send monster updates
2299 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2301 // send all monsters (periodic sync)
2302 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2304 for I
:= 0 to High(gPlayers
) do
2306 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2309 g_Mons_ForEach(sendMonsPos
);
2311 // update flags that aren't stationary
2312 if gGameSettings
.GameMode
= GM_CTF
then
2313 for I
:= FLAG_RED
to FLAG_BLUE
do
2314 if gFlags
[I
].NeedSend
then
2316 gFlags
[I
].NeedSend
:= False;
2320 // update items that aren't stationary
2321 g_Items_ForEachAlive(sendItemPos
);
2323 if reliableUpdate
then
2325 NetTimeToReliable
:= 0;
2326 NetTimeToUpdate
:= NetUpdateRate
;
2330 NetTimeToUpdate
:= 0;
2335 // send only mosters with some unexpected changes
2336 g_Mons_ForEach(sendMonsPosUnexpected
);
2339 // send unexpected platform changes
2340 g_Map_NetSendInterestingPanels();
2342 g_Net_Slist_ServerUpdate();
2344 if NetUseMaster then
2346 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2348 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2350 NetTimeToMaster := gTime + NetMasterRate;
2355 else if (NetMode
= NET_CLIENT
) then
2357 MC_SEND_PlayerPos();
2359 end; // if gameOn ...
2361 // Активно окно интерфейса - передаем клавиши ему:
2362 if g_ActiveWindow
<> nil then
2364 w
:= e_GetFirstKeyPressed();
2366 if (w
<> IK_INVALID
) then
2368 Msg
.Msg
:= MESSAGE_DIKEY
;
2370 g_ActiveWindow
.OnMessage(Msg
);
2373 // Если оно от этого не закрылось, то обновляем:
2374 if g_ActiveWindow
<> nil then
2375 g_ActiveWindow
.Update();
2377 // Нужно сменить разрешение:
2378 if gResolutionChange
then
2380 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2381 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2382 gResolutionChange
:= False;
2383 g_ActiveWindow
:= nil;
2386 // Нужно сменить язык:
2387 if gLanguageChange
then
2389 //e_WriteLog('Read language file', MSG_NOTIFY);
2390 //g_Language_Load(DataDir + gLanguage + '.txt');
2391 g_Language_Set(gLanguage
);
2395 gLanguageChange
:= False;
2399 // Горячая клавиша для вызова меню выхода из игры (F10):
2400 if e_KeyPressed(IK_F10
) and
2402 (not gConsoleShow
) and
2403 (g_ActiveWindow
= nil) then
2408 Time
:= sys_GetTicks() {div 1000};
2410 // Обработка отложенных событий:
2411 if gDelayedEvents
<> nil then
2412 for a
:= 0 to High(gDelayedEvents
) do
2413 if gDelayedEvents
[a
].Pending
and
2415 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2416 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2419 case gDelayedEvents
[a
].DEType
of
2421 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2424 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2428 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2429 if g_Game_IsNet
and g_Game_IsServer
then
2430 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2434 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2436 gDelayedEvents
[a
].Pending
:= False;
2439 // Каждую секунду обновляем счетчик обновлений:
2440 UPSCounter
:= UPSCounter
+ 1;
2441 if Time
- UPSTime
>= 1000 then
2450 g_Weapon_AddDynLights();
2451 g_Items_AddDynLights();
2455 procedure g_Game_LoadChatSounds(Resource
: string);
2458 FileName
, Snd
: string;
2460 len
, cnt
, tags
, i
, j
: Integer;
2463 FileName
:= g_ExtractWadName(Resource
);
2465 WAD
:= TWADFile
.Create();
2466 WAD
.ReadFile(FileName
);
2468 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2475 cfg
:= TConfig
.CreateMem(p
, len
);
2476 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2478 SetLength(gChatSounds
, cnt
);
2479 for i
:= 0 to Length(gChatSounds
) - 1 do
2481 gChatSounds
[i
].Sound
:= nil;
2482 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2483 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2484 if (Snd
= '') or (Tags
<= 0) then
2486 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2487 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2488 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2489 SetLength(gChatSounds
[i
].Tags
, tags
);
2490 for j
:= 0 to tags
- 1 do
2491 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2492 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2499 procedure g_Game_FreeChatSounds();
2503 for i
:= 0 to Length(gChatSounds
) - 1 do
2505 gChatSounds
[i
].Sound
.Free();
2506 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2508 SetLength(gChatSounds
, 0);
2512 procedure g_Game_LoadData();
2519 if DataLoaded
then Exit
;
2521 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2523 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2524 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2525 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2526 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2527 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2528 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2529 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2530 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2531 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2532 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2533 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2534 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2535 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2536 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2537 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2540 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2541 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2542 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2543 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2547 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2548 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2549 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2550 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2551 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
2557 hasPBarGfx
:= false;
2561 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2562 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2563 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2564 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2565 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2566 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2567 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2568 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2569 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2570 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2571 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2572 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2573 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2574 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2575 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2576 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2577 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2578 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2579 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2580 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2581 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2582 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2583 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2584 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2585 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2586 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2587 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2588 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2589 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2590 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2591 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2592 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2593 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2594 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2595 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2596 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2597 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2598 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2599 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2601 goodsnd
[0] := TPlayableSound
.Create();
2602 goodsnd
[1] := TPlayableSound
.Create();
2603 goodsnd
[2] := TPlayableSound
.Create();
2604 goodsnd
[3] := TPlayableSound
.Create();
2606 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2607 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2608 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2609 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2611 killsnd
[0] := TPlayableSound
.Create();
2612 killsnd
[1] := TPlayableSound
.Create();
2613 killsnd
[2] := TPlayableSound
.Create();
2614 killsnd
[3] := TPlayableSound
.Create();
2616 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2617 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2618 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2619 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2621 hahasnd
[0] := TPlayableSound
.Create();
2622 hahasnd
[1] := TPlayableSound
.Create();
2623 hahasnd
[2] := TPlayableSound
.Create();
2625 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2626 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2627 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2629 sound_get_flag
[0] := TPlayableSound
.Create();
2630 sound_get_flag
[1] := TPlayableSound
.Create();
2631 sound_lost_flag
[0] := TPlayableSound
.Create();
2632 sound_lost_flag
[1] := TPlayableSound
.Create();
2633 sound_ret_flag
[0] := TPlayableSound
.Create();
2634 sound_ret_flag
[1] := TPlayableSound
.Create();
2635 sound_cap_flag
[0] := TPlayableSound
.Create();
2636 sound_cap_flag
[1] := TPlayableSound
.Create();
2638 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2639 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2640 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2641 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2642 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2643 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2644 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2645 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2647 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2649 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2652 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2653 g_Weapon_LoadData();
2655 g_Monsters_LoadData();
2660 procedure g_Game_Quit();
2662 g_Game_StopAllSounds(True);
2665 g_PlayerModel_FreeData();
2666 g_Texture_DeleteAll();
2667 g_Frames_DeleteAll();
2669 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2672 if NetInitDone
then g_Net_Free
;
2674 // remove map after test
2675 if gMapToDelete
<> '' then
2676 g_Game_DeleteTestMap();
2682 procedure g_Game_FreeData();
2684 if not DataLoaded
then Exit
;
2687 g_Weapon_FreeData();
2688 g_Monsters_FreeData();
2690 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2692 g_Texture_Delete('NOTEXTURE');
2693 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2694 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2695 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2696 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2697 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2698 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2699 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2700 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2701 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2702 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2703 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2704 g_Frames_DeleteByName('FRAMES_TELEPORT');
2705 g_Frames_DeleteByName('FRAMES_PUNCH');
2706 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2707 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2708 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2709 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2710 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2711 g_Sound_Delete('SOUND_GAME_TELEPORT');
2712 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2713 g_Sound_Delete('SOUND_GAME_SECRET');
2714 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2715 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2716 g_Sound_Delete('SOUND_GAME_BULK1');
2717 g_Sound_Delete('SOUND_GAME_BULK2');
2718 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2719 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2720 g_Sound_Delete('SOUND_GAME_BURNING');
2721 g_Sound_Delete('SOUND_GAME_SWITCH1');
2722 g_Sound_Delete('SOUND_GAME_SWITCH0');
2729 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2730 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2731 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2732 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2739 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2740 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2741 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2742 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2748 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2749 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2750 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2752 sound_get_flag
[0].Free();
2753 sound_get_flag
[1].Free();
2754 sound_lost_flag
[0].Free();
2755 sound_lost_flag
[1].Free();
2756 sound_ret_flag
[0].Free();
2757 sound_ret_flag
[1].Free();
2758 sound_cap_flag
[0].Free();
2759 sound_cap_flag
[1].Free();
2761 g_Sound_Delete('SOUND_CTF_GET1');
2762 g_Sound_Delete('SOUND_CTF_GET2');
2763 g_Sound_Delete('SOUND_CTF_LOST1');
2764 g_Sound_Delete('SOUND_CTF_LOST2');
2765 g_Sound_Delete('SOUND_CTF_RETURN1');
2766 g_Sound_Delete('SOUND_CTF_RETURN2');
2767 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2768 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2770 g_Game_FreeChatSounds();
2772 DataLoaded
:= False;
2775 procedure g_FatalError(Text: String);
2777 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2778 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2780 gExit
:= EXIT_SIMPLE
;
2781 if gGameOn
then EndGame
;
2784 procedure g_SimpleError(Text: String);
2786 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2787 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2790 procedure g_Game_SetupScreenSize();
2792 RES_FACTOR
= 4.0 / 3.0;
2798 // Размер экранов игроков:
2799 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2800 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2801 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
2803 gPlayerScreenSize
.Y
:= gScreenHeight
;
2805 // Размер заднего плана:
2806 if BackID
<> DWORD(-1) then
2809 if (gScreenWidth
*s
> gMapInfo
.Width
) or
2810 (gScreenHeight
*s
> gMapInfo
.Height
) then
2812 gBackSize
.X
:= gScreenWidth
;
2813 gBackSize
.Y
:= gScreenHeight
;
2817 e_GetTextureSize(BackID
, @bw
, @bh
);
2818 rf
:= Single(bw
) / Single(bh
);
2819 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
2820 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
2821 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
2822 if (s
< 1.0) then s
:= 1.0;
2823 gBackSize
.X
:= Round(bw
*s
);
2824 gBackSize
.Y
:= Round(bh
*s
);
2829 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
2831 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
2834 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2836 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2837 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2840 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2843 if gPlayer1
= nil then
2845 if g_Game_IsClient
then
2847 if NetPlrUID1
> -1 then
2848 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2852 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2853 Team
:= gPlayer1Settings
.Team
;
2855 // Создание первого игрока:
2856 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2857 gPlayer1Settings
.Color
,
2859 if gPlayer1
= nil then
2860 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2863 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2864 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2865 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2866 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2867 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2868 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2869 if g_Game_IsServer
and g_Game_IsNet
then
2870 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2871 gPlayer1
.Respawn(False, True);
2872 g_Net_Slist_ServerPlayerComes();
2877 if gPlayer2
= nil then
2879 if g_Game_IsClient
then
2881 if NetPlrUID2
> -1 then
2882 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2886 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2887 Team
:= gPlayer2Settings
.Team
;
2889 // Создание второго игрока:
2890 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2891 gPlayer2Settings
.Color
,
2893 if gPlayer2
= nil then
2894 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2897 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2898 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2899 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2900 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2901 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2902 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2903 if g_Game_IsServer
and g_Game_IsNet
then
2904 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2905 gPlayer2
.Respawn(False, True);
2906 g_Net_Slist_ServerPlayerComes();
2913 procedure g_Game_RemovePlayer();
2917 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2918 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2923 if g_Game_IsServer
then
2926 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2927 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2928 g_Player_Remove(Pl
.UID
);
2929 g_Net_Slist_ServerPlayerLeaves();
2933 gSpectLatchPID2
:= Pl
.UID
;
2941 if g_Game_IsServer
then
2944 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2945 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2946 g_Player_Remove(Pl
.UID
);
2947 g_Net_Slist_ServerPlayerLeaves();
2950 gSpectLatchPID1
:= Pl
.UID
;
2952 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2956 g_Net_Slist_ServerPlayerLeaves();
2959 procedure g_Game_Spectate();
2961 g_Game_RemovePlayer();
2962 if gPlayer1
<> nil then
2963 g_Game_RemovePlayer();
2966 procedure g_Game_SpectateCenterView();
2968 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2969 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2972 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2979 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2981 g_Game_ClearLoading();
2984 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2987 gGameSettings
.GameType
:= GT_SINGLE
;
2988 gGameSettings
.MaxLives
:= 0;
2989 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2990 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2991 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2992 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2993 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2994 gSwitchGameMode
:= GM_SINGLE
;
2996 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2997 gLMSRespawnTime
:= 0;
2998 gSpectLatchPID1
:= 0;
2999 gSpectLatchPID2
:= 0;
3001 g_Game_ExecuteEvent('ongamestart');
3003 // Установка размеров окон игроков:
3004 g_Game_SetupScreenSize();
3006 // Создание первого игрока:
3007 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3008 gPlayer1Settings
.Color
,
3009 gPlayer1Settings
.Team
, False));
3010 if gPlayer1
= nil then
3012 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3016 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3017 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3018 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3019 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3020 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3023 // Создание второго игрока, если есть:
3026 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3027 gPlayer2Settings
.Color
,
3028 gPlayer2Settings
.Team
, False));
3029 if gPlayer2
= nil then
3031 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3035 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3036 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3037 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3038 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3039 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3043 // Загрузка и запуск карты:
3044 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
3046 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
3047 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
3051 // Настройки игроков и ботов:
3055 for i
:= nPl
+1 to nPlayers
do
3056 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3059 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3060 TimeLimit
, ScoreLimit
: Word;
3062 Options
: LongWord; nPlayers
: Byte);
3068 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
3070 g_Game_ClearLoading();
3073 gGameSettings
.GameType
:= GT_CUSTOM
;
3074 gGameSettings
.GameMode
:= GameMode
;
3075 gSwitchGameMode
:= GameMode
;
3076 gGameSettings
.TimeLimit
:= TimeLimit
;
3077 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3078 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3079 gGameSettings
.Options
:= Options
;
3081 gCoopTotalMonstersKilled
:= 0;
3082 gCoopTotalSecretsFound
:= 0;
3083 gCoopTotalMonsters
:= 0;
3084 gCoopTotalSecrets
:= 0;
3088 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3089 gLMSRespawnTime
:= 0;
3090 gSpectLatchPID1
:= 0;
3091 gSpectLatchPID2
:= 0;
3093 g_Game_ExecuteEvent('ongamestart');
3095 // Установка размеров окон игроков:
3096 g_Game_SetupScreenSize();
3098 // Режим наблюдателя:
3099 if nPlayers
= 0 then
3106 if nPlayers
>= 1 then
3108 // Создание первого игрока:
3109 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3110 gPlayer1Settings
.Color
,
3111 gPlayer1Settings
.Team
, False));
3112 if gPlayer1
= nil then
3114 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3118 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3119 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3120 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3121 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3122 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3126 if nPlayers
>= 2 then
3128 // Создание второго игрока:
3129 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3130 gPlayer2Settings
.Color
,
3131 gPlayer2Settings
.Team
, False));
3132 if gPlayer2
= nil then
3134 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3138 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3139 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3140 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3141 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3142 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3146 // Загрузка и запуск карты:
3147 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
3149 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3153 // Нет точек появления:
3154 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3155 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3156 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3157 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3158 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3160 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3164 // Настройки игроков и ботов:
3168 for i
:= nPl
+1 to nPlayers
do
3169 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3172 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3173 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
3174 Options
: LongWord; nPlayers
: Byte;
3175 IPAddr
: LongWord; Port
: Word);
3178 g_Net_Slist_ServerClosed();
3180 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
3182 g_Game_ClearLoading();
3187 gGameSettings
.GameType
:= GT_SERVER
;
3188 gGameSettings
.GameMode
:= GameMode
;
3189 gSwitchGameMode
:= GameMode
;
3190 gGameSettings
.TimeLimit
:= TimeLimit
;
3191 gGameSettings
.ScoreLimit
:= ScoreLimit
;
3192 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3193 gGameSettings
.Options
:= Options
;
3195 gCoopTotalMonstersKilled
:= 0;
3196 gCoopTotalSecretsFound
:= 0;
3197 gCoopTotalMonsters
:= 0;
3198 gCoopTotalSecrets
:= 0;
3202 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3203 gLMSRespawnTime
:= 0;
3204 gSpectLatchPID1
:= 0;
3205 gSpectLatchPID2
:= 0;
3207 g_Game_ExecuteEvent('ongamestart');
3209 // Установка размеров окна игрока
3210 g_Game_SetupScreenSize();
3212 // Режим наблюдателя:
3213 if nPlayers
= 0 then
3219 if nPlayers
>= 1 then
3221 // Создание первого игрока:
3222 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3223 gPlayer1Settings
.Color
,
3224 gPlayer1Settings
.Team
, False));
3225 if gPlayer1
= nil then
3227 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3231 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3232 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3233 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3234 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3235 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3238 if nPlayers
>= 2 then
3240 // Создание второго игрока:
3241 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3242 gPlayer2Settings
.Color
,
3243 gPlayer2Settings
.Team
, False));
3244 if gPlayer2
= nil then
3246 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3250 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3251 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
3252 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
3253 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
3254 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
3257 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
3258 if NetForwardPorts
then
3259 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
3262 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3264 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
3268 g_Net_Slist_Set(NetMasterList
);
3270 g_Net_Slist_ServerStarted();
3272 // Загрузка и запуск карты:
3273 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
3275 g_Net_Slist_ServerClosed();
3276 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3280 // Нет точек появления:
3281 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3282 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3283 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3284 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3285 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3287 g_Net_Slist_ServerClosed();
3288 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3292 // Настройки игроков и ботов:
3295 g_Net_Slist_ServerMapStarted();
3296 NetState
:= NET_STATE_GAME
;
3299 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3314 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
3315 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
3317 g_Game_ClearLoading();
3322 gGameSettings
.GameType
:= GT_CLIENT
;
3324 gCoopTotalMonstersKilled
:= 0;
3325 gCoopTotalSecretsFound
:= 0;
3326 gCoopTotalMonsters
:= 0;
3327 gCoopTotalSecrets
:= 0;
3331 g_Game_ExecuteEvent('ongamestart');
3333 // Установка размеров окон игроков:
3334 g_Game_SetupScreenSize();
3336 NetState
:= NET_STATE_AUTH
;
3338 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3340 // create (or update) map/resource databases
3341 g_Res_CreateDatabases(true);
3343 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3344 gLMSRespawnTime
:= 0;
3345 gSpectLatchPID1
:= 0;
3346 gSpectLatchPID2
:= 0;
3349 if not g_Net_Connect(Addr
, Port
) then
3351 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3352 NetState
:= NET_STATE_NONE
;
3356 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3358 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3363 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3364 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3365 // thank you, enet. let's ignore failures altogether then.
3366 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3368 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3370 Ptr
:= NetEvent
.packet
^.data
;
3371 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3373 enet_packet_destroy(NetEvent
.packet
);
3377 InMsg
.ReadLongWord(); // skip size
3378 MID
:= InMsg
.ReadByte();
3380 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3382 NetMyID
:= InMsg
.ReadByte();
3383 NetPlrUID1
:= InMsg
.ReadWord();
3385 WadName
:= InMsg
.ReadString();
3386 Map
:= InMsg
.ReadString();
3388 gWADHash
:= InMsg
.ReadMD5();
3390 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3391 gSwitchGameMode
:= gGameSettings
.GameMode
;
3392 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3393 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3394 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3395 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3396 T
:= InMsg
.ReadLongWord();
3398 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3399 //if newResPath = '' then
3401 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3402 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3403 if newResPath
= '' then
3405 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3406 enet_packet_destroy(NetEvent
.packet
);
3407 NetState
:= NET_STATE_NONE
;
3410 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3412 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3415 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3416 gPlayer1Settings
.Color
,
3417 gPlayer1Settings
.Team
, False));
3419 if gPlayer1
= nil then
3421 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3423 enet_packet_destroy(NetEvent
.packet
);
3424 NetState
:= NET_STATE_NONE
;
3428 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3429 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3430 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3431 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3432 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3433 gPlayer1
.UID
:= NetPlrUID1
;
3434 gPlayer1
.Reset(True);
3436 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3438 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3440 enet_packet_destroy(NetEvent
.packet
);
3441 NetState
:= NET_STATE_NONE
;
3449 enet_packet_destroy(NetEvent
.packet
);
3453 enet_packet_destroy(NetEvent
.packet
);
3457 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3460 if (NetEvent
.data
<= NET_DISC_MAX
) then
3461 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3462 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3469 ProcessLoading(True);
3470 if g_Net_UserRequestExit() then
3479 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3480 NetState
:= NET_STATE_NONE
;
3485 NetState
:= NET_STATE_GAME
;
3486 MC_SEND_FullStateRequest
;
3487 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3491 lastAsMegaWad
: Boolean = false;
3493 procedure g_Game_ChangeMap(const MapPath
: String);
3497 g_Game_ClearLoading();
3499 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3500 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3501 if gExitByTrigger
then
3504 gExitByTrigger
:= False;
3506 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3507 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3510 procedure g_Game_Restart();
3514 if g_Game_IsClient
then
3516 map
:= g_ExtractFileName(gMapInfo
.Map
);
3517 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3521 g_Game_ClearLoading();
3522 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3525 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3527 NewWAD
, ResName
: String;
3531 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3532 g_Player_RemoveAllCorpses();
3534 if (not g_Game_IsClient
) and
3535 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3536 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3538 if gSwitchGameMode
= GM_CTF
then
3539 gGameSettings
.MaxLives
:= 0;
3540 gGameSettings
.GameMode
:= gSwitchGameMode
;
3543 gSwitchGameMode
:= gGameSettings
.GameMode
;
3545 g_Player_ResetTeams();
3547 lastAsMegaWad
:= asMegawad
;
3548 if isWadPath(Map
) then
3550 NewWAD
:= g_ExtractWadName(Map
);
3551 ResName
:= g_ExtractFileName(Map
);
3552 if g_Game_IsServer
then
3554 nws
:= findDiskWad(NewWAD
);
3555 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3558 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3559 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3563 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3564 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3566 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3567 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3569 if (length(nws
) = 0) then
3571 ResName
:= ''; // failed
3576 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3577 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3578 g_Game_LoadWAD(NewWAD
);
3583 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3584 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3589 NewWAD
:= gGameSettings
.WAD
;
3595 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3597 if (ResName
<> '') and (NewWAD
<> '') then
3599 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3600 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3604 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3606 gState
:= STATE_NONE
;
3607 g_ActiveWindow
:= nil;
3611 wNeedTimeReset
:= True;
3613 if gGameSettings
.GameMode
= GM_CTF
then
3615 g_Map_ResetFlag(FLAG_RED
);
3616 g_Map_ResetFlag(FLAG_BLUE
);
3617 // CTF, а флагов нет:
3618 if not g_Map_HaveFlagPoints() then
3619 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3624 gState
:= STATE_MENU
;
3629 gPauseMain
:= false;
3630 gPauseHolmes
:= false;
3631 NetTimeToUpdate
:= 1;
3632 NetTimeToReliable
:= 0;
3633 NetTimeToMaster
:= NetMasterRate
;
3634 gSpectLatchPID1
:= 0;
3635 gSpectLatchPID2
:= 0;
3636 gMissionFailed
:= False;
3639 gCoopMonstersKilled
:= 0;
3640 gCoopSecretsFound
:= 0;
3642 gVoteInProgress
:= False;
3643 gVotePassed
:= False;
3649 if not gGameOn
then Exit
;
3651 g_Game_SpectateCenterView();
3653 if g_Game_IsServer
then
3655 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3657 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3658 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3659 gLMSSoftSpawn
:= True;
3660 if g_Game_IsNet
then
3661 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3665 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3666 gLMSRespawnTime
:= 0;
3670 if NetMode
= NET_SERVER
then
3672 // reset full state flags
3673 if NetClients
<> nil then
3674 for I
:= 0 to High(NetClients
) do
3675 NetClients
[I
].FullUpdateSent
:= False;
3677 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3680 g_Net_Slist_ServerMapStarted();
3682 if NetClients
<> nil then
3683 for I
:= 0 to High(NetClients
) do
3684 if NetClients
[I
].Used
then
3686 NetClients
[I
].Voted
:= False;
3687 if NetClients
[I
].RequestedFullUpdate
then
3689 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3690 NetClients
[I
].RequestedFullUpdate
:= False;
3694 g_Net_UnbanNonPermHosts();
3699 gCoopTotalMonstersKilled
:= 0;
3700 gCoopTotalSecretsFound
:= 0;
3701 gCoopTotalMonsters
:= 0;
3702 gCoopTotalSecrets
:= 0;
3706 g_Game_ExecuteEvent('onmapstart');
3709 procedure SetFirstLevel
;
3713 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3714 if MapList
= nil then
3717 SortSArray(MapList
);
3718 gNextMap
:= MapList
[Low(MapList
)];
3723 procedure g_Game_ExitLevel(const Map
: AnsiString);
3727 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3728 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3729 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3730 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3732 // Вышли в выход в Одиночной игре:
3733 if gGameSettings
.GameType
= GT_SINGLE
then
3734 gExit
:= EXIT_ENDLEVELSINGLE
3735 else // Вышли в выход в Своей игре
3737 gExit
:= EXIT_ENDLEVELCUSTOM
;
3738 if gGameSettings
.GameMode
= GM_COOP
then
3739 g_Player_RememberAll
;
3741 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3744 if gGameSettings
.GameMode
= GM_COOP
then
3747 gStatsPressed
:= True;
3748 gNextMap
:= 'MAP01';
3750 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3753 if g_Game_IsNet
then
3755 MH_SEND_GameStats();
3756 MH_SEND_CoopStats();
3762 procedure g_Game_RestartLevel();
3766 if gGameSettings
.GameMode
= GM_SINGLE
then
3771 gExit
:= EXIT_ENDLEVELCUSTOM
;
3772 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3776 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3778 gWAD
{, xwad}: String;
3781 if not g_Game_IsClient
then Exit
;
3782 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3784 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3789 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3793 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3796 g_Game_LoadWAD(NewWAD
);
3800 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3801 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3804 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3805 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3809 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3813 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3814 g_Game_LoadWAD(NewWAD);
3818 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3820 i
, n
, nb
, nr
: Integer;
3822 if not g_Game_IsServer
then Exit
;
3823 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3824 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3825 gLMSRespawnTime
:= 0;
3828 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3830 gMissionFailed
:= True;
3831 g_Game_RestartLevel
;
3835 n
:= 0; nb
:= 0; nr
:= 0;
3836 for i
:= Low(gPlayers
) to High(gPlayers
) do
3837 if (gPlayers
[i
] <> nil) and
3838 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3839 (gPlayers
[i
] is TBot
)) then
3842 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3843 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3846 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3848 // wait a second until the fuckers finally decide to join
3849 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3850 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3851 gLMSSoftSpawn
:= NoMapRestart
;
3852 if g_Game_IsNet
then
3853 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3857 g_Player_RemoveAllCorpses
;
3858 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3859 if g_Game_IsNet
then
3860 MH_SEND_GameEvent(NET_EV_LMS_START
);
3862 for i
:= Low(gPlayers
) to High(gPlayers
) do
3864 if gPlayers
[i
] = nil then continue
;
3865 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3866 // don't touch normal spectators
3867 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3869 gPlayers
[i
].FNoRespawn
:= True;
3870 gPlayers
[i
].Lives
:= 0;
3871 if g_Game_IsNet
then
3872 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3875 gPlayers
[i
].FNoRespawn
:= False;
3876 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3877 gPlayers
[i
].Respawn(False, True);
3878 if gGameSettings
.GameMode
= GM_COOP
then
3880 gPlayers
[i
].Frags
:= 0;
3881 gPlayers
[i
].RecallState
;
3883 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3884 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3885 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3886 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3889 g_Items_RestartRound();
3891 gLMSSoftSpawn
:= False;
3894 function g_Game_GetFirstMap(WAD
: String): String;
3898 MapList
:= g_Map_GetMapsList(WAD
);
3899 if MapList
= nil then
3902 SortSArray(MapList
);
3903 Result
:= MapList
[Low(MapList
)];
3905 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3911 function g_Game_GetNextMap(): String;
3918 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3919 if MapList
= nil then
3922 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3924 SortSArray(MapList
);
3926 for I
:= Low(MapList
) to High(MapList
) do
3927 if Map
= MapList
[I
] then
3933 if MapIndex
<> -255 then
3935 if MapIndex
= High(MapList
) then
3936 Result
:= MapList
[Low(MapList
)]
3938 Result
:= MapList
[MapIndex
+ 1];
3940 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3946 procedure g_Game_NextLevel();
3948 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3949 gExit
:= EXIT_ENDLEVELCUSTOM
3952 gExit
:= EXIT_ENDLEVELSINGLE
;
3956 if gNextMap
<> '' then Exit
;
3957 gNextMap
:= g_Game_GetNextMap();
3960 function g_Game_IsTestMap(): Boolean;
3962 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3965 procedure g_Game_DeleteTestMap();
3968 //MapName: AnsiString;
3976 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3977 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3978 if (a
= 0) then exit
;
3980 // Выделяем имя wad-файла и имя карты
3981 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3982 Delete(gMapToDelete
, 1, a
+5);
3983 gMapToDelete
:= UpperCase(gMapToDelete
);
3985 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3988 // Имя карты не стандартное тестовое:
3989 if MapName <> TEST_MAP_NAME then
3992 if not gTempDelete then
3994 time := g_GetFileTime(WadName);
3995 WAD := TWADFile.Create();
3998 if not WAD.ReadFile(WadName) then
3999 begin // Нет такого WAD-файла
4004 // Составляем список карт и ищем нужную:
4006 MapList := WAD.GetResourcesList('');
4008 if MapList <> nil then
4009 for a := 0 to High(MapList) do
4010 if MapList[a] = MapName then
4012 // Удаляем и сохраняем:
4013 WAD.RemoveResource('', MapName);
4014 WAD.SaveTo(WadName);
4019 g_SetFileTime(WadName, time);
4022 if gTempDelete
then DeleteFile(WadName
);
4025 procedure GameCVars(P
: SSArray
);
4028 stat
: TPlayerStatArray
;
4031 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
4035 if Length(P
) > 1 then
4040 gsGameFlags
:= gsGameFlags
or Flag
4042 gsGameFlags
:= gsGameFlags
and (not Flag
);
4044 if g_Game_IsServer
then
4047 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
4049 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
4050 if g_Game_IsNet
then MH_SEND_GameSettings
;
4054 if LongBool(gsGameFlags
and Flag
) then
4055 g_Console_Add(_lc
[OnMsg
])
4057 g_Console_Add(_lc
[OffMsg
]);
4059 if OnMapChange
and g_Game_IsServer
then
4060 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4065 cmd
:= LowerCase(P
[0]);
4067 if cmd
= 'g_gamemode' then
4069 if (Length(P
) > 1) then
4071 a
:= g_Game_TextToMode(P
[1]);
4072 if a
= GM_SINGLE
then a
:= GM_COOP
;
4073 gsGameMode
:= g_Game_ModeToText(a
);
4074 if g_Game_IsServer
then
4076 gSwitchGameMode
:= a
;
4077 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4078 (gState
= STATE_INTERSINGLE
) then
4079 gSwitchGameMode
:= GM_SINGLE
;
4081 gGameSettings
.GameMode
:= gSwitchGameMode
;
4085 if gSwitchGameMode
= gGameSettings
.GameMode
then
4086 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4087 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4089 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4090 [g_Game_ModeToText(gGameSettings
.GameMode
),
4091 g_Game_ModeToText(gSwitchGameMode
)]));
4093 else if cmd
= 'g_friendlyfire' then
4095 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
4097 else if cmd
= 'g_friendly_absorb_damage' then
4099 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
4101 else if cmd
= 'g_friendly_hit_trace' then
4103 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
4105 else if cmd
= 'g_friendly_hit_projectile' then
4107 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
4109 else if cmd
= 'g_weaponstay' then
4111 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
4113 else if cmd
= 'g_allow_exit' then
4115 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
4117 else if cmd
= 'g_allow_monsters' then
4119 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
4121 else if cmd
= 'g_allow_dropflag' then
4123 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
4125 else if cmd
= 'g_throw_flag' then
4127 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
4129 else if cmd
= 'g_bot_vsplayers' then
4131 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
4133 else if cmd
= 'g_bot_vsmonsters' then
4135 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
4137 else if cmd
= 'g_dm_keys' then
4139 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
4141 else if cmd
= 'g_gameflags' then
4143 if Length(P
) > 1 then
4145 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
4146 if g_Game_IsServer
then
4148 gGameSettings
.Options
:= gsGameFlags
;
4149 if g_Game_IsNet
then MH_SEND_GameSettings
;
4153 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
4155 else if cmd
= 'g_warmup_time' then
4157 if Length(P
) > 1 then
4159 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
4160 if g_Game_IsServer
then
4162 gGameSettings
.WarmupTime
:= gsWarmupTime
;
4163 // extend warmup if it's already going
4164 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
4166 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
4167 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
4169 if g_Game_IsNet
then MH_SEND_GameSettings
;
4173 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
4174 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4176 else if cmd
= 'g_spawn_invul' then
4178 if Length(P
) > 1 then
4180 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
4181 if g_Game_IsServer
then
4183 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
4184 if g_Game_IsNet
then MH_SEND_GameSettings
;
4188 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
4190 else if cmd
= 'g_item_respawn_time' then
4192 if Length(P
) > 1 then
4194 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
4195 if g_Game_IsServer
then
4197 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
4198 if g_Game_IsNet
then MH_SEND_GameSettings
;
4202 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
4203 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4205 else if cmd
= 'sv_intertime' then
4207 if (Length(P
) > 1) then
4208 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4210 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4212 else if cmd
= 'g_max_particles' then
4214 if Length(p
) = 2 then
4216 a
:= Max(0, StrToIntDef(p
[1], 0));
4219 else if Length(p
) = 1 then
4221 e_LogWritefln('%s', [g_GFX_GetMax()])
4225 e_LogWritefln('usage: %s <n>', [cmd
])
4228 else if cmd
= 'g_max_shells' then
4230 if Length(p
) = 2 then
4232 a
:= Max(0, StrToIntDef(p
[1], 0));
4235 else if Length(p
) = 1 then
4237 e_LogWritefln('%s', [g_Shells_GetMax()])
4241 e_LogWritefln('usage: %s <n>', [cmd
])
4244 else if cmd
= 'g_max_gibs' then
4246 if Length(p
) = 2 then
4248 a
:= Max(0, StrToIntDef(p
[1], 0));
4251 else if Length(p
) = 1 then
4253 e_LogWritefln('%s', [g_Gibs_GetMax()])
4257 e_LogWritefln('usage: %s <n>', [cmd
])
4260 else if cmd
= 'g_max_corpses' then
4262 if Length(p
) = 2 then
4264 a
:= Max(0, StrToIntDef(p
[1], 0));
4267 else if Length(p
) = 1 then
4269 e_LogWritefln('%s', [g_Corpses_GetMax()])
4273 e_LogWritefln('usage: %s <n>', [cmd
])
4276 else if cmd
= 'g_force_model' then
4278 if Length(p
) = 2 then
4280 a
:= StrToIntDef(p
[1], 0);
4281 g_Force_Model_Set(a
);
4282 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4284 for a
:= Low(gPlayers
) to High(gPlayers
) do
4286 if (gPlayers
[a
] <> nil) then
4288 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4290 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4292 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4296 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
4298 for a
:= Low(gPlayers
) to High(gPlayers
) do
4300 if (gPlayers
[a
] <> nil) then
4302 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4304 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4306 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
4312 else if cmd
= 'g_force_model_name' then
4314 if (Length(P
) > 1) then
4316 cmd
:= b_Text_Unformat(P
[1]);
4317 g_Forced_Model_SetName(cmd
);
4318 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
4320 for a
:= Low(gPlayers
) to High(gPlayers
) do
4322 if (gPlayers
[a
] <> nil) then
4324 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
4326 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
4328 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4334 else if cmd
= 'g_scorelimit' then
4336 if Length(P
) > 1 then
4338 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4340 if g_Game_IsServer
then
4343 if gGameSettings
.GameMode
= GM_DM
then
4345 stat
:= g_Player_GetStats();
4347 for a
:= 0 to High(stat
) do
4348 if stat
[a
].Frags
> b
then
4352 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4354 // if someone has a higher score, set it to that instead
4355 gsScoreLimit
:= max(gsScoreLimit
, b
);
4356 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4358 if g_Game_IsNet
then MH_SEND_GameSettings
;
4362 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4364 else if cmd
= 'g_timelimit' then
4366 if Length(P
) > 1 then
4368 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4369 if g_Game_IsServer
then
4371 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4372 if g_Game_IsNet
then MH_SEND_GameSettings
;
4375 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4376 [gsTimeLimit
div 3600,
4377 (gsTimeLimit
div 60) mod 60,
4378 gsTimeLimit
mod 60]));
4380 else if cmd
= 'g_max_bots' then
4382 if Length(P
) > 1 then
4383 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4384 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4386 else if cmd
= 'g_maxlives' then
4388 if Length(P
) > 1 then
4390 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4391 if g_Game_IsServer
then
4393 gGameSettings
.MaxLives
:= gsMaxLives
;
4394 if g_Game_IsNet
then MH_SEND_GameSettings
;
4398 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4402 procedure PlayerSettingsCVars(P
: SSArray
);
4407 function ParseTeam(s
: string): Byte;
4411 'red', '1': result
:= TEAM_RED
;
4412 'blue', '2': result
:= TEAM_BLUE
;
4413 else result
:= TEAM_NONE
;
4417 cmd
:= LowerCase(P
[0]);
4421 if (Length(P
) > 1) then
4423 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4424 if g_Game_IsClient
then
4425 MC_SEND_PlayerSettings
4426 else if gGameOn
and (gPlayer1
<> nil) then
4428 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4429 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4435 if (Length(P
) > 1) then
4437 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4438 if g_Game_IsClient
then
4439 MC_SEND_PlayerSettings
4440 else if gGameOn
and (gPlayer2
<> nil) then
4442 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4443 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4449 if Length(P
) > 3 then
4451 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4452 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4453 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4454 if g_Game_IsClient
then
4455 MC_SEND_PlayerSettings
4456 else if gGameOn
and (gPlayer1
<> nil) then
4458 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4459 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4465 if Length(P
) > 3 then
4467 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4468 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4469 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4470 if g_Game_IsClient
then
4471 MC_SEND_PlayerSettings
4472 else if gGameOn
and (gPlayer2
<> nil) then
4474 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4475 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4481 if (Length(P
) > 1) then
4483 gPlayer1Settings
.Model
:= P
[1];
4484 if g_Game_IsClient
then
4485 MC_SEND_PlayerSettings
4486 else if gGameOn
and (gPlayer1
<> nil) then
4488 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4489 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4490 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4496 if (Length(P
) > 1) then
4498 gPlayer2Settings
.Model
:= P
[1];
4499 if g_Game_IsClient
then
4500 MC_SEND_PlayerSettings
4501 else if gGameOn
and (gPlayer2
<> nil) then
4503 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4504 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4505 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4511 // TODO: switch teams if in game or store this separately
4512 if (Length(P
) > 1) then
4514 team
:= ParseTeam(P
[1]);
4515 if team
= TEAM_NONE
then
4516 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4517 else if not gGameOn
and not g_Game_IsNet
then
4518 gPlayer1Settings
.Team
:= team
4520 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4525 // TODO: switch teams if in game or store this separately
4526 if (Length(P
) > 1) then
4528 team
:= ParseTeam(P
[1]);
4529 if team
= TEAM_NONE
then
4530 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4531 else if not gGameOn
and not g_Game_IsNet
then
4532 gPlayer2Settings
.Team
:= team
4534 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4539 if (Length(P
) = 2) then
4540 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4544 if (Length(P
) = 2) then
4545 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4549 if (Length(P
) = 2) then
4550 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4554 if (Length(P
) = 2) then
4555 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4559 if (Length(P
) = 2) then
4560 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4564 if (Length(P
) = 2) then
4565 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4567 'p1_priority_kastet':
4569 if (Length(P
) = 2) then
4570 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4572 'p2_priority_kastet':
4574 if (Length(P
) = 2) then
4575 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4579 if (Length(P
) = 2) then
4580 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4584 if (Length(P
) = 2) then
4585 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4587 'p1_priority_pistol':
4589 if (Length(P
) = 2) then
4590 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4592 'p2_priority_pistol':
4594 if (Length(P
) = 2) then
4595 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4597 'p1_priority_shotgun1':
4599 if (Length(P
) = 2) then
4600 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4602 'p2_priority_shotgun1':
4604 if (Length(P
) = 2) then
4605 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4607 'p1_priority_shotgun2':
4609 if (Length(P
) = 2) then
4610 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4612 'p2_priority_shotgun2':
4614 if (Length(P
) = 2) then
4615 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4617 'p1_priority_chaingun':
4619 if (Length(P
) = 2) then
4620 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4622 'p2_priority_chaingun':
4624 if (Length(P
) = 2) then
4625 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4627 'p1_priority_rocketlauncher':
4629 if (Length(P
) = 2) then
4630 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4632 'p2_priority_rocketlauncher':
4634 if (Length(P
) = 2) then
4635 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4637 'p1_priority_plasma':
4639 if (Length(P
) = 2) then
4640 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4642 'p2_priority_plasma':
4644 if (Length(P
) = 2) then
4645 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4649 if (Length(P
) = 2) then
4650 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4654 if (Length(P
) = 2) then
4655 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4657 'p1_priority_super':
4659 if (Length(P
) = 2) then
4660 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4662 'p2_priority_super':
4664 if (Length(P
) = 2) then
4665 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4667 'p1_priority_flamethrower':
4669 if (Length(P
) = 2) then
4670 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4672 'p2_priority_flamethrower':
4674 if (Length(P
) = 2) then
4675 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4677 'p1_priority_berserk':
4679 if (Length(P
) = 2) then
4680 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4682 'p2_priority_berserk':
4684 if (Length(P
) = 2) then
4685 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4690 procedure PrintHeapStats();
4694 hs
:= GetFPCHeapStatus();
4695 e_LogWriteLn ('v===== heap status =====v');
4696 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4697 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4698 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4699 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4700 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4701 e_LogWriteLn ('^=======================^');
4704 procedure DebugCommands(P
: SSArray
);
4711 // Команды отладочного режима:
4712 if {gDebugMode}conIsCheatsEnabled
then
4714 cmd
:= LowerCase(P
[0]);
4715 if cmd
= 'd_window' then
4717 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4718 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4720 else if cmd
= 'd_sounds' then
4722 if (Length(P
) > 1) and
4723 ((P
[1] = '1') or (P
[1] = '0')) then
4724 g_Debug_Sounds
:= (P
[1][1] = '1');
4726 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4728 else if cmd
= 'd_frames' then
4730 if (Length(P
) > 1) and
4731 ((P
[1] = '1') or (P
[1] = '0')) then
4732 g_Debug_Frames
:= (P
[1][1] = '1');
4734 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4736 else if cmd
= 'd_winmsg' then
4738 if (Length(P
) > 1) and
4739 ((P
[1] = '1') or (P
[1] = '0')) then
4740 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4742 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4744 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4746 if (Length(P
) > 1) and
4747 ((P
[1] = '1') or (P
[1] = '0')) then
4748 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4750 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4752 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4754 if Length(P
) > 1 then
4756 '0': g_debug_BotAIOff
:= 0;
4757 '1': g_debug_BotAIOff
:= 1;
4758 '2': g_debug_BotAIOff
:= 2;
4759 '3': g_debug_BotAIOff
:= 3;
4762 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4764 else if cmd
= 'd_monster' then
4766 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4767 if Length(P
) < 2 then
4769 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4770 g_Console_Add('ID | Name');
4771 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4772 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4773 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4776 a
:= StrToIntDef(P
[1], 0);
4777 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4778 a
:= g_Mons_TypeIdByName(P
[1]);
4780 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4781 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4784 with gPlayer1
.Obj
do
4786 mon
:= g_Monsters_Create(a
,
4787 X
+ Rect
.X
+ (Rect
.Width
div 2),
4788 Y
+ Rect
.Y
+ Rect
.Height
,
4789 gPlayer1
.Direction
, True);
4791 if (Length(P
) > 2) and (mon
<> nil) then
4793 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4794 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4795 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4796 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4797 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4798 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4799 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4800 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4801 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4806 else if (cmd
= 'd_health') then
4808 if (Length(P
) > 1) and
4809 ((P
[1] = '1') or (P
[1] = '0')) then
4810 g_debug_HealthBar
:= (P
[1][1] = '1');
4812 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4814 else if (cmd
= 'd_player') then
4816 if (Length(P
) > 1) and
4817 ((P
[1] = '1') or (P
[1] = '0')) then
4818 g_debug_Player
:= (P
[1][1] = '1');
4820 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4822 else if (cmd
= 'd_mem') then
4828 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4832 procedure GameCheats(P
: SSArray
);
4838 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4840 g_Console_Add('not available');
4846 g_Console_Add('where is the player?!');
4849 cmd
:= LowerCase(P
[0]);
4853 plr
.GodMode
:= not plr
.GodMode
;
4854 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4857 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4858 if cmd
= 'give' then
4860 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4861 for f
:= 1 to High(P
) do
4863 cmd
:= LowerCase(P
[f
]);
4864 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4865 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4866 if cmd
= 'exit' then
4868 if gTriggers
<> nil then
4870 for a
:= 0 to High(gTriggers
) do
4872 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4874 g_Console_Add('player left the map');
4875 gExitByTrigger
:= True;
4876 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4877 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4885 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4886 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4887 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4888 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4889 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4891 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4892 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4894 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4895 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;
4897 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4898 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4900 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4901 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4903 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4904 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4906 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4907 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4908 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4910 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4911 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4912 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4913 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;
4914 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4915 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4917 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;
4918 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;
4919 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;
4920 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;
4921 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;
4922 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;
4924 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4925 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;
4927 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;
4928 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;
4930 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4932 if cmd
= 'ammo' then
4934 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4935 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4936 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4937 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4938 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4939 g_Console_Add('player got some ammo');
4943 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4944 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4946 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4947 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4949 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4950 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4952 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4953 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4955 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4957 if cmd
= 'weapons' then
4959 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4960 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4961 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4962 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4963 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4964 plr
.GiveItem(ITEM_WEAPON_BFG
);
4965 g_Console_Add('player got weapons');
4969 if cmd
= 'keys' then
4971 plr
.GiveItem(ITEM_KEY_RED
);
4972 plr
.GiveItem(ITEM_KEY_GREEN
);
4973 plr
.GiveItem(ITEM_KEY_BLUE
);
4974 g_Console_Add('player got all keys');
4978 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4983 if cmd
= 'open' then
4985 g_Console_Add('player activated sesame');
4986 g_Triggers_OpenAll();
4993 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4997 if cmd
= 'noclip' then
5000 g_Console_Add('wall hardeness adjusted');
5004 if cmd
= 'notarget' then
5006 plr
.NoTarget
:= not plr
.NoTarget
;
5007 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
5011 if cmd
= 'noreload' then
5013 plr
.NoReload
:= not plr
.NoReload
;
5014 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
5018 if cmd
= 'speedy' then
5020 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
5021 g_Console_Add('speed adjusted');
5025 if cmd
= 'jumpy' then
5027 VEL_JUMP
:= 30-VEL_JUMP
;
5028 g_Console_Add('jump height adjusted');
5032 if cmd
= 'automap' then
5034 gShowMap
:= not gShowMap
;
5035 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
5039 if cmd
= 'aimline' then
5041 gAimLine
:= not gAimLine
;
5042 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
5047 procedure GameCommands(P
: SSArray
);
5053 pl
: pTNetClient
= nil;
5061 cmd
:= LowerCase(P
[0]);
5063 if cmd
= 'pause' then
5065 if (g_ActiveWindow
= nil) then
5066 g_Game_Pause(not gPauseMain
);
5068 else if cmd
= 'endgame' then
5069 gExit
:= EXIT_SIMPLE
5070 else if cmd
= 'restart' then
5072 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5074 if g_Game_IsClient
then
5076 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5081 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5083 else if cmd
= 'kick' then
5085 if g_Game_IsServer
then
5087 if Length(P
) < 2 then
5089 g_Console_Add('kick <name>');
5094 g_Console_Add('kick <name>');
5098 if g_Game_IsNet
then
5099 pl
:= g_Net_Client_ByName(P
[1]);
5102 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5103 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5104 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5105 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5106 g_Net_Slist_ServerPlayerLeaves();
5107 end else if gPlayers
<> nil then
5108 for a
:= Low(gPlayers
) to High(gPlayers
) do
5109 if gPlayers
[a
] <> nil then
5110 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5112 // Не отключать основных игроков в сингле
5113 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5115 gPlayers
[a
].Lives
:= 0;
5116 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5117 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5118 g_Player_Remove(gPlayers
[a
].UID
);
5119 g_Net_Slist_ServerPlayerLeaves();
5120 // Если не перемешать, при добавлении новых ботов появятся старые
5124 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5126 else if cmd
= 'kick_id' then
5128 if g_Game_IsServer
and g_Game_IsNet
then
5130 if Length(P
) < 2 then
5132 g_Console_Add('kick_id <client ID>');
5137 g_Console_Add('kick_id <client ID>');
5141 a
:= StrToIntDef(P
[1], 0);
5142 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5144 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5146 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5147 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
5148 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5149 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5150 g_Net_Slist_ServerPlayerLeaves();
5154 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5156 else if cmd
= 'kick_pid' then
5158 if g_Game_IsServer
and g_Game_IsNet
then
5160 if Length(P
) < 2 then
5162 g_Console_Add('kick_pid <player ID>');
5167 g_Console_Add('kick_pid <player ID>');
5171 a
:= StrToIntDef(P
[1], 0);
5172 pl
:= g_Net_Client_ByPlayer(a
);
5173 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5175 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5176 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
5177 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5178 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5179 g_Net_Slist_ServerPlayerLeaves();
5182 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5184 else if cmd
= 'ban' then
5186 if g_Game_IsServer
and g_Game_IsNet
then
5188 if Length(P
) < 2 then
5190 g_Console_Add('ban <name>');
5195 g_Console_Add('ban <name>');
5199 pl
:= g_Net_Client_ByName(P
[1]);
5202 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5203 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5204 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5205 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5206 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5207 g_Net_Slist_ServerPlayerLeaves();
5209 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5211 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5213 else if cmd
= 'ban_id' then
5215 if g_Game_IsServer
and g_Game_IsNet
then
5217 if Length(P
) < 2 then
5219 g_Console_Add('ban_id <client ID>');
5224 g_Console_Add('ban_id <client ID>');
5228 a
:= StrToIntDef(P
[1], 0);
5229 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5230 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5232 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5233 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5234 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
5235 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5236 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5237 g_Net_Slist_ServerPlayerLeaves();
5240 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5242 else if cmd
= 'ban_pid' then
5244 if g_Game_IsServer
and g_Game_IsNet
then
5246 if Length(P
) < 2 then
5248 g_Console_Add('ban_pid <player ID>');
5253 g_Console_Add('ban_pid <player ID>');
5257 a
:= StrToIntDef(P
[1], 0);
5258 pl
:= g_Net_Client_ByPlayer(a
);
5259 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5261 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5262 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5263 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5264 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5265 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5266 g_Net_Slist_ServerPlayerLeaves();
5269 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5271 else if cmd
= 'permban' then
5273 if g_Game_IsServer
and g_Game_IsNet
then
5275 if Length(P
) < 2 then
5277 g_Console_Add('permban <name>');
5282 g_Console_Add('permban <name>');
5286 pl
:= g_Net_Client_ByName(P
[1]);
5289 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5290 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5291 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
5292 g_Net_SaveBanList();
5293 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5294 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5295 g_Net_Slist_ServerPlayerLeaves();
5297 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5299 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5301 else if cmd
= 'permban_id' then
5303 if g_Game_IsServer
and g_Game_IsNet
then
5305 if Length(P
) < 2 then
5307 g_Console_Add('permban_id <client ID>');
5312 g_Console_Add('permban_id <client ID>');
5316 a
:= StrToIntDef(P
[1], 0);
5317 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5318 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5320 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5321 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5322 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
5323 g_Net_SaveBanList();
5324 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5325 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5326 g_Net_Slist_ServerPlayerLeaves();
5329 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5331 else if cmd
= 'permban_pid' then
5333 if g_Game_IsServer
and g_Game_IsNet
then
5335 if Length(P
) < 2 then
5337 g_Console_Add('permban_pid <player ID>');
5342 g_Console_Add('permban_pid <player ID>');
5346 a
:= StrToIntDef(P
[1], 0);
5347 pl
:= g_Net_Client_ByPlayer(a
);
5348 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5350 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5351 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5352 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5353 g_Net_SaveBanList();
5354 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5355 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5356 g_Net_Slist_ServerPlayerLeaves();
5359 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5361 else if cmd
= 'permban_ip' then
5363 if g_Game_IsServer
and g_Game_IsNet
then
5365 if Length(P
) < 2 then
5367 g_Console_Add('permban_ip <IP address>');
5372 g_Console_Add('permban_ip <IP address>');
5376 g_Net_BanHost(P
[1]);
5377 g_Net_SaveBanList();
5378 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5380 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5382 else if cmd
= 'unban' then
5384 if g_Game_IsServer
and g_Game_IsNet
then
5386 if Length(P
) < 2 then
5388 g_Console_Add('unban <IP Address>');
5393 g_Console_Add('unban <IP Address>');
5397 if g_Net_UnbanHost(P
[1]) then
5399 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5400 g_Net_SaveBanList();
5402 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5404 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5406 else if cmd
= 'clientlist' then
5408 if g_Game_IsServer
and g_Game_IsNet
then
5411 if NetClients
<> nil then
5412 for a
:= Low(NetClients
) to High(NetClients
) do
5413 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5415 plr
:= g_Player_Get(NetClients
[a
].Player
);
5416 if plr
= nil then continue
;
5418 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5419 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5422 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5424 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5426 else if cmd
= 'connect' then
5428 if (NetMode
= NET_NONE
) then
5430 if Length(P
) < 2 then
5432 g_Console_Add('connect <IP> [port] [password]');
5437 g_Console_Add('connect <IP> [port] [password]');
5441 if Length(P
) > 2 then
5442 prt
:= StrToIntDef(P
[2], 25666)
5446 if Length(P
) > 3 then
5451 g_Game_StartClient(P
[1], prt
, pw
);
5454 else if cmd
= 'disconnect' then
5456 if (NetMode
= NET_CLIENT
) then
5459 else if cmd
= 'reconnect' then
5461 if (NetMode
= NET_SERVER
) then
5464 if (NetMode
= NET_CLIENT
) then
5467 gExit
:= EXIT_SIMPLE
;
5471 //TODO: Use last successful password to reconnect, instead of ''
5472 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5474 else if (cmd
= 'addbot') or
5475 (cmd
= 'bot_add') then
5477 if Length(P
) > 2 then
5478 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5479 else if Length(P
) > 1 then
5480 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5482 g_Bot_Add(TEAM_NONE
, 2);
5484 else if cmd
= 'bot_addlist' then
5486 if Length(P
) > 1 then
5488 if Length(P
) = 2 then
5489 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5490 else if Length(P
) = 3 then
5491 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5493 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5496 else if cmd
= 'bot_removeall' then
5498 else if cmd
= 'chat' then
5500 if g_Game_IsNet
then
5502 if Length(P
) > 1 then
5504 for a
:= 1 to High(P
) do
5505 chstr
:= chstr
+ P
[a
] + ' ';
5507 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5509 if Length(chstr
) < 1 then
5511 g_Console_Add('chat <text>');
5515 chstr
:= b_Text_Format(chstr
);
5516 if g_Game_IsClient
then
5517 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5519 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5522 g_Console_Add('chat <text>');
5524 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5526 else if cmd
= 'teamchat' then
5528 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5530 if Length(P
) > 1 then
5532 for a
:= 1 to High(P
) do
5533 chstr
:= chstr
+ P
[a
] + ' ';
5535 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5537 if Length(chstr
) < 1 then
5539 g_Console_Add('teamchat <text>');
5543 chstr
:= b_Text_Format(chstr
);
5544 if g_Game_IsClient
then
5545 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5547 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5548 gPlayer1Settings
.Team
);
5551 g_Console_Add('teamchat <text>');
5553 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5555 else if (cmd
= 'an') or (cmd
= 'announce') then
5557 if g_Game_IsNet
then
5559 if Length(P
) > 1 then
5561 for a
:= 1 to High(P
) do
5562 chstr
:= chstr
+ P
[a
] + ' ';
5564 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5566 if Length(chstr
) < 1 then
5568 g_Console_Add('announce <text>');
5572 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5573 if g_Game_IsClient
then
5574 MC_SEND_RCONCommand(chstr
)
5576 g_Console_Process(chstr
, True);
5579 g_Console_Add('announce <text>');
5581 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5583 else if cmd
= 'game' then
5585 if gGameSettings
.GameType
<> GT_NONE
then
5587 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5590 if Length(P
) = 1 then
5592 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5595 // game not started yet, load fist map from some wad
5597 s
:= addWadExtension(P
[1]);
5598 found
:= e_FindResource(AllMapDirs
, s
);
5602 P
[1] := ExpandFileName(P
[1]);
5603 // if map not choosed then set first map
5604 if Length(P
) < 3 then
5607 P
[2] := g_Game_GetFirstMap(P
[1]);
5610 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5612 if g_Map_Exist(s
) then
5616 with gGameSettings
do
5618 Options
:= gsGameFlags
;
5619 GameMode
:= g_Game_TextToMode(gsGameMode
);
5620 if gSwitchGameMode
<> GM_NONE
then
5621 GameMode
:= gSwitchGameMode
;
5622 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5623 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5625 if Length(P
) >= 4 then
5626 b
:= StrToIntDef(P
[3], 1);
5627 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5628 ScoreLimit
, MaxLives
, Options
, b
);
5633 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5635 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5637 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5639 else if cmd
= 'host' then
5641 if gGameSettings
.GameType
<> GT_NONE
then
5643 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5646 if Length(P
) < 4 then
5648 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5651 if not StrToIp(P
[1], listen
) then
5653 prt
:= StrToIntDef(P
[2], 25666);
5655 s
:= addWadExtension(P
[3]);
5656 found
:= e_FindResource(AllMapDirs
, s
);
5660 // get first map in wad, if not specified
5661 if Length(P
) < 5 then
5664 P
[4] := g_Game_GetFirstMap(P
[1]);
5666 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5667 if g_Map_Exist(s
) then
5671 with gGameSettings
do
5673 Options
:= gsGameFlags
;
5674 GameMode
:= g_Game_TextToMode(gsGameMode
);
5675 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5676 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5677 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5679 if Length(P
) >= 6 then
5680 b
:= StrToIntDef(P
[5], 0);
5681 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5687 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5689 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5694 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5697 else if cmd
= 'map' then
5699 if Length(P
) = 1 then
5701 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5703 g_Console_Add(cmd
+ ' <MAP>');
5704 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5708 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5713 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5715 if Length(P
) < 3 then
5717 // first param is map or wad
5718 s
:= UpperCase(P
[1]);
5719 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5721 gExitByTrigger
:= False;
5724 // already in game, finish current map
5726 gExit
:= EXIT_ENDLEVELCUSTOM
;
5730 // intermission, so change map immediately
5737 found
:= e_FindResource(AllMapDirs
, s
);
5739 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5742 // no such map, found wad
5745 P
[1] := ExpandFileName(pw
);
5746 P
[2] := g_Game_GetFirstMap(P
[1]);
5747 s
:= P
[1] + ':\' + P
[2];
5748 if g_Map_Exist(s
) then
5750 gExitByTrigger
:= False;
5753 // already in game, finish current map
5755 gExit
:= EXIT_ENDLEVELCUSTOM
5759 // intermission, so change map immediately
5766 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5768 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5773 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5779 s
:= addWadExtension(P
[1]);
5780 found
:= e_FindResource(AllMapDirs
, s
);
5784 P
[2] := UpperCase(P
[2]);
5785 s
:= P
[1] + ':\' + P
[2];
5786 if g_Map_Exist(s
) then
5788 gExitByTrigger
:= False;
5792 gExit
:= EXIT_ENDLEVELCUSTOM
5801 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5806 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5812 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5816 else if cmd
= 'nextmap' then
5818 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5820 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5825 if Length(P
) = 1 then
5827 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5829 g_Console_Add(cmd
+ ' <MAP>');
5830 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5835 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5841 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5843 if Length(P
) < 3 then
5845 // first param is map or wad
5846 s
:= UpperCase(P
[1]);
5847 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5850 gExitByTrigger
:= False;
5856 // no such map, found wad
5857 pw
:= addWadExtension(P
[1]);
5858 found
:= e_FindResource(MapDirs
, pw
);
5860 found
:= e_FindResource(WadDirs
, pw
);
5862 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5865 // map not specified, select first map
5867 P
[2] := g_Game_GetFirstMap(P
[1]);
5868 s
:= P
[1] + ':\' + P
[2];
5869 if g_Map_Exist(s
) then
5871 gExitByTrigger
:= False;
5878 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5880 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5885 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5891 // specified two params wad + map
5892 pw
:= addWadExtension(P
[1]);
5893 found
:= e_FindResource(MapDirs
, pw
);
5895 found
:= e_FindResource(MapDirs
, pw
);
5899 P
[2] := UpperCase(P
[2]);
5900 s
:= P
[1] + ':\' + P
[2];
5901 if g_Map_Exist(s
) then
5903 gExitByTrigger
:= False;
5909 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5914 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5920 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5925 if gNextMap
= '' then
5926 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5928 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5932 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5936 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5940 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5942 gExitByTrigger
:= False;
5943 // next map not specified, try to find trigger EXIT
5944 if (gNextMap
= '') and (gTriggers
<> nil) then
5946 for a
:= 0 to High(gTriggers
) do
5948 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5950 gExitByTrigger
:= True;
5951 //gNextMap := gTriggers[a].Data.MapName;
5952 gNextMap
:= gTriggers
[a
].tgcMap
;
5957 if gNextMap
= '' then
5958 gNextMap
:= g_Game_GetNextMap();
5959 if not isWadPath(gNextMap
) then
5960 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5963 if g_Map_Exist(s
) then
5964 gExit
:= EXIT_ENDLEVELCUSTOM
5966 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5970 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5974 else if (cmd
= 'event') then
5976 if (Length(P
) <= 1) then
5978 for a
:= 0 to High(gEvents
) do
5979 if gEvents
[a
].Command
= '' then
5980 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5982 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5985 if (Length(P
) = 2) then
5987 for a
:= 0 to High(gEvents
) do
5988 if gEvents
[a
].Name
= P
[1] then
5989 if gEvents
[a
].Command
= '' then
5990 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5992 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5995 for a
:= 0 to High(gEvents
) do
5996 if gEvents
[a
].Name
= P
[1] then
5998 gEvents
[a
].Command
:= '';
5999 for b
:= 2 to High(P
) do
6000 if Pos(' ', P
[b
]) = 0 then
6001 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6003 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6004 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6008 else if cmd
= 'suicide' then
6012 if g_Game_IsClient
then
6013 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6016 if gPlayer1
<> nil then
6017 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6018 if gPlayer2
<> nil then
6019 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6023 else if cmd
= 'screenshot' then
6027 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
6029 a
:= 1 - (ord(cmd
[5]) - ord('n'));
6031 gWeaponAction
[0, WP_PREV
] := True;
6033 gWeaponAction
[0, WP_NEXT
] := True;
6035 else if cmd
= 'weapon' then
6037 if Length(p
) = 2 then
6039 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
6040 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6041 gSelectWeapon
[0, a
] := True
6044 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
6045 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
6047 a
:= 1 - (ord(cmd
[8]) - ord('n'));
6048 b
:= ord(cmd
[2]) - ord('1');
6050 gWeaponAction
[b
, WP_PREV
] := True;
6052 gWeaponAction
[b
, WP_NEXT
] := True;
6054 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
6056 if Length(p
) = 2 then
6058 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
6059 b
:= ord(cmd
[2]) - ord('1');
6060 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
6061 gSelectWeapon
[b
, a
] := True
6064 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
6066 b
:= ord(cmd
[2]) - ord('1');
6068 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
6070 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
6072 else if (cmd
= 'dropflag') then
6074 if g_Game_IsServer
then
6076 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
6077 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
6080 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6082 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
6084 b
:= ord(cmd
[2]) - ord('1');
6085 if g_Game_IsServer
then
6087 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
6088 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
6091 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
6093 // Команды Своей игры:
6094 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6096 if cmd
= 'bot_addred' then
6098 if Length(P
) > 1 then
6099 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6101 g_Bot_Add(TEAM_RED
, 2);
6103 else if cmd
= 'bot_addblue' then
6105 if Length(P
) > 1 then
6106 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6108 g_Bot_Add(TEAM_BLUE
, 2);
6110 else if cmd
= 'spectate' then
6116 else if cmd
= 'say' then
6118 if g_Game_IsServer
and g_Game_IsNet
then
6120 if Length(P
) > 1 then
6123 for a
:= 1 to High(P
) do
6124 chstr
:= chstr
+ P
[a
] + ' ';
6126 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6128 if Length(chstr
) < 1 then
6130 g_Console_Add('say <text>');
6134 chstr
:= b_Text_Format(chstr
);
6135 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6137 else g_Console_Add('say <text>');
6139 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6141 else if cmd
= 'tell' then
6143 if g_Game_IsServer
and g_Game_IsNet
then
6145 if (Length(P
) > 2) and (P
[1] <> '') then
6148 for a
:= 2 to High(P
) do
6149 chstr
:= chstr
+ P
[a
] + ' ';
6151 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6153 if Length(chstr
) < 1 then
6155 g_Console_Add('tell <playername> <text>');
6159 pl
:= g_Net_Client_ByName(P
[1]);
6161 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6163 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6165 else g_Console_Add('tell <playername> <text>');
6167 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6169 else if cmd
= 'centerprint' then
6171 if (Length(P
) > 2) and (P
[1] <> '') then
6174 for a
:= 2 to High(P
) do
6175 chstr
:= chstr
+ P
[a
] + ' ';
6177 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6179 if Length(chstr
) < 1 then
6181 g_Console_Add('centerprint <timeout> <text>');
6185 a
:= StrToIntDef(P
[1], 100);
6186 chstr
:= b_Text_Format(chstr
);
6187 g_Game_Message(chstr
, a
);
6188 if g_Game_IsNet
and g_Game_IsServer
then
6189 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
6191 else g_Console_Add('centerprint <timeout> <text>');
6193 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6195 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6197 // Дополнительное время:
6198 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6200 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6201 [gGameSettings
.TimeLimit
div 3600,
6202 (gGameSettings
.TimeLimit
div 60) mod 60,
6203 gGameSettings
.TimeLimit
mod 60]));
6204 if g_Game_IsNet
then MH_SEND_GameSettings
;
6206 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6208 if (Length(P
) <= 1) then
6209 g_Console_Add('rcon_password <password>')
6211 MC_SEND_RCONPassword(P
[1]);
6213 else if cmd
= 'rcon' then
6215 if g_Game_IsClient
then
6217 if Length(P
) > 1 then
6220 for a
:= 1 to High(P
) do
6221 chstr
:= chstr
+ P
[a
] + ' ';
6223 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6225 if Length(chstr
) < 1 then
6227 g_Console_Add('rcon <command>');
6231 MC_SEND_RCONCommand(chstr
);
6233 else g_Console_Add('rcon <command>');
6236 else if cmd
= 'ready' then
6238 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6239 gLMSRespawnTime
:= gTime
+ 100;
6241 else if (cmd
= 'callvote') and g_Game_IsNet
then
6243 if Length(P
) > 1 then
6246 for a
:= 1 to High(P
) do begin
6247 if a
> 1 then chstr
:= chstr
+ ' ';
6248 chstr
:= chstr
+ P
[a
];
6251 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6253 if Length(chstr
) < 1 then
6255 g_Console_Add('callvote <command>');
6259 if g_Game_IsClient
then
6260 MC_SEND_Vote(True, chstr
)
6262 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6263 g_Console_Process('vote', True);
6266 g_Console_Add('callvote <command>');
6268 else if (cmd
= 'vote') and g_Game_IsNet
then
6270 if g_Game_IsClient
then
6272 else if gVoteInProgress
then
6274 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6275 a
:= Floor((NetClientCount
+1)/2.0) + 1
6277 a
:= Floor(NetClientCount
/2.0) + 1;
6282 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6283 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6289 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6290 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6298 procedure SystemCommands(P
: SSArray
);
6302 cmd
:= LowerCase(P
[0]);
6311 gRC_Width
:= Max(1, gRC_Width
);
6312 gRC_Height
:= Max(1, gRC_Height
);
6313 gBPP
:= Max(1, gBPP
);
6314 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
6315 e_LogWriteln('resolution changed')
6317 e_LogWriteln('resolution not changed');
6318 sys_EnableVSync(gVSync
);
6322 if Length(p
) = 2 then
6324 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
6326 gFrameTime
:= 1000 div gMaxFPS
6330 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6334 if Length(p
) = 2 then
6336 gAskLanguage
:= true;
6337 gLanguage
:= LANGUAGE_ENGLISH
;
6338 case LowerCase(p
[1]) of
6341 gAskLanguage
:= false;
6342 gLanguage
:= LANGUAGE_ENGLISH
;
6346 gAskLanguage
:= false;
6347 gLanguage
:= LANGUAGE_RUSSIAN
;
6351 gAskLanguage
:= true;
6352 gLanguage
:= LANGUAGE_ENGLISH
;
6355 g_Language_Set(gLanguage
);
6359 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6365 procedure g_TakeScreenShot(Filename
: string = '');
6366 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
6368 if e_NoGraphics
then Exit
;
6370 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6372 if Filename
= '' then
6375 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6376 Filename
:= 'screenshot-' + date
;
6379 name
:= e_CatPath(dir
, Filename
+ '.png');
6380 s
:= createDiskFile(name
);
6382 e_MakeScreenshot(s
, gWinSizeX
, gWinSizeY
);
6384 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6386 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6391 g_Console_Add('oh shit, i can''t create screenshot!')
6395 procedure g_Game_InGameMenu(Show
: Boolean);
6397 if (g_ActiveWindow
= nil) and Show
then
6399 if gGameSettings
.GameType
= GT_SINGLE
then
6400 g_GUI_ShowWindow('GameSingleMenu')
6403 if g_Game_IsClient
then
6404 g_GUI_ShowWindow('GameClientMenu')
6406 if g_Game_IsNet
then
6407 g_GUI_ShowWindow('GameServerMenu')
6409 g_GUI_ShowWindow('GameCustomMenu');
6411 g_Sound_PlayEx('MENU_OPEN');
6413 // Пауза при меню только в одиночной игре:
6414 if (not g_Game_IsNet
) then
6418 if (g_ActiveWindow
<> nil) and (not Show
) then
6420 // Пауза при меню только в одиночной игре:
6421 if (not g_Game_IsNet
) then
6422 g_Game_Pause(False);
6426 procedure g_Game_Pause (Enable
: Boolean);
6430 if not gGameOn
then exit
;
6432 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6435 gPauseMain
:= Enable
;
6437 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6440 procedure g_Game_HolmesPause (Enable
: Boolean);
6444 if not gGameOn
then exit
;
6445 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6448 gPauseHolmes
:= Enable
;
6450 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6453 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6458 if gTriggers
<> nil then
6459 for i
:= 0 to High(gTriggers
) do
6460 with gTriggers
[i
] do
6461 if (TriggerType
= TRIGGER_SOUND
) and
6463 Sound
.IsPlaying() then
6465 Sound
.Pause(Enable
);
6469 if gPlayers
<> nil then
6470 for i
:= 0 to High(gPlayers
) do
6471 if gPlayers
[i
] <> nil then
6472 gPlayers
[i
].PauseSounds(Enable
);
6475 if gMusic
<> nil then
6476 gMusic
.Pause(Enable
);
6479 procedure g_Game_StopAllSounds(all
: Boolean);
6483 if gTriggers
<> nil then
6484 for i
:= 0 to High(gTriggers
) do
6485 with gTriggers
[i
] do
6486 if (TriggerType
= TRIGGER_SOUND
) and
6490 if gMusic
<> nil then
6497 procedure g_Game_UpdateTriggerSounds
;
6500 if gTriggers
<> nil then
6501 for i
:= 0 to High(gTriggers
) do
6502 with gTriggers
[i
] do
6503 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6504 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6507 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6510 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6515 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6520 if gSpectMode
<> SPECT_PLAYERS
then
6522 if gSpectPID1
= UID
then
6527 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6534 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6539 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6544 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6549 if gSpectMode
<> SPECT_PLAYERS
then
6551 Pl
:= g_Player_Get(gSpectPID1
);
6552 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6557 if gSpectViewTwo
then
6559 Pl
:= g_Player_Get(gSpectPID2
);
6560 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6568 procedure g_Game_Message(Msg
: string; Time
: Word);
6570 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
6571 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
6572 MessageTime
:= Time
;
6575 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6577 punct
: Array[0..13] of String =
6578 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6584 function IsPunctuation(S
: String): Boolean;
6589 if Length(S
) <> 1 then
6591 for i
:= Low(punct
) to High(punct
) do
6592 if S
= punct
[i
] then
6598 function FilterPunctuation(S
: String): String;
6602 for i
:= Low(punct
) to High(punct
) do
6603 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6609 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6611 // remove player name
6612 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6613 // for FullWord check
6614 Text := toLowerCase1251(' ' + Text + ' ');
6615 fpText
:= FilterPunctuation(Text);
6617 for i
:= 0 to Length(gChatSounds
) - 1 do
6620 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6622 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6623 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6625 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6631 gChatSounds
[i
].Sound
.Play();
6637 g_Sound_PlayEx('SOUND_GAME_RADIO');
6640 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6649 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6653 if goodsnd
[a
].IsPlaying() then
6656 goodsnd
[Random(4)].Play();
6659 procedure g_Game_Announce_KillCombo(Param
: Integer);
6666 UID
:= Param
and $FFFF;
6671 Pl
:= g_Player_Get(UID
);
6680 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6684 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6688 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6692 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6700 if not g_Game_IsWatchedPlayer(UID
) then
6703 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6707 if killsnd
[n
].IsPlaying() then
6712 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6720 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6724 if hahasnd
[a
].IsPlaying() then
6727 hahasnd
[Random(3)].Play();
6730 procedure g_Game_StartVote(Command
, Initiator
: string);
6734 if not gVotesEnabled
then Exit
;
6735 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6736 if gVoteInProgress
or gVotePassed
then
6738 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6739 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6742 gVoteInProgress
:= True;
6743 gVotePassed
:= False;
6744 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6747 gVoteCommand
:= Command
;
6749 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6750 Need
:= Floor((NetClientCount
+1)/2.0)+1
6752 Need
:= Floor(NetClientCount
/2.0)+1;
6753 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6754 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6757 procedure g_Game_CheckVote
;
6761 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6762 if not gVoteInProgress
then Exit
;
6764 if (gTime
>= gVoteTimer
) then
6766 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6767 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6769 Need
:= Floor(NetClientCount
/2.0) + 1;
6770 if gVoteCount
>= Need
then
6772 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6773 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6774 gVotePassed
:= True;
6775 gVoteCmdTimer
:= gTime
+ 5000;
6779 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6780 MH_SEND_VoteEvent(NET_VE_FAILED
);
6782 if NetClients
<> nil then
6783 for I
:= Low(NetClients
) to High(NetClients
) do
6784 if NetClients
[i
].Used
then
6785 NetClients
[i
].Voted
:= False;
6786 gVoteInProgress
:= False;
6792 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6793 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6795 Need
:= Floor(NetClientCount
/2.0) + 1;
6796 if gVoteCount
>= Need
then
6798 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6799 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6800 gVoteInProgress
:= False;
6801 gVotePassed
:= True;
6802 gVoteCmdTimer
:= gTime
+ 5000;
6805 if NetClients
<> nil then
6806 for I
:= Low(NetClients
) to High(NetClients
) do
6807 if NetClients
[i
].Used
then
6808 NetClients
[i
].Voted
:= False;
6813 procedure g_Game_LoadMapList(FileName
: string);
6821 if not FileExists(FileName
) then Exit
;
6823 AssignFile(ListFile
, FileName
);
6825 while not EOF(ListFile
) do
6827 ReadLn(ListFile
, s
);
6830 if s
= '' then Continue
;
6832 SetLength(MapList
, Length(MapList
)+1);
6833 MapList
[High(MapList
)] := s
;
6835 CloseFile(ListFile
);
6838 procedure g_Game_SetDebugMode();
6841 // Читы (даже в своей игре):
6845 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6849 if Length(LoadingStat
.Msgs
) = 0 then
6855 begin // Переходим на следующую строку или скроллируем:
6856 if NextMsg
= Length(Msgs
) then
6858 for i
:= 0 to High(Msgs
)-1 do
6859 Msgs
[i
] := Msgs
[i
+1];
6867 Msgs
[NextMsg
-1] := Text;
6871 PBarWasHere
:= false;
6874 g_ActiveWindow
:= nil;
6875 ProcessLoading(True);
6878 procedure g_Game_StepLoading(Value
: Integer = -1);
6890 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6893 ProcessLoading(False);
6898 procedure g_Game_ClearLoading();
6907 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6908 if len
< 1 then len
:= 1;
6909 SetLength(Msgs
, len
);
6910 for len
:= Low(Msgs
) to High(Msgs
) do
6913 PBarWasHere
:= false;
6917 procedure Parse_Params(var pars
: TParamStrValues
);
6924 while i
<= ParamCount
do
6927 if (Length(s
) > 1) and (s
[1] = '-') then
6929 if (Length(s
) > 2) and (s
[2] = '-') then
6930 begin // Одиночный параметр
6931 SetLength(pars
, Length(pars
) + 1);
6932 with pars
[High(pars
)] do
6934 Name
:= LowerCase(s
);
6939 if (i
< ParamCount
) then
6940 begin // Параметр со значением
6942 SetLength(pars
, Length(pars
) + 1);
6943 with pars
[High(pars
)] do
6945 Name
:= LowerCase(s
);
6946 Value
:= LowerCase(ParamStr(i
));
6955 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6960 for i
:= 0 to High(pars
) do
6961 if pars
[i
].Name
= aName
then
6963 Result
:= pars
[i
].Value
;
6968 procedure g_Game_Process_Params();
6970 pars
: TParamStrValues
;
6973 LimT
, LimS
: Integer;
6984 s
:= Find_Param_Value(pars
, '--debug');
6987 g_Game_SetDebugMode();
6988 s
:= Find_Param_Value(pars
, '--netdump');
6993 // Connect when game loads
6994 ip
:= Find_Param_Value(pars
, '-connect');
6998 s
:= Find_Param_Value(pars
, '-port');
6999 if (s
= '') or not TryStrToInt(s
, Port
) then
7002 s
:= Find_Param_Value(pars
, '-pw');
7004 g_Game_StartClient(ip
, Port
, s
);
7008 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
7011 gDefaultMegawadStart
:= s
;
7014 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
7015 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
7017 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
7020 // Start map when game loads:
7021 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
7022 if isWadPath(map
) then
7025 s
:= Find_Param_Value(pars
, '-gm');
7026 GMode
:= g_Game_TextToMode(s
);
7027 if GMode
= GM_NONE
then GMode
:= GM_DM
;
7028 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
7031 s
:= Find_Param_Value(pars
, '-limt');
7032 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
7038 s
:= Find_Param_Value(pars
, '-lims');
7039 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
7045 s
:= Find_Param_Value(pars
, '-lives');
7046 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
7052 s
:= Find_Param_Value(pars
, '-opt');
7056 Opt
:= StrToIntDef(s
, 0);
7059 s
:= Find_Param_Value(pars
, '--close');
7063 // Override map to test:
7064 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
7067 if e_IsValidResourceName(s
) then
7068 e_FindResource(AllMapDirs
, s
);
7069 gTestMap
:= ExpandFileName(s
);
7072 // Delete test map after play:
7073 s
:= Find_Param_Value(pars
, '--testdelete');
7076 //gMapToDelete := MapsDir + map;
7077 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
7081 // Delete temporary WAD after play:
7082 s
:= Find_Param_Value(pars
, '--tempdelete');
7083 if (s
<> '') and (gTestMap
<> '') then
7085 gMapToDelete
:= gTestMap
;
7086 gTempDelete
:= True;
7089 // Number of players:
7090 s
:= Find_Param_Value(pars
, '-pl');
7092 n
:= DEFAULT_PLAYERS
7094 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
7097 s
:= Find_Param_Value(pars
, '-port');
7098 if (s
= '') or not TryStrToInt(s
, Port
) then
7099 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
7101 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
7104 // Execute script when game loads:
7105 s
:= Find_Param_Value(pars
, '-exec');
7108 // if not isWadPath(s) then
7109 // s := GameDir + '/' + s;
7114 if IOResult
<> 0 then
7116 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7117 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7121 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
7122 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7127 if IOResult
<> 0 then
7129 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7130 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7134 if Pos('#', s
) <> 1 then // script comment
7135 g_Console_Process(s
, True);
7146 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7147 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7148 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7149 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7151 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7152 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7153 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7154 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7156 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7157 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7159 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7160 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7162 {$IFDEF ENABLE_HOLMES}
7163 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7166 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7168 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7169 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7171 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7172 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7174 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
7175 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
7176 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
7177 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
7178 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
7179 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
7180 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
7181 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
7182 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');