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 SetWinPause(Enable: Boolean); }
161 LOADING_SHOW_STEP
= 100;
162 LOADING_INTERLINE
= 20;
177 MESSAGE_DIKEY
= WM_USER
+ 1;
182 EXIT_ENDLEVELSINGLE
= 4;
183 EXIT_ENDLEVELCUSTOM
= 5;
185 GAME_OPTION_RESERVED
= 1;
186 GAME_OPTION_TEAMDAMAGE
= 2;
187 GAME_OPTION_ALLOWEXIT
= 4;
188 GAME_OPTION_WEAPONSTAY
= 8;
189 GAME_OPTION_MONSTERS
= 16;
190 GAME_OPTION_BOTVSPLAYER
= 32;
191 GAME_OPTION_BOTVSMONSTER
= 64;
192 GAME_OPTION_DMKEYS
= 128;
193 GAME_OPTION_TEAMHITTRACE
= 256;
194 GAME_OPTION_TEAMHITPROJECTILE
= 512;
195 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
196 GAME_OPTION_ALLOWDROPFLAG
= 2048;
197 GAME_OPTION_THROWFLAG
= 4096;
202 STATE_INTERCUSTOM
= 3;
203 STATE_INTERSINGLE
= 4;
209 LMS_RESPAWN_NONE
= 0;
210 LMS_RESPAWN_WARMUP
= 1;
211 LMS_RESPAWN_FINAL
= 2;
228 CONFIG_FILENAME
= 'Doom2DF.cfg';
230 TEST_MAP_NAME
= '$$$_TEST_$$$';
232 STD_PLAYER_MODEL
= 'Doomer';
240 STATFILE_VERSION
= $03;
244 gGameSettings
: TGameSettings
;
245 gPlayer1Settings
: TPlayerSettings
;
246 gPlayer2Settings
: TPlayerSettings
;
248 gPlayerScreenSize
: TDFPoint
;
249 gPlayer1ScreenCoord
: TDFPoint
;
250 gPlayer2ScreenCoord
: TDFPoint
;
251 gPlayer1
: TPlayer
= nil;
252 gPlayer2
: TPlayer
= nil;
253 gPlayerDrawn
: TPlayer
= nil;
255 gLerpFactor
: Single = 1.0;
256 gSwitchGameMode
: Byte = GM_DM
;
257 gHearPoint1
, gHearPoint2
: THearPoint
;
258 gSoundEffectsDF
: Boolean = False;
259 gSoundTriggerTime
: Word = 0;
260 gAnnouncer
: Integer = ANNOUNCE_NONE
;
261 goodsnd
: array[0..3] of TPlayableSound
;
262 killsnd
: array[0..3] of TPlayableSound
;
263 hahasnd
: array[0..2] of TPlayableSound
;
264 sound_get_flag
: array[0..1] of TPlayableSound
;
265 sound_lost_flag
: array[0..1] of TPlayableSound
;
266 sound_ret_flag
: array[0..1] of TPlayableSound
;
267 sound_cap_flag
: array[0..1] of TPlayableSound
;
268 gBodyKillEvent
: Integer = -1;
269 gDefInterTime
: ShortInt = -1;
270 gInterEndTime
: LongWord = 0;
271 gInterTime
: LongWord = 0;
272 gServInterTime
: Byte = 0;
273 gGameStartTime
: LongWord = 0;
274 gTotalMonsters
: Integer = 0;
275 gPauseMain
: Boolean = false;
276 gPauseHolmes
: Boolean = false;
277 gShowTime
: Boolean = False;
278 gShowFPS
: Boolean = False;
279 gShowScore
: Boolean = True;
280 gShowStat
: Boolean = True;
281 gShowPIDs
: Boolean = False;
282 gShowKillMsg
: Boolean = True;
283 gShowLives
: Boolean = True;
284 gShowPing
: Boolean = False;
285 gShowMap
: Boolean = False;
287 gState
: Byte = STATE_NONE
;
289 sWidth
, sHeight
: Word;
290 gSpectMode
: Byte = SPECT_NONE
;
291 gSpectHUD
: Boolean = True;
292 gSpectKeyPress
: Boolean = False;
293 gSpectX
: Integer = 0;
294 gSpectY
: Integer = 0;
295 gSpectStep
: Byte = 8;
296 gSpectViewTwo
: Boolean = False;
297 gSpectPID1
: Integer = -1;
298 gSpectPID2
: Integer = -1;
299 gSpectAuto
: Boolean = False;
300 gSpectAutoNext
: LongWord;
301 gSpectAutoStepX
: Integer;
302 gSpectAutoStepY
: Integer;
303 gMusic
: TMusic
= nil;
304 gLoadGameMode
: Boolean;
305 gCheats
: Boolean = False;
306 gMapOnce
: Boolean = False;
307 gMapToDelete
: String;
308 gTempDelete
: Boolean = False;
309 gLastMap
: Boolean = False;
312 gResolutionChange
: Boolean = False;
313 gRC_Width
, gRC_Height
: Integer;
314 gRC_FullScreen
, gRC_Maximized
: Boolean;
315 gLanguageChange
: Boolean = False;
316 gDebugMode
: Boolean = False;
317 g_debug_Sounds
: Boolean = False;
318 g_debug_Frames
: Boolean = False;
319 g_debug_WinMsgs
: Boolean = False;
320 g_debug_MonsterOff
: Boolean = False;
321 g_debug_BotAIOff
: Byte = 0;
322 g_debug_HealthBar
: Boolean = False;
323 g_Debug_Player
: Boolean = False;
324 gCoopMonstersKilled
: Word = 0;
325 gCoopSecretsFound
: Word = 0;
326 gCoopTotalMonstersKilled
: Word = 0;
327 gCoopTotalSecretsFound
: Word = 0;
328 gCoopTotalMonsters
: Word = 0;
329 gCoopTotalSecrets
: Word = 0;
330 gStatsOff
: Boolean = False;
331 gStatsPressed
: Boolean = False;
332 gExitByTrigger
: Boolean = False;
333 gNextMap
: String = '';
334 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
335 gLMSRespawnTime
: Cardinal = 0;
336 gLMSSoftSpawn
: Boolean = False;
337 gMissionFailed
: Boolean = False;
338 gVoteInProgress
: Boolean = False;
339 gVotePassed
: Boolean = False;
340 gVoteCommand
: string = '';
341 gVoteTimer
: Cardinal = 0;
342 gVoteCmdTimer
: Cardinal = 0;
343 gVoteCount
: Integer = 0;
344 gVoteTimeout
: Cardinal = 30;
345 gVoted
: Boolean = False;
346 gVotesEnabled
: Boolean = True;
347 gEvents
: Array of TGameEvent
;
348 gDelayedEvents
: Array of TDelayedEvent
;
349 gUseChatSounds
: Boolean = True;
350 gChatSounds
: Array of TChatSound
;
351 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
352 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
353 gInterReadyCount
: Integer = 0;
354 gMaxBots
: Integer = 127;
356 g_dbg_ignore_bounds
: Boolean = false;
357 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
358 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
360 // move button values:
361 // bits 0-1: l/r state:
362 // 0: neither left, nor right pressed
365 // bits 4-5: l/r state when strafe was pressed
366 P1MoveButton
: Byte = 0;
367 P2MoveButton
: Byte = 0;
369 g_profile_frame_update
: Boolean = false;
370 g_profile_frame_draw
: Boolean = false;
371 g_profile_collision
: Boolean = false;
372 g_profile_los
: Boolean = false;
373 g_profile_history_size
: Integer = 1000;
375 g_rlayer_back
: Boolean = true;
376 g_rlayer_step
: Boolean = true;
377 g_rlayer_wall
: Boolean = true;
378 g_rlayer_door
: Boolean = true;
379 g_rlayer_acid1
: Boolean = true;
380 g_rlayer_acid2
: Boolean = true;
381 g_rlayer_water
: Boolean = true;
382 g_rlayer_fore
: Boolean = true;
385 procedure g_ResetDynlights ();
386 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
387 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
389 function conIsCheatsEnabled (): Boolean; inline;
390 function gPause (): Boolean; inline;
392 type (* private state *)
393 TEndCustomGameStat
= record
394 PlayerStat
: TPlayerStatArray
;
398 Map
, MapName
: String;
401 TEndSingleGameStat
= record
402 PlayerStat
: Array [0..1] of record
408 TotalSecrets
: Integer;
411 TLoadingStat
= record
415 Msgs
: Array of String;
417 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
421 x
, y
, radius
: Integer;
424 exploRadius
: Integer;
427 var (* private state *)
428 CustomStat
: TEndCustomGameStat
;
429 StatShotDone
: Boolean;
430 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
431 SingleStat
: TEndSingleGameStat
;
433 LoadingStat
: TLoadingStat
;
436 EndingGameCounter
: Byte;
438 g_playerLight
: Boolean;
439 g_dynLights
: array of TDynLight
= nil;
440 g_dynLightCount
: Integer = 0;
445 {$IFDEF ENABLE_HOLMES}
448 e_res
, g_textures
, g_window
, g_menu
,
449 e_input
, e_log
, g_console
, r_console
, g_items
, g_map
, g_panel
,
450 g_playermodel
, g_gfx
, g_options
, Math
,
451 g_triggers
, g_monsters
, e_sound
, CONFIG
,
452 g_language
, g_net
, g_main
, g_phys
,
453 ENet
, e_msg
, g_netmsg
, g_netmaster
,
454 sfs
, wadreader
, g_system
, r_playermodel
;
457 // ////////////////////////////////////////////////////////////////////////// //
458 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
460 procedure g_ResetDynlights ();
464 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
466 for idx
:= 0 to g_dynLightCount
-1 do
468 if g_dynLights
[idx
].exploCount
= -666 then
475 Inc(g_dynLights
[idx
].exploCount
);
476 if (g_dynLights
[idx
].exploCount
< 10) then
478 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
479 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
480 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
481 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
486 g_dynLightCount
:= lnum
;
489 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
491 if not gwin_has_stencil
then exit
;
492 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
493 g_dynLights
[g_dynLightCount
].x
:= x
;
494 g_dynLights
[g_dynLightCount
].y
:= y
;
495 g_dynLights
[g_dynLightCount
].radius
:= radius
;
496 g_dynLights
[g_dynLightCount
].r
:= r
;
497 g_dynLights
[g_dynLightCount
].g
:= g
;
498 g_dynLights
[g_dynLightCount
].b
:= b
;
499 g_dynLights
[g_dynLightCount
].a
:= a
;
500 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
501 Inc(g_dynLightCount
);
504 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
506 if not gwin_has_stencil
then exit
;
507 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
508 g_dynLights
[g_dynLightCount
].x
:= x
;
509 g_dynLights
[g_dynLightCount
].y
:= y
;
510 g_dynLights
[g_dynLightCount
].radius
:= 0;
511 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
512 g_dynLights
[g_dynLightCount
].r
:= r
;
513 g_dynLights
[g_dynLightCount
].g
:= g
;
514 g_dynLights
[g_dynLightCount
].b
:= b
;
515 g_dynLights
[g_dynLightCount
].a
:= 0;
516 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
517 Inc(g_dynLightCount
);
520 // ////////////////////////////////////////////////////////////////////////// //
521 function conIsCheatsEnabled (): Boolean; inline;
524 if g_Game_IsNet
then exit
;
525 if not gDebugMode
then
527 //if not gCheats then exit;
528 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
529 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
534 // ////////////////////////////////////////////////////////////////////////// //
536 TParamStrValue
= record
541 TParamStrValues
= Array of TParamStrValue
;
544 INTER_ACTION_TEXT
= 1;
545 INTER_ACTION_PIC
= 2;
546 INTER_ACTION_MUSIC
= 3;
551 DataLoaded
: Boolean = False;
553 MessageLineLength
: Integer = 80;
554 MapList
: SSArray
= nil;
555 MapIndex
: Integer = -1;
556 InterReadyTime
: Integer = -1;
557 StatDate
: string = '';
563 text: Array of ShortString;
564 anim
: Array of ShortString;
565 pic
: Array of ShortString;
566 mus
: Array of ShortString;
568 triggers
: Array of record
570 actions
: Array of record
571 action
, p1
, p2
: Integer;
574 cur_trigger
: Integer;
587 function Compare(a
, b
: TPlayerStat
): Integer;
589 if a
.Spectator
then Result
:= 1
590 else if b
.Spectator
then Result
:= -1
591 else if a
.Frags
< b
.Frags
then Result
:= 1
592 else if a
.Frags
> b
.Frags
then Result
:= -1
593 else if a
.Deaths
< b
.Deaths
then Result
:= -1
594 else if a
.Deaths
> b
.Deaths
then Result
:= 1
595 else if a
.Kills
< b
.Kills
then Result
:= -1
599 procedure SortGameStat(var stat
: TPlayerStatArray
);
604 if stat
= nil then Exit
;
606 for I
:= High(stat
) downto Low(stat
) do
607 for J
:= Low(stat
) to High(stat
) - 1 do
608 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
611 stat
[J
] := stat
[J
+ 1];
616 // saves a shitty CSV containing the game stats passed to it
617 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
620 dir
, fname
, map
, mode
, etime
: String;
624 dir
:= e_GetWriteableDir(StatsDirs
);
625 // stats are placed in stats/yy/mm/dd/*.csv
626 fname
:= e_CatPath(dir
, Path
);
627 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
628 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
629 AssignFile(s
, fname
);
631 SetTextCodePage(s
, CP_UTF8
);
633 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
634 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
635 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
636 mode
:= g_Game_ModeToText(Stat
.GameMode
);
637 etime
:= Format('%d:%.2d:%.2d', [
638 Stat
.GameTime
div 1000 div 3600,
639 (Stat
.GameTime
div 1000 div 60) mod 60,
640 Stat
.GameTime
div 1000 mod 60
642 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
643 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
649 gGameSettings
.TimeLimit
,
650 gGameSettings
.ScoreLimit
,
651 gGameSettings
.Options
,
653 Length(Stat
.PlayerStat
)
655 // line 2: game specific shit
656 // if it's a team game: red score, blue score
657 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
659 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
661 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
662 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
664 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
665 // lines 3-...: team, player name, frags, deaths
666 WriteLn(s
, 'team,name,frags,deaths');
667 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
668 with Stat
.PlayerStat
[I
] do
669 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
671 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
674 g_Console_Add('could not create gamestats file "' + fname
+ '"');
679 procedure ClearDebugCvars();
681 g_debug_Sounds
:= False;
682 g_debug_Frames
:= False;
683 g_debug_WinMsgs
:= False;
684 g_debug_MonsterOff
:= False;
685 g_debug_BotAIOff
:= 0;
686 g_debug_HealthBar
:= False;
687 g_Debug_Player
:= False;
690 function g_Game_ModeToText(Mode
: Byte): string;
694 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
695 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
696 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
697 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
698 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
702 function g_Game_TextToMode(Mode
: string): Byte;
705 Mode
:= UpperCase(Mode
);
706 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
711 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
716 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
721 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
726 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
733 function g_Game_IsNet(): Boolean;
735 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
738 function g_Game_IsServer(): Boolean;
740 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
743 function g_Game_IsClient(): Boolean;
745 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
748 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
755 Result
.name
:= ExtractFileName(WAD
);
756 Result
.description
:= '';
759 w
:= TWADFile
.Create();
762 if not w
.GetResource('INTERSCRIPT', p
, len
) then
768 cfg
:= TConfig
.CreateMem(p
, len
);
769 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
770 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
771 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
772 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
778 procedure g_Game_FreeWAD();
782 for a
:= 0 to High(MegaWAD
.res
.pic
) do
783 if MegaWAD
.res
.pic
[a
] <> '' then
784 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
786 for a
:= 0 to High(MegaWAD
.res
.mus
) do
787 if MegaWAD
.res
.mus
[a
] <> '' then
788 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
790 MegaWAD
.res
.pic
:= nil;
791 MegaWAD
.res
.text := nil;
792 MegaWAD
.res
.anim
:= nil;
793 MegaWAD
.res
.mus
:= nil;
794 MegaWAD
.triggers
:= nil;
796 g_Texture_Delete('TEXTURE_endpic');
797 g_Sound_Delete('MUSIC_endmus');
799 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
800 gGameSettings
.WAD
:= '';
803 procedure g_Game_LoadWAD(WAD
: string);
812 gGameSettings
.WAD
:= WAD
;
813 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
816 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
818 w
:= TWADFile
.Create();
821 if not w
.GetResource('INTERSCRIPT', p
, len
) then
827 cfg
:= TConfig
.CreateMem(p
, len
);
832 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
833 if s = '' then Break;
836 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
837 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
839 g_Texture_CreateWADEx(s, s);
845 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
846 if s = '' then Break;
849 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
850 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
852 g_Music_CreateWADEx(s, s);
855 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
856 if MegaWAD
.endpic
<> '' then
858 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
859 g_Texture_CreateWADEx('TEXTURE_endpic', s
, gTextureFilter
);
861 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
862 if MegaWAD
.endmus
<> '' then
864 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
865 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
873 {procedure start_trigger(t: string);
877 function next_trigger(): Boolean;
881 procedure DisableCheats();
887 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
888 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
889 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
890 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
892 {$IF DEFINED(D2F_DEBUG)}
893 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
894 gAimLine
:= g_dbg_aimline_on
;
898 procedure g_Game_ExecuteEvent(Name
: String);
904 if gEvents
= nil then
906 for a
:= 0 to High(gEvents
) do
907 if gEvents
[a
].Name
= Name
then
909 if gEvents
[a
].Command
<> '' then
910 g_Console_Process(gEvents
[a
].Command
, True);
915 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
920 if gDelayedEvents
<> nil then
921 for a
:= 0 to High(gDelayedEvents
) do
922 if not gDelayedEvents
[a
].Pending
then
929 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
930 n
:= High(gDelayedEvents
);
932 gDelayedEvents
[n
].Pending
:= True;
933 gDelayedEvents
[n
].DEType
:= DEType
;
934 gDelayedEvents
[n
].DENum
:= Num
;
935 gDelayedEvents
[n
].DEStr
:= Str
;
936 if DEType
= DE_GLOBEVENT
then
937 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
939 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
949 if g_Game_IsNet
and g_Game_IsServer
then
950 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
954 gPauseHolmes
:= false;
957 g_Game_StopAllSounds(False);
962 EndingGameCounter
:= 0;
963 g_ActiveWindow
:= nil;
965 gLMSRespawn
:= LMS_RESPAWN_NONE
;
966 gLMSRespawnTime
:= 0;
969 EXIT_SIMPLE
: // Выход через меню или конец теста
974 begin // Это был тест
978 begin // Выход в главное меню
979 gMusic
.SetByName('MUSIC_MENU');
981 if gState
<> STATE_SLIST
then
983 g_GUI_ShowWindow('MainMenu');
984 gState
:= STATE_MENU
;
987 // Обновляем список серверов
988 slReturnPressed
:= True;
989 if g_Net_Slist_Fetch(slCurrent
) then
991 if slCurrent
= nil then
992 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
995 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
996 g_Serverlist_GenerateTable(slCurrent
, slTable
);
999 g_Game_ExecuteEvent('ongameend');
1003 EXIT_RESTART
: // Начать уровень сначала
1005 if not g_Game_IsClient
then g_Game_Restart();
1008 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1010 // Статистика Своей игры:
1011 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1013 CustomStat
.GameTime
:= gTime
;
1014 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1015 CustomStat
.MapName
:= gMapInfo
.Name
;
1016 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1017 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1018 CustomStat
.TeamStat
:= gTeamStat
;
1020 CustomStat
.PlayerStat
:= nil;
1022 // Статистика игроков:
1023 if gPlayers
<> nil then
1025 for a
:= 0 to High(gPlayers
) do
1026 if gPlayers
[a
] <> nil then
1028 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1029 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1032 Name
:= gPlayers
[a
].Name
;
1033 Frags
:= gPlayers
[a
].Frags
;
1034 Deaths
:= gPlayers
[a
].Death
;
1035 Kills
:= gPlayers
[a
].Kills
;
1036 Team
:= gPlayers
[a
].Team
;
1037 Color
:= gPlayers
[a
].Model
.Color
;
1038 Spectator
:= gPlayers
[a
].FSpectator
;
1042 SortGameStat(CustomStat
.PlayerStat
);
1044 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1047 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1048 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1049 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1050 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1052 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1055 StatShotDone
:= False;
1058 g_Game_ExecuteEvent('onmapend');
1059 if not g_Game_IsClient
then g_Player_ResetReady
;
1060 gInterReadyCount
:= 0;
1062 // Затухающий экран:
1063 EndingGameCounter
:= 255;
1064 gState
:= STATE_FOLD
;
1066 if gDefInterTime
< 0 then
1067 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1069 gInterEndTime
:= gDefInterTime
* 1000;
1072 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1074 // Статистика Одиночной игры:
1075 SingleStat
.GameTime
:= gTime
;
1076 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1077 SingleStat
.TotalSecrets
:= gSecretsCount
;
1078 // Статистика первого игрока:
1079 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1080 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1081 // Статистика второго игрока (если есть):
1082 if SingleStat
.TwoPlayers
then
1084 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1085 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1088 g_Game_ExecuteEvent('onmapend');
1091 if gNextMap
<> '' then
1093 gMusic
.SetByName('MUSIC_INTERMUS');
1095 gState
:= STATE_INTERSINGLE
;
1098 g_Game_ExecuteEvent('oninter');
1100 else // Больше нет карт
1102 // Затухающий экран:
1103 EndingGameCounter
:= 255;
1104 gState
:= STATE_FOLD
;
1109 // Окончание обработано:
1110 if gExit
<> EXIT_QUIT
then
1114 procedure g_Game_Init();
1117 knownFiles
: array of AnsiString = nil;
1119 wext
, s
: AnsiString;
1124 gTempDelete
:= False;
1126 sfsGCDisable(); // temporary disable removing of temporary volumes
1129 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE', gTextureFilter
);
1130 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER', gTextureFilter
);
1131 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN', gTextureFilter
);
1132 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU', gTextureFilter
);
1134 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1135 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1136 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1138 g_Game_ClearLoading();
1139 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1140 g_Game_SetLoadingText('', 0, False);
1142 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1146 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1147 r_PlayerModel_Initialize
;
1149 // load models from all possible wad types, in all known directories
1150 // this does a loosy job (linear search, ooph!), but meh
1151 for wext
in wadExtensions
do
1153 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1155 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1159 for s
in knownFiles
do
1161 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1169 SetLength(knownFiles
, length(knownFiles
)+1);
1170 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1172 until (FindNext(SR
) <> 0);
1178 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1180 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
);
1181 for s
in knownFiles
do
1183 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1187 gPauseMain
:= false;
1188 gPauseHolmes
:= false;
1191 {e_MouseInfo.Accel := 1.0;}
1193 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1196 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1197 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1198 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1199 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1200 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1203 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1207 gMusic
:= TMusic
.Create();
1208 gMusic
.SetByName('MUSIC_MENU');
1211 gGameSettings
.WarmupTime
:= 30;
1213 gState
:= STATE_MENU
;
1215 SetLength(gEvents
, 6);
1216 gEvents
[0].Name
:= 'ongamestart';
1217 gEvents
[1].Name
:= 'ongameend';
1218 gEvents
[2].Name
:= 'onmapstart';
1219 gEvents
[3].Name
:= 'onmapend';
1220 gEvents
[4].Name
:= 'oninter';
1221 gEvents
[5].Name
:= 'onwadend';
1223 sfsGCEnable(); // enable releasing unused volumes
1227 procedure g_Game_Free(freeTextures
: Boolean=true);
1229 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1230 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1232 g_Map_Free(freeTextures
);
1234 g_Player_RemoveAllCorpses();
1236 gGameSettings
.GameType
:= GT_NONE
;
1237 if gGameSettings
.GameMode
= GM_SINGLE
then
1238 gGameSettings
.GameMode
:= GM_DM
;
1239 gSwitchGameMode
:= gGameSettings
.GameMode
;
1242 gExitByTrigger
:= False;
1245 function IsActivePlayer(p
: TPlayer
): Boolean;
1250 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1253 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1259 if gPlayers
= nil then
1263 for a
:= Low(gPlayers
) to High(gPlayers
) do
1264 if IsActivePlayer(gPlayers
[a
]) then
1266 SetLength(ids
, Length(ids
) + 1);
1267 ids
[High(ids
)] := gPlayers
[a
].UID
;
1268 if gPlayers
[a
].UID
= Skip
then
1271 if Length(ids
) = 0 then
1276 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1279 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1285 if gPlayers
= nil then
1289 for a
:= Low(gPlayers
) to High(gPlayers
) do
1290 if IsActivePlayer(gPlayers
[a
]) then
1292 SetLength(ids
, Length(ids
) + 1);
1293 ids
[High(ids
)] := gPlayers
[a
].UID
;
1294 if gPlayers
[a
].UID
= Skip
then
1297 if Length(ids
) = 0 then
1300 Result
:= ids
[Length(ids
) - 1]
1302 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1305 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1311 if gPlayers
= nil then
1315 for a
:= Low(gPlayers
) to High(gPlayers
) do
1316 if IsActivePlayer(gPlayers
[a
]) then
1318 SetLength(ids
, Length(ids
) + 1);
1319 ids
[High(ids
)] := gPlayers
[a
].UID
;
1320 if gPlayers
[a
].UID
= Skip
then
1323 if Length(ids
) = 0 then
1325 if Length(ids
) = 1 then
1330 Result
:= ids
[Random(Length(ids
))];
1332 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1334 Result
:= ids
[Random(Length(ids
))];
1339 function GetRandomSpectMode(Current
: Byte): Byte;
1346 0: Result
:= SPECT_STATS
;
1347 1: Result
:= SPECT_MAPVIEW
;
1348 2: Result
:= SPECT_MAPVIEW
;
1349 3: Result
:= SPECT_PLAYERS
;
1350 4: Result
:= SPECT_PLAYERS
;
1351 5: Result
:= SPECT_PLAYERS
;
1352 6: Result
:= SPECT_PLAYERS
;
1354 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1358 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1364 if (plr
= nil) then exit
;
1365 if (p
= 2) then time
:= 1000 else time
:= 1;
1366 strafeDir
:= MoveButton
shr 4;
1367 MoveButton
:= MoveButton
and $0F;
1369 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1370 MoveButton
:= 1 // Нажата только "Влево"
1371 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1372 MoveButton
:= 2 // Нажата только "Вправо"
1373 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1374 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1376 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1377 if MoveButton
= 1 then
1378 plr
.PressKey(KEY_LEFT
, time
)
1379 else if MoveButton
= 2 then
1380 plr
.PressKey(KEY_RIGHT
, time
);
1382 // if we have "strafe" key, turn off old strafe mechanics
1383 if gPlayerAction
[p
, ACTION_STRAFE
] then
1385 // new strafe mechanics
1386 if (strafeDir
= 0) then
1387 strafeDir
:= MoveButton
; // start strafing
1388 // now set direction according to strafe (reversed)
1389 if (strafeDir
= 2) then
1390 plr
.SetDirection(TDirection
.D_LEFT
)
1391 else if (strafeDir
= 1) then
1392 plr
.SetDirection(TDirection
.D_RIGHT
)
1396 strafeDir
:= 0; // not strafing anymore
1397 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1398 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1399 plr
.SetDirection(TDirection
.D_LEFT
)
1400 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1401 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1402 plr
.SetDirection(TDirection
.D_RIGHT
)
1403 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1404 else if MoveButton
<> 0 then
1405 plr
.SetDirection(TDirection(MoveButton
-1))
1408 // fix movebutton state
1409 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1411 // Остальные клавиши:
1412 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1413 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1414 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1415 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1416 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1418 for i
:= WP_FACT
to WP_LACT
do
1420 if gWeaponAction
[p
, i
] then
1422 plr
.ProcessWeaponAction(i
);
1423 gWeaponAction
[p
, i
] := False
1427 for i
:= WP_FIRST
to WP_LAST
do
1429 if gSelectWeapon
[p
, i
] then
1431 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1432 gSelectWeapon
[p
, i
] := False
1436 // HACK: add dynlight here
1437 if gwin_k8_enable_light_experiments
then
1439 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1441 g_playerLight
:= true;
1443 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1445 g_playerLight
:= false;
1449 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1452 // HACK: don't have a "key was pressed" function
1453 procedure InterReady();
1455 if InterReadyTime
> gTime
then Exit
;
1456 InterReadyTime
:= gTime
+ 3000;
1457 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1460 procedure g_Game_PreUpdate();
1462 // these are in separate PreUpdate functions because they can interact during Update()
1463 // and are synced over the net
1464 // we don't care that much about corpses and gibs
1465 g_Player_PreUpdate();
1466 g_Monsters_PreUpdate();
1467 g_Items_PreUpdate();
1468 g_Weapon_PreUpdate();
1471 procedure g_Game_Update();
1473 Msg
: g_gui
.TMessage
;
1479 function sendMonsPos (mon
: TMonster
): Boolean;
1481 result
:= false; // don't stop
1482 // this will also reset "need-send" flag
1483 if mon
.gncNeedSend
then
1485 MH_SEND_MonsterPos(mon
.UID
);
1487 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1489 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1491 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1493 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1497 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1499 result
:= false; // don't stop
1500 // this will also reset "need-send" flag
1501 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1504 function sendItemPos (it
: PItem
): Boolean;
1506 result
:= false; // don't stop
1509 MH_SEND_ItemPos(it
.myId
);
1510 it
.needSend
:= False;
1515 reliableUpdate
: Boolean;
1520 // Пора выключать игру:
1521 if gExit
= EXIT_QUIT
then
1523 // Игра закончилась - обрабатываем:
1527 if gExit
= EXIT_QUIT
then
1531 // Читаем клавиатуру и джойстик, если окно активно
1532 // no need to, as we'll do it in event handler
1534 // Обновляем консоль (движение и сообщения):
1538 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1540 gExit
:= EXIT_SIMPLE
;
1545 // process master server communications
1546 g_Net_Slist_Pulse();
1549 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1550 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1551 STATE_INTERTEXT
, // Текст между уровнями
1552 STATE_INTERPIC
: // Картинка между уровнями
1554 if g_Game_IsNet
and g_Game_IsServer
then
1556 gInterTime
:= gInterTime
+ GAME_TICK
;
1557 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1558 if a
<> gServInterTime
then
1560 gServInterTime
:= a
;
1561 MH_SEND_TimeSync(gServInterTime
);
1565 if (not g_Game_IsClient
) and
1569 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1570 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1571 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1572 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1574 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1575 and (g_ActiveWindow
= nil)
1577 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1580 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1581 g_Game_StopAllSounds(True);
1583 if gMapOnce
then // Это был тест
1584 gExit
:= EXIT_SIMPLE
1586 if gNextMap
<> '' then // Переходим на следующую карту
1587 g_Game_ChangeMap(gNextMap
)
1588 else // Следующей карты нет
1590 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1592 // Выход в главное меню:
1594 g_GUI_ShowWindow('MainMenu');
1595 gMusic
.SetByName('MUSIC_MENU');
1597 gState
:= STATE_MENU
;
1600 // Финальная картинка:
1601 g_Game_ExecuteEvent('onwadend');
1603 if not gMusic
.SetByName('MUSIC_endmus') then
1604 gMusic
.SetByName('MUSIC_STDENDMUS');
1606 gState
:= STATE_ENDPIC
;
1608 g_Game_ExecuteEvent('ongameend');
1613 else if g_Game_IsClient
and
1616 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1617 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1618 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1619 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1621 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1622 and (g_ActiveWindow
= nil)
1630 if gState
= STATE_INTERTEXT
then
1631 if InterText
.counter
> 0 then
1632 InterText
.counter
:= InterText
.counter
- 1;
1635 STATE_FOLD
: // Затухание экрана
1637 if EndingGameCounter
= 0 then
1639 // Закончился уровень в Своей игре:
1640 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1642 gState
:= STATE_INTERCUSTOM
;
1643 InterReadyTime
:= -1;
1644 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1646 g_Game_ExecuteEvent('onwadend');
1647 if not gMusic
.SetByName('MUSIC_endmus') then
1648 gMusic
.SetByName('MUSIC_STDENDMUS');
1651 gMusic
.SetByName('MUSIC_ROUNDMUS');
1655 else // Закончилась последняя карта в Одиночной игре
1657 gMusic
.SetByName('MUSIC_INTERMUS');
1659 gState
:= STATE_INTERSINGLE
;
1662 g_Game_ExecuteEvent('oninter');
1665 DecMin(EndingGameCounter
, 6, 0);
1668 STATE_ENDPIC
: // Картинка окончания мегаВада
1670 if gMapOnce
then // Это был тест
1672 gExit
:= EXIT_SIMPLE
;
1678 g_Serverlist_Control(slCurrent
, slTable
);
1681 // Статистика по Tab:
1683 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1686 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1688 // Время += 28 миллисекунд:
1689 gTime
:= gTime
+ GAME_TICK
;
1691 // Сообщение посередине экрана:
1692 if MessageTime
= 0 then
1694 if MessageTime
> 0 then
1695 MessageTime
:= MessageTime
- 1;
1697 if (g_Game_IsServer
) then
1699 // Был задан лимит времени:
1700 if (gGameSettings
.TimeLimit
> 0) then
1701 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1702 begin // Он прошел => конец уровня
1707 // Надо респавнить игроков в LMS:
1708 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1709 g_Game_RestartRound(gLMSSoftSpawn
);
1711 // Проверим результат голосования, если время прошло
1712 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1714 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1716 g_Console_Process(gVoteCommand
);
1718 gVotePassed
:= False;
1721 // Замеряем время захвата флагов
1722 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1723 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1724 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1725 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1727 // Был задан лимит побед:
1728 if (gGameSettings
.ScoreLimit
> 0) then
1732 if gGameSettings
.GameMode
= GM_DM
then
1733 begin // В DM ищем игрока с max фрагами
1734 for i
:= 0 to High(gPlayers
) do
1735 if gPlayers
[i
] <> nil then
1736 if gPlayers
[i
].Frags
> b
then
1737 b
:= gPlayers
[i
].Frags
;
1740 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1741 begin // В CTF/TDM выбираем команду с наибольшим счетом
1742 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
1745 // Лимит побед набран => конец уровня:
1746 if b
>= gGameSettings
.ScoreLimit
then
1753 // Обрабатываем клавиши игроков:
1754 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1755 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1756 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1758 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1759 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1760 end // if not console
1763 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1765 // process weapon switch queue
1769 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1770 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1772 if not gSpectKeyPress
then
1774 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
1776 // switch spect mode
1778 SPECT_NONE
: ; // not spectator
1780 SPECT_MAPVIEW
: Inc(gSpectMode
);
1781 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1783 gSpectKeyPress
:= True;
1785 if (gSpectMode
= SPECT_MAPVIEW
)
1786 and (not gSpectAuto
) then
1788 if gPlayerAction
[0, ACTION_MOVELEFT
] then
1789 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1790 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
1791 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1792 if gPlayerAction
[0, ACTION_LOOKUP
] then
1793 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1794 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
1795 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1796 if gWeaponAction
[0, WP_PREV
] then
1799 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1800 gWeaponAction
[0, WP_PREV
] := False;
1802 if gWeaponAction
[0, WP_NEXT
] then
1805 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1806 gWeaponAction
[0, WP_NEXT
] := False;
1809 if (gSpectMode
= SPECT_PLAYERS
)
1810 and (not gSpectAuto
) then
1812 if gPlayerAction
[0, ACTION_LOOKUP
] then
1815 gSpectViewTwo
:= True;
1816 gSpectKeyPress
:= True;
1818 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
1820 // remove second view
1821 gSpectViewTwo
:= False;
1822 gSpectKeyPress
:= True;
1824 if gPlayerAction
[0, ACTION_MOVELEFT
] then
1826 // prev player (view 1)
1827 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1828 gSpectKeyPress
:= True;
1830 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
1832 // next player (view 1)
1833 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1834 gSpectKeyPress
:= True;
1836 if gWeaponAction
[0, WP_PREV
] then
1838 // prev player (view 2)
1839 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1840 gWeaponAction
[0, WP_PREV
] := False;
1842 if gWeaponAction
[0, WP_NEXT
] then
1844 // next player (view 2)
1845 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1846 gWeaponAction
[0, WP_NEXT
] := False;
1849 if gPlayerAction
[0, ACTION_ATTACK
] then
1851 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
1854 gSpectAutoNext
:= 0;
1855 gSpectViewTwo
:= False;
1856 gSpectKeyPress
:= True;
1861 gSpectMode
:= SPECT_STATS
;
1862 gSpectAuto
:= False;
1863 gSpectKeyPress
:= True;
1868 if (not gPlayerAction
[0, ACTION_JUMP
]) and
1869 (not gPlayerAction
[0, ACTION_ATTACK
]) and
1870 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
1871 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
1872 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
1873 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
1874 gSpectKeyPress
:= False;
1878 if gSpectMode
= SPECT_MAPVIEW
then
1880 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
1882 gSpectAutoNext
:= gTime
1885 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
1887 gSpectAutoNext
:= gTime
1891 if gSpectAutoNext
<= gTime
then
1893 if gSpectAutoNext
> 0 then
1895 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
1899 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
1900 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
1901 gSpectAutoStepX
:= Random(9) - 4;
1902 gSpectAutoStepY
:= Random(9) - 4;
1903 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
1904 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
1905 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
1906 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
1907 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
1908 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
1912 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
1917 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
1918 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
1919 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
1925 // Обновляем все остальное:
1928 g_Triggers_Update();
1930 g_Monsters_Update();
1932 g_Player_UpdateAll();
1933 g_Player_UpdatePhysicalObjects();
1935 // server: send newly spawned monsters unconditionally
1936 if (gGameSettings
.GameType
= GT_SERVER
) then
1938 if (Length(gMonstersSpawned
) > 0) then
1940 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1941 SetLength(gMonstersSpawned
, 0);
1945 if (gSoundTriggerTime
> 8) then
1947 g_Game_UpdateTriggerSounds();
1948 gSoundTriggerTime
:= 0;
1952 Inc(gSoundTriggerTime
);
1955 if (NetMode
= NET_SERVER
) then
1957 Inc(NetTimeToUpdate
);
1958 Inc(NetTimeToReliable
);
1960 // send monster updates
1961 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
1963 // send all monsters (periodic sync)
1964 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
1966 for I
:= 0 to High(gPlayers
) do
1968 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
1971 g_Mons_ForEach(sendMonsPos
);
1973 // update flags that aren't stationary
1974 if gGameSettings
.GameMode
= GM_CTF
then
1975 for I
:= FLAG_RED
to FLAG_BLUE
do
1976 if gFlags
[I
].NeedSend
then
1978 gFlags
[I
].NeedSend
:= False;
1982 // update items that aren't stationary
1983 g_Items_ForEachAlive(sendItemPos
);
1985 if reliableUpdate
then
1987 NetTimeToReliable
:= 0;
1988 NetTimeToUpdate
:= NetUpdateRate
;
1992 NetTimeToUpdate
:= 0;
1997 // send only mosters with some unexpected changes
1998 g_Mons_ForEach(sendMonsPosUnexpected
);
2001 // send unexpected platform changes
2002 g_Map_NetSendInterestingPanels();
2004 g_Net_Slist_ServerUpdate();
2006 if NetUseMaster then
2008 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2010 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2012 NetTimeToMaster := gTime + NetMasterRate;
2017 else if (NetMode
= NET_CLIENT
) then
2019 MC_SEND_PlayerPos();
2021 end; // if gameOn ...
2023 // Активно окно интерфейса - передаем клавиши ему:
2024 if g_ActiveWindow
<> nil then
2026 w
:= e_GetFirstKeyPressed();
2028 if (w
<> IK_INVALID
) then
2030 Msg
.Msg
:= MESSAGE_DIKEY
;
2032 g_ActiveWindow
.OnMessage(Msg
);
2035 // Если оно от этого не закрылось, то обновляем:
2036 if g_ActiveWindow
<> nil then
2037 g_ActiveWindow
.Update();
2039 // Нужно сменить разрешение:
2040 if gResolutionChange
then
2042 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2043 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2044 gResolutionChange
:= False;
2045 g_ActiveWindow
:= nil;
2048 // Нужно сменить язык:
2049 if gLanguageChange
then
2051 //e_WriteLog('Read language file', MSG_NOTIFY);
2052 //g_Language_Load(DataDir + gLanguage + '.txt');
2053 g_Language_Set(gLanguage
);
2057 gLanguageChange
:= False;
2061 // Горячая клавиша для вызова меню выхода из игры (F10):
2062 if e_KeyPressed(IK_F10
) and
2064 (not gConsoleShow
) and
2065 (g_ActiveWindow
= nil) then
2070 Time
:= sys_GetTicks() {div 1000};
2072 // Обработка отложенных событий:
2073 if gDelayedEvents
<> nil then
2074 for a
:= 0 to High(gDelayedEvents
) do
2075 if gDelayedEvents
[a
].Pending
and
2077 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2078 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2081 case gDelayedEvents
[a
].DEType
of
2083 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2086 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2090 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2091 if g_Game_IsNet
and g_Game_IsServer
then
2092 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2096 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2098 gDelayedEvents
[a
].Pending
:= False;
2101 // Каждую секунду обновляем счетчик обновлений:
2102 UPSCounter
:= UPSCounter
+ 1;
2103 if Time
- UPSTime
>= 1000 then
2112 g_Weapon_AddDynLights();
2113 g_Items_AddDynLights();
2117 procedure g_Game_LoadChatSounds(Resource
: string);
2120 FileName
, Snd
: string;
2122 len
, cnt
, tags
, i
, j
: Integer;
2125 FileName
:= g_ExtractWadName(Resource
);
2127 WAD
:= TWADFile
.Create();
2128 WAD
.ReadFile(FileName
);
2130 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2137 cfg
:= TConfig
.CreateMem(p
, len
);
2138 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2140 SetLength(gChatSounds
, cnt
);
2141 for i
:= 0 to Length(gChatSounds
) - 1 do
2143 gChatSounds
[i
].Sound
:= nil;
2144 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2145 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2146 if (Snd
= '') or (Tags
<= 0) then
2148 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2149 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2150 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2151 SetLength(gChatSounds
[i
].Tags
, tags
);
2152 for j
:= 0 to tags
- 1 do
2153 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2154 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2161 procedure g_Game_FreeChatSounds();
2165 for i
:= 0 to Length(gChatSounds
) - 1 do
2167 gChatSounds
[i
].Sound
.Free();
2168 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2170 SetLength(gChatSounds
, 0);
2174 procedure g_Game_LoadData();
2181 if DataLoaded
then Exit
;
2183 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2185 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2186 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2187 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2188 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2189 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2190 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2191 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2192 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2193 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2194 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2195 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2196 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2197 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2198 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2199 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2202 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2203 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2204 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2205 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2209 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2210 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2211 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2212 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2213 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
2219 hasPBarGfx
:= false;
2223 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2224 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2225 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2226 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2227 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2228 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2229 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2230 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2231 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2232 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2233 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2234 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2235 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2236 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2237 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2238 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2239 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2240 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2241 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2242 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2243 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2244 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2245 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2246 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2247 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2248 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2249 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2250 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2251 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2252 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2253 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2254 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2255 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2256 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2257 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2258 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2259 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2260 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2261 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2263 goodsnd
[0] := TPlayableSound
.Create();
2264 goodsnd
[1] := TPlayableSound
.Create();
2265 goodsnd
[2] := TPlayableSound
.Create();
2266 goodsnd
[3] := TPlayableSound
.Create();
2268 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2269 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2270 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2271 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2273 killsnd
[0] := TPlayableSound
.Create();
2274 killsnd
[1] := TPlayableSound
.Create();
2275 killsnd
[2] := TPlayableSound
.Create();
2276 killsnd
[3] := TPlayableSound
.Create();
2278 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2279 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2280 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2281 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2283 hahasnd
[0] := TPlayableSound
.Create();
2284 hahasnd
[1] := TPlayableSound
.Create();
2285 hahasnd
[2] := TPlayableSound
.Create();
2287 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2288 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2289 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2291 sound_get_flag
[0] := TPlayableSound
.Create();
2292 sound_get_flag
[1] := TPlayableSound
.Create();
2293 sound_lost_flag
[0] := TPlayableSound
.Create();
2294 sound_lost_flag
[1] := TPlayableSound
.Create();
2295 sound_ret_flag
[0] := TPlayableSound
.Create();
2296 sound_ret_flag
[1] := TPlayableSound
.Create();
2297 sound_cap_flag
[0] := TPlayableSound
.Create();
2298 sound_cap_flag
[1] := TPlayableSound
.Create();
2300 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2301 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2302 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2303 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2304 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2305 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2306 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2307 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2309 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2311 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2314 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2315 g_Weapon_LoadData();
2317 g_Monsters_LoadData();
2322 procedure g_Game_Quit();
2324 g_Game_StopAllSounds(True);
2327 r_PlayerModel_Finalize
;
2328 g_PlayerModel_FreeData();
2329 g_Texture_DeleteAll();
2330 g_Frames_DeleteAll();
2332 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2335 if NetInitDone
then g_Net_Free
;
2337 // remove map after test
2338 if gMapToDelete
<> '' then
2339 g_Game_DeleteTestMap();
2345 procedure g_Game_FreeData();
2347 if not DataLoaded
then Exit
;
2350 g_Weapon_FreeData();
2351 g_Monsters_FreeData();
2353 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2355 g_Texture_Delete('NOTEXTURE');
2356 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2357 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2358 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2359 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2360 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2361 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2362 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2363 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2364 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2365 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2366 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2367 g_Frames_DeleteByName('FRAMES_TELEPORT');
2368 g_Frames_DeleteByName('FRAMES_PUNCH');
2369 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2370 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2371 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2372 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2373 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2374 g_Sound_Delete('SOUND_GAME_TELEPORT');
2375 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2376 g_Sound_Delete('SOUND_GAME_SECRET');
2377 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2378 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2379 g_Sound_Delete('SOUND_GAME_BULK1');
2380 g_Sound_Delete('SOUND_GAME_BULK2');
2381 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2382 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2383 g_Sound_Delete('SOUND_GAME_BURNING');
2384 g_Sound_Delete('SOUND_GAME_SWITCH1');
2385 g_Sound_Delete('SOUND_GAME_SWITCH0');
2392 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2393 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2394 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2395 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2402 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2403 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2404 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2405 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2411 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2412 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2413 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2415 sound_get_flag
[0].Free();
2416 sound_get_flag
[1].Free();
2417 sound_lost_flag
[0].Free();
2418 sound_lost_flag
[1].Free();
2419 sound_ret_flag
[0].Free();
2420 sound_ret_flag
[1].Free();
2421 sound_cap_flag
[0].Free();
2422 sound_cap_flag
[1].Free();
2424 g_Sound_Delete('SOUND_CTF_GET1');
2425 g_Sound_Delete('SOUND_CTF_GET2');
2426 g_Sound_Delete('SOUND_CTF_LOST1');
2427 g_Sound_Delete('SOUND_CTF_LOST2');
2428 g_Sound_Delete('SOUND_CTF_RETURN1');
2429 g_Sound_Delete('SOUND_CTF_RETURN2');
2430 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2431 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2433 g_Game_FreeChatSounds();
2435 DataLoaded
:= False;
2438 procedure g_FatalError(Text: String);
2440 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2441 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2443 gExit
:= EXIT_SIMPLE
;
2444 if gGameOn
then EndGame
;
2447 procedure g_SimpleError(Text: String);
2449 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2450 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2453 procedure g_Game_SetupScreenSize();
2455 RES_FACTOR
= 4.0 / 3.0;
2461 // Размер экранов игроков:
2462 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2463 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2464 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
2466 gPlayerScreenSize
.Y
:= gScreenHeight
;
2468 // Размер заднего плана:
2469 if BackID
<> DWORD(-1) then
2472 if (gScreenWidth
*s
> gMapInfo
.Width
) or
2473 (gScreenHeight
*s
> gMapInfo
.Height
) then
2475 gBackSize
.X
:= gScreenWidth
;
2476 gBackSize
.Y
:= gScreenHeight
;
2480 e_GetTextureSize(BackID
, @bw
, @bh
);
2481 rf
:= Single(bw
) / Single(bh
);
2482 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
2483 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
2484 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
2485 if (s
< 1.0) then s
:= 1.0;
2486 gBackSize
.X
:= Round(bw
*s
);
2487 gBackSize
.Y
:= Round(bh
*s
);
2492 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
2494 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
2497 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2499 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2500 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2503 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2506 if gPlayer1
= nil then
2508 if g_Game_IsClient
then
2510 if NetPlrUID1
> -1 then
2511 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2515 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2516 Team
:= gPlayer1Settings
.Team
;
2518 // Создание первого игрока:
2519 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2520 gPlayer1Settings
.Color
,
2522 if gPlayer1
= nil then
2523 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2526 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2527 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2528 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2529 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2530 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2531 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2532 if g_Game_IsServer
and g_Game_IsNet
then
2533 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2534 gPlayer1
.Respawn(False, True);
2535 g_Net_Slist_ServerPlayerComes();
2540 if gPlayer2
= nil then
2542 if g_Game_IsClient
then
2544 if NetPlrUID2
> -1 then
2545 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2549 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2550 Team
:= gPlayer2Settings
.Team
;
2552 // Создание второго игрока:
2553 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2554 gPlayer2Settings
.Color
,
2556 if gPlayer2
= nil then
2557 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2560 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2561 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2562 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2563 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2564 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2565 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2566 if g_Game_IsServer
and g_Game_IsNet
then
2567 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2568 gPlayer2
.Respawn(False, True);
2569 g_Net_Slist_ServerPlayerComes();
2576 procedure g_Game_RemovePlayer();
2580 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2581 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2586 if g_Game_IsServer
then
2589 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2590 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2591 g_Player_Remove(Pl
.UID
);
2592 g_Net_Slist_ServerPlayerLeaves();
2596 gSpectLatchPID2
:= Pl
.UID
;
2604 if g_Game_IsServer
then
2607 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2608 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2609 g_Player_Remove(Pl
.UID
);
2610 g_Net_Slist_ServerPlayerLeaves();
2613 gSpectLatchPID1
:= Pl
.UID
;
2615 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2619 g_Net_Slist_ServerPlayerLeaves();
2622 procedure g_Game_Spectate();
2624 g_Game_RemovePlayer();
2625 if gPlayer1
<> nil then
2626 g_Game_RemovePlayer();
2629 procedure g_Game_SpectateCenterView();
2631 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2632 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2635 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2642 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2644 g_Game_ClearLoading();
2647 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2650 gGameSettings
.GameType
:= GT_SINGLE
;
2651 gGameSettings
.MaxLives
:= 0;
2652 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2653 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2654 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2655 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2656 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2657 gSwitchGameMode
:= GM_SINGLE
;
2659 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2660 gLMSRespawnTime
:= 0;
2661 gSpectLatchPID1
:= 0;
2662 gSpectLatchPID2
:= 0;
2664 g_Game_ExecuteEvent('ongamestart');
2666 // Установка размеров окон игроков:
2667 g_Game_SetupScreenSize();
2669 // Создание первого игрока:
2670 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2671 gPlayer1Settings
.Color
,
2672 gPlayer1Settings
.Team
, False));
2673 if gPlayer1
= nil then
2675 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2679 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2680 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2681 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2682 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2683 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2686 // Создание второго игрока, если есть:
2689 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2690 gPlayer2Settings
.Color
,
2691 gPlayer2Settings
.Team
, False));
2692 if gPlayer2
= nil then
2694 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2698 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2699 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2700 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2701 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2702 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2706 // Загрузка и запуск карты:
2707 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2709 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2710 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2714 // Настройки игроков и ботов:
2718 for i
:= nPl
+1 to nPlayers
do
2719 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2722 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2723 TimeLimit
, ScoreLimit
: Word;
2725 Options
: LongWord; nPlayers
: Byte);
2731 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2733 g_Game_ClearLoading();
2736 gGameSettings
.GameType
:= GT_CUSTOM
;
2737 gGameSettings
.GameMode
:= GameMode
;
2738 gSwitchGameMode
:= GameMode
;
2739 gGameSettings
.TimeLimit
:= TimeLimit
;
2740 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2741 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2742 gGameSettings
.Options
:= Options
;
2744 gCoopTotalMonstersKilled
:= 0;
2745 gCoopTotalSecretsFound
:= 0;
2746 gCoopTotalMonsters
:= 0;
2747 gCoopTotalSecrets
:= 0;
2751 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2752 gLMSRespawnTime
:= 0;
2753 gSpectLatchPID1
:= 0;
2754 gSpectLatchPID2
:= 0;
2756 g_Game_ExecuteEvent('ongamestart');
2758 // Установка размеров окон игроков:
2759 g_Game_SetupScreenSize();
2761 // Режим наблюдателя:
2762 if nPlayers
= 0 then
2769 if nPlayers
>= 1 then
2771 // Создание первого игрока:
2772 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2773 gPlayer1Settings
.Color
,
2774 gPlayer1Settings
.Team
, False));
2775 if gPlayer1
= nil then
2777 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2781 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2782 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2783 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2784 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2785 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2789 if nPlayers
>= 2 then
2791 // Создание второго игрока:
2792 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2793 gPlayer2Settings
.Color
,
2794 gPlayer2Settings
.Team
, False));
2795 if gPlayer2
= nil then
2797 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2801 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2802 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2803 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2804 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2805 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2809 // Загрузка и запуск карты:
2810 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
2812 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2816 // Нет точек появления:
2817 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2818 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2819 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2820 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2821 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2823 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2827 // Настройки игроков и ботов:
2831 for i
:= nPl
+1 to nPlayers
do
2832 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2835 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
2836 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
2837 Options
: LongWord; nPlayers
: Byte;
2838 IPAddr
: LongWord; Port
: Word);
2841 g_Net_Slist_ServerClosed();
2843 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
2845 g_Game_ClearLoading();
2850 gGameSettings
.GameType
:= GT_SERVER
;
2851 gGameSettings
.GameMode
:= GameMode
;
2852 gSwitchGameMode
:= GameMode
;
2853 gGameSettings
.TimeLimit
:= TimeLimit
;
2854 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2855 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2856 gGameSettings
.Options
:= Options
;
2858 gCoopTotalMonstersKilled
:= 0;
2859 gCoopTotalSecretsFound
:= 0;
2860 gCoopTotalMonsters
:= 0;
2861 gCoopTotalSecrets
:= 0;
2865 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2866 gLMSRespawnTime
:= 0;
2867 gSpectLatchPID1
:= 0;
2868 gSpectLatchPID2
:= 0;
2870 g_Game_ExecuteEvent('ongamestart');
2872 // Установка размеров окна игрока
2873 g_Game_SetupScreenSize();
2875 // Режим наблюдателя:
2876 if nPlayers
= 0 then
2882 if nPlayers
>= 1 then
2884 // Создание первого игрока:
2885 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2886 gPlayer1Settings
.Color
,
2887 gPlayer1Settings
.Team
, False));
2888 if gPlayer1
= nil then
2890 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2894 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2895 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2896 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2897 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2898 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2901 if nPlayers
>= 2 then
2903 // Создание второго игрока:
2904 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2905 gPlayer2Settings
.Color
,
2906 gPlayer2Settings
.Team
, False));
2907 if gPlayer2
= nil then
2909 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2913 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2914 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2915 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2916 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2917 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2920 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
2921 if NetForwardPorts
then
2922 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
2925 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
2927 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
2931 g_Net_Slist_Set(NetMasterList
);
2933 g_Net_Slist_ServerStarted();
2935 // Загрузка и запуск карты:
2936 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
2938 g_Net_Slist_ServerClosed();
2939 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2943 // Нет точек появления:
2944 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2945 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2946 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2947 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2948 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2950 g_Net_Slist_ServerClosed();
2951 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2955 // Настройки игроков и ботов:
2958 g_Net_Slist_ServerMapStarted();
2959 NetState
:= NET_STATE_GAME
;
2962 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
2977 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
2978 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
2980 g_Game_ClearLoading();
2985 gGameSettings
.GameType
:= GT_CLIENT
;
2987 gCoopTotalMonstersKilled
:= 0;
2988 gCoopTotalSecretsFound
:= 0;
2989 gCoopTotalMonsters
:= 0;
2990 gCoopTotalSecrets
:= 0;
2994 g_Game_ExecuteEvent('ongamestart');
2996 // Установка размеров окон игроков:
2997 g_Game_SetupScreenSize();
2999 NetState
:= NET_STATE_AUTH
;
3001 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3003 // create (or update) map/resource databases
3004 g_Res_CreateDatabases(true);
3006 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3007 gLMSRespawnTime
:= 0;
3008 gSpectLatchPID1
:= 0;
3009 gSpectLatchPID2
:= 0;
3012 if not g_Net_Connect(Addr
, Port
) then
3014 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3015 NetState
:= NET_STATE_NONE
;
3019 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3021 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3026 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3027 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3028 // thank you, enet. let's ignore failures altogether then.
3029 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3031 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3033 Ptr
:= NetEvent
.packet
^.data
;
3034 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3036 enet_packet_destroy(NetEvent
.packet
);
3040 InMsg
.ReadLongWord(); // skip size
3041 MID
:= InMsg
.ReadByte();
3043 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3045 NetMyID
:= InMsg
.ReadByte();
3046 NetPlrUID1
:= InMsg
.ReadWord();
3048 WadName
:= InMsg
.ReadString();
3049 Map
:= InMsg
.ReadString();
3051 gWADHash
:= InMsg
.ReadMD5();
3053 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3054 gSwitchGameMode
:= gGameSettings
.GameMode
;
3055 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3056 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3057 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3058 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3059 T
:= InMsg
.ReadLongWord();
3061 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3062 //if newResPath = '' then
3064 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3065 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3066 if newResPath
= '' then
3068 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3069 enet_packet_destroy(NetEvent
.packet
);
3070 NetState
:= NET_STATE_NONE
;
3073 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3075 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3078 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3079 gPlayer1Settings
.Color
,
3080 gPlayer1Settings
.Team
, False));
3082 if gPlayer1
= nil then
3084 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3086 enet_packet_destroy(NetEvent
.packet
);
3087 NetState
:= NET_STATE_NONE
;
3091 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3092 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3093 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3094 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3095 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3096 gPlayer1
.UID
:= NetPlrUID1
;
3097 gPlayer1
.Reset(True);
3099 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3101 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3103 enet_packet_destroy(NetEvent
.packet
);
3104 NetState
:= NET_STATE_NONE
;
3112 enet_packet_destroy(NetEvent
.packet
);
3116 enet_packet_destroy(NetEvent
.packet
);
3120 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3123 if (NetEvent
.data
<= NET_DISC_MAX
) then
3124 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3125 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3132 ProcessLoading(True);
3133 if g_Net_UserRequestExit() then
3142 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3143 NetState
:= NET_STATE_NONE
;
3148 NetState
:= NET_STATE_GAME
;
3149 MC_SEND_FullStateRequest
;
3150 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3154 lastAsMegaWad
: Boolean = false;
3156 procedure g_Game_ChangeMap(const MapPath
: String);
3160 g_Game_ClearLoading();
3162 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3163 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3164 if gExitByTrigger
then
3167 gExitByTrigger
:= False;
3169 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3170 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3173 procedure g_Game_Restart();
3177 if g_Game_IsClient
then
3179 map
:= g_ExtractFileName(gMapInfo
.Map
);
3180 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3184 g_Game_ClearLoading();
3185 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3188 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3190 NewWAD
, ResName
: String;
3194 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3195 g_Player_RemoveAllCorpses();
3197 if (not g_Game_IsClient
) and
3198 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3199 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3201 if gSwitchGameMode
= GM_CTF
then
3202 gGameSettings
.MaxLives
:= 0;
3203 gGameSettings
.GameMode
:= gSwitchGameMode
;
3206 gSwitchGameMode
:= gGameSettings
.GameMode
;
3208 g_Player_ResetTeams();
3210 lastAsMegaWad
:= asMegawad
;
3211 if isWadPath(Map
) then
3213 NewWAD
:= g_ExtractWadName(Map
);
3214 ResName
:= g_ExtractFileName(Map
);
3215 if g_Game_IsServer
then
3217 nws
:= findDiskWad(NewWAD
);
3218 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3221 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3222 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3226 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3227 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3229 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3230 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3232 if (length(nws
) = 0) then
3234 ResName
:= ''; // failed
3239 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3240 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3241 g_Game_LoadWAD(NewWAD
);
3246 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3247 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3252 NewWAD
:= gGameSettings
.WAD
;
3258 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3260 if (ResName
<> '') and (NewWAD
<> '') then
3262 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3263 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3267 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3269 gState
:= STATE_NONE
;
3270 g_ActiveWindow
:= nil;
3276 if gGameSettings
.GameMode
= GM_CTF
then
3278 g_Map_ResetFlag(FLAG_RED
);
3279 g_Map_ResetFlag(FLAG_BLUE
);
3280 // CTF, а флагов нет:
3281 if not g_Map_HaveFlagPoints() then
3282 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3287 gState
:= STATE_MENU
;
3292 gPauseMain
:= false;
3293 gPauseHolmes
:= false;
3294 NetTimeToUpdate
:= 1;
3295 NetTimeToReliable
:= 0;
3296 NetTimeToMaster
:= NetMasterRate
;
3297 gSpectLatchPID1
:= 0;
3298 gSpectLatchPID2
:= 0;
3299 gMissionFailed
:= False;
3302 gCoopMonstersKilled
:= 0;
3303 gCoopSecretsFound
:= 0;
3305 gVoteInProgress
:= False;
3306 gVotePassed
:= False;
3312 if not gGameOn
then Exit
;
3314 g_Game_SpectateCenterView();
3316 if g_Game_IsServer
then
3318 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3320 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3321 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3322 gLMSSoftSpawn
:= True;
3323 if g_Game_IsNet
then
3324 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3328 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3329 gLMSRespawnTime
:= 0;
3333 if NetMode
= NET_SERVER
then
3335 // reset full state flags
3336 if NetClients
<> nil then
3337 for I
:= 0 to High(NetClients
) do
3338 NetClients
[I
].FullUpdateSent
:= False;
3340 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3343 g_Net_Slist_ServerMapStarted();
3345 if NetClients
<> nil then
3346 for I
:= 0 to High(NetClients
) do
3347 if NetClients
[I
].Used
then
3349 NetClients
[I
].Voted
:= False;
3350 if NetClients
[I
].RequestedFullUpdate
then
3352 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3353 NetClients
[I
].RequestedFullUpdate
:= False;
3357 g_Net_UnbanNonPermHosts();
3362 gCoopTotalMonstersKilled
:= 0;
3363 gCoopTotalSecretsFound
:= 0;
3364 gCoopTotalMonsters
:= 0;
3365 gCoopTotalSecrets
:= 0;
3369 g_Game_ExecuteEvent('onmapstart');
3372 procedure SetFirstLevel
;
3376 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3377 if MapList
= nil then
3380 SortSArray(MapList
);
3381 gNextMap
:= MapList
[Low(MapList
)];
3386 procedure g_Game_ExitLevel(const Map
: AnsiString);
3390 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3391 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3392 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3393 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3395 // Вышли в выход в Одиночной игре:
3396 if gGameSettings
.GameType
= GT_SINGLE
then
3397 gExit
:= EXIT_ENDLEVELSINGLE
3398 else // Вышли в выход в Своей игре
3400 gExit
:= EXIT_ENDLEVELCUSTOM
;
3401 if gGameSettings
.GameMode
= GM_COOP
then
3402 g_Player_RememberAll
;
3404 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3407 if gGameSettings
.GameMode
= GM_COOP
then
3410 gStatsPressed
:= True;
3411 gNextMap
:= 'MAP01';
3413 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3416 if g_Game_IsNet
then
3418 MH_SEND_GameStats();
3419 MH_SEND_CoopStats();
3425 procedure g_Game_RestartLevel();
3429 if gGameSettings
.GameMode
= GM_SINGLE
then
3434 gExit
:= EXIT_ENDLEVELCUSTOM
;
3435 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3439 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3441 gWAD
{, xwad}: String;
3444 if not g_Game_IsClient
then Exit
;
3445 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3447 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3452 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3456 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3459 g_Game_LoadWAD(NewWAD
);
3463 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3464 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3467 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3468 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3472 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3476 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3477 g_Game_LoadWAD(NewWAD);
3481 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3483 i
, n
, nb
, nr
: Integer;
3485 if not g_Game_IsServer
then Exit
;
3486 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3487 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3488 gLMSRespawnTime
:= 0;
3491 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3493 gMissionFailed
:= True;
3494 g_Game_RestartLevel
;
3498 n
:= 0; nb
:= 0; nr
:= 0;
3499 for i
:= Low(gPlayers
) to High(gPlayers
) do
3500 if (gPlayers
[i
] <> nil) and
3501 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3502 (gPlayers
[i
] is TBot
)) then
3505 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3506 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3509 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3511 // wait a second until the fuckers finally decide to join
3512 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3513 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3514 gLMSSoftSpawn
:= NoMapRestart
;
3515 if g_Game_IsNet
then
3516 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3520 g_Player_RemoveAllCorpses
;
3521 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3522 if g_Game_IsNet
then
3523 MH_SEND_GameEvent(NET_EV_LMS_START
);
3525 for i
:= Low(gPlayers
) to High(gPlayers
) do
3527 if gPlayers
[i
] = nil then continue
;
3528 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3529 // don't touch normal spectators
3530 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3532 gPlayers
[i
].FNoRespawn
:= True;
3533 gPlayers
[i
].Lives
:= 0;
3534 if g_Game_IsNet
then
3535 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3538 gPlayers
[i
].FNoRespawn
:= False;
3539 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3540 gPlayers
[i
].Respawn(False, True);
3541 if gGameSettings
.GameMode
= GM_COOP
then
3543 gPlayers
[i
].Frags
:= 0;
3544 gPlayers
[i
].RecallState
;
3546 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3547 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3548 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3549 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3552 g_Items_RestartRound();
3554 gLMSSoftSpawn
:= False;
3557 function g_Game_GetFirstMap(WAD
: String): String;
3561 MapList
:= g_Map_GetMapsList(WAD
);
3562 if MapList
= nil then
3565 SortSArray(MapList
);
3566 Result
:= MapList
[Low(MapList
)];
3568 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3574 function g_Game_GetNextMap(): String;
3581 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3582 if MapList
= nil then
3585 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3587 SortSArray(MapList
);
3589 for I
:= Low(MapList
) to High(MapList
) do
3590 if Map
= MapList
[I
] then
3596 if MapIndex
<> -255 then
3598 if MapIndex
= High(MapList
) then
3599 Result
:= MapList
[Low(MapList
)]
3601 Result
:= MapList
[MapIndex
+ 1];
3603 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3609 procedure g_Game_NextLevel();
3611 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3612 gExit
:= EXIT_ENDLEVELCUSTOM
3615 gExit
:= EXIT_ENDLEVELSINGLE
;
3619 if gNextMap
<> '' then Exit
;
3620 gNextMap
:= g_Game_GetNextMap();
3623 function g_Game_IsTestMap(): Boolean;
3625 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3628 procedure g_Game_DeleteTestMap();
3631 //MapName: AnsiString;
3639 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3640 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3641 if (a
= 0) then exit
;
3643 // Выделяем имя wad-файла и имя карты
3644 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3645 Delete(gMapToDelete
, 1, a
+5);
3646 gMapToDelete
:= UpperCase(gMapToDelete
);
3648 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3651 // Имя карты не стандартное тестовое:
3652 if MapName <> TEST_MAP_NAME then
3655 if not gTempDelete then
3657 time := g_GetFileTime(WadName);
3658 WAD := TWADFile.Create();
3661 if not WAD.ReadFile(WadName) then
3662 begin // Нет такого WAD-файла
3667 // Составляем список карт и ищем нужную:
3669 MapList := WAD.GetResourcesList('');
3671 if MapList <> nil then
3672 for a := 0 to High(MapList) do
3673 if MapList[a] = MapName then
3675 // Удаляем и сохраняем:
3676 WAD.RemoveResource('', MapName);
3677 WAD.SaveTo(WadName);
3682 g_SetFileTime(WadName, time);
3685 if gTempDelete
then DeleteFile(WadName
);
3688 procedure GameCVars(P
: SSArray
);
3691 stat
: TPlayerStatArray
;
3694 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3698 if Length(P
) > 1 then
3703 gsGameFlags
:= gsGameFlags
or Flag
3705 gsGameFlags
:= gsGameFlags
and (not Flag
);
3707 if g_Game_IsServer
then
3710 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3712 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3713 if g_Game_IsNet
then MH_SEND_GameSettings
;
3717 if LongBool(gsGameFlags
and Flag
) then
3718 g_Console_Add(_lc
[OnMsg
])
3720 g_Console_Add(_lc
[OffMsg
]);
3722 if OnMapChange
and g_Game_IsServer
then
3723 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3728 cmd
:= LowerCase(P
[0]);
3730 if cmd
= 'g_gamemode' then
3732 if (Length(P
) > 1) then
3734 a
:= g_Game_TextToMode(P
[1]);
3735 if a
= GM_SINGLE
then a
:= GM_COOP
;
3736 gsGameMode
:= g_Game_ModeToText(a
);
3737 if g_Game_IsServer
then
3739 gSwitchGameMode
:= a
;
3740 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3741 (gState
= STATE_INTERSINGLE
) then
3742 gSwitchGameMode
:= GM_SINGLE
;
3744 gGameSettings
.GameMode
:= gSwitchGameMode
;
3748 if gSwitchGameMode
= gGameSettings
.GameMode
then
3749 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3750 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3752 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3753 [g_Game_ModeToText(gGameSettings
.GameMode
),
3754 g_Game_ModeToText(gSwitchGameMode
)]));
3756 else if cmd
= 'g_friendlyfire' then
3758 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3760 else if cmd
= 'g_friendly_absorb_damage' then
3762 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
3764 else if cmd
= 'g_friendly_hit_trace' then
3766 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
3768 else if cmd
= 'g_friendly_hit_projectile' then
3770 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
3772 else if cmd
= 'g_weaponstay' then
3774 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3776 else if cmd
= 'g_allow_exit' then
3778 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3780 else if cmd
= 'g_allow_monsters' then
3782 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3784 else if cmd
= 'g_allow_dropflag' then
3786 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
3788 else if cmd
= 'g_throw_flag' then
3790 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
3792 else if cmd
= 'g_bot_vsplayers' then
3794 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3796 else if cmd
= 'g_bot_vsmonsters' then
3798 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3800 else if cmd
= 'g_dm_keys' then
3802 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
3804 else if cmd
= 'g_gameflags' then
3806 if Length(P
) > 1 then
3808 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
3809 if g_Game_IsServer
then
3811 gGameSettings
.Options
:= gsGameFlags
;
3812 if g_Game_IsNet
then MH_SEND_GameSettings
;
3816 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
3818 else if cmd
= 'g_warmup_time' then
3820 if Length(P
) > 1 then
3822 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
3823 if g_Game_IsServer
then
3825 gGameSettings
.WarmupTime
:= gsWarmupTime
;
3826 // extend warmup if it's already going
3827 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
3829 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
3830 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3832 if g_Game_IsNet
then MH_SEND_GameSettings
;
3836 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
3837 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3839 else if cmd
= 'g_spawn_invul' then
3841 if Length(P
) > 1 then
3843 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
3844 if g_Game_IsServer
then
3846 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
3847 if g_Game_IsNet
then MH_SEND_GameSettings
;
3851 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
3853 else if cmd
= 'g_item_respawn_time' then
3855 if Length(P
) > 1 then
3857 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
3858 if g_Game_IsServer
then
3860 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
3861 if g_Game_IsNet
then MH_SEND_GameSettings
;
3865 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
3866 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3868 else if cmd
= 'sv_intertime' then
3870 if (Length(P
) > 1) then
3871 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
3873 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
3875 else if cmd
= 'g_max_particles' then
3877 if Length(p
) = 2 then
3879 a
:= Max(0, StrToIntDef(p
[1], 0));
3882 else if Length(p
) = 1 then
3884 e_LogWritefln('%s', [g_GFX_GetMax()])
3888 e_LogWritefln('usage: %s <n>', [cmd
])
3891 else if cmd
= 'g_max_shells' then
3893 if Length(p
) = 2 then
3895 a
:= Max(0, StrToIntDef(p
[1], 0));
3898 else if Length(p
) = 1 then
3900 e_LogWritefln('%s', [g_Shells_GetMax()])
3904 e_LogWritefln('usage: %s <n>', [cmd
])
3907 else if cmd
= 'g_max_gibs' then
3909 if Length(p
) = 2 then
3911 a
:= Max(0, StrToIntDef(p
[1], 0));
3914 else if Length(p
) = 1 then
3916 e_LogWritefln('%s', [g_Gibs_GetMax()])
3920 e_LogWritefln('usage: %s <n>', [cmd
])
3923 else if cmd
= 'g_max_corpses' then
3925 if Length(p
) = 2 then
3927 a
:= Max(0, StrToIntDef(p
[1], 0));
3930 else if Length(p
) = 1 then
3932 e_LogWritefln('%s', [g_Corpses_GetMax()])
3936 e_LogWritefln('usage: %s <n>', [cmd
])
3939 else if cmd
= 'g_force_model' then
3941 if Length(p
) = 2 then
3943 a
:= StrToIntDef(p
[1], 0);
3944 g_Force_Model_Set(a
);
3945 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
3947 for a
:= Low(gPlayers
) to High(gPlayers
) do
3949 if (gPlayers
[a
] <> nil) then
3951 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
3953 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
3955 gPlayers
[a
].setModel(g_Forced_Model_GetName());
3959 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
3961 for a
:= Low(gPlayers
) to High(gPlayers
) do
3963 if (gPlayers
[a
] <> nil) then
3965 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
3967 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
3969 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
3975 else if cmd
= 'g_force_model_name' then
3977 if (Length(P
) > 1) then
3979 cmd
:= b_Text_Unformat(P
[1]);
3980 g_Forced_Model_SetName(cmd
);
3981 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
3983 for a
:= Low(gPlayers
) to High(gPlayers
) do
3985 if (gPlayers
[a
] <> nil) then
3987 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
3989 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
3991 gPlayers
[a
].setModel(g_Forced_Model_GetName());
3997 else if cmd
= 'g_scorelimit' then
3999 if Length(P
) > 1 then
4001 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4003 if g_Game_IsServer
then
4006 if gGameSettings
.GameMode
= GM_DM
then
4008 stat
:= g_Player_GetStats();
4010 for a
:= 0 to High(stat
) do
4011 if stat
[a
].Frags
> b
then
4015 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4017 // if someone has a higher score, set it to that instead
4018 gsScoreLimit
:= max(gsScoreLimit
, b
);
4019 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4021 if g_Game_IsNet
then MH_SEND_GameSettings
;
4025 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4027 else if cmd
= 'g_timelimit' then
4029 if Length(P
) > 1 then
4031 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4032 if g_Game_IsServer
then
4034 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4035 if g_Game_IsNet
then MH_SEND_GameSettings
;
4038 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4039 [gsTimeLimit
div 3600,
4040 (gsTimeLimit
div 60) mod 60,
4041 gsTimeLimit
mod 60]));
4043 else if cmd
= 'g_max_bots' then
4045 if Length(P
) > 1 then
4046 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4047 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4049 else if cmd
= 'g_maxlives' then
4051 if Length(P
) > 1 then
4053 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4054 if g_Game_IsServer
then
4056 gGameSettings
.MaxLives
:= gsMaxLives
;
4057 if g_Game_IsNet
then MH_SEND_GameSettings
;
4061 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4065 procedure PlayerSettingsCVars(P
: SSArray
);
4070 function ParseTeam(s
: string): Byte;
4074 'red', '1': result
:= TEAM_RED
;
4075 'blue', '2': result
:= TEAM_BLUE
;
4076 else result
:= TEAM_NONE
;
4080 cmd
:= LowerCase(P
[0]);
4084 if (Length(P
) > 1) then
4086 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4087 if g_Game_IsClient
then
4088 MC_SEND_PlayerSettings
4089 else if gGameOn
and (gPlayer1
<> nil) then
4091 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4092 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4098 if (Length(P
) > 1) then
4100 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4101 if g_Game_IsClient
then
4102 MC_SEND_PlayerSettings
4103 else if gGameOn
and (gPlayer2
<> nil) then
4105 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4106 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4112 if Length(P
) > 3 then
4114 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4115 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4116 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4117 if g_Game_IsClient
then
4118 MC_SEND_PlayerSettings
4119 else if gGameOn
and (gPlayer1
<> nil) then
4121 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4122 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4128 if Length(P
) > 3 then
4130 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4131 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4132 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4133 if g_Game_IsClient
then
4134 MC_SEND_PlayerSettings
4135 else if gGameOn
and (gPlayer2
<> nil) then
4137 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4138 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4144 if (Length(P
) > 1) then
4146 gPlayer1Settings
.Model
:= P
[1];
4147 if g_Game_IsClient
then
4148 MC_SEND_PlayerSettings
4149 else if gGameOn
and (gPlayer1
<> nil) then
4151 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4152 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4153 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4159 if (Length(P
) > 1) then
4161 gPlayer2Settings
.Model
:= P
[1];
4162 if g_Game_IsClient
then
4163 MC_SEND_PlayerSettings
4164 else if gGameOn
and (gPlayer2
<> nil) then
4166 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4167 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4168 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4174 // TODO: switch teams if in game or store this separately
4175 if (Length(P
) > 1) then
4177 team
:= ParseTeam(P
[1]);
4178 if team
= TEAM_NONE
then
4179 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4180 else if not gGameOn
and not g_Game_IsNet
then
4181 gPlayer1Settings
.Team
:= team
4183 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4188 // TODO: switch teams if in game or store this separately
4189 if (Length(P
) > 1) then
4191 team
:= ParseTeam(P
[1]);
4192 if team
= TEAM_NONE
then
4193 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4194 else if not gGameOn
and not g_Game_IsNet
then
4195 gPlayer2Settings
.Team
:= team
4197 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4202 if (Length(P
) = 2) then
4203 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4207 if (Length(P
) = 2) then
4208 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4212 if (Length(P
) = 2) then
4213 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4217 if (Length(P
) = 2) then
4218 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4222 if (Length(P
) = 2) then
4223 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4227 if (Length(P
) = 2) then
4228 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4230 'p1_priority_kastet':
4232 if (Length(P
) = 2) then
4233 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4235 'p2_priority_kastet':
4237 if (Length(P
) = 2) then
4238 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4242 if (Length(P
) = 2) then
4243 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4247 if (Length(P
) = 2) then
4248 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4250 'p1_priority_pistol':
4252 if (Length(P
) = 2) then
4253 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4255 'p2_priority_pistol':
4257 if (Length(P
) = 2) then
4258 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4260 'p1_priority_shotgun1':
4262 if (Length(P
) = 2) then
4263 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4265 'p2_priority_shotgun1':
4267 if (Length(P
) = 2) then
4268 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4270 'p1_priority_shotgun2':
4272 if (Length(P
) = 2) then
4273 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4275 'p2_priority_shotgun2':
4277 if (Length(P
) = 2) then
4278 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4280 'p1_priority_chaingun':
4282 if (Length(P
) = 2) then
4283 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4285 'p2_priority_chaingun':
4287 if (Length(P
) = 2) then
4288 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4290 'p1_priority_rocketlauncher':
4292 if (Length(P
) = 2) then
4293 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4295 'p2_priority_rocketlauncher':
4297 if (Length(P
) = 2) then
4298 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4300 'p1_priority_plasma':
4302 if (Length(P
) = 2) then
4303 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4305 'p2_priority_plasma':
4307 if (Length(P
) = 2) then
4308 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4312 if (Length(P
) = 2) then
4313 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4317 if (Length(P
) = 2) then
4318 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4320 'p1_priority_super':
4322 if (Length(P
) = 2) then
4323 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4325 'p2_priority_super':
4327 if (Length(P
) = 2) then
4328 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4330 'p1_priority_flamethrower':
4332 if (Length(P
) = 2) then
4333 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4335 'p2_priority_flamethrower':
4337 if (Length(P
) = 2) then
4338 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4340 'p1_priority_berserk':
4342 if (Length(P
) = 2) then
4343 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4345 'p2_priority_berserk':
4347 if (Length(P
) = 2) then
4348 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4353 procedure PrintHeapStats();
4357 hs
:= GetFPCHeapStatus();
4358 e_LogWriteLn ('v===== heap status =====v');
4359 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4360 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4361 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4362 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4363 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4364 e_LogWriteLn ('^=======================^');
4367 procedure DebugCommands(P
: SSArray
);
4374 // Команды отладочного режима:
4375 if {gDebugMode}conIsCheatsEnabled
then
4377 cmd
:= LowerCase(P
[0]);
4378 if cmd
= 'd_window' then
4380 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4381 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4383 else if cmd
= 'd_sounds' then
4385 if (Length(P
) > 1) and
4386 ((P
[1] = '1') or (P
[1] = '0')) then
4387 g_Debug_Sounds
:= (P
[1][1] = '1');
4389 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4391 else if cmd
= 'd_frames' then
4393 if (Length(P
) > 1) and
4394 ((P
[1] = '1') or (P
[1] = '0')) then
4395 g_Debug_Frames
:= (P
[1][1] = '1');
4397 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4399 else if cmd
= 'd_winmsg' then
4401 if (Length(P
) > 1) and
4402 ((P
[1] = '1') or (P
[1] = '0')) then
4403 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4405 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4407 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4409 if (Length(P
) > 1) and
4410 ((P
[1] = '1') or (P
[1] = '0')) then
4411 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4413 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4415 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4417 if Length(P
) > 1 then
4419 '0': g_debug_BotAIOff
:= 0;
4420 '1': g_debug_BotAIOff
:= 1;
4421 '2': g_debug_BotAIOff
:= 2;
4422 '3': g_debug_BotAIOff
:= 3;
4425 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4427 else if cmd
= 'd_monster' then
4429 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4430 if Length(P
) < 2 then
4432 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4433 g_Console_Add('ID | Name');
4434 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4435 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4436 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4439 a
:= StrToIntDef(P
[1], 0);
4440 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4441 a
:= g_Mons_TypeIdByName(P
[1]);
4443 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4444 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4447 with gPlayer1
.Obj
do
4449 mon
:= g_Monsters_Create(a
,
4450 X
+ Rect
.X
+ (Rect
.Width
div 2),
4451 Y
+ Rect
.Y
+ Rect
.Height
,
4452 gPlayer1
.Direction
, True);
4454 if (Length(P
) > 2) and (mon
<> nil) then
4456 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4457 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4458 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4459 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4460 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4461 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4462 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4463 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4464 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4469 else if (cmd
= 'd_health') then
4471 if (Length(P
) > 1) and
4472 ((P
[1] = '1') or (P
[1] = '0')) then
4473 g_debug_HealthBar
:= (P
[1][1] = '1');
4475 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4477 else if (cmd
= 'd_player') then
4479 if (Length(P
) > 1) and
4480 ((P
[1] = '1') or (P
[1] = '0')) then
4481 g_debug_Player
:= (P
[1][1] = '1');
4483 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4485 else if (cmd
= 'd_mem') then
4491 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4495 procedure GameCheats(P
: SSArray
);
4501 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4503 g_Console_Add('not available');
4509 g_Console_Add('where is the player?!');
4512 cmd
:= LowerCase(P
[0]);
4516 plr
.GodMode
:= not plr
.GodMode
;
4517 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4520 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4521 if cmd
= 'give' then
4523 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4524 for f
:= 1 to High(P
) do
4526 cmd
:= LowerCase(P
[f
]);
4527 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4528 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4529 if cmd
= 'exit' then
4531 if gTriggers
<> nil then
4533 for a
:= 0 to High(gTriggers
) do
4535 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4537 g_Console_Add('player left the map');
4538 gExitByTrigger
:= True;
4539 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4540 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4548 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4549 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4550 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4551 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4552 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4554 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4555 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4557 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4558 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;
4560 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4561 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4563 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4564 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4566 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4567 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4569 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4570 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4571 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4573 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4574 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4575 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4576 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;
4577 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4578 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4580 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;
4581 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;
4582 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;
4583 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;
4584 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;
4585 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;
4587 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4588 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;
4590 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;
4591 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;
4593 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4595 if cmd
= 'ammo' then
4597 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4598 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4599 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4600 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4601 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4602 g_Console_Add('player got some ammo');
4606 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4607 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4609 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4610 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4612 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4613 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4615 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4616 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4618 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4620 if cmd
= 'weapons' then
4622 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4623 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4624 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4625 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4626 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4627 plr
.GiveItem(ITEM_WEAPON_BFG
);
4628 g_Console_Add('player got weapons');
4632 if cmd
= 'keys' then
4634 plr
.GiveItem(ITEM_KEY_RED
);
4635 plr
.GiveItem(ITEM_KEY_GREEN
);
4636 plr
.GiveItem(ITEM_KEY_BLUE
);
4637 g_Console_Add('player got all keys');
4641 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4646 if cmd
= 'open' then
4648 g_Console_Add('player activated sesame');
4649 g_Triggers_OpenAll();
4656 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4660 if cmd
= 'noclip' then
4663 g_Console_Add('wall hardeness adjusted');
4667 if cmd
= 'notarget' then
4669 plr
.NoTarget
:= not plr
.NoTarget
;
4670 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4674 if cmd
= 'noreload' then
4676 plr
.NoReload
:= not plr
.NoReload
;
4677 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4681 if cmd
= 'speedy' then
4683 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4684 g_Console_Add('speed adjusted');
4688 if cmd
= 'jumpy' then
4690 VEL_JUMP
:= 30-VEL_JUMP
;
4691 g_Console_Add('jump height adjusted');
4695 if cmd
= 'automap' then
4697 gShowMap
:= not gShowMap
;
4698 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4702 if cmd
= 'aimline' then
4704 gAimLine
:= not gAimLine
;
4705 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4710 procedure GameCommands(P
: SSArray
);
4716 pl
: pTNetClient
= nil;
4724 cmd
:= LowerCase(P
[0]);
4726 if cmd
= 'pause' then
4728 if (g_ActiveWindow
= nil) then
4729 g_Game_Pause(not gPauseMain
);
4731 else if cmd
= 'endgame' then
4732 gExit
:= EXIT_SIMPLE
4733 else if cmd
= 'restart' then
4735 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4737 if g_Game_IsClient
then
4739 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4744 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4746 else if cmd
= 'kick' then
4748 if g_Game_IsServer
then
4750 if Length(P
) < 2 then
4752 g_Console_Add('kick <name>');
4757 g_Console_Add('kick <name>');
4761 if g_Game_IsNet
then
4762 pl
:= g_Net_Client_ByName(P
[1]);
4765 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4766 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4767 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4768 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4769 g_Net_Slist_ServerPlayerLeaves();
4770 end else if gPlayers
<> nil then
4771 for a
:= Low(gPlayers
) to High(gPlayers
) do
4772 if gPlayers
[a
] <> nil then
4773 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4775 // Не отключать основных игроков в сингле
4776 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4778 gPlayers
[a
].Lives
:= 0;
4779 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4780 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4781 g_Player_Remove(gPlayers
[a
].UID
);
4782 g_Net_Slist_ServerPlayerLeaves();
4783 // Если не перемешать, при добавлении новых ботов появятся старые
4787 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4789 else if cmd
= 'kick_id' then
4791 if g_Game_IsServer
and g_Game_IsNet
then
4793 if Length(P
) < 2 then
4795 g_Console_Add('kick_id <client ID>');
4800 g_Console_Add('kick_id <client ID>');
4804 a
:= StrToIntDef(P
[1], 0);
4805 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4807 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4809 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4810 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
4811 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4812 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4813 g_Net_Slist_ServerPlayerLeaves();
4817 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4819 else if cmd
= 'kick_pid' then
4821 if g_Game_IsServer
and g_Game_IsNet
then
4823 if Length(P
) < 2 then
4825 g_Console_Add('kick_pid <player ID>');
4830 g_Console_Add('kick_pid <player ID>');
4834 a
:= StrToIntDef(P
[1], 0);
4835 pl
:= g_Net_Client_ByPlayer(a
);
4836 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4838 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4839 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4840 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4841 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4842 g_Net_Slist_ServerPlayerLeaves();
4845 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4847 else if cmd
= 'ban' then
4849 if g_Game_IsServer
and g_Game_IsNet
then
4851 if Length(P
) < 2 then
4853 g_Console_Add('ban <name>');
4858 g_Console_Add('ban <name>');
4862 pl
:= g_Net_Client_ByName(P
[1]);
4865 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4866 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4867 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
4868 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4869 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4870 g_Net_Slist_ServerPlayerLeaves();
4872 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4874 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4876 else if cmd
= 'ban_id' then
4878 if g_Game_IsServer
and g_Game_IsNet
then
4880 if Length(P
) < 2 then
4882 g_Console_Add('ban_id <client ID>');
4887 g_Console_Add('ban_id <client ID>');
4891 a
:= StrToIntDef(P
[1], 0);
4892 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4893 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4895 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4896 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
4897 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
4898 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4899 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4900 g_Net_Slist_ServerPlayerLeaves();
4903 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4905 else if cmd
= 'ban_pid' then
4907 if g_Game_IsServer
and g_Game_IsNet
then
4909 if Length(P
) < 2 then
4911 g_Console_Add('ban_pid <player ID>');
4916 g_Console_Add('ban_pid <player ID>');
4920 a
:= StrToIntDef(P
[1], 0);
4921 pl
:= g_Net_Client_ByPlayer(a
);
4922 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4924 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4925 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4926 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
4927 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4928 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4929 g_Net_Slist_ServerPlayerLeaves();
4932 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4934 else if cmd
= 'permban' then
4936 if g_Game_IsServer
and g_Game_IsNet
then
4938 if Length(P
) < 2 then
4940 g_Console_Add('permban <name>');
4945 g_Console_Add('permban <name>');
4949 pl
:= g_Net_Client_ByName(P
[1]);
4952 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4953 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4954 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
4955 g_Net_SaveBanList();
4956 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4957 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4958 g_Net_Slist_ServerPlayerLeaves();
4960 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4962 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4964 else if cmd
= 'permban_id' then
4966 if g_Game_IsServer
and g_Game_IsNet
then
4968 if Length(P
) < 2 then
4970 g_Console_Add('permban_id <client ID>');
4975 g_Console_Add('permban_id <client ID>');
4979 a
:= StrToIntDef(P
[1], 0);
4980 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4981 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4983 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4984 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
4985 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
4986 g_Net_SaveBanList();
4987 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4988 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4989 g_Net_Slist_ServerPlayerLeaves();
4992 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4994 else if cmd
= 'permban_pid' then
4996 if g_Game_IsServer
and g_Game_IsNet
then
4998 if Length(P
) < 2 then
5000 g_Console_Add('permban_pid <player ID>');
5005 g_Console_Add('permban_pid <player ID>');
5009 a
:= StrToIntDef(P
[1], 0);
5010 pl
:= g_Net_Client_ByPlayer(a
);
5011 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5013 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5014 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5015 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5016 g_Net_SaveBanList();
5017 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5018 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5019 g_Net_Slist_ServerPlayerLeaves();
5022 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5024 else if cmd
= 'permban_ip' then
5026 if g_Game_IsServer
and g_Game_IsNet
then
5028 if Length(P
) < 2 then
5030 g_Console_Add('permban_ip <IP address>');
5035 g_Console_Add('permban_ip <IP address>');
5039 g_Net_BanHost(P
[1]);
5040 g_Net_SaveBanList();
5041 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5043 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5045 else if cmd
= 'unban' then
5047 if g_Game_IsServer
and g_Game_IsNet
then
5049 if Length(P
) < 2 then
5051 g_Console_Add('unban <IP Address>');
5056 g_Console_Add('unban <IP Address>');
5060 if g_Net_UnbanHost(P
[1]) then
5062 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5063 g_Net_SaveBanList();
5065 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5067 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5069 else if cmd
= 'clientlist' then
5071 if g_Game_IsServer
and g_Game_IsNet
then
5074 if NetClients
<> nil then
5075 for a
:= Low(NetClients
) to High(NetClients
) do
5076 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5078 plr
:= g_Player_Get(NetClients
[a
].Player
);
5079 if plr
= nil then continue
;
5081 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5082 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5085 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5087 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5089 else if cmd
= 'connect' then
5091 if (NetMode
= NET_NONE
) then
5093 if Length(P
) < 2 then
5095 g_Console_Add('connect <IP> [port] [password]');
5100 g_Console_Add('connect <IP> [port] [password]');
5104 if Length(P
) > 2 then
5105 prt
:= StrToIntDef(P
[2], 25666)
5109 if Length(P
) > 3 then
5114 g_Game_StartClient(P
[1], prt
, pw
);
5117 else if cmd
= 'disconnect' then
5119 if (NetMode
= NET_CLIENT
) then
5122 else if cmd
= 'reconnect' then
5124 if (NetMode
= NET_SERVER
) then
5127 if (NetMode
= NET_CLIENT
) then
5130 gExit
:= EXIT_SIMPLE
;
5134 //TODO: Use last successful password to reconnect, instead of ''
5135 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5137 else if (cmd
= 'addbot') or
5138 (cmd
= 'bot_add') then
5140 if Length(P
) > 2 then
5141 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5142 else if Length(P
) > 1 then
5143 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5145 g_Bot_Add(TEAM_NONE
, 2);
5147 else if cmd
= 'bot_addlist' then
5149 if Length(P
) > 1 then
5151 if Length(P
) = 2 then
5152 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5153 else if Length(P
) = 3 then
5154 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5156 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5159 else if cmd
= 'bot_removeall' then
5161 else if cmd
= 'chat' then
5163 if g_Game_IsNet
then
5165 if Length(P
) > 1 then
5167 for a
:= 1 to High(P
) do
5168 chstr
:= chstr
+ P
[a
] + ' ';
5170 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5172 if Length(chstr
) < 1 then
5174 g_Console_Add('chat <text>');
5178 chstr
:= b_Text_Format(chstr
);
5179 if g_Game_IsClient
then
5180 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5182 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5185 g_Console_Add('chat <text>');
5187 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5189 else if cmd
= 'teamchat' then
5191 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5193 if Length(P
) > 1 then
5195 for a
:= 1 to High(P
) do
5196 chstr
:= chstr
+ P
[a
] + ' ';
5198 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5200 if Length(chstr
) < 1 then
5202 g_Console_Add('teamchat <text>');
5206 chstr
:= b_Text_Format(chstr
);
5207 if g_Game_IsClient
then
5208 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5210 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5211 gPlayer1Settings
.Team
);
5214 g_Console_Add('teamchat <text>');
5216 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5218 else if (cmd
= 'an') or (cmd
= 'announce') then
5220 if g_Game_IsNet
then
5222 if Length(P
) > 1 then
5224 for a
:= 1 to High(P
) do
5225 chstr
:= chstr
+ P
[a
] + ' ';
5227 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5229 if Length(chstr
) < 1 then
5231 g_Console_Add('announce <text>');
5235 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5236 if g_Game_IsClient
then
5237 MC_SEND_RCONCommand(chstr
)
5239 g_Console_Process(chstr
, True);
5242 g_Console_Add('announce <text>');
5244 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5246 else if cmd
= 'game' then
5248 if gGameSettings
.GameType
<> GT_NONE
then
5250 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5253 if Length(P
) = 1 then
5255 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5258 // game not started yet, load fist map from some wad
5260 s
:= addWadExtension(P
[1]);
5261 found
:= e_FindResource(AllMapDirs
, s
);
5265 P
[1] := ExpandFileName(P
[1]);
5266 // if map not choosed then set first map
5267 if Length(P
) < 3 then
5270 P
[2] := g_Game_GetFirstMap(P
[1]);
5273 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5275 if g_Map_Exist(s
) then
5279 with gGameSettings
do
5281 Options
:= gsGameFlags
;
5282 GameMode
:= g_Game_TextToMode(gsGameMode
);
5283 if gSwitchGameMode
<> GM_NONE
then
5284 GameMode
:= gSwitchGameMode
;
5285 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5286 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5288 if Length(P
) >= 4 then
5289 b
:= StrToIntDef(P
[3], 1);
5290 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5291 ScoreLimit
, MaxLives
, Options
, b
);
5296 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5298 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5300 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5302 else if cmd
= 'host' then
5304 if gGameSettings
.GameType
<> GT_NONE
then
5306 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5309 if Length(P
) < 4 then
5311 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5314 if not StrToIp(P
[1], listen
) then
5316 prt
:= StrToIntDef(P
[2], 25666);
5318 s
:= addWadExtension(P
[3]);
5319 found
:= e_FindResource(AllMapDirs
, s
);
5323 // get first map in wad, if not specified
5324 if Length(P
) < 5 then
5327 P
[4] := g_Game_GetFirstMap(P
[1]);
5329 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5330 if g_Map_Exist(s
) then
5334 with gGameSettings
do
5336 Options
:= gsGameFlags
;
5337 GameMode
:= g_Game_TextToMode(gsGameMode
);
5338 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5339 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5340 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5342 if Length(P
) >= 6 then
5343 b
:= StrToIntDef(P
[5], 0);
5344 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5350 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5352 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5357 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5360 else if cmd
= 'map' then
5362 if Length(P
) = 1 then
5364 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5366 g_Console_Add(cmd
+ ' <MAP>');
5367 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5371 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5376 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5378 if Length(P
) < 3 then
5380 // first param is map or wad
5381 s
:= UpperCase(P
[1]);
5382 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5384 gExitByTrigger
:= False;
5387 // already in game, finish current map
5389 gExit
:= EXIT_ENDLEVELCUSTOM
;
5393 // intermission, so change map immediately
5400 found
:= e_FindResource(AllMapDirs
, s
);
5402 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5405 // no such map, found wad
5408 P
[1] := ExpandFileName(pw
);
5409 P
[2] := g_Game_GetFirstMap(P
[1]);
5410 s
:= P
[1] + ':\' + P
[2];
5411 if g_Map_Exist(s
) then
5413 gExitByTrigger
:= False;
5416 // already in game, finish current map
5418 gExit
:= EXIT_ENDLEVELCUSTOM
5422 // intermission, so change map immediately
5429 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5431 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5436 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5442 s
:= addWadExtension(P
[1]);
5443 found
:= e_FindResource(AllMapDirs
, s
);
5447 P
[2] := UpperCase(P
[2]);
5448 s
:= P
[1] + ':\' + P
[2];
5449 if g_Map_Exist(s
) then
5451 gExitByTrigger
:= False;
5455 gExit
:= EXIT_ENDLEVELCUSTOM
5464 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5469 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5475 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5479 else if cmd
= 'nextmap' then
5481 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5483 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5488 if Length(P
) = 1 then
5490 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5492 g_Console_Add(cmd
+ ' <MAP>');
5493 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5498 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5504 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5506 if Length(P
) < 3 then
5508 // first param is map or wad
5509 s
:= UpperCase(P
[1]);
5510 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5513 gExitByTrigger
:= False;
5519 // no such map, found wad
5520 pw
:= addWadExtension(P
[1]);
5521 found
:= e_FindResource(MapDirs
, pw
);
5523 found
:= e_FindResource(WadDirs
, pw
);
5525 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5528 // map not specified, select first map
5530 P
[2] := g_Game_GetFirstMap(P
[1]);
5531 s
:= P
[1] + ':\' + P
[2];
5532 if g_Map_Exist(s
) then
5534 gExitByTrigger
:= False;
5541 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5543 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5548 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5554 // specified two params wad + map
5555 pw
:= addWadExtension(P
[1]);
5556 found
:= e_FindResource(MapDirs
, pw
);
5558 found
:= e_FindResource(MapDirs
, pw
);
5562 P
[2] := UpperCase(P
[2]);
5563 s
:= P
[1] + ':\' + P
[2];
5564 if g_Map_Exist(s
) then
5566 gExitByTrigger
:= False;
5572 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5577 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5583 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5588 if gNextMap
= '' then
5589 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5591 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5595 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5599 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5603 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5605 gExitByTrigger
:= False;
5606 // next map not specified, try to find trigger EXIT
5607 if (gNextMap
= '') and (gTriggers
<> nil) then
5609 for a
:= 0 to High(gTriggers
) do
5611 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5613 gExitByTrigger
:= True;
5614 //gNextMap := gTriggers[a].Data.MapName;
5615 gNextMap
:= gTriggers
[a
].tgcMap
;
5620 if gNextMap
= '' then
5621 gNextMap
:= g_Game_GetNextMap();
5622 if not isWadPath(gNextMap
) then
5623 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5626 if g_Map_Exist(s
) then
5627 gExit
:= EXIT_ENDLEVELCUSTOM
5629 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5633 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5637 else if (cmd
= 'event') then
5639 if (Length(P
) <= 1) then
5641 for a
:= 0 to High(gEvents
) do
5642 if gEvents
[a
].Command
= '' then
5643 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5645 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5648 if (Length(P
) = 2) then
5650 for a
:= 0 to High(gEvents
) do
5651 if gEvents
[a
].Name
= P
[1] then
5652 if gEvents
[a
].Command
= '' then
5653 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5655 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5658 for a
:= 0 to High(gEvents
) do
5659 if gEvents
[a
].Name
= P
[1] then
5661 gEvents
[a
].Command
:= '';
5662 for b
:= 2 to High(P
) do
5663 if Pos(' ', P
[b
]) = 0 then
5664 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5666 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5667 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5671 else if cmd
= 'suicide' then
5675 if g_Game_IsClient
then
5676 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5679 if gPlayer1
<> nil then
5680 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5681 if gPlayer2
<> nil then
5682 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5686 else if cmd
= 'screenshot' then
5690 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5692 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5694 gWeaponAction
[0, WP_PREV
] := True;
5696 gWeaponAction
[0, WP_NEXT
] := True;
5698 else if cmd
= 'weapon' then
5700 if Length(p
) = 2 then
5702 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5703 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5704 gSelectWeapon
[0, a
] := True
5707 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5708 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5710 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5711 b
:= ord(cmd
[2]) - ord('1');
5713 gWeaponAction
[b
, WP_PREV
] := True;
5715 gWeaponAction
[b
, WP_NEXT
] := True;
5717 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5719 if Length(p
) = 2 then
5721 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5722 b
:= ord(cmd
[2]) - ord('1');
5723 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5724 gSelectWeapon
[b
, a
] := True
5727 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
5729 b
:= ord(cmd
[2]) - ord('1');
5731 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
5733 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
5735 else if (cmd
= 'dropflag') then
5737 if g_Game_IsServer
then
5739 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
5740 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
5743 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5745 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
5747 b
:= ord(cmd
[2]) - ord('1');
5748 if g_Game_IsServer
then
5750 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
5751 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
5754 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5756 // Команды Своей игры:
5757 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5759 if cmd
= 'bot_addred' then
5761 if Length(P
) > 1 then
5762 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5764 g_Bot_Add(TEAM_RED
, 2);
5766 else if cmd
= 'bot_addblue' then
5768 if Length(P
) > 1 then
5769 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5771 g_Bot_Add(TEAM_BLUE
, 2);
5773 else if cmd
= 'spectate' then
5779 else if cmd
= 'say' then
5781 if g_Game_IsServer
and g_Game_IsNet
then
5783 if Length(P
) > 1 then
5786 for a
:= 1 to High(P
) do
5787 chstr
:= chstr
+ P
[a
] + ' ';
5789 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5791 if Length(chstr
) < 1 then
5793 g_Console_Add('say <text>');
5797 chstr
:= b_Text_Format(chstr
);
5798 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5800 else g_Console_Add('say <text>');
5802 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5804 else if cmd
= 'tell' then
5806 if g_Game_IsServer
and g_Game_IsNet
then
5808 if (Length(P
) > 2) and (P
[1] <> '') then
5811 for a
:= 2 to High(P
) do
5812 chstr
:= chstr
+ P
[a
] + ' ';
5814 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5816 if Length(chstr
) < 1 then
5818 g_Console_Add('tell <playername> <text>');
5822 pl
:= g_Net_Client_ByName(P
[1]);
5824 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5826 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5828 else g_Console_Add('tell <playername> <text>');
5830 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5832 else if cmd
= 'centerprint' then
5834 if (Length(P
) > 2) and (P
[1] <> '') then
5837 for a
:= 2 to High(P
) do
5838 chstr
:= chstr
+ P
[a
] + ' ';
5840 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5842 if Length(chstr
) < 1 then
5844 g_Console_Add('centerprint <timeout> <text>');
5848 a
:= StrToIntDef(P
[1], 100);
5849 chstr
:= b_Text_Format(chstr
);
5850 g_Game_Message(chstr
, a
);
5851 if g_Game_IsNet
and g_Game_IsServer
then
5852 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
5854 else g_Console_Add('centerprint <timeout> <text>');
5856 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5858 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5860 // Дополнительное время:
5861 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5863 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5864 [gGameSettings
.TimeLimit
div 3600,
5865 (gGameSettings
.TimeLimit
div 60) mod 60,
5866 gGameSettings
.TimeLimit
mod 60]));
5867 if g_Game_IsNet
then MH_SEND_GameSettings
;
5869 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5871 if (Length(P
) <= 1) then
5872 g_Console_Add('rcon_password <password>')
5874 MC_SEND_RCONPassword(P
[1]);
5876 else if cmd
= 'rcon' then
5878 if g_Game_IsClient
then
5880 if Length(P
) > 1 then
5883 for a
:= 1 to High(P
) do
5884 chstr
:= chstr
+ P
[a
] + ' ';
5886 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5888 if Length(chstr
) < 1 then
5890 g_Console_Add('rcon <command>');
5894 MC_SEND_RCONCommand(chstr
);
5896 else g_Console_Add('rcon <command>');
5899 else if cmd
= 'ready' then
5901 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5902 gLMSRespawnTime
:= gTime
+ 100;
5904 else if (cmd
= 'callvote') and g_Game_IsNet
then
5906 if Length(P
) > 1 then
5909 for a
:= 1 to High(P
) do begin
5910 if a
> 1 then chstr
:= chstr
+ ' ';
5911 chstr
:= chstr
+ P
[a
];
5914 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5916 if Length(chstr
) < 1 then
5918 g_Console_Add('callvote <command>');
5922 if g_Game_IsClient
then
5923 MC_SEND_Vote(True, chstr
)
5925 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5926 g_Console_Process('vote', True);
5929 g_Console_Add('callvote <command>');
5931 else if (cmd
= 'vote') and g_Game_IsNet
then
5933 if g_Game_IsClient
then
5935 else if gVoteInProgress
then
5937 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5938 a
:= Floor((NetClientCount
+1)/2.0) + 1
5940 a
:= Floor(NetClientCount
/2.0) + 1;
5945 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5946 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5952 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5953 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5961 procedure SystemCommands(P
: SSArray
);
5965 cmd
:= LowerCase(P
[0]);
5974 gRC_Width
:= Max(1, gRC_Width
);
5975 gRC_Height
:= Max(1, gRC_Height
);
5976 gBPP
:= Max(1, gBPP
);
5977 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
5978 e_LogWriteln('resolution changed')
5980 e_LogWriteln('resolution not changed');
5981 sys_EnableVSync(gVSync
);
5985 if Length(p
) = 2 then
5987 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
5989 gFrameTime
:= 1000 div gMaxFPS
5993 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
5997 if Length(p
) = 2 then
5999 gAskLanguage
:= true;
6000 gLanguage
:= LANGUAGE_ENGLISH
;
6001 case LowerCase(p
[1]) of
6004 gAskLanguage
:= false;
6005 gLanguage
:= LANGUAGE_ENGLISH
;
6009 gAskLanguage
:= false;
6010 gLanguage
:= LANGUAGE_RUSSIAN
;
6014 gAskLanguage
:= true;
6015 gLanguage
:= LANGUAGE_ENGLISH
;
6018 g_Language_Set(gLanguage
);
6022 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6028 procedure g_TakeScreenShot(Filename
: string = '');
6029 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
6031 if e_NoGraphics
then Exit
;
6033 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6035 if Filename
= '' then
6038 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6039 Filename
:= 'screenshot-' + date
;
6042 name
:= e_CatPath(dir
, Filename
+ '.png');
6043 s
:= createDiskFile(name
);
6045 e_MakeScreenshot(s
, gWinSizeX
, gWinSizeY
);
6047 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6049 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6054 g_Console_Add('oh shit, i can''t create screenshot!')
6058 procedure g_Game_InGameMenu(Show
: Boolean);
6060 if (g_ActiveWindow
= nil) and Show
then
6062 if gGameSettings
.GameType
= GT_SINGLE
then
6063 g_GUI_ShowWindow('GameSingleMenu')
6066 if g_Game_IsClient
then
6067 g_GUI_ShowWindow('GameClientMenu')
6069 if g_Game_IsNet
then
6070 g_GUI_ShowWindow('GameServerMenu')
6072 g_GUI_ShowWindow('GameCustomMenu');
6074 g_Sound_PlayEx('MENU_OPEN');
6076 // Пауза при меню только в одиночной игре:
6077 if (not g_Game_IsNet
) then
6081 if (g_ActiveWindow
<> nil) and (not Show
) then
6083 // Пауза при меню только в одиночной игре:
6084 if (not g_Game_IsNet
) then
6085 g_Game_Pause(False);
6089 procedure g_Game_Pause (Enable
: Boolean);
6093 if not gGameOn
then exit
;
6095 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6098 gPauseMain
:= Enable
;
6100 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6103 procedure g_Game_HolmesPause (Enable
: Boolean);
6107 if not gGameOn
then exit
;
6108 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6111 gPauseHolmes
:= Enable
;
6113 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6116 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6121 if gTriggers
<> nil then
6122 for i
:= 0 to High(gTriggers
) do
6123 with gTriggers
[i
] do
6124 if (TriggerType
= TRIGGER_SOUND
) and
6126 Sound
.IsPlaying() then
6128 Sound
.Pause(Enable
);
6132 if gPlayers
<> nil then
6133 for i
:= 0 to High(gPlayers
) do
6134 if gPlayers
[i
] <> nil then
6135 gPlayers
[i
].PauseSounds(Enable
);
6138 if gMusic
<> nil then
6139 gMusic
.Pause(Enable
);
6142 procedure g_Game_StopAllSounds(all
: Boolean);
6146 if gTriggers
<> nil then
6147 for i
:= 0 to High(gTriggers
) do
6148 with gTriggers
[i
] do
6149 if (TriggerType
= TRIGGER_SOUND
) and
6153 if gMusic
<> nil then
6160 procedure g_Game_UpdateTriggerSounds
;
6163 if gTriggers
<> nil then
6164 for i
:= 0 to High(gTriggers
) do
6165 with gTriggers
[i
] do
6166 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6167 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6170 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6173 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6178 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6183 if gSpectMode
<> SPECT_PLAYERS
then
6185 if gSpectPID1
= UID
then
6190 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6197 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6202 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6207 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6212 if gSpectMode
<> SPECT_PLAYERS
then
6214 Pl
:= g_Player_Get(gSpectPID1
);
6215 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6220 if gSpectViewTwo
then
6222 Pl
:= g_Player_Get(gSpectPID2
);
6223 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6231 procedure g_Game_Message(Msg
: string; Time
: Word);
6233 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
6234 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
6235 MessageTime
:= Time
;
6238 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6240 punct
: Array[0..13] of String =
6241 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6247 function IsPunctuation(S
: String): Boolean;
6252 if Length(S
) <> 1 then
6254 for i
:= Low(punct
) to High(punct
) do
6255 if S
= punct
[i
] then
6261 function FilterPunctuation(S
: String): String;
6265 for i
:= Low(punct
) to High(punct
) do
6266 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6272 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6274 // remove player name
6275 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6276 // for FullWord check
6277 Text := toLowerCase1251(' ' + Text + ' ');
6278 fpText
:= FilterPunctuation(Text);
6280 for i
:= 0 to Length(gChatSounds
) - 1 do
6283 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6285 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6286 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6288 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6294 gChatSounds
[i
].Sound
.Play();
6300 g_Sound_PlayEx('SOUND_GAME_RADIO');
6303 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6312 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6316 if goodsnd
[a
].IsPlaying() then
6319 goodsnd
[Random(4)].Play();
6322 procedure g_Game_Announce_KillCombo(Param
: Integer);
6329 UID
:= Param
and $FFFF;
6334 Pl
:= g_Player_Get(UID
);
6343 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6347 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6351 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6355 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6363 if not g_Game_IsWatchedPlayer(UID
) then
6366 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6370 if killsnd
[n
].IsPlaying() then
6375 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6383 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6387 if hahasnd
[a
].IsPlaying() then
6390 hahasnd
[Random(3)].Play();
6393 procedure g_Game_StartVote(Command
, Initiator
: string);
6397 if not gVotesEnabled
then Exit
;
6398 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6399 if gVoteInProgress
or gVotePassed
then
6401 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6402 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6405 gVoteInProgress
:= True;
6406 gVotePassed
:= False;
6407 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6410 gVoteCommand
:= Command
;
6412 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6413 Need
:= Floor((NetClientCount
+1)/2.0)+1
6415 Need
:= Floor(NetClientCount
/2.0)+1;
6416 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6417 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6420 procedure g_Game_CheckVote
;
6424 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6425 if not gVoteInProgress
then Exit
;
6427 if (gTime
>= gVoteTimer
) then
6429 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6430 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6432 Need
:= Floor(NetClientCount
/2.0) + 1;
6433 if gVoteCount
>= Need
then
6435 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6436 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6437 gVotePassed
:= True;
6438 gVoteCmdTimer
:= gTime
+ 5000;
6442 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6443 MH_SEND_VoteEvent(NET_VE_FAILED
);
6445 if NetClients
<> nil then
6446 for I
:= Low(NetClients
) to High(NetClients
) do
6447 if NetClients
[i
].Used
then
6448 NetClients
[i
].Voted
:= False;
6449 gVoteInProgress
:= False;
6455 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6456 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6458 Need
:= Floor(NetClientCount
/2.0) + 1;
6459 if gVoteCount
>= Need
then
6461 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6462 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6463 gVoteInProgress
:= False;
6464 gVotePassed
:= True;
6465 gVoteCmdTimer
:= gTime
+ 5000;
6468 if NetClients
<> nil then
6469 for I
:= Low(NetClients
) to High(NetClients
) do
6470 if NetClients
[i
].Used
then
6471 NetClients
[i
].Voted
:= False;
6476 procedure g_Game_LoadMapList(FileName
: string);
6484 if not FileExists(FileName
) then Exit
;
6486 AssignFile(ListFile
, FileName
);
6488 while not EOF(ListFile
) do
6490 ReadLn(ListFile
, s
);
6493 if s
= '' then Continue
;
6495 SetLength(MapList
, Length(MapList
)+1);
6496 MapList
[High(MapList
)] := s
;
6498 CloseFile(ListFile
);
6501 procedure g_Game_SetDebugMode();
6504 // Читы (даже в своей игре):
6508 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6512 if Length(LoadingStat
.Msgs
) = 0 then
6518 begin // Переходим на следующую строку или скроллируем:
6519 if NextMsg
= Length(Msgs
) then
6521 for i
:= 0 to High(Msgs
)-1 do
6522 Msgs
[i
] := Msgs
[i
+1];
6530 Msgs
[NextMsg
-1] := Text;
6534 PBarWasHere
:= false;
6537 g_ActiveWindow
:= nil;
6538 ProcessLoading(True);
6541 procedure g_Game_StepLoading(Value
: Integer = -1);
6553 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6556 ProcessLoading(False);
6561 procedure g_Game_ClearLoading();
6570 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6571 if len
< 1 then len
:= 1;
6572 SetLength(Msgs
, len
);
6573 for len
:= Low(Msgs
) to High(Msgs
) do
6576 PBarWasHere
:= false;
6580 procedure Parse_Params(var pars
: TParamStrValues
);
6587 while i
<= ParamCount
do
6590 if (Length(s
) > 1) and (s
[1] = '-') then
6592 if (Length(s
) > 2) and (s
[2] = '-') then
6593 begin // Одиночный параметр
6594 SetLength(pars
, Length(pars
) + 1);
6595 with pars
[High(pars
)] do
6597 Name
:= LowerCase(s
);
6602 if (i
< ParamCount
) then
6603 begin // Параметр со значением
6605 SetLength(pars
, Length(pars
) + 1);
6606 with pars
[High(pars
)] do
6608 Name
:= LowerCase(s
);
6609 Value
:= LowerCase(ParamStr(i
));
6618 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6623 for i
:= 0 to High(pars
) do
6624 if pars
[i
].Name
= aName
then
6626 Result
:= pars
[i
].Value
;
6631 procedure g_Game_Process_Params();
6633 pars
: TParamStrValues
;
6636 LimT
, LimS
: Integer;
6647 s
:= Find_Param_Value(pars
, '--debug');
6650 g_Game_SetDebugMode();
6651 s
:= Find_Param_Value(pars
, '--netdump');
6656 // Connect when game loads
6657 ip
:= Find_Param_Value(pars
, '-connect');
6661 s
:= Find_Param_Value(pars
, '-port');
6662 if (s
= '') or not TryStrToInt(s
, Port
) then
6665 s
:= Find_Param_Value(pars
, '-pw');
6667 g_Game_StartClient(ip
, Port
, s
);
6671 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6674 gDefaultMegawadStart
:= s
;
6677 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6678 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6680 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6683 // Start map when game loads:
6684 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6685 if isWadPath(map
) then
6688 s
:= Find_Param_Value(pars
, '-gm');
6689 GMode
:= g_Game_TextToMode(s
);
6690 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6691 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6694 s
:= Find_Param_Value(pars
, '-limt');
6695 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6701 s
:= Find_Param_Value(pars
, '-lims');
6702 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6708 s
:= Find_Param_Value(pars
, '-lives');
6709 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6715 s
:= Find_Param_Value(pars
, '-opt');
6719 Opt
:= StrToIntDef(s
, 0);
6722 s
:= Find_Param_Value(pars
, '--close');
6726 // Override map to test:
6727 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6730 if e_IsValidResourceName(s
) then
6731 e_FindResource(AllMapDirs
, s
);
6732 gTestMap
:= ExpandFileName(s
);
6735 // Delete test map after play:
6736 s
:= Find_Param_Value(pars
, '--testdelete');
6739 //gMapToDelete := MapsDir + map;
6740 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6744 // Delete temporary WAD after play:
6745 s
:= Find_Param_Value(pars
, '--tempdelete');
6746 if (s
<> '') and (gTestMap
<> '') then
6748 gMapToDelete
:= gTestMap
;
6749 gTempDelete
:= True;
6752 // Number of players:
6753 s
:= Find_Param_Value(pars
, '-pl');
6755 n
:= DEFAULT_PLAYERS
6757 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6760 s
:= Find_Param_Value(pars
, '-port');
6761 if (s
= '') or not TryStrToInt(s
, Port
) then
6762 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6764 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6767 // Execute script when game loads:
6768 s
:= Find_Param_Value(pars
, '-exec');
6771 // if not isWadPath(s) then
6772 // s := GameDir + '/' + s;
6777 if IOResult
<> 0 then
6779 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6780 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6784 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6785 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6790 if IOResult
<> 0 then
6792 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6793 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6797 if Pos('#', s
) <> 1 then // script comment
6798 g_Console_Process(s
, True);
6809 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6810 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6811 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6812 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6814 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6815 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6816 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6817 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6819 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6820 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6822 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6823 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6825 {$IFDEF ENABLE_HOLMES}
6826 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6829 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6831 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6832 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6834 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6835 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6837 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6838 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6839 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6840 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
6841 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6842 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6843 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6844 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6845 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');