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_basic
, g_player
, e_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 {$INCLUDE ../nogl/noGLuses.inc}
446 {$IFDEF ENABLE_HOLMES}
449 e_texture
, e_res
, g_textures
, g_window
, g_menu
,
450 e_input
, e_log
, g_console
, r_console
, g_items
, g_map
, g_panel
,
451 g_playermodel
, g_gfx
, g_options
, Math
,
452 g_triggers
, g_monsters
, e_sound
, CONFIG
,
453 g_language
, g_net
, g_main
, g_phys
,
454 ENet
, e_msg
, g_netmsg
, g_netmaster
,
455 sfs
, wadreader
, g_system
;
458 // ////////////////////////////////////////////////////////////////////////// //
459 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
461 procedure g_ResetDynlights ();
465 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
467 for idx
:= 0 to g_dynLightCount
-1 do
469 if g_dynLights
[idx
].exploCount
= -666 then
476 Inc(g_dynLights
[idx
].exploCount
);
477 if (g_dynLights
[idx
].exploCount
< 10) then
479 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
480 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
481 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
482 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
487 g_dynLightCount
:= lnum
;
490 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
492 if not gwin_has_stencil
then exit
;
493 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
494 g_dynLights
[g_dynLightCount
].x
:= x
;
495 g_dynLights
[g_dynLightCount
].y
:= y
;
496 g_dynLights
[g_dynLightCount
].radius
:= radius
;
497 g_dynLights
[g_dynLightCount
].r
:= r
;
498 g_dynLights
[g_dynLightCount
].g
:= g
;
499 g_dynLights
[g_dynLightCount
].b
:= b
;
500 g_dynLights
[g_dynLightCount
].a
:= a
;
501 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
502 Inc(g_dynLightCount
);
505 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
507 if not gwin_has_stencil
then exit
;
508 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
509 g_dynLights
[g_dynLightCount
].x
:= x
;
510 g_dynLights
[g_dynLightCount
].y
:= y
;
511 g_dynLights
[g_dynLightCount
].radius
:= 0;
512 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
513 g_dynLights
[g_dynLightCount
].r
:= r
;
514 g_dynLights
[g_dynLightCount
].g
:= g
;
515 g_dynLights
[g_dynLightCount
].b
:= b
;
516 g_dynLights
[g_dynLightCount
].a
:= 0;
517 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
518 Inc(g_dynLightCount
);
521 // ////////////////////////////////////////////////////////////////////////// //
522 function conIsCheatsEnabled (): Boolean; inline;
525 if g_Game_IsNet
then exit
;
526 if not gDebugMode
then
528 //if not gCheats then exit;
529 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
530 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
535 // ////////////////////////////////////////////////////////////////////////// //
537 TParamStrValue
= record
542 TParamStrValues
= Array of TParamStrValue
;
545 INTER_ACTION_TEXT
= 1;
546 INTER_ACTION_PIC
= 2;
547 INTER_ACTION_MUSIC
= 3;
552 DataLoaded
: Boolean = False;
554 MessageLineLength
: Integer = 80;
555 MapList
: SSArray
= nil;
556 MapIndex
: Integer = -1;
557 InterReadyTime
: Integer = -1;
558 StatDate
: string = '';
564 text: Array of ShortString;
565 anim
: Array of ShortString;
566 pic
: Array of ShortString;
567 mus
: Array of ShortString;
569 triggers
: Array of record
571 actions
: Array of record
572 action
, p1
, p2
: Integer;
575 cur_trigger
: Integer;
588 function Compare(a
, b
: TPlayerStat
): Integer;
590 if a
.Spectator
then Result
:= 1
591 else if b
.Spectator
then Result
:= -1
592 else if a
.Frags
< b
.Frags
then Result
:= 1
593 else if a
.Frags
> b
.Frags
then Result
:= -1
594 else if a
.Deaths
< b
.Deaths
then Result
:= -1
595 else if a
.Deaths
> b
.Deaths
then Result
:= 1
596 else if a
.Kills
< b
.Kills
then Result
:= -1
600 procedure SortGameStat(var stat
: TPlayerStatArray
);
605 if stat
= nil then Exit
;
607 for I
:= High(stat
) downto Low(stat
) do
608 for J
:= Low(stat
) to High(stat
) - 1 do
609 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
612 stat
[J
] := stat
[J
+ 1];
617 // saves a shitty CSV containing the game stats passed to it
618 procedure SaveGameStat(Stat
: TEndCustomGameStat
; Path
: string);
621 dir
, fname
, map
, mode
, etime
: String;
625 dir
:= e_GetWriteableDir(StatsDirs
);
626 // stats are placed in stats/yy/mm/dd/*.csv
627 fname
:= e_CatPath(dir
, Path
);
628 ForceDirectories(fname
); // ensure yy/mm/dd exists within the stats dir
629 fname
:= e_CatPath(fname
, StatFilename
+ '.csv');
630 AssignFile(s
, fname
);
632 SetTextCodePage(s
, CP_UTF8
);
634 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
635 if g_Game_IsNet
then fname
:= NetServerName
else fname
:= '';
636 map
:= g_ExtractWadNameNoPath(gMapInfo
.Map
) + ':/' + g_ExtractFileName(gMapInfo
.Map
);
637 mode
:= g_Game_ModeToText(Stat
.GameMode
);
638 etime
:= Format('%d:%.2d:%.2d', [
639 Stat
.GameTime
div 1000 div 3600,
640 (Stat
.GameTime
div 1000 div 60) mod 60,
641 Stat
.GameTime
div 1000 mod 60
643 WriteLn(s
, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
644 WriteLn(s
, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
650 gGameSettings
.TimeLimit
,
651 gGameSettings
.ScoreLimit
,
652 gGameSettings
.Options
,
654 Length(Stat
.PlayerStat
)
656 // line 2: game specific shit
657 // if it's a team game: red score, blue score
658 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
660 if Stat
.GameMode
in [GM_TDM
, GM_CTF
] then
662 Format('red_score,blue_score' + LineEnding
+ '%d,%d', [Stat
.TeamStat
[TEAM_RED
].Score
, Stat
.TeamStat
[TEAM_BLUE
].Score
]))
663 else if Stat
.GameMode
in [GM_COOP
, GM_SINGLE
] then
665 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding
+ '%d,%d,%d,%d',[gCoopMonstersKilled
, gTotalMonsters
, gCoopSecretsFound
, gSecretsCount
]));
666 // lines 3-...: team, player name, frags, deaths
667 WriteLn(s
, 'team,name,frags,deaths');
668 for I
:= Low(Stat
.PlayerStat
) to High(Stat
.PlayerStat
) do
669 with Stat
.PlayerStat
[I
] do
670 WriteLn(s
, Format('%d,%s,%d,%d', [Team
, dquoteStr(Name
), Frags
, Deaths
]));
672 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [fname
]));
675 g_Console_Add('could not create gamestats file "' + fname
+ '"');
680 procedure ClearDebugCvars();
682 g_debug_Sounds
:= False;
683 g_debug_Frames
:= False;
684 g_debug_WinMsgs
:= False;
685 g_debug_MonsterOff
:= False;
686 g_debug_BotAIOff
:= 0;
687 g_debug_HealthBar
:= False;
688 g_Debug_Player
:= False;
691 function g_Game_ModeToText(Mode
: Byte): string;
695 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
696 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
697 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
698 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
699 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
703 function g_Game_TextToMode(Mode
: string): Byte;
706 Mode
:= UpperCase(Mode
);
707 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
712 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
717 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
722 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
727 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
734 function g_Game_IsNet(): Boolean;
736 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
739 function g_Game_IsServer(): Boolean;
741 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
744 function g_Game_IsClient(): Boolean;
746 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
749 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
756 Result
.name
:= ExtractFileName(WAD
);
757 Result
.description
:= '';
760 w
:= TWADFile
.Create();
763 if not w
.GetResource('INTERSCRIPT', p
, len
) then
769 cfg
:= TConfig
.CreateMem(p
, len
);
770 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
771 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
772 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
773 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
779 procedure g_Game_FreeWAD();
783 for a
:= 0 to High(MegaWAD
.res
.pic
) do
784 if MegaWAD
.res
.pic
[a
] <> '' then
785 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
787 for a
:= 0 to High(MegaWAD
.res
.mus
) do
788 if MegaWAD
.res
.mus
[a
] <> '' then
789 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
791 MegaWAD
.res
.pic
:= nil;
792 MegaWAD
.res
.text := nil;
793 MegaWAD
.res
.anim
:= nil;
794 MegaWAD
.res
.mus
:= nil;
795 MegaWAD
.triggers
:= nil;
797 g_Texture_Delete('TEXTURE_endpic');
798 g_Sound_Delete('MUSIC_endmus');
800 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
801 gGameSettings
.WAD
:= '';
804 procedure g_Game_LoadWAD(WAD
: string);
813 gGameSettings
.WAD
:= WAD
;
814 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
817 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
819 w
:= TWADFile
.Create();
822 if not w
.GetResource('INTERSCRIPT', p
, len
) then
828 cfg
:= TConfig
.CreateMem(p
, len
);
833 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
834 if s = '' then Break;
837 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
838 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
840 g_Texture_CreateWADEx(s, s);
846 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
847 if s = '' then Break;
850 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
851 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
853 g_Music_CreateWADEx(s, s);
856 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
857 if MegaWAD
.endpic
<> '' then
859 TEXTUREFILTER
:= GL_LINEAR
;
860 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
861 g_Texture_CreateWADEx('TEXTURE_endpic', s
);
862 TEXTUREFILTER
:= GL_NEAREST
;
864 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
865 if MegaWAD
.endmus
<> '' then
867 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
868 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
876 {procedure start_trigger(t: string);
880 function next_trigger(): Boolean;
884 procedure DisableCheats();
890 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
891 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
892 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
893 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
895 {$IF DEFINED(D2F_DEBUG)}
896 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
897 gAimLine
:= g_dbg_aimline_on
;
901 procedure g_Game_ExecuteEvent(Name
: String);
907 if gEvents
= nil then
909 for a
:= 0 to High(gEvents
) do
910 if gEvents
[a
].Name
= Name
then
912 if gEvents
[a
].Command
<> '' then
913 g_Console_Process(gEvents
[a
].Command
, True);
918 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
923 if gDelayedEvents
<> nil then
924 for a
:= 0 to High(gDelayedEvents
) do
925 if not gDelayedEvents
[a
].Pending
then
932 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
933 n
:= High(gDelayedEvents
);
935 gDelayedEvents
[n
].Pending
:= True;
936 gDelayedEvents
[n
].DEType
:= DEType
;
937 gDelayedEvents
[n
].DENum
:= Num
;
938 gDelayedEvents
[n
].DEStr
:= Str
;
939 if DEType
= DE_GLOBEVENT
then
940 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
942 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
952 if g_Game_IsNet
and g_Game_IsServer
then
953 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
957 gPauseHolmes
:= false;
960 g_Game_StopAllSounds(False);
965 EndingGameCounter
:= 0;
966 g_ActiveWindow
:= nil;
968 gLMSRespawn
:= LMS_RESPAWN_NONE
;
969 gLMSRespawnTime
:= 0;
972 EXIT_SIMPLE
: // Выход через меню или конец теста
977 begin // Это был тест
981 begin // Выход в главное меню
982 gMusic
.SetByName('MUSIC_MENU');
984 if gState
<> STATE_SLIST
then
986 g_GUI_ShowWindow('MainMenu');
987 gState
:= STATE_MENU
;
990 // Обновляем список серверов
991 slReturnPressed
:= True;
992 if g_Net_Slist_Fetch(slCurrent
) then
994 if slCurrent
= nil then
995 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
998 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
999 g_Serverlist_GenerateTable(slCurrent
, slTable
);
1002 g_Game_ExecuteEvent('ongameend');
1006 EXIT_RESTART
: // Начать уровень сначала
1008 if not g_Game_IsClient
then g_Game_Restart();
1011 EXIT_ENDLEVELCUSTOM
: // Закончился уровень в Своей игре
1013 // Статистика Своей игры:
1014 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
1016 CustomStat
.GameTime
:= gTime
;
1017 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
1018 CustomStat
.MapName
:= gMapInfo
.Name
;
1019 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
1020 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1021 CustomStat
.TeamStat
:= gTeamStat
;
1023 CustomStat
.PlayerStat
:= nil;
1025 // Статистика игроков:
1026 if gPlayers
<> nil then
1028 for a
:= 0 to High(gPlayers
) do
1029 if gPlayers
[a
] <> nil then
1031 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
1032 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
1035 Name
:= gPlayers
[a
].Name
;
1036 Frags
:= gPlayers
[a
].Frags
;
1037 Deaths
:= gPlayers
[a
].Death
;
1038 Kills
:= gPlayers
[a
].Kills
;
1039 Team
:= gPlayers
[a
].Team
;
1040 Color
:= gPlayers
[a
].Model
.Color
;
1041 Spectator
:= gPlayers
[a
].FSpectator
;
1045 SortGameStat(CustomStat
.PlayerStat
);
1047 if (gSaveStats
or gScreenshotStats
) and (Length(CustomStat
.PlayerStat
) > 1) then
1050 if g_Game_IsNet
then StatFilename
:= NetServerName
else StatFilename
:= 'local';
1051 StatDate
:= FormatDateTime('yymmdd_hhnnss', t
);
1052 StatFilename
:= StatFilename
+ '_' + CustomStat
.Map
+ '_' + g_Game_ModeToText(CustomStat
.GameMode
);
1053 StatFilename
:= sanitizeFilename(StatFilename
) + '_' + StatDate
;
1055 SaveGameStat(CustomStat
, FormatDateTime('yyyy"/"mm"/"dd', t
));
1058 StatShotDone
:= False;
1061 g_Game_ExecuteEvent('onmapend');
1062 if not g_Game_IsClient
then g_Player_ResetReady
;
1063 gInterReadyCount
:= 0;
1065 // Затухающий экран:
1066 EndingGameCounter
:= 255;
1067 gState
:= STATE_FOLD
;
1069 if gDefInterTime
< 0 then
1070 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1072 gInterEndTime
:= gDefInterTime
* 1000;
1075 EXIT_ENDLEVELSINGLE
: // Закончился уровень в Одиночной игре
1077 // Статистика Одиночной игры:
1078 SingleStat
.GameTime
:= gTime
;
1079 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1080 SingleStat
.TotalSecrets
:= gSecretsCount
;
1081 // Статистика первого игрока:
1082 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1083 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1084 // Статистика второго игрока (если есть):
1085 if SingleStat
.TwoPlayers
then
1087 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1088 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1091 g_Game_ExecuteEvent('onmapend');
1094 if gNextMap
<> '' then
1096 gMusic
.SetByName('MUSIC_INTERMUS');
1098 gState
:= STATE_INTERSINGLE
;
1101 g_Game_ExecuteEvent('oninter');
1103 else // Больше нет карт
1105 // Затухающий экран:
1106 EndingGameCounter
:= 255;
1107 gState
:= STATE_FOLD
;
1112 // Окончание обработано:
1113 if gExit
<> EXIT_QUIT
then
1117 procedure g_Game_Init();
1120 knownFiles
: array of AnsiString = nil;
1122 wext
, s
: AnsiString;
1127 gTempDelete
:= False;
1129 sfsGCDisable(); // temporary disable removing of temporary volumes
1132 TEXTUREFILTER
:= GL_LINEAR
;
1133 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1134 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1135 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1136 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1137 TEXTUREFILTER
:= GL_NEAREST
;
1139 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1140 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1141 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1143 g_Game_ClearLoading();
1144 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1145 g_Game_SetLoadingText('', 0, False);
1147 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1151 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1152 g_PlayerModel_LoadData();
1154 // load models from all possible wad types, in all known directories
1155 // this does a loosy job (linear search, ooph!), but meh
1156 for wext
in wadExtensions
do
1158 for f
:= High(ModelDirs
) downto Low(ModelDirs
) do
1160 if (FindFirst(ModelDirs
[f
]+DirectorySeparator
+'*'+wext
, faAnyFile
, SR
) = 0) then
1164 for s
in knownFiles
do
1166 if (strEquCI1251(forceFilenameExt(SR
.Name
, ''), forceFilenameExt(ExtractFileName(s
), ''))) then
1174 SetLength(knownFiles
, length(knownFiles
)+1);
1175 knownFiles
[High(knownFiles
)] := ModelDirs
[f
]+DirectorySeparator
+SR
.Name
;
1177 until (FindNext(SR
) <> 0);
1183 if (length(knownFiles
) = 0) then raise Exception
.Create('no player models found!');
1185 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
);
1186 for s
in knownFiles
do
1188 if not g_PlayerModel_Load(s
) then e_LogWritefln('Error loading model "%s"', [s
], TMsgType
.Warning
);
1192 gPauseMain
:= false;
1193 gPauseHolmes
:= false;
1196 {e_MouseInfo.Accel := 1.0;}
1198 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1201 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1202 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1203 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1204 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1205 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1208 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1212 gMusic
:= TMusic
.Create();
1213 gMusic
.SetByName('MUSIC_MENU');
1216 gGameSettings
.WarmupTime
:= 30;
1218 gState
:= STATE_MENU
;
1220 SetLength(gEvents
, 6);
1221 gEvents
[0].Name
:= 'ongamestart';
1222 gEvents
[1].Name
:= 'ongameend';
1223 gEvents
[2].Name
:= 'onmapstart';
1224 gEvents
[3].Name
:= 'onmapend';
1225 gEvents
[4].Name
:= 'oninter';
1226 gEvents
[5].Name
:= 'onwadend';
1228 sfsGCEnable(); // enable releasing unused volumes
1232 procedure g_Game_Free(freeTextures
: Boolean=true);
1234 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1235 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1237 g_Map_Free(freeTextures
);
1239 g_Player_RemoveAllCorpses();
1241 gGameSettings
.GameType
:= GT_NONE
;
1242 if gGameSettings
.GameMode
= GM_SINGLE
then
1243 gGameSettings
.GameMode
:= GM_DM
;
1244 gSwitchGameMode
:= gGameSettings
.GameMode
;
1247 gExitByTrigger
:= False;
1250 function IsActivePlayer(p
: TPlayer
): Boolean;
1255 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1258 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1264 if gPlayers
= nil then
1268 for a
:= Low(gPlayers
) to High(gPlayers
) do
1269 if IsActivePlayer(gPlayers
[a
]) then
1271 SetLength(ids
, Length(ids
) + 1);
1272 ids
[High(ids
)] := gPlayers
[a
].UID
;
1273 if gPlayers
[a
].UID
= Skip
then
1276 if Length(ids
) = 0 then
1281 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1284 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1290 if gPlayers
= nil then
1294 for a
:= Low(gPlayers
) to High(gPlayers
) do
1295 if IsActivePlayer(gPlayers
[a
]) then
1297 SetLength(ids
, Length(ids
) + 1);
1298 ids
[High(ids
)] := gPlayers
[a
].UID
;
1299 if gPlayers
[a
].UID
= Skip
then
1302 if Length(ids
) = 0 then
1305 Result
:= ids
[Length(ids
) - 1]
1307 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1310 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1316 if gPlayers
= nil then
1320 for a
:= Low(gPlayers
) to High(gPlayers
) do
1321 if IsActivePlayer(gPlayers
[a
]) then
1323 SetLength(ids
, Length(ids
) + 1);
1324 ids
[High(ids
)] := gPlayers
[a
].UID
;
1325 if gPlayers
[a
].UID
= Skip
then
1328 if Length(ids
) = 0 then
1330 if Length(ids
) = 1 then
1335 Result
:= ids
[Random(Length(ids
))];
1337 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1339 Result
:= ids
[Random(Length(ids
))];
1344 function GetRandomSpectMode(Current
: Byte): Byte;
1351 0: Result
:= SPECT_STATS
;
1352 1: Result
:= SPECT_MAPVIEW
;
1353 2: Result
:= SPECT_MAPVIEW
;
1354 3: Result
:= SPECT_PLAYERS
;
1355 4: Result
:= SPECT_PLAYERS
;
1356 5: Result
:= SPECT_PLAYERS
;
1357 6: Result
:= SPECT_PLAYERS
;
1359 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1363 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1369 if (plr
= nil) then exit
;
1370 if (p
= 2) then time
:= 1000 else time
:= 1;
1371 strafeDir
:= MoveButton
shr 4;
1372 MoveButton
:= MoveButton
and $0F;
1374 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1375 MoveButton
:= 1 // Нажата только "Влево"
1376 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1377 MoveButton
:= 2 // Нажата только "Вправо"
1378 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1379 MoveButton
:= 0; // Не нажаты ни "Влево", ни "Вправо"
1381 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1382 if MoveButton
= 1 then
1383 plr
.PressKey(KEY_LEFT
, time
)
1384 else if MoveButton
= 2 then
1385 plr
.PressKey(KEY_RIGHT
, time
);
1387 // if we have "strafe" key, turn off old strafe mechanics
1388 if gPlayerAction
[p
, ACTION_STRAFE
] then
1390 // new strafe mechanics
1391 if (strafeDir
= 0) then
1392 strafeDir
:= MoveButton
; // start strafing
1393 // now set direction according to strafe (reversed)
1394 if (strafeDir
= 2) then
1395 plr
.SetDirection(TDirection
.D_LEFT
)
1396 else if (strafeDir
= 1) then
1397 plr
.SetDirection(TDirection
.D_RIGHT
)
1401 strafeDir
:= 0; // not strafing anymore
1402 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1403 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1404 plr
.SetDirection(TDirection
.D_LEFT
)
1405 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1406 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1407 plr
.SetDirection(TDirection
.D_RIGHT
)
1408 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1409 else if MoveButton
<> 0 then
1410 plr
.SetDirection(TDirection(MoveButton
-1))
1413 // fix movebutton state
1414 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1416 // Остальные клавиши:
1417 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1418 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1419 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1420 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1421 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1423 for i
:= WP_FACT
to WP_LACT
do
1425 if gWeaponAction
[p
, i
] then
1427 plr
.ProcessWeaponAction(i
);
1428 gWeaponAction
[p
, i
] := False
1432 for i
:= WP_FIRST
to WP_LAST
do
1434 if gSelectWeapon
[p
, i
] then
1436 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1437 gSelectWeapon
[p
, i
] := False
1441 // HACK: add dynlight here
1442 if gwin_k8_enable_light_experiments
then
1444 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1446 g_playerLight
:= true;
1448 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1450 g_playerLight
:= false;
1454 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1457 // HACK: don't have a "key was pressed" function
1458 procedure InterReady();
1460 if InterReadyTime
> gTime
then Exit
;
1461 InterReadyTime
:= gTime
+ 3000;
1462 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1465 procedure g_Game_PreUpdate();
1467 // these are in separate PreUpdate functions because they can interact during Update()
1468 // and are synced over the net
1469 // we don't care that much about corpses and gibs
1470 g_Player_PreUpdate();
1471 g_Monsters_PreUpdate();
1472 g_Items_PreUpdate();
1473 g_Weapon_PreUpdate();
1476 procedure g_Game_Update();
1478 Msg
: g_gui
.TMessage
;
1484 function sendMonsPos (mon
: TMonster
): Boolean;
1486 result
:= false; // don't stop
1487 // this will also reset "need-send" flag
1488 if mon
.gncNeedSend
then
1490 MH_SEND_MonsterPos(mon
.UID
);
1492 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1494 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1496 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1498 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1502 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1504 result
:= false; // don't stop
1505 // this will also reset "need-send" flag
1506 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1509 function sendItemPos (it
: PItem
): Boolean;
1511 result
:= false; // don't stop
1514 MH_SEND_ItemPos(it
.myId
);
1515 it
.needSend
:= False;
1520 reliableUpdate
: Boolean;
1525 // Пора выключать игру:
1526 if gExit
= EXIT_QUIT
then
1528 // Игра закончилась - обрабатываем:
1532 if gExit
= EXIT_QUIT
then
1536 // Читаем клавиатуру и джойстик, если окно активно
1537 // no need to, as we'll do it in event handler
1539 // Обновляем консоль (движение и сообщения):
1543 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1545 gExit
:= EXIT_SIMPLE
;
1550 // process master server communications
1551 g_Net_Slist_Pulse();
1554 STATE_INTERSINGLE
, // Статистка после прохождения уровня в Одиночной игре
1555 STATE_INTERCUSTOM
, // Статистка после прохождения уровня в Своей игре
1556 STATE_INTERTEXT
, // Текст между уровнями
1557 STATE_INTERPIC
: // Картинка между уровнями
1559 if g_Game_IsNet
and g_Game_IsServer
then
1561 gInterTime
:= gInterTime
+ GAME_TICK
;
1562 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1563 if a
<> gServInterTime
then
1565 gServInterTime
:= a
;
1566 MH_SEND_TimeSync(gServInterTime
);
1570 if (not g_Game_IsClient
) and
1574 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1575 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1576 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1577 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1579 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1580 and (g_ActiveWindow
= nil)
1582 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or ((gInterReadyCount
>= NetClientCount
) and (NetClientCount
> 0))))
1585 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1586 g_Game_StopAllSounds(True);
1588 if gMapOnce
then // Это был тест
1589 gExit
:= EXIT_SIMPLE
1591 if gNextMap
<> '' then // Переходим на следующую карту
1592 g_Game_ChangeMap(gNextMap
)
1593 else // Следующей карты нет
1595 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1597 // Выход в главное меню:
1599 g_GUI_ShowWindow('MainMenu');
1600 gMusic
.SetByName('MUSIC_MENU');
1602 gState
:= STATE_MENU
;
1605 // Финальная картинка:
1606 g_Game_ExecuteEvent('onwadend');
1608 if not gMusic
.SetByName('MUSIC_endmus') then
1609 gMusic
.SetByName('MUSIC_STDENDMUS');
1611 gState
:= STATE_ENDPIC
;
1613 g_Game_ExecuteEvent('ongameend');
1618 else if g_Game_IsClient
and
1621 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1622 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1623 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1624 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1626 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1627 and (g_ActiveWindow
= nil)
1635 if gState
= STATE_INTERTEXT
then
1636 if InterText
.counter
> 0 then
1637 InterText
.counter
:= InterText
.counter
- 1;
1640 STATE_FOLD
: // Затухание экрана
1642 if EndingGameCounter
= 0 then
1644 // Закончился уровень в Своей игре:
1645 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1647 gState
:= STATE_INTERCUSTOM
;
1648 InterReadyTime
:= -1;
1649 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1651 g_Game_ExecuteEvent('onwadend');
1652 if not gMusic
.SetByName('MUSIC_endmus') then
1653 gMusic
.SetByName('MUSIC_STDENDMUS');
1656 gMusic
.SetByName('MUSIC_ROUNDMUS');
1660 else // Закончилась последняя карта в Одиночной игре
1662 gMusic
.SetByName('MUSIC_INTERMUS');
1664 gState
:= STATE_INTERSINGLE
;
1667 g_Game_ExecuteEvent('oninter');
1670 DecMin(EndingGameCounter
, 6, 0);
1673 STATE_ENDPIC
: // Картинка окончания мегаВада
1675 if gMapOnce
then // Это был тест
1677 gExit
:= EXIT_SIMPLE
;
1683 g_Serverlist_Control(slCurrent
, slTable
);
1686 // Статистика по Tab:
1688 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1691 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1693 // Время += 28 миллисекунд:
1694 gTime
:= gTime
+ GAME_TICK
;
1696 // Сообщение посередине экрана:
1697 if MessageTime
= 0 then
1699 if MessageTime
> 0 then
1700 MessageTime
:= MessageTime
- 1;
1702 if (g_Game_IsServer
) then
1704 // Был задан лимит времени:
1705 if (gGameSettings
.TimeLimit
> 0) then
1706 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1707 begin // Он прошел => конец уровня
1712 // Надо респавнить игроков в LMS:
1713 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1714 g_Game_RestartRound(gLMSSoftSpawn
);
1716 // Проверим результат голосования, если время прошло
1717 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1719 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1721 g_Console_Process(gVoteCommand
);
1723 gVotePassed
:= False;
1726 // Замеряем время захвата флагов
1727 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1728 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1729 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1730 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1732 // Был задан лимит побед:
1733 if (gGameSettings
.ScoreLimit
> 0) then
1737 if gGameSettings
.GameMode
= GM_DM
then
1738 begin // В DM ищем игрока с max фрагами
1739 for i
:= 0 to High(gPlayers
) do
1740 if gPlayers
[i
] <> nil then
1741 if gPlayers
[i
].Frags
> b
then
1742 b
:= gPlayers
[i
].Frags
;
1745 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1746 begin // В CTF/TDM выбираем команду с наибольшим счетом
1747 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
1750 // Лимит побед набран => конец уровня:
1751 if b
>= gGameSettings
.ScoreLimit
then
1758 // Обрабатываем клавиши игроков:
1759 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1760 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1761 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1763 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1764 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1765 end // if not console
1768 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1770 // process weapon switch queue
1774 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1775 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1777 if not gSpectKeyPress
then
1779 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
1781 // switch spect mode
1783 SPECT_NONE
: ; // not spectator
1785 SPECT_MAPVIEW
: Inc(gSpectMode
);
1786 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1788 gSpectKeyPress
:= True;
1790 if (gSpectMode
= SPECT_MAPVIEW
)
1791 and (not gSpectAuto
) then
1793 if gPlayerAction
[0, ACTION_MOVELEFT
] then
1794 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1795 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
1796 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1797 if gPlayerAction
[0, ACTION_LOOKUP
] then
1798 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1799 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
1800 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1801 if gWeaponAction
[0, WP_PREV
] then
1804 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1805 gWeaponAction
[0, WP_PREV
] := False;
1807 if gWeaponAction
[0, WP_NEXT
] then
1810 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1811 gWeaponAction
[0, WP_NEXT
] := False;
1814 if (gSpectMode
= SPECT_PLAYERS
)
1815 and (not gSpectAuto
) then
1817 if gPlayerAction
[0, ACTION_LOOKUP
] then
1820 gSpectViewTwo
:= True;
1821 gSpectKeyPress
:= True;
1823 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
1825 // remove second view
1826 gSpectViewTwo
:= False;
1827 gSpectKeyPress
:= True;
1829 if gPlayerAction
[0, ACTION_MOVELEFT
] then
1831 // prev player (view 1)
1832 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1833 gSpectKeyPress
:= True;
1835 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
1837 // next player (view 1)
1838 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1839 gSpectKeyPress
:= True;
1841 if gWeaponAction
[0, WP_PREV
] then
1843 // prev player (view 2)
1844 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1845 gWeaponAction
[0, WP_PREV
] := False;
1847 if gWeaponAction
[0, WP_NEXT
] then
1849 // next player (view 2)
1850 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1851 gWeaponAction
[0, WP_NEXT
] := False;
1854 if gPlayerAction
[0, ACTION_ATTACK
] then
1856 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
1859 gSpectAutoNext
:= 0;
1860 gSpectViewTwo
:= False;
1861 gSpectKeyPress
:= True;
1866 gSpectMode
:= SPECT_STATS
;
1867 gSpectAuto
:= False;
1868 gSpectKeyPress
:= True;
1873 if (not gPlayerAction
[0, ACTION_JUMP
]) and
1874 (not gPlayerAction
[0, ACTION_ATTACK
]) and
1875 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
1876 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
1877 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
1878 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) then
1879 gSpectKeyPress
:= False;
1883 if gSpectMode
= SPECT_MAPVIEW
then
1885 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
1887 gSpectAutoNext
:= gTime
1890 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
1892 gSpectAutoNext
:= gTime
1896 if gSpectAutoNext
<= gTime
then
1898 if gSpectAutoNext
> 0 then
1900 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
1904 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
1905 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
1906 gSpectAutoStepX
:= Random(9) - 4;
1907 gSpectAutoStepY
:= Random(9) - 4;
1908 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
1909 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
1910 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
1911 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
1912 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
1913 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
1917 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
1922 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
1923 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
1924 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
1930 // Обновляем все остальное:
1933 g_Triggers_Update();
1935 g_Monsters_Update();
1937 g_Player_UpdateAll();
1938 g_Player_UpdatePhysicalObjects();
1940 // server: send newly spawned monsters unconditionally
1941 if (gGameSettings
.GameType
= GT_SERVER
) then
1943 if (Length(gMonstersSpawned
) > 0) then
1945 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1946 SetLength(gMonstersSpawned
, 0);
1950 if (gSoundTriggerTime
> 8) then
1952 g_Game_UpdateTriggerSounds();
1953 gSoundTriggerTime
:= 0;
1957 Inc(gSoundTriggerTime
);
1960 if (NetMode
= NET_SERVER
) then
1962 Inc(NetTimeToUpdate
);
1963 Inc(NetTimeToReliable
);
1965 // send monster updates
1966 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
1968 // send all monsters (periodic sync)
1969 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
1971 for I
:= 0 to High(gPlayers
) do
1973 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
1976 g_Mons_ForEach(sendMonsPos
);
1978 // update flags that aren't stationary
1979 if gGameSettings
.GameMode
= GM_CTF
then
1980 for I
:= FLAG_RED
to FLAG_BLUE
do
1981 if gFlags
[I
].NeedSend
then
1983 gFlags
[I
].NeedSend
:= False;
1987 // update items that aren't stationary
1988 g_Items_ForEachAlive(sendItemPos
);
1990 if reliableUpdate
then
1992 NetTimeToReliable
:= 0;
1993 NetTimeToUpdate
:= NetUpdateRate
;
1997 NetTimeToUpdate
:= 0;
2002 // send only mosters with some unexpected changes
2003 g_Mons_ForEach(sendMonsPosUnexpected
);
2006 // send unexpected platform changes
2007 g_Map_NetSendInterestingPanels();
2009 g_Net_Slist_ServerUpdate();
2011 if NetUseMaster then
2013 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2015 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2017 NetTimeToMaster := gTime + NetMasterRate;
2022 else if (NetMode
= NET_CLIENT
) then
2024 MC_SEND_PlayerPos();
2026 end; // if gameOn ...
2028 // Активно окно интерфейса - передаем клавиши ему:
2029 if g_ActiveWindow
<> nil then
2031 w
:= e_GetFirstKeyPressed();
2033 if (w
<> IK_INVALID
) then
2035 Msg
.Msg
:= MESSAGE_DIKEY
;
2037 g_ActiveWindow
.OnMessage(Msg
);
2040 // Если оно от этого не закрылось, то обновляем:
2041 if g_ActiveWindow
<> nil then
2042 g_ActiveWindow
.Update();
2044 // Нужно сменить разрешение:
2045 if gResolutionChange
then
2047 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2048 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2049 gResolutionChange
:= False;
2050 g_ActiveWindow
:= nil;
2053 // Нужно сменить язык:
2054 if gLanguageChange
then
2056 //e_WriteLog('Read language file', MSG_NOTIFY);
2057 //g_Language_Load(DataDir + gLanguage + '.txt');
2058 g_Language_Set(gLanguage
);
2062 gLanguageChange
:= False;
2066 // Горячая клавиша для вызова меню выхода из игры (F10):
2067 if e_KeyPressed(IK_F10
) and
2069 (not gConsoleShow
) and
2070 (g_ActiveWindow
= nil) then
2075 Time
:= sys_GetTicks() {div 1000};
2077 // Обработка отложенных событий:
2078 if gDelayedEvents
<> nil then
2079 for a
:= 0 to High(gDelayedEvents
) do
2080 if gDelayedEvents
[a
].Pending
and
2082 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2083 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2086 case gDelayedEvents
[a
].DEType
of
2088 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2091 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2095 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2096 if g_Game_IsNet
and g_Game_IsServer
then
2097 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2101 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2103 gDelayedEvents
[a
].Pending
:= False;
2106 // Каждую секунду обновляем счетчик обновлений:
2107 UPSCounter
:= UPSCounter
+ 1;
2108 if Time
- UPSTime
>= 1000 then
2117 g_Weapon_AddDynLights();
2118 g_Items_AddDynLights();
2122 procedure g_Game_LoadChatSounds(Resource
: string);
2125 FileName
, Snd
: string;
2127 len
, cnt
, tags
, i
, j
: Integer;
2130 FileName
:= g_ExtractWadName(Resource
);
2132 WAD
:= TWADFile
.Create();
2133 WAD
.ReadFile(FileName
);
2135 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2142 cfg
:= TConfig
.CreateMem(p
, len
);
2143 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2145 SetLength(gChatSounds
, cnt
);
2146 for i
:= 0 to Length(gChatSounds
) - 1 do
2148 gChatSounds
[i
].Sound
:= nil;
2149 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2150 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2151 if (Snd
= '') or (Tags
<= 0) then
2153 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2154 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2155 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2156 SetLength(gChatSounds
[i
].Tags
, tags
);
2157 for j
:= 0 to tags
- 1 do
2158 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2159 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2166 procedure g_Game_FreeChatSounds();
2170 for i
:= 0 to Length(gChatSounds
) - 1 do
2172 gChatSounds
[i
].Sound
.Free();
2173 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2175 SetLength(gChatSounds
, 0);
2179 procedure g_Game_LoadData();
2186 if DataLoaded
then Exit
;
2188 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2190 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2191 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2192 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2193 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2194 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2195 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2196 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2197 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2198 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2199 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2200 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2201 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2202 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2203 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2204 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2207 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2208 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2209 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2210 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2214 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2215 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2216 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2217 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2218 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
2224 hasPBarGfx
:= false;
2228 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2229 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2230 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2231 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2232 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2233 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2234 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2235 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2236 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2237 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2238 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2239 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2240 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2241 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2242 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2243 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2244 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2245 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2246 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2247 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2248 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2249 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2250 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2251 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2252 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2253 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2254 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2255 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2256 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2257 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2258 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2259 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2260 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2261 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2262 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2263 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2264 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2265 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2266 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2268 goodsnd
[0] := TPlayableSound
.Create();
2269 goodsnd
[1] := TPlayableSound
.Create();
2270 goodsnd
[2] := TPlayableSound
.Create();
2271 goodsnd
[3] := TPlayableSound
.Create();
2273 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2274 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2275 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2276 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2278 killsnd
[0] := TPlayableSound
.Create();
2279 killsnd
[1] := TPlayableSound
.Create();
2280 killsnd
[2] := TPlayableSound
.Create();
2281 killsnd
[3] := TPlayableSound
.Create();
2283 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2284 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2285 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2286 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2288 hahasnd
[0] := TPlayableSound
.Create();
2289 hahasnd
[1] := TPlayableSound
.Create();
2290 hahasnd
[2] := TPlayableSound
.Create();
2292 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2293 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2294 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2296 sound_get_flag
[0] := TPlayableSound
.Create();
2297 sound_get_flag
[1] := TPlayableSound
.Create();
2298 sound_lost_flag
[0] := TPlayableSound
.Create();
2299 sound_lost_flag
[1] := TPlayableSound
.Create();
2300 sound_ret_flag
[0] := TPlayableSound
.Create();
2301 sound_ret_flag
[1] := TPlayableSound
.Create();
2302 sound_cap_flag
[0] := TPlayableSound
.Create();
2303 sound_cap_flag
[1] := TPlayableSound
.Create();
2305 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2306 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2307 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2308 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2309 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2310 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2311 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2312 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2314 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2316 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2319 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2320 g_Weapon_LoadData();
2322 g_Monsters_LoadData();
2327 procedure g_Game_Quit();
2329 g_Game_StopAllSounds(True);
2332 g_PlayerModel_FreeData();
2333 g_Texture_DeleteAll();
2334 g_Frames_DeleteAll();
2336 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2339 if NetInitDone
then g_Net_Free
;
2341 // remove map after test
2342 if gMapToDelete
<> '' then
2343 g_Game_DeleteTestMap();
2349 procedure g_Game_FreeData();
2351 if not DataLoaded
then Exit
;
2354 g_Weapon_FreeData();
2355 g_Monsters_FreeData();
2357 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2359 g_Texture_Delete('NOTEXTURE');
2360 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2361 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2362 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2363 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2364 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2365 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2366 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2367 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2368 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2369 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2370 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2371 g_Frames_DeleteByName('FRAMES_TELEPORT');
2372 g_Frames_DeleteByName('FRAMES_PUNCH');
2373 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2374 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2375 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2376 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2377 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2378 g_Sound_Delete('SOUND_GAME_TELEPORT');
2379 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2380 g_Sound_Delete('SOUND_GAME_SECRET');
2381 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2382 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2383 g_Sound_Delete('SOUND_GAME_BULK1');
2384 g_Sound_Delete('SOUND_GAME_BULK2');
2385 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2386 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2387 g_Sound_Delete('SOUND_GAME_BURNING');
2388 g_Sound_Delete('SOUND_GAME_SWITCH1');
2389 g_Sound_Delete('SOUND_GAME_SWITCH0');
2396 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2397 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2398 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2399 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2406 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2407 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2408 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2409 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2415 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2416 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2417 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2419 sound_get_flag
[0].Free();
2420 sound_get_flag
[1].Free();
2421 sound_lost_flag
[0].Free();
2422 sound_lost_flag
[1].Free();
2423 sound_ret_flag
[0].Free();
2424 sound_ret_flag
[1].Free();
2425 sound_cap_flag
[0].Free();
2426 sound_cap_flag
[1].Free();
2428 g_Sound_Delete('SOUND_CTF_GET1');
2429 g_Sound_Delete('SOUND_CTF_GET2');
2430 g_Sound_Delete('SOUND_CTF_LOST1');
2431 g_Sound_Delete('SOUND_CTF_LOST2');
2432 g_Sound_Delete('SOUND_CTF_RETURN1');
2433 g_Sound_Delete('SOUND_CTF_RETURN2');
2434 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2435 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2437 g_Game_FreeChatSounds();
2439 DataLoaded
:= False;
2442 procedure g_FatalError(Text: String);
2444 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2445 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2447 gExit
:= EXIT_SIMPLE
;
2448 if gGameOn
then EndGame
;
2451 procedure g_SimpleError(Text: String);
2453 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2454 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2457 procedure g_Game_SetupScreenSize();
2459 RES_FACTOR
= 4.0 / 3.0;
2465 // Размер экранов игроков:
2466 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2467 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2468 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
2470 gPlayerScreenSize
.Y
:= gScreenHeight
;
2472 // Размер заднего плана:
2473 if BackID
<> DWORD(-1) then
2476 if (gScreenWidth
*s
> gMapInfo
.Width
) or
2477 (gScreenHeight
*s
> gMapInfo
.Height
) then
2479 gBackSize
.X
:= gScreenWidth
;
2480 gBackSize
.Y
:= gScreenHeight
;
2484 e_GetTextureSize(BackID
, @bw
, @bh
);
2485 rf
:= Single(bw
) / Single(bh
);
2486 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
2487 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
2488 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
2489 if (s
< 1.0) then s
:= 1.0;
2490 gBackSize
.X
:= Round(bw
*s
);
2491 gBackSize
.Y
:= Round(bh
*s
);
2496 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
2498 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
2501 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2503 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2504 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2507 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2510 if gPlayer1
= nil then
2512 if g_Game_IsClient
then
2514 if NetPlrUID1
> -1 then
2515 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2519 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2520 Team
:= gPlayer1Settings
.Team
;
2522 // Создание первого игрока:
2523 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2524 gPlayer1Settings
.Color
,
2526 if gPlayer1
= nil then
2527 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2530 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2531 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2532 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2533 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2534 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2535 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2536 if g_Game_IsServer
and g_Game_IsNet
then
2537 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2538 gPlayer1
.Respawn(False, True);
2539 g_Net_Slist_ServerPlayerComes();
2544 if gPlayer2
= nil then
2546 if g_Game_IsClient
then
2548 if NetPlrUID2
> -1 then
2549 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2553 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2554 Team
:= gPlayer2Settings
.Team
;
2556 // Создание второго игрока:
2557 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2558 gPlayer2Settings
.Color
,
2560 if gPlayer2
= nil then
2561 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2564 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2565 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2566 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2567 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2568 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2569 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2570 if g_Game_IsServer
and g_Game_IsNet
then
2571 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2572 gPlayer2
.Respawn(False, True);
2573 g_Net_Slist_ServerPlayerComes();
2580 procedure g_Game_RemovePlayer();
2584 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2585 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2590 if g_Game_IsServer
then
2593 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2594 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2595 g_Player_Remove(Pl
.UID
);
2596 g_Net_Slist_ServerPlayerLeaves();
2600 gSpectLatchPID2
:= Pl
.UID
;
2608 if g_Game_IsServer
then
2611 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2612 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2613 g_Player_Remove(Pl
.UID
);
2614 g_Net_Slist_ServerPlayerLeaves();
2617 gSpectLatchPID1
:= Pl
.UID
;
2619 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2623 g_Net_Slist_ServerPlayerLeaves();
2626 procedure g_Game_Spectate();
2628 g_Game_RemovePlayer();
2629 if gPlayer1
<> nil then
2630 g_Game_RemovePlayer();
2633 procedure g_Game_SpectateCenterView();
2635 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2636 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2639 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2646 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2648 g_Game_ClearLoading();
2651 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2654 gGameSettings
.GameType
:= GT_SINGLE
;
2655 gGameSettings
.MaxLives
:= 0;
2656 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2657 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2658 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2659 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2660 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2661 gSwitchGameMode
:= GM_SINGLE
;
2663 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2664 gLMSRespawnTime
:= 0;
2665 gSpectLatchPID1
:= 0;
2666 gSpectLatchPID2
:= 0;
2668 g_Game_ExecuteEvent('ongamestart');
2670 // Установка размеров окон игроков:
2671 g_Game_SetupScreenSize();
2673 // Создание первого игрока:
2674 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2675 gPlayer1Settings
.Color
,
2676 gPlayer1Settings
.Team
, False));
2677 if gPlayer1
= nil then
2679 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2683 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2684 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2685 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2686 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2687 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2690 // Создание второго игрока, если есть:
2693 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2694 gPlayer2Settings
.Color
,
2695 gPlayer2Settings
.Team
, False));
2696 if gPlayer2
= nil then
2698 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2702 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2703 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2704 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2705 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2706 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2710 // Загрузка и запуск карты:
2711 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2713 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2714 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2718 // Настройки игроков и ботов:
2722 for i
:= nPl
+1 to nPlayers
do
2723 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2726 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2727 TimeLimit
, ScoreLimit
: Word;
2729 Options
: LongWord; nPlayers
: Byte);
2735 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2737 g_Game_ClearLoading();
2740 gGameSettings
.GameType
:= GT_CUSTOM
;
2741 gGameSettings
.GameMode
:= GameMode
;
2742 gSwitchGameMode
:= GameMode
;
2743 gGameSettings
.TimeLimit
:= TimeLimit
;
2744 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2745 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2746 gGameSettings
.Options
:= Options
;
2748 gCoopTotalMonstersKilled
:= 0;
2749 gCoopTotalSecretsFound
:= 0;
2750 gCoopTotalMonsters
:= 0;
2751 gCoopTotalSecrets
:= 0;
2755 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2756 gLMSRespawnTime
:= 0;
2757 gSpectLatchPID1
:= 0;
2758 gSpectLatchPID2
:= 0;
2760 g_Game_ExecuteEvent('ongamestart');
2762 // Установка размеров окон игроков:
2763 g_Game_SetupScreenSize();
2765 // Режим наблюдателя:
2766 if nPlayers
= 0 then
2773 if nPlayers
>= 1 then
2775 // Создание первого игрока:
2776 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2777 gPlayer1Settings
.Color
,
2778 gPlayer1Settings
.Team
, False));
2779 if gPlayer1
= nil then
2781 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2785 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2786 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2787 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2788 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2789 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2793 if nPlayers
>= 2 then
2795 // Создание второго игрока:
2796 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2797 gPlayer2Settings
.Color
,
2798 gPlayer2Settings
.Team
, False));
2799 if gPlayer2
= nil then
2801 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2805 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2806 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2807 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2808 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2809 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2813 // Загрузка и запуск карты:
2814 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
2816 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2820 // Нет точек появления:
2821 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2822 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2823 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2824 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2825 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2827 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2831 // Настройки игроков и ботов:
2835 for i
:= nPl
+1 to nPlayers
do
2836 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2839 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
2840 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
2841 Options
: LongWord; nPlayers
: Byte;
2842 IPAddr
: LongWord; Port
: Word);
2845 g_Net_Slist_ServerClosed();
2847 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
2849 g_Game_ClearLoading();
2854 gGameSettings
.GameType
:= GT_SERVER
;
2855 gGameSettings
.GameMode
:= GameMode
;
2856 gSwitchGameMode
:= GameMode
;
2857 gGameSettings
.TimeLimit
:= TimeLimit
;
2858 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2859 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2860 gGameSettings
.Options
:= Options
;
2862 gCoopTotalMonstersKilled
:= 0;
2863 gCoopTotalSecretsFound
:= 0;
2864 gCoopTotalMonsters
:= 0;
2865 gCoopTotalSecrets
:= 0;
2869 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2870 gLMSRespawnTime
:= 0;
2871 gSpectLatchPID1
:= 0;
2872 gSpectLatchPID2
:= 0;
2874 g_Game_ExecuteEvent('ongamestart');
2876 // Установка размеров окна игрока
2877 g_Game_SetupScreenSize();
2879 // Режим наблюдателя:
2880 if nPlayers
= 0 then
2886 if nPlayers
>= 1 then
2888 // Создание первого игрока:
2889 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2890 gPlayer1Settings
.Color
,
2891 gPlayer1Settings
.Team
, False));
2892 if gPlayer1
= nil then
2894 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2898 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2899 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2900 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2901 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2902 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2905 if nPlayers
>= 2 then
2907 // Создание второго игрока:
2908 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2909 gPlayer2Settings
.Color
,
2910 gPlayer2Settings
.Team
, False));
2911 if gPlayer2
= nil then
2913 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2917 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2918 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2919 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2920 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2921 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2924 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
2925 if NetForwardPorts
then
2926 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
2929 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
2931 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
2935 g_Net_Slist_Set(NetMasterList
);
2937 g_Net_Slist_ServerStarted();
2939 // Загрузка и запуск карты:
2940 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
2942 g_Net_Slist_ServerClosed();
2943 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2947 // Нет точек появления:
2948 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2949 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2950 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2951 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2952 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2954 g_Net_Slist_ServerClosed();
2955 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2959 // Настройки игроков и ботов:
2962 g_Net_Slist_ServerMapStarted();
2963 NetState
:= NET_STATE_GAME
;
2966 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
2981 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
2982 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
2984 g_Game_ClearLoading();
2989 gGameSettings
.GameType
:= GT_CLIENT
;
2991 gCoopTotalMonstersKilled
:= 0;
2992 gCoopTotalSecretsFound
:= 0;
2993 gCoopTotalMonsters
:= 0;
2994 gCoopTotalSecrets
:= 0;
2998 g_Game_ExecuteEvent('ongamestart');
3000 // Установка размеров окон игроков:
3001 g_Game_SetupScreenSize();
3003 NetState
:= NET_STATE_AUTH
;
3005 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3007 // create (or update) map/resource databases
3008 g_Res_CreateDatabases(true);
3010 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3011 gLMSRespawnTime
:= 0;
3012 gSpectLatchPID1
:= 0;
3013 gSpectLatchPID2
:= 0;
3016 if not g_Net_Connect(Addr
, Port
) then
3018 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3019 NetState
:= NET_STATE_NONE
;
3023 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3025 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3030 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3031 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3032 // thank you, enet. let's ignore failures altogether then.
3033 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3035 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3037 Ptr
:= NetEvent
.packet
^.data
;
3038 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3040 enet_packet_destroy(NetEvent
.packet
);
3044 InMsg
.ReadLongWord(); // skip size
3045 MID
:= InMsg
.ReadByte();
3047 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3049 NetMyID
:= InMsg
.ReadByte();
3050 NetPlrUID1
:= InMsg
.ReadWord();
3052 WadName
:= InMsg
.ReadString();
3053 Map
:= InMsg
.ReadString();
3055 gWADHash
:= InMsg
.ReadMD5();
3057 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3058 gSwitchGameMode
:= gGameSettings
.GameMode
;
3059 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3060 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3061 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3062 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3063 T
:= InMsg
.ReadLongWord();
3065 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3066 //if newResPath = '' then
3068 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3069 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3070 if newResPath
= '' then
3072 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3073 enet_packet_destroy(NetEvent
.packet
);
3074 NetState
:= NET_STATE_NONE
;
3077 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3079 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3082 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3083 gPlayer1Settings
.Color
,
3084 gPlayer1Settings
.Team
, False));
3086 if gPlayer1
= nil then
3088 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3090 enet_packet_destroy(NetEvent
.packet
);
3091 NetState
:= NET_STATE_NONE
;
3095 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3096 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3097 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3098 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3099 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3100 gPlayer1
.UID
:= NetPlrUID1
;
3101 gPlayer1
.Reset(True);
3103 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3105 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3107 enet_packet_destroy(NetEvent
.packet
);
3108 NetState
:= NET_STATE_NONE
;
3116 enet_packet_destroy(NetEvent
.packet
);
3120 enet_packet_destroy(NetEvent
.packet
);
3124 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3127 if (NetEvent
.data
<= NET_DISC_MAX
) then
3128 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3129 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3136 ProcessLoading(True);
3137 if g_Net_UserRequestExit() then
3146 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3147 NetState
:= NET_STATE_NONE
;
3152 NetState
:= NET_STATE_GAME
;
3153 MC_SEND_FullStateRequest
;
3154 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3158 lastAsMegaWad
: Boolean = false;
3160 procedure g_Game_ChangeMap(const MapPath
: String);
3164 g_Game_ClearLoading();
3166 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3167 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3168 if gExitByTrigger
then
3171 gExitByTrigger
:= False;
3173 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3174 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3177 procedure g_Game_Restart();
3181 if g_Game_IsClient
then
3183 map
:= g_ExtractFileName(gMapInfo
.Map
);
3184 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3188 g_Game_ClearLoading();
3189 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3192 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3194 NewWAD
, ResName
: String;
3198 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3199 g_Player_RemoveAllCorpses();
3201 if (not g_Game_IsClient
) and
3202 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3203 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3205 if gSwitchGameMode
= GM_CTF
then
3206 gGameSettings
.MaxLives
:= 0;
3207 gGameSettings
.GameMode
:= gSwitchGameMode
;
3210 gSwitchGameMode
:= gGameSettings
.GameMode
;
3212 g_Player_ResetTeams();
3214 lastAsMegaWad
:= asMegawad
;
3215 if isWadPath(Map
) then
3217 NewWAD
:= g_ExtractWadName(Map
);
3218 ResName
:= g_ExtractFileName(Map
);
3219 if g_Game_IsServer
then
3221 nws
:= findDiskWad(NewWAD
);
3222 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3225 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3226 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3230 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3231 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3233 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3234 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3236 if (length(nws
) = 0) then
3238 ResName
:= ''; // failed
3243 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3244 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3245 g_Game_LoadWAD(NewWAD
);
3250 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3251 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3256 NewWAD
:= gGameSettings
.WAD
;
3262 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3264 if (ResName
<> '') and (NewWAD
<> '') then
3266 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3267 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3271 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3273 gState
:= STATE_NONE
;
3274 g_ActiveWindow
:= nil;
3280 if gGameSettings
.GameMode
= GM_CTF
then
3282 g_Map_ResetFlag(FLAG_RED
);
3283 g_Map_ResetFlag(FLAG_BLUE
);
3284 // CTF, а флагов нет:
3285 if not g_Map_HaveFlagPoints() then
3286 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3291 gState
:= STATE_MENU
;
3296 gPauseMain
:= false;
3297 gPauseHolmes
:= false;
3298 NetTimeToUpdate
:= 1;
3299 NetTimeToReliable
:= 0;
3300 NetTimeToMaster
:= NetMasterRate
;
3301 gSpectLatchPID1
:= 0;
3302 gSpectLatchPID2
:= 0;
3303 gMissionFailed
:= False;
3306 gCoopMonstersKilled
:= 0;
3307 gCoopSecretsFound
:= 0;
3309 gVoteInProgress
:= False;
3310 gVotePassed
:= False;
3316 if not gGameOn
then Exit
;
3318 g_Game_SpectateCenterView();
3320 if g_Game_IsServer
then
3322 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3324 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3325 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3326 gLMSSoftSpawn
:= True;
3327 if g_Game_IsNet
then
3328 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3332 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3333 gLMSRespawnTime
:= 0;
3337 if NetMode
= NET_SERVER
then
3339 // reset full state flags
3340 if NetClients
<> nil then
3341 for I
:= 0 to High(NetClients
) do
3342 NetClients
[I
].FullUpdateSent
:= False;
3344 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3347 g_Net_Slist_ServerMapStarted();
3349 if NetClients
<> nil then
3350 for I
:= 0 to High(NetClients
) do
3351 if NetClients
[I
].Used
then
3353 NetClients
[I
].Voted
:= False;
3354 if NetClients
[I
].RequestedFullUpdate
then
3356 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3357 NetClients
[I
].RequestedFullUpdate
:= False;
3361 g_Net_UnbanNonPermHosts();
3366 gCoopTotalMonstersKilled
:= 0;
3367 gCoopTotalSecretsFound
:= 0;
3368 gCoopTotalMonsters
:= 0;
3369 gCoopTotalSecrets
:= 0;
3373 g_Game_ExecuteEvent('onmapstart');
3376 procedure SetFirstLevel
;
3380 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3381 if MapList
= nil then
3384 SortSArray(MapList
);
3385 gNextMap
:= MapList
[Low(MapList
)];
3390 procedure g_Game_ExitLevel(const Map
: AnsiString);
3394 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3395 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3396 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3397 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3399 // Вышли в выход в Одиночной игре:
3400 if gGameSettings
.GameType
= GT_SINGLE
then
3401 gExit
:= EXIT_ENDLEVELSINGLE
3402 else // Вышли в выход в Своей игре
3404 gExit
:= EXIT_ENDLEVELCUSTOM
;
3405 if gGameSettings
.GameMode
= GM_COOP
then
3406 g_Player_RememberAll
;
3408 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3411 if gGameSettings
.GameMode
= GM_COOP
then
3414 gStatsPressed
:= True;
3415 gNextMap
:= 'MAP01';
3417 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3420 if g_Game_IsNet
then
3422 MH_SEND_GameStats();
3423 MH_SEND_CoopStats();
3429 procedure g_Game_RestartLevel();
3433 if gGameSettings
.GameMode
= GM_SINGLE
then
3438 gExit
:= EXIT_ENDLEVELCUSTOM
;
3439 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3443 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3445 gWAD
{, xwad}: String;
3448 if not g_Game_IsClient
then Exit
;
3449 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3451 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3456 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3460 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3463 g_Game_LoadWAD(NewWAD
);
3467 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3468 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3471 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3472 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3476 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3480 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3481 g_Game_LoadWAD(NewWAD);
3485 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3487 i
, n
, nb
, nr
: Integer;
3489 if not g_Game_IsServer
then Exit
;
3490 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3491 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3492 gLMSRespawnTime
:= 0;
3495 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3497 gMissionFailed
:= True;
3498 g_Game_RestartLevel
;
3502 n
:= 0; nb
:= 0; nr
:= 0;
3503 for i
:= Low(gPlayers
) to High(gPlayers
) do
3504 if (gPlayers
[i
] <> nil) and
3505 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3506 (gPlayers
[i
] is TBot
)) then
3509 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3510 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3513 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3515 // wait a second until the fuckers finally decide to join
3516 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3517 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3518 gLMSSoftSpawn
:= NoMapRestart
;
3519 if g_Game_IsNet
then
3520 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3524 g_Player_RemoveAllCorpses
;
3525 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3526 if g_Game_IsNet
then
3527 MH_SEND_GameEvent(NET_EV_LMS_START
);
3529 for i
:= Low(gPlayers
) to High(gPlayers
) do
3531 if gPlayers
[i
] = nil then continue
;
3532 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3533 // don't touch normal spectators
3534 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3536 gPlayers
[i
].FNoRespawn
:= True;
3537 gPlayers
[i
].Lives
:= 0;
3538 if g_Game_IsNet
then
3539 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3542 gPlayers
[i
].FNoRespawn
:= False;
3543 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3544 gPlayers
[i
].Respawn(False, True);
3545 if gGameSettings
.GameMode
= GM_COOP
then
3547 gPlayers
[i
].Frags
:= 0;
3548 gPlayers
[i
].RecallState
;
3550 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3551 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3552 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3553 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3556 g_Items_RestartRound();
3558 gLMSSoftSpawn
:= False;
3561 function g_Game_GetFirstMap(WAD
: String): String;
3565 MapList
:= g_Map_GetMapsList(WAD
);
3566 if MapList
= nil then
3569 SortSArray(MapList
);
3570 Result
:= MapList
[Low(MapList
)];
3572 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3578 function g_Game_GetNextMap(): String;
3585 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3586 if MapList
= nil then
3589 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3591 SortSArray(MapList
);
3593 for I
:= Low(MapList
) to High(MapList
) do
3594 if Map
= MapList
[I
] then
3600 if MapIndex
<> -255 then
3602 if MapIndex
= High(MapList
) then
3603 Result
:= MapList
[Low(MapList
)]
3605 Result
:= MapList
[MapIndex
+ 1];
3607 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3613 procedure g_Game_NextLevel();
3615 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3616 gExit
:= EXIT_ENDLEVELCUSTOM
3619 gExit
:= EXIT_ENDLEVELSINGLE
;
3623 if gNextMap
<> '' then Exit
;
3624 gNextMap
:= g_Game_GetNextMap();
3627 function g_Game_IsTestMap(): Boolean;
3629 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3632 procedure g_Game_DeleteTestMap();
3635 //MapName: AnsiString;
3643 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3644 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3645 if (a
= 0) then exit
;
3647 // Выделяем имя wad-файла и имя карты
3648 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3649 Delete(gMapToDelete
, 1, a
+5);
3650 gMapToDelete
:= UpperCase(gMapToDelete
);
3652 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3655 // Имя карты не стандартное тестовое:
3656 if MapName <> TEST_MAP_NAME then
3659 if not gTempDelete then
3661 time := g_GetFileTime(WadName);
3662 WAD := TWADFile.Create();
3665 if not WAD.ReadFile(WadName) then
3666 begin // Нет такого WAD-файла
3671 // Составляем список карт и ищем нужную:
3673 MapList := WAD.GetResourcesList('');
3675 if MapList <> nil then
3676 for a := 0 to High(MapList) do
3677 if MapList[a] = MapName then
3679 // Удаляем и сохраняем:
3680 WAD.RemoveResource('', MapName);
3681 WAD.SaveTo(WadName);
3686 g_SetFileTime(WadName, time);
3689 if gTempDelete
then DeleteFile(WadName
);
3692 procedure GameCVars(P
: SSArray
);
3695 stat
: TPlayerStatArray
;
3698 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3702 if Length(P
) > 1 then
3707 gsGameFlags
:= gsGameFlags
or Flag
3709 gsGameFlags
:= gsGameFlags
and (not Flag
);
3711 if g_Game_IsServer
then
3714 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3716 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3717 if g_Game_IsNet
then MH_SEND_GameSettings
;
3721 if LongBool(gsGameFlags
and Flag
) then
3722 g_Console_Add(_lc
[OnMsg
])
3724 g_Console_Add(_lc
[OffMsg
]);
3726 if OnMapChange
and g_Game_IsServer
then
3727 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3732 cmd
:= LowerCase(P
[0]);
3734 if cmd
= 'g_gamemode' then
3736 if (Length(P
) > 1) then
3738 a
:= g_Game_TextToMode(P
[1]);
3739 if a
= GM_SINGLE
then a
:= GM_COOP
;
3740 gsGameMode
:= g_Game_ModeToText(a
);
3741 if g_Game_IsServer
then
3743 gSwitchGameMode
:= a
;
3744 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3745 (gState
= STATE_INTERSINGLE
) then
3746 gSwitchGameMode
:= GM_SINGLE
;
3748 gGameSettings
.GameMode
:= gSwitchGameMode
;
3752 if gSwitchGameMode
= gGameSettings
.GameMode
then
3753 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3754 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3756 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3757 [g_Game_ModeToText(gGameSettings
.GameMode
),
3758 g_Game_ModeToText(gSwitchGameMode
)]));
3760 else if cmd
= 'g_friendlyfire' then
3762 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3764 else if cmd
= 'g_friendly_absorb_damage' then
3766 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
3768 else if cmd
= 'g_friendly_hit_trace' then
3770 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
3772 else if cmd
= 'g_friendly_hit_projectile' then
3774 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
3776 else if cmd
= 'g_weaponstay' then
3778 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3780 else if cmd
= 'g_allow_exit' then
3782 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3784 else if cmd
= 'g_allow_monsters' then
3786 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3788 else if cmd
= 'g_allow_dropflag' then
3790 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
3792 else if cmd
= 'g_throw_flag' then
3794 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
3796 else if cmd
= 'g_bot_vsplayers' then
3798 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3800 else if cmd
= 'g_bot_vsmonsters' then
3802 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3804 else if cmd
= 'g_dm_keys' then
3806 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
3808 else if cmd
= 'g_gameflags' then
3810 if Length(P
) > 1 then
3812 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
3813 if g_Game_IsServer
then
3815 gGameSettings
.Options
:= gsGameFlags
;
3816 if g_Game_IsNet
then MH_SEND_GameSettings
;
3820 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
3822 else if cmd
= 'g_warmup_time' then
3824 if Length(P
) > 1 then
3826 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
3827 if g_Game_IsServer
then
3829 gGameSettings
.WarmupTime
:= gsWarmupTime
;
3830 // extend warmup if it's already going
3831 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
3833 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
3834 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3836 if g_Game_IsNet
then MH_SEND_GameSettings
;
3840 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
3841 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3843 else if cmd
= 'g_spawn_invul' then
3845 if Length(P
) > 1 then
3847 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
3848 if g_Game_IsServer
then
3850 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
3851 if g_Game_IsNet
then MH_SEND_GameSettings
;
3855 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
3857 else if cmd
= 'g_item_respawn_time' then
3859 if Length(P
) > 1 then
3861 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
3862 if g_Game_IsServer
then
3864 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
3865 if g_Game_IsNet
then MH_SEND_GameSettings
;
3869 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
3870 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3872 else if cmd
= 'sv_intertime' then
3874 if (Length(P
) > 1) then
3875 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
3877 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
3879 else if cmd
= 'g_max_particles' then
3881 if Length(p
) = 2 then
3883 a
:= Max(0, StrToIntDef(p
[1], 0));
3886 else if Length(p
) = 1 then
3888 e_LogWritefln('%s', [g_GFX_GetMax()])
3892 e_LogWritefln('usage: %s <n>', [cmd
])
3895 else if cmd
= 'g_max_shells' then
3897 if Length(p
) = 2 then
3899 a
:= Max(0, StrToIntDef(p
[1], 0));
3902 else if Length(p
) = 1 then
3904 e_LogWritefln('%s', [g_Shells_GetMax()])
3908 e_LogWritefln('usage: %s <n>', [cmd
])
3911 else if cmd
= 'g_max_gibs' then
3913 if Length(p
) = 2 then
3915 a
:= Max(0, StrToIntDef(p
[1], 0));
3918 else if Length(p
) = 1 then
3920 e_LogWritefln('%s', [g_Gibs_GetMax()])
3924 e_LogWritefln('usage: %s <n>', [cmd
])
3927 else if cmd
= 'g_max_corpses' then
3929 if Length(p
) = 2 then
3931 a
:= Max(0, StrToIntDef(p
[1], 0));
3934 else if Length(p
) = 1 then
3936 e_LogWritefln('%s', [g_Corpses_GetMax()])
3940 e_LogWritefln('usage: %s <n>', [cmd
])
3943 else if cmd
= 'g_force_model' then
3945 if Length(p
) = 2 then
3947 a
:= StrToIntDef(p
[1], 0);
3948 g_Force_Model_Set(a
);
3949 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
3951 for a
:= Low(gPlayers
) to High(gPlayers
) do
3953 if (gPlayers
[a
] <> nil) then
3955 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
3957 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
3959 gPlayers
[a
].setModel(g_Forced_Model_GetName());
3963 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
3965 for a
:= Low(gPlayers
) to High(gPlayers
) do
3967 if (gPlayers
[a
] <> nil) then
3969 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
3971 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
3973 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
3979 else if cmd
= 'g_force_model_name' then
3981 if (Length(P
) > 1) then
3983 cmd
:= b_Text_Unformat(P
[1]);
3984 g_Forced_Model_SetName(cmd
);
3985 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
3987 for a
:= Low(gPlayers
) to High(gPlayers
) do
3989 if (gPlayers
[a
] <> nil) then
3991 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
3993 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
3995 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4001 else if cmd
= 'g_scorelimit' then
4003 if Length(P
) > 1 then
4005 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4007 if g_Game_IsServer
then
4010 if gGameSettings
.GameMode
= GM_DM
then
4012 stat
:= g_Player_GetStats();
4014 for a
:= 0 to High(stat
) do
4015 if stat
[a
].Frags
> b
then
4019 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4021 // if someone has a higher score, set it to that instead
4022 gsScoreLimit
:= max(gsScoreLimit
, b
);
4023 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4025 if g_Game_IsNet
then MH_SEND_GameSettings
;
4029 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4031 else if cmd
= 'g_timelimit' then
4033 if Length(P
) > 1 then
4035 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4036 if g_Game_IsServer
then
4038 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4039 if g_Game_IsNet
then MH_SEND_GameSettings
;
4042 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4043 [gsTimeLimit
div 3600,
4044 (gsTimeLimit
div 60) mod 60,
4045 gsTimeLimit
mod 60]));
4047 else if cmd
= 'g_max_bots' then
4049 if Length(P
) > 1 then
4050 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4051 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4053 else if cmd
= 'g_maxlives' then
4055 if Length(P
) > 1 then
4057 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4058 if g_Game_IsServer
then
4060 gGameSettings
.MaxLives
:= gsMaxLives
;
4061 if g_Game_IsNet
then MH_SEND_GameSettings
;
4065 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4069 procedure PlayerSettingsCVars(P
: SSArray
);
4074 function ParseTeam(s
: string): Byte;
4078 'red', '1': result
:= TEAM_RED
;
4079 'blue', '2': result
:= TEAM_BLUE
;
4080 else result
:= TEAM_NONE
;
4084 cmd
:= LowerCase(P
[0]);
4088 if (Length(P
) > 1) then
4090 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4091 if g_Game_IsClient
then
4092 MC_SEND_PlayerSettings
4093 else if gGameOn
and (gPlayer1
<> nil) then
4095 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4096 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4102 if (Length(P
) > 1) then
4104 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4105 if g_Game_IsClient
then
4106 MC_SEND_PlayerSettings
4107 else if gGameOn
and (gPlayer2
<> nil) then
4109 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4110 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4116 if Length(P
) > 3 then
4118 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4119 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4120 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4121 if g_Game_IsClient
then
4122 MC_SEND_PlayerSettings
4123 else if gGameOn
and (gPlayer1
<> nil) then
4125 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4126 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4132 if Length(P
) > 3 then
4134 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4135 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4136 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4137 if g_Game_IsClient
then
4138 MC_SEND_PlayerSettings
4139 else if gGameOn
and (gPlayer2
<> nil) then
4141 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4142 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4148 if (Length(P
) > 1) then
4150 gPlayer1Settings
.Model
:= P
[1];
4151 if g_Game_IsClient
then
4152 MC_SEND_PlayerSettings
4153 else if gGameOn
and (gPlayer1
<> nil) then
4155 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4156 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4157 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4163 if (Length(P
) > 1) then
4165 gPlayer2Settings
.Model
:= P
[1];
4166 if g_Game_IsClient
then
4167 MC_SEND_PlayerSettings
4168 else if gGameOn
and (gPlayer2
<> nil) then
4170 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4171 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4172 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4178 // TODO: switch teams if in game or store this separately
4179 if (Length(P
) > 1) then
4181 team
:= ParseTeam(P
[1]);
4182 if team
= TEAM_NONE
then
4183 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4184 else if not gGameOn
and not g_Game_IsNet
then
4185 gPlayer1Settings
.Team
:= team
4187 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4192 // TODO: switch teams if in game or store this separately
4193 if (Length(P
) > 1) then
4195 team
:= ParseTeam(P
[1]);
4196 if team
= TEAM_NONE
then
4197 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4198 else if not gGameOn
and not g_Game_IsNet
then
4199 gPlayer2Settings
.Team
:= team
4201 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4206 if (Length(P
) = 2) then
4207 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4211 if (Length(P
) = 2) then
4212 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4216 if (Length(P
) = 2) then
4217 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4221 if (Length(P
) = 2) then
4222 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4226 if (Length(P
) = 2) then
4227 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4231 if (Length(P
) = 2) then
4232 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4234 'p1_priority_kastet':
4236 if (Length(P
) = 2) then
4237 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4239 'p2_priority_kastet':
4241 if (Length(P
) = 2) then
4242 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4246 if (Length(P
) = 2) then
4247 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4251 if (Length(P
) = 2) then
4252 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4254 'p1_priority_pistol':
4256 if (Length(P
) = 2) then
4257 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4259 'p2_priority_pistol':
4261 if (Length(P
) = 2) then
4262 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4264 'p1_priority_shotgun1':
4266 if (Length(P
) = 2) then
4267 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4269 'p2_priority_shotgun1':
4271 if (Length(P
) = 2) then
4272 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4274 'p1_priority_shotgun2':
4276 if (Length(P
) = 2) then
4277 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4279 'p2_priority_shotgun2':
4281 if (Length(P
) = 2) then
4282 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4284 'p1_priority_chaingun':
4286 if (Length(P
) = 2) then
4287 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4289 'p2_priority_chaingun':
4291 if (Length(P
) = 2) then
4292 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4294 'p1_priority_rocketlauncher':
4296 if (Length(P
) = 2) then
4297 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4299 'p2_priority_rocketlauncher':
4301 if (Length(P
) = 2) then
4302 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4304 'p1_priority_plasma':
4306 if (Length(P
) = 2) then
4307 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4309 'p2_priority_plasma':
4311 if (Length(P
) = 2) then
4312 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4316 if (Length(P
) = 2) then
4317 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4321 if (Length(P
) = 2) then
4322 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4324 'p1_priority_super':
4326 if (Length(P
) = 2) then
4327 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4329 'p2_priority_super':
4331 if (Length(P
) = 2) then
4332 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4334 'p1_priority_flamethrower':
4336 if (Length(P
) = 2) then
4337 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4339 'p2_priority_flamethrower':
4341 if (Length(P
) = 2) then
4342 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4344 'p1_priority_berserk':
4346 if (Length(P
) = 2) then
4347 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4349 'p2_priority_berserk':
4351 if (Length(P
) = 2) then
4352 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4357 procedure PrintHeapStats();
4361 hs
:= GetFPCHeapStatus();
4362 e_LogWriteLn ('v===== heap status =====v');
4363 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4364 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4365 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4366 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4367 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4368 e_LogWriteLn ('^=======================^');
4371 procedure DebugCommands(P
: SSArray
);
4378 // Команды отладочного режима:
4379 if {gDebugMode}conIsCheatsEnabled
then
4381 cmd
:= LowerCase(P
[0]);
4382 if cmd
= 'd_window' then
4384 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4385 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4387 else if cmd
= 'd_sounds' then
4389 if (Length(P
) > 1) and
4390 ((P
[1] = '1') or (P
[1] = '0')) then
4391 g_Debug_Sounds
:= (P
[1][1] = '1');
4393 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4395 else if cmd
= 'd_frames' then
4397 if (Length(P
) > 1) and
4398 ((P
[1] = '1') or (P
[1] = '0')) then
4399 g_Debug_Frames
:= (P
[1][1] = '1');
4401 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4403 else if cmd
= 'd_winmsg' then
4405 if (Length(P
) > 1) and
4406 ((P
[1] = '1') or (P
[1] = '0')) then
4407 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4409 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4411 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4413 if (Length(P
) > 1) and
4414 ((P
[1] = '1') or (P
[1] = '0')) then
4415 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4417 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4419 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4421 if Length(P
) > 1 then
4423 '0': g_debug_BotAIOff
:= 0;
4424 '1': g_debug_BotAIOff
:= 1;
4425 '2': g_debug_BotAIOff
:= 2;
4426 '3': g_debug_BotAIOff
:= 3;
4429 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4431 else if cmd
= 'd_monster' then
4433 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4434 if Length(P
) < 2 then
4436 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4437 g_Console_Add('ID | Name');
4438 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4439 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4440 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4443 a
:= StrToIntDef(P
[1], 0);
4444 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4445 a
:= g_Mons_TypeIdByName(P
[1]);
4447 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4448 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4451 with gPlayer1
.Obj
do
4453 mon
:= g_Monsters_Create(a
,
4454 X
+ Rect
.X
+ (Rect
.Width
div 2),
4455 Y
+ Rect
.Y
+ Rect
.Height
,
4456 gPlayer1
.Direction
, True);
4458 if (Length(P
) > 2) and (mon
<> nil) then
4460 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4461 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4462 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4463 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4464 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4465 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4466 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4467 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4468 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4473 else if (cmd
= 'd_health') then
4475 if (Length(P
) > 1) and
4476 ((P
[1] = '1') or (P
[1] = '0')) then
4477 g_debug_HealthBar
:= (P
[1][1] = '1');
4479 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4481 else if (cmd
= 'd_player') then
4483 if (Length(P
) > 1) and
4484 ((P
[1] = '1') or (P
[1] = '0')) then
4485 g_debug_Player
:= (P
[1][1] = '1');
4487 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4489 else if (cmd
= 'd_mem') then
4495 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4499 procedure GameCheats(P
: SSArray
);
4505 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4507 g_Console_Add('not available');
4513 g_Console_Add('where is the player?!');
4516 cmd
:= LowerCase(P
[0]);
4520 plr
.GodMode
:= not plr
.GodMode
;
4521 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4524 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4525 if cmd
= 'give' then
4527 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4528 for f
:= 1 to High(P
) do
4530 cmd
:= LowerCase(P
[f
]);
4531 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4532 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4533 if cmd
= 'exit' then
4535 if gTriggers
<> nil then
4537 for a
:= 0 to High(gTriggers
) do
4539 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4541 g_Console_Add('player left the map');
4542 gExitByTrigger
:= True;
4543 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4544 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4552 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4553 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4554 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4555 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4556 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4558 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4559 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4561 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4562 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;
4564 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4565 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4567 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4568 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4570 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4571 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4573 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4574 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4575 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4577 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4578 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4579 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4580 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;
4581 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4582 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4584 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;
4585 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;
4586 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;
4587 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;
4588 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;
4589 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;
4591 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4592 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;
4594 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;
4595 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;
4597 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4599 if cmd
= 'ammo' then
4601 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4602 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4603 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4604 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4605 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4606 g_Console_Add('player got some ammo');
4610 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4611 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4613 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4614 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4616 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4617 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4619 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4620 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4622 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4624 if cmd
= 'weapons' then
4626 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4627 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4628 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4629 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4630 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4631 plr
.GiveItem(ITEM_WEAPON_BFG
);
4632 g_Console_Add('player got weapons');
4636 if cmd
= 'keys' then
4638 plr
.GiveItem(ITEM_KEY_RED
);
4639 plr
.GiveItem(ITEM_KEY_GREEN
);
4640 plr
.GiveItem(ITEM_KEY_BLUE
);
4641 g_Console_Add('player got all keys');
4645 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4650 if cmd
= 'open' then
4652 g_Console_Add('player activated sesame');
4653 g_Triggers_OpenAll();
4660 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4664 if cmd
= 'noclip' then
4667 g_Console_Add('wall hardeness adjusted');
4671 if cmd
= 'notarget' then
4673 plr
.NoTarget
:= not plr
.NoTarget
;
4674 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4678 if cmd
= 'noreload' then
4680 plr
.NoReload
:= not plr
.NoReload
;
4681 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4685 if cmd
= 'speedy' then
4687 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4688 g_Console_Add('speed adjusted');
4692 if cmd
= 'jumpy' then
4694 VEL_JUMP
:= 30-VEL_JUMP
;
4695 g_Console_Add('jump height adjusted');
4699 if cmd
= 'automap' then
4701 gShowMap
:= not gShowMap
;
4702 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4706 if cmd
= 'aimline' then
4708 gAimLine
:= not gAimLine
;
4709 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4714 procedure GameCommands(P
: SSArray
);
4720 pl
: pTNetClient
= nil;
4728 cmd
:= LowerCase(P
[0]);
4730 if cmd
= 'pause' then
4732 if (g_ActiveWindow
= nil) then
4733 g_Game_Pause(not gPauseMain
);
4735 else if cmd
= 'endgame' then
4736 gExit
:= EXIT_SIMPLE
4737 else if cmd
= 'restart' then
4739 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4741 if g_Game_IsClient
then
4743 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4748 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4750 else if cmd
= 'kick' then
4752 if g_Game_IsServer
then
4754 if Length(P
) < 2 then
4756 g_Console_Add('kick <name>');
4761 g_Console_Add('kick <name>');
4765 if g_Game_IsNet
then
4766 pl
:= g_Net_Client_ByName(P
[1]);
4769 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4770 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4771 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4772 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4773 g_Net_Slist_ServerPlayerLeaves();
4774 end else if gPlayers
<> nil then
4775 for a
:= Low(gPlayers
) to High(gPlayers
) do
4776 if gPlayers
[a
] <> nil then
4777 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4779 // Не отключать основных игроков в сингле
4780 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4782 gPlayers
[a
].Lives
:= 0;
4783 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4784 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4785 g_Player_Remove(gPlayers
[a
].UID
);
4786 g_Net_Slist_ServerPlayerLeaves();
4787 // Если не перемешать, при добавлении новых ботов появятся старые
4791 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4793 else if cmd
= 'kick_id' then
4795 if g_Game_IsServer
and g_Game_IsNet
then
4797 if Length(P
) < 2 then
4799 g_Console_Add('kick_id <client ID>');
4804 g_Console_Add('kick_id <client ID>');
4808 a
:= StrToIntDef(P
[1], 0);
4809 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4811 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4813 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4814 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
4815 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4816 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4817 g_Net_Slist_ServerPlayerLeaves();
4821 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4823 else if cmd
= 'kick_pid' then
4825 if g_Game_IsServer
and g_Game_IsNet
then
4827 if Length(P
) < 2 then
4829 g_Console_Add('kick_pid <player ID>');
4834 g_Console_Add('kick_pid <player ID>');
4838 a
:= StrToIntDef(P
[1], 0);
4839 pl
:= g_Net_Client_ByPlayer(a
);
4840 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4842 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4843 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4844 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4845 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4846 g_Net_Slist_ServerPlayerLeaves();
4849 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4851 else if cmd
= 'ban' then
4853 if g_Game_IsServer
and g_Game_IsNet
then
4855 if Length(P
) < 2 then
4857 g_Console_Add('ban <name>');
4862 g_Console_Add('ban <name>');
4866 pl
:= g_Net_Client_ByName(P
[1]);
4869 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4870 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4871 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
4872 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4873 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4874 g_Net_Slist_ServerPlayerLeaves();
4876 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4878 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4880 else if cmd
= 'ban_id' then
4882 if g_Game_IsServer
and g_Game_IsNet
then
4884 if Length(P
) < 2 then
4886 g_Console_Add('ban_id <client ID>');
4891 g_Console_Add('ban_id <client ID>');
4895 a
:= StrToIntDef(P
[1], 0);
4896 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4897 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4899 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4900 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
4901 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
4902 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4903 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4904 g_Net_Slist_ServerPlayerLeaves();
4907 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4909 else if cmd
= 'ban_pid' then
4911 if g_Game_IsServer
and g_Game_IsNet
then
4913 if Length(P
) < 2 then
4915 g_Console_Add('ban_pid <player ID>');
4920 g_Console_Add('ban_pid <player ID>');
4924 a
:= StrToIntDef(P
[1], 0);
4925 pl
:= g_Net_Client_ByPlayer(a
);
4926 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4928 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4929 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4930 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
4931 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4932 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4933 g_Net_Slist_ServerPlayerLeaves();
4936 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4938 else if cmd
= 'permban' then
4940 if g_Game_IsServer
and g_Game_IsNet
then
4942 if Length(P
) < 2 then
4944 g_Console_Add('permban <name>');
4949 g_Console_Add('permban <name>');
4953 pl
:= g_Net_Client_ByName(P
[1]);
4956 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4957 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4958 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
4959 g_Net_SaveBanList();
4960 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4961 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4962 g_Net_Slist_ServerPlayerLeaves();
4964 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4966 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4968 else if cmd
= 'permban_id' then
4970 if g_Game_IsServer
and g_Game_IsNet
then
4972 if Length(P
) < 2 then
4974 g_Console_Add('permban_id <client ID>');
4979 g_Console_Add('permban_id <client ID>');
4983 a
:= StrToIntDef(P
[1], 0);
4984 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4985 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4987 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4988 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
4989 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
4990 g_Net_SaveBanList();
4991 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4992 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4993 g_Net_Slist_ServerPlayerLeaves();
4996 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4998 else if cmd
= 'permban_pid' then
5000 if g_Game_IsServer
and g_Game_IsNet
then
5002 if Length(P
) < 2 then
5004 g_Console_Add('permban_pid <player ID>');
5009 g_Console_Add('permban_pid <player ID>');
5013 a
:= StrToIntDef(P
[1], 0);
5014 pl
:= g_Net_Client_ByPlayer(a
);
5015 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5017 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5018 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5019 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5020 g_Net_SaveBanList();
5021 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5022 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5023 g_Net_Slist_ServerPlayerLeaves();
5026 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5028 else if cmd
= 'permban_ip' then
5030 if g_Game_IsServer
and g_Game_IsNet
then
5032 if Length(P
) < 2 then
5034 g_Console_Add('permban_ip <IP address>');
5039 g_Console_Add('permban_ip <IP address>');
5043 g_Net_BanHost(P
[1]);
5044 g_Net_SaveBanList();
5045 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5047 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5049 else if cmd
= 'unban' then
5051 if g_Game_IsServer
and g_Game_IsNet
then
5053 if Length(P
) < 2 then
5055 g_Console_Add('unban <IP Address>');
5060 g_Console_Add('unban <IP Address>');
5064 if g_Net_UnbanHost(P
[1]) then
5066 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5067 g_Net_SaveBanList();
5069 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5071 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5073 else if cmd
= 'clientlist' then
5075 if g_Game_IsServer
and g_Game_IsNet
then
5078 if NetClients
<> nil then
5079 for a
:= Low(NetClients
) to High(NetClients
) do
5080 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5082 plr
:= g_Player_Get(NetClients
[a
].Player
);
5083 if plr
= nil then continue
;
5085 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5086 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5089 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5091 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5093 else if cmd
= 'connect' then
5095 if (NetMode
= NET_NONE
) then
5097 if Length(P
) < 2 then
5099 g_Console_Add('connect <IP> [port] [password]');
5104 g_Console_Add('connect <IP> [port] [password]');
5108 if Length(P
) > 2 then
5109 prt
:= StrToIntDef(P
[2], 25666)
5113 if Length(P
) > 3 then
5118 g_Game_StartClient(P
[1], prt
, pw
);
5121 else if cmd
= 'disconnect' then
5123 if (NetMode
= NET_CLIENT
) then
5126 else if cmd
= 'reconnect' then
5128 if (NetMode
= NET_SERVER
) then
5131 if (NetMode
= NET_CLIENT
) then
5134 gExit
:= EXIT_SIMPLE
;
5138 //TODO: Use last successful password to reconnect, instead of ''
5139 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5141 else if (cmd
= 'addbot') or
5142 (cmd
= 'bot_add') then
5144 if Length(P
) > 2 then
5145 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5146 else if Length(P
) > 1 then
5147 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5149 g_Bot_Add(TEAM_NONE
, 2);
5151 else if cmd
= 'bot_addlist' then
5153 if Length(P
) > 1 then
5155 if Length(P
) = 2 then
5156 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5157 else if Length(P
) = 3 then
5158 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5160 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5163 else if cmd
= 'bot_removeall' then
5165 else if cmd
= 'chat' then
5167 if g_Game_IsNet
then
5169 if Length(P
) > 1 then
5171 for a
:= 1 to High(P
) do
5172 chstr
:= chstr
+ P
[a
] + ' ';
5174 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5176 if Length(chstr
) < 1 then
5178 g_Console_Add('chat <text>');
5182 chstr
:= b_Text_Format(chstr
);
5183 if g_Game_IsClient
then
5184 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5186 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5189 g_Console_Add('chat <text>');
5191 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5193 else if cmd
= 'teamchat' then
5195 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5197 if Length(P
) > 1 then
5199 for a
:= 1 to High(P
) do
5200 chstr
:= chstr
+ P
[a
] + ' ';
5202 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5204 if Length(chstr
) < 1 then
5206 g_Console_Add('teamchat <text>');
5210 chstr
:= b_Text_Format(chstr
);
5211 if g_Game_IsClient
then
5212 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5214 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5215 gPlayer1Settings
.Team
);
5218 g_Console_Add('teamchat <text>');
5220 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5222 else if (cmd
= 'an') or (cmd
= 'announce') then
5224 if g_Game_IsNet
then
5226 if Length(P
) > 1 then
5228 for a
:= 1 to High(P
) do
5229 chstr
:= chstr
+ P
[a
] + ' ';
5231 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5233 if Length(chstr
) < 1 then
5235 g_Console_Add('announce <text>');
5239 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5240 if g_Game_IsClient
then
5241 MC_SEND_RCONCommand(chstr
)
5243 g_Console_Process(chstr
, True);
5246 g_Console_Add('announce <text>');
5248 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5250 else if cmd
= 'game' then
5252 if gGameSettings
.GameType
<> GT_NONE
then
5254 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5257 if Length(P
) = 1 then
5259 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5262 // game not started yet, load fist map from some wad
5264 s
:= addWadExtension(P
[1]);
5265 found
:= e_FindResource(AllMapDirs
, s
);
5269 P
[1] := ExpandFileName(P
[1]);
5270 // if map not choosed then set first map
5271 if Length(P
) < 3 then
5274 P
[2] := g_Game_GetFirstMap(P
[1]);
5277 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5279 if g_Map_Exist(s
) then
5283 with gGameSettings
do
5285 Options
:= gsGameFlags
;
5286 GameMode
:= g_Game_TextToMode(gsGameMode
);
5287 if gSwitchGameMode
<> GM_NONE
then
5288 GameMode
:= gSwitchGameMode
;
5289 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5290 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5292 if Length(P
) >= 4 then
5293 b
:= StrToIntDef(P
[3], 1);
5294 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5295 ScoreLimit
, MaxLives
, Options
, b
);
5300 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5302 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5304 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5306 else if cmd
= 'host' then
5308 if gGameSettings
.GameType
<> GT_NONE
then
5310 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5313 if Length(P
) < 4 then
5315 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5318 if not StrToIp(P
[1], listen
) then
5320 prt
:= StrToIntDef(P
[2], 25666);
5322 s
:= addWadExtension(P
[3]);
5323 found
:= e_FindResource(AllMapDirs
, s
);
5327 // get first map in wad, if not specified
5328 if Length(P
) < 5 then
5331 P
[4] := g_Game_GetFirstMap(P
[1]);
5333 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5334 if g_Map_Exist(s
) then
5338 with gGameSettings
do
5340 Options
:= gsGameFlags
;
5341 GameMode
:= g_Game_TextToMode(gsGameMode
);
5342 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5343 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5344 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5346 if Length(P
) >= 6 then
5347 b
:= StrToIntDef(P
[5], 0);
5348 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5354 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5356 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5361 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5364 else if cmd
= 'map' then
5366 if Length(P
) = 1 then
5368 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5370 g_Console_Add(cmd
+ ' <MAP>');
5371 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5375 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5380 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5382 if Length(P
) < 3 then
5384 // first param is map or wad
5385 s
:= UpperCase(P
[1]);
5386 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5388 gExitByTrigger
:= False;
5391 // already in game, finish current map
5393 gExit
:= EXIT_ENDLEVELCUSTOM
;
5397 // intermission, so change map immediately
5404 found
:= e_FindResource(AllMapDirs
, s
);
5406 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5409 // no such map, found wad
5412 P
[1] := ExpandFileName(pw
);
5413 P
[2] := g_Game_GetFirstMap(P
[1]);
5414 s
:= P
[1] + ':\' + P
[2];
5415 if g_Map_Exist(s
) then
5417 gExitByTrigger
:= False;
5420 // already in game, finish current map
5422 gExit
:= EXIT_ENDLEVELCUSTOM
5426 // intermission, so change map immediately
5433 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5435 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5440 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5446 s
:= addWadExtension(P
[1]);
5447 found
:= e_FindResource(AllMapDirs
, s
);
5451 P
[2] := UpperCase(P
[2]);
5452 s
:= P
[1] + ':\' + P
[2];
5453 if g_Map_Exist(s
) then
5455 gExitByTrigger
:= False;
5459 gExit
:= EXIT_ENDLEVELCUSTOM
5468 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5473 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5479 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5483 else if cmd
= 'nextmap' then
5485 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5487 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5492 if Length(P
) = 1 then
5494 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5496 g_Console_Add(cmd
+ ' <MAP>');
5497 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5502 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5508 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5510 if Length(P
) < 3 then
5512 // first param is map or wad
5513 s
:= UpperCase(P
[1]);
5514 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5517 gExitByTrigger
:= False;
5523 // no such map, found wad
5524 pw
:= addWadExtension(P
[1]);
5525 found
:= e_FindResource(MapDirs
, pw
);
5527 found
:= e_FindResource(WadDirs
, pw
);
5529 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5532 // map not specified, select first map
5534 P
[2] := g_Game_GetFirstMap(P
[1]);
5535 s
:= P
[1] + ':\' + P
[2];
5536 if g_Map_Exist(s
) then
5538 gExitByTrigger
:= False;
5545 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5547 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5552 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5558 // specified two params wad + map
5559 pw
:= addWadExtension(P
[1]);
5560 found
:= e_FindResource(MapDirs
, pw
);
5562 found
:= e_FindResource(MapDirs
, pw
);
5566 P
[2] := UpperCase(P
[2]);
5567 s
:= P
[1] + ':\' + P
[2];
5568 if g_Map_Exist(s
) then
5570 gExitByTrigger
:= False;
5576 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5581 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5587 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5592 if gNextMap
= '' then
5593 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5595 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5599 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5603 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5607 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5609 gExitByTrigger
:= False;
5610 // next map not specified, try to find trigger EXIT
5611 if (gNextMap
= '') and (gTriggers
<> nil) then
5613 for a
:= 0 to High(gTriggers
) do
5615 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5617 gExitByTrigger
:= True;
5618 //gNextMap := gTriggers[a].Data.MapName;
5619 gNextMap
:= gTriggers
[a
].tgcMap
;
5624 if gNextMap
= '' then
5625 gNextMap
:= g_Game_GetNextMap();
5626 if not isWadPath(gNextMap
) then
5627 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5630 if g_Map_Exist(s
) then
5631 gExit
:= EXIT_ENDLEVELCUSTOM
5633 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5637 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5641 else if (cmd
= 'event') then
5643 if (Length(P
) <= 1) then
5645 for a
:= 0 to High(gEvents
) do
5646 if gEvents
[a
].Command
= '' then
5647 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5649 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5652 if (Length(P
) = 2) then
5654 for a
:= 0 to High(gEvents
) do
5655 if gEvents
[a
].Name
= P
[1] then
5656 if gEvents
[a
].Command
= '' then
5657 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5659 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5662 for a
:= 0 to High(gEvents
) do
5663 if gEvents
[a
].Name
= P
[1] then
5665 gEvents
[a
].Command
:= '';
5666 for b
:= 2 to High(P
) do
5667 if Pos(' ', P
[b
]) = 0 then
5668 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5670 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5671 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5675 else if cmd
= 'suicide' then
5679 if g_Game_IsClient
then
5680 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5683 if gPlayer1
<> nil then
5684 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5685 if gPlayer2
<> nil then
5686 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5690 else if cmd
= 'screenshot' then
5694 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5696 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5698 gWeaponAction
[0, WP_PREV
] := True;
5700 gWeaponAction
[0, WP_NEXT
] := True;
5702 else if cmd
= 'weapon' then
5704 if Length(p
) = 2 then
5706 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5707 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5708 gSelectWeapon
[0, a
] := True
5711 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5712 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5714 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5715 b
:= ord(cmd
[2]) - ord('1');
5717 gWeaponAction
[b
, WP_PREV
] := True;
5719 gWeaponAction
[b
, WP_NEXT
] := True;
5721 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5723 if Length(p
) = 2 then
5725 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5726 b
:= ord(cmd
[2]) - ord('1');
5727 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5728 gSelectWeapon
[b
, a
] := True
5731 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
5733 b
:= ord(cmd
[2]) - ord('1');
5735 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
5737 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
5739 else if (cmd
= 'dropflag') then
5741 if g_Game_IsServer
then
5743 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
5744 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
5747 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5749 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
5751 b
:= ord(cmd
[2]) - ord('1');
5752 if g_Game_IsServer
then
5754 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
5755 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
5758 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5760 // Команды Своей игры:
5761 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5763 if cmd
= 'bot_addred' then
5765 if Length(P
) > 1 then
5766 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5768 g_Bot_Add(TEAM_RED
, 2);
5770 else if cmd
= 'bot_addblue' then
5772 if Length(P
) > 1 then
5773 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5775 g_Bot_Add(TEAM_BLUE
, 2);
5777 else if cmd
= 'spectate' then
5783 else if cmd
= 'say' then
5785 if g_Game_IsServer
and g_Game_IsNet
then
5787 if Length(P
) > 1 then
5790 for a
:= 1 to High(P
) do
5791 chstr
:= chstr
+ P
[a
] + ' ';
5793 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5795 if Length(chstr
) < 1 then
5797 g_Console_Add('say <text>');
5801 chstr
:= b_Text_Format(chstr
);
5802 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5804 else g_Console_Add('say <text>');
5806 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5808 else if cmd
= 'tell' then
5810 if g_Game_IsServer
and g_Game_IsNet
then
5812 if (Length(P
) > 2) and (P
[1] <> '') then
5815 for a
:= 2 to High(P
) do
5816 chstr
:= chstr
+ P
[a
] + ' ';
5818 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5820 if Length(chstr
) < 1 then
5822 g_Console_Add('tell <playername> <text>');
5826 pl
:= g_Net_Client_ByName(P
[1]);
5828 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5830 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5832 else g_Console_Add('tell <playername> <text>');
5834 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5836 else if cmd
= 'centerprint' then
5838 if (Length(P
) > 2) and (P
[1] <> '') then
5841 for a
:= 2 to High(P
) do
5842 chstr
:= chstr
+ P
[a
] + ' ';
5844 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5846 if Length(chstr
) < 1 then
5848 g_Console_Add('centerprint <timeout> <text>');
5852 a
:= StrToIntDef(P
[1], 100);
5853 chstr
:= b_Text_Format(chstr
);
5854 g_Game_Message(chstr
, a
);
5855 if g_Game_IsNet
and g_Game_IsServer
then
5856 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
5858 else g_Console_Add('centerprint <timeout> <text>');
5860 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5862 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5864 // Дополнительное время:
5865 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5867 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5868 [gGameSettings
.TimeLimit
div 3600,
5869 (gGameSettings
.TimeLimit
div 60) mod 60,
5870 gGameSettings
.TimeLimit
mod 60]));
5871 if g_Game_IsNet
then MH_SEND_GameSettings
;
5873 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5875 if (Length(P
) <= 1) then
5876 g_Console_Add('rcon_password <password>')
5878 MC_SEND_RCONPassword(P
[1]);
5880 else if cmd
= 'rcon' then
5882 if g_Game_IsClient
then
5884 if Length(P
) > 1 then
5887 for a
:= 1 to High(P
) do
5888 chstr
:= chstr
+ P
[a
] + ' ';
5890 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5892 if Length(chstr
) < 1 then
5894 g_Console_Add('rcon <command>');
5898 MC_SEND_RCONCommand(chstr
);
5900 else g_Console_Add('rcon <command>');
5903 else if cmd
= 'ready' then
5905 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5906 gLMSRespawnTime
:= gTime
+ 100;
5908 else if (cmd
= 'callvote') and g_Game_IsNet
then
5910 if Length(P
) > 1 then
5913 for a
:= 1 to High(P
) do begin
5914 if a
> 1 then chstr
:= chstr
+ ' ';
5915 chstr
:= chstr
+ P
[a
];
5918 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5920 if Length(chstr
) < 1 then
5922 g_Console_Add('callvote <command>');
5926 if g_Game_IsClient
then
5927 MC_SEND_Vote(True, chstr
)
5929 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5930 g_Console_Process('vote', True);
5933 g_Console_Add('callvote <command>');
5935 else if (cmd
= 'vote') and g_Game_IsNet
then
5937 if g_Game_IsClient
then
5939 else if gVoteInProgress
then
5941 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5942 a
:= Floor((NetClientCount
+1)/2.0) + 1
5944 a
:= Floor(NetClientCount
/2.0) + 1;
5949 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5950 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5956 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5957 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5965 procedure SystemCommands(P
: SSArray
);
5969 cmd
:= LowerCase(P
[0]);
5978 gRC_Width
:= Max(1, gRC_Width
);
5979 gRC_Height
:= Max(1, gRC_Height
);
5980 gBPP
:= Max(1, gBPP
);
5981 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
5982 e_LogWriteln('resolution changed')
5984 e_LogWriteln('resolution not changed');
5985 sys_EnableVSync(gVSync
);
5989 if Length(p
) = 2 then
5991 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
5993 gFrameTime
:= 1000 div gMaxFPS
5997 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6001 if Length(p
) = 2 then
6003 gAskLanguage
:= true;
6004 gLanguage
:= LANGUAGE_ENGLISH
;
6005 case LowerCase(p
[1]) of
6008 gAskLanguage
:= false;
6009 gLanguage
:= LANGUAGE_ENGLISH
;
6013 gAskLanguage
:= false;
6014 gLanguage
:= LANGUAGE_RUSSIAN
;
6018 gAskLanguage
:= true;
6019 gLanguage
:= LANGUAGE_ENGLISH
;
6022 g_Language_Set(gLanguage
);
6026 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6032 procedure g_TakeScreenShot(Filename
: string = '');
6033 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
6035 if e_NoGraphics
then Exit
;
6037 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6039 if Filename
= '' then
6042 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6043 Filename
:= 'screenshot-' + date
;
6046 name
:= e_CatPath(dir
, Filename
+ '.png');
6047 s
:= createDiskFile(name
);
6049 e_MakeScreenshot(s
, gWinSizeX
, gWinSizeY
);
6051 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6053 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6058 g_Console_Add('oh shit, i can''t create screenshot!')
6062 procedure g_Game_InGameMenu(Show
: Boolean);
6064 if (g_ActiveWindow
= nil) and Show
then
6066 if gGameSettings
.GameType
= GT_SINGLE
then
6067 g_GUI_ShowWindow('GameSingleMenu')
6070 if g_Game_IsClient
then
6071 g_GUI_ShowWindow('GameClientMenu')
6073 if g_Game_IsNet
then
6074 g_GUI_ShowWindow('GameServerMenu')
6076 g_GUI_ShowWindow('GameCustomMenu');
6078 g_Sound_PlayEx('MENU_OPEN');
6080 // Пауза при меню только в одиночной игре:
6081 if (not g_Game_IsNet
) then
6085 if (g_ActiveWindow
<> nil) and (not Show
) then
6087 // Пауза при меню только в одиночной игре:
6088 if (not g_Game_IsNet
) then
6089 g_Game_Pause(False);
6093 procedure g_Game_Pause (Enable
: Boolean);
6097 if not gGameOn
then exit
;
6099 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6102 gPauseMain
:= Enable
;
6104 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6107 procedure g_Game_HolmesPause (Enable
: Boolean);
6111 if not gGameOn
then exit
;
6112 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6115 gPauseHolmes
:= Enable
;
6117 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6120 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6125 if gTriggers
<> nil then
6126 for i
:= 0 to High(gTriggers
) do
6127 with gTriggers
[i
] do
6128 if (TriggerType
= TRIGGER_SOUND
) and
6130 Sound
.IsPlaying() then
6132 Sound
.Pause(Enable
);
6136 if gPlayers
<> nil then
6137 for i
:= 0 to High(gPlayers
) do
6138 if gPlayers
[i
] <> nil then
6139 gPlayers
[i
].PauseSounds(Enable
);
6142 if gMusic
<> nil then
6143 gMusic
.Pause(Enable
);
6146 procedure g_Game_StopAllSounds(all
: Boolean);
6150 if gTriggers
<> nil then
6151 for i
:= 0 to High(gTriggers
) do
6152 with gTriggers
[i
] do
6153 if (TriggerType
= TRIGGER_SOUND
) and
6157 if gMusic
<> nil then
6164 procedure g_Game_UpdateTriggerSounds
;
6167 if gTriggers
<> nil then
6168 for i
:= 0 to High(gTriggers
) do
6169 with gTriggers
[i
] do
6170 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6171 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6174 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6177 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6182 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6187 if gSpectMode
<> SPECT_PLAYERS
then
6189 if gSpectPID1
= UID
then
6194 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6201 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6206 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6211 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6216 if gSpectMode
<> SPECT_PLAYERS
then
6218 Pl
:= g_Player_Get(gSpectPID1
);
6219 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6224 if gSpectViewTwo
then
6226 Pl
:= g_Player_Get(gSpectPID2
);
6227 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6235 procedure g_Game_Message(Msg
: string; Time
: Word);
6237 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
6238 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
6239 MessageTime
:= Time
;
6242 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6244 punct
: Array[0..13] of String =
6245 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6251 function IsPunctuation(S
: String): Boolean;
6256 if Length(S
) <> 1 then
6258 for i
:= Low(punct
) to High(punct
) do
6259 if S
= punct
[i
] then
6265 function FilterPunctuation(S
: String): String;
6269 for i
:= Low(punct
) to High(punct
) do
6270 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6276 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6278 // remove player name
6279 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6280 // for FullWord check
6281 Text := toLowerCase1251(' ' + Text + ' ');
6282 fpText
:= FilterPunctuation(Text);
6284 for i
:= 0 to Length(gChatSounds
) - 1 do
6287 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6289 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6290 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6292 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6298 gChatSounds
[i
].Sound
.Play();
6304 g_Sound_PlayEx('SOUND_GAME_RADIO');
6307 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6316 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6320 if goodsnd
[a
].IsPlaying() then
6323 goodsnd
[Random(4)].Play();
6326 procedure g_Game_Announce_KillCombo(Param
: Integer);
6333 UID
:= Param
and $FFFF;
6338 Pl
:= g_Player_Get(UID
);
6347 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6351 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6355 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6359 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6367 if not g_Game_IsWatchedPlayer(UID
) then
6370 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6374 if killsnd
[n
].IsPlaying() then
6379 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6387 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6391 if hahasnd
[a
].IsPlaying() then
6394 hahasnd
[Random(3)].Play();
6397 procedure g_Game_StartVote(Command
, Initiator
: string);
6401 if not gVotesEnabled
then Exit
;
6402 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6403 if gVoteInProgress
or gVotePassed
then
6405 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6406 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6409 gVoteInProgress
:= True;
6410 gVotePassed
:= False;
6411 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6414 gVoteCommand
:= Command
;
6416 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6417 Need
:= Floor((NetClientCount
+1)/2.0)+1
6419 Need
:= Floor(NetClientCount
/2.0)+1;
6420 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6421 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6424 procedure g_Game_CheckVote
;
6428 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6429 if not gVoteInProgress
then Exit
;
6431 if (gTime
>= gVoteTimer
) then
6433 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6434 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6436 Need
:= Floor(NetClientCount
/2.0) + 1;
6437 if gVoteCount
>= Need
then
6439 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6440 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6441 gVotePassed
:= True;
6442 gVoteCmdTimer
:= gTime
+ 5000;
6446 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6447 MH_SEND_VoteEvent(NET_VE_FAILED
);
6449 if NetClients
<> nil then
6450 for I
:= Low(NetClients
) to High(NetClients
) do
6451 if NetClients
[i
].Used
then
6452 NetClients
[i
].Voted
:= False;
6453 gVoteInProgress
:= False;
6459 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6460 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6462 Need
:= Floor(NetClientCount
/2.0) + 1;
6463 if gVoteCount
>= Need
then
6465 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6466 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6467 gVoteInProgress
:= False;
6468 gVotePassed
:= True;
6469 gVoteCmdTimer
:= gTime
+ 5000;
6472 if NetClients
<> nil then
6473 for I
:= Low(NetClients
) to High(NetClients
) do
6474 if NetClients
[i
].Used
then
6475 NetClients
[i
].Voted
:= False;
6480 procedure g_Game_LoadMapList(FileName
: string);
6488 if not FileExists(FileName
) then Exit
;
6490 AssignFile(ListFile
, FileName
);
6492 while not EOF(ListFile
) do
6494 ReadLn(ListFile
, s
);
6497 if s
= '' then Continue
;
6499 SetLength(MapList
, Length(MapList
)+1);
6500 MapList
[High(MapList
)] := s
;
6502 CloseFile(ListFile
);
6505 procedure g_Game_SetDebugMode();
6508 // Читы (даже в своей игре):
6512 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6516 if Length(LoadingStat
.Msgs
) = 0 then
6522 begin // Переходим на следующую строку или скроллируем:
6523 if NextMsg
= Length(Msgs
) then
6525 for i
:= 0 to High(Msgs
)-1 do
6526 Msgs
[i
] := Msgs
[i
+1];
6534 Msgs
[NextMsg
-1] := Text;
6538 PBarWasHere
:= false;
6541 g_ActiveWindow
:= nil;
6542 ProcessLoading(True);
6545 procedure g_Game_StepLoading(Value
: Integer = -1);
6557 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6560 ProcessLoading(False);
6565 procedure g_Game_ClearLoading();
6574 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6575 if len
< 1 then len
:= 1;
6576 SetLength(Msgs
, len
);
6577 for len
:= Low(Msgs
) to High(Msgs
) do
6580 PBarWasHere
:= false;
6584 procedure Parse_Params(var pars
: TParamStrValues
);
6591 while i
<= ParamCount
do
6594 if (Length(s
) > 1) and (s
[1] = '-') then
6596 if (Length(s
) > 2) and (s
[2] = '-') then
6597 begin // Одиночный параметр
6598 SetLength(pars
, Length(pars
) + 1);
6599 with pars
[High(pars
)] do
6601 Name
:= LowerCase(s
);
6606 if (i
< ParamCount
) then
6607 begin // Параметр со значением
6609 SetLength(pars
, Length(pars
) + 1);
6610 with pars
[High(pars
)] do
6612 Name
:= LowerCase(s
);
6613 Value
:= LowerCase(ParamStr(i
));
6622 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6627 for i
:= 0 to High(pars
) do
6628 if pars
[i
].Name
= aName
then
6630 Result
:= pars
[i
].Value
;
6635 procedure g_Game_Process_Params();
6637 pars
: TParamStrValues
;
6640 LimT
, LimS
: Integer;
6651 s
:= Find_Param_Value(pars
, '--debug');
6654 g_Game_SetDebugMode();
6655 s
:= Find_Param_Value(pars
, '--netdump');
6660 // Connect when game loads
6661 ip
:= Find_Param_Value(pars
, '-connect');
6665 s
:= Find_Param_Value(pars
, '-port');
6666 if (s
= '') or not TryStrToInt(s
, Port
) then
6669 s
:= Find_Param_Value(pars
, '-pw');
6671 g_Game_StartClient(ip
, Port
, s
);
6675 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6678 gDefaultMegawadStart
:= s
;
6681 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6682 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6684 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6687 // Start map when game loads:
6688 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6689 if isWadPath(map
) then
6692 s
:= Find_Param_Value(pars
, '-gm');
6693 GMode
:= g_Game_TextToMode(s
);
6694 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6695 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6698 s
:= Find_Param_Value(pars
, '-limt');
6699 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6705 s
:= Find_Param_Value(pars
, '-lims');
6706 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6712 s
:= Find_Param_Value(pars
, '-lives');
6713 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6719 s
:= Find_Param_Value(pars
, '-opt');
6723 Opt
:= StrToIntDef(s
, 0);
6726 s
:= Find_Param_Value(pars
, '--close');
6730 // Override map to test:
6731 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6734 if e_IsValidResourceName(s
) then
6735 e_FindResource(AllMapDirs
, s
);
6736 gTestMap
:= ExpandFileName(s
);
6739 // Delete test map after play:
6740 s
:= Find_Param_Value(pars
, '--testdelete');
6743 //gMapToDelete := MapsDir + map;
6744 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6748 // Delete temporary WAD after play:
6749 s
:= Find_Param_Value(pars
, '--tempdelete');
6750 if (s
<> '') and (gTestMap
<> '') then
6752 gMapToDelete
:= gTestMap
;
6753 gTempDelete
:= True;
6756 // Number of players:
6757 s
:= Find_Param_Value(pars
, '-pl');
6759 n
:= DEFAULT_PLAYERS
6761 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6764 s
:= Find_Param_Value(pars
, '-port');
6765 if (s
= '') or not TryStrToInt(s
, Port
) then
6766 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6768 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6771 // Execute script when game loads:
6772 s
:= Find_Param_Value(pars
, '-exec');
6775 // if not isWadPath(s) then
6776 // s := GameDir + '/' + s;
6781 if IOResult
<> 0 then
6783 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6784 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6788 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6789 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6794 if IOResult
<> 0 then
6796 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6797 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6801 if Pos('#', s
) <> 1 then // script comment
6802 g_Console_Process(s
, True);
6813 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6814 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6815 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6816 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6818 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6819 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6820 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6821 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6823 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6824 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6826 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6827 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6829 {$IFDEF ENABLE_HOLMES}
6830 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6833 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6835 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
6836 conRegVar('r_resolution_scale', @r_pixel_scale
, 0.01, 100.0, 'upscale factor', '', false);
6838 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6839 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6841 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6842 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6844 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6845 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6846 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6847 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
6848 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6849 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6850 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6851 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6852 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');