1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 g_base
, g_basic
, g_player
, r_graphics
, g_res_downloader
,
24 g_sound
, g_gui
, utils
, md5
, mempool
, xprofiler
,
28 TGameSettings
= record
35 ItemRespawnTime
: Word;
46 TDelayedEvent
= record
55 Sound
: TPlayableSound
;
56 Tags
: Array of String;
60 TPlayerSettings
= record
65 // ones below are sent only to the server
67 WeaponPreferences
: Array[WP_FIRST
..WP_LAST
+1] of Byte;
84 function g_Game_IsNet(): Boolean;
85 function g_Game_IsServer(): Boolean;
86 function g_Game_IsClient(): Boolean;
87 procedure g_Game_Init();
88 procedure g_Game_Free (freeTextures
: Boolean=true);
89 procedure g_Game_LoadData();
90 procedure g_Game_FreeData();
91 procedure g_Game_Update();
92 procedure g_Game_PreUpdate();
93 procedure g_Game_Quit();
94 procedure g_Game_SetupScreenSize();
95 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
96 function g_Game_ModeToText(Mode
: Byte): string;
97 function g_Game_TextToMode(Mode
: string): Byte;
98 procedure g_Game_ExecuteEvent(Name
: String);
99 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
100 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
101 procedure g_Game_RemovePlayer();
102 procedure g_Game_Spectate();
103 procedure g_Game_SpectateCenterView();
104 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
105 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
106 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
107 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
108 procedure g_Game_Restart();
109 procedure g_Game_RestartLevel();
110 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
111 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
112 function g_Game_StartMap(asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
113 procedure g_Game_ChangeMap(const MapPath
: String);
114 procedure g_Game_ExitLevel(const Map
: AnsiString);
115 function g_Game_GetFirstMap(WAD
: String): String;
116 function g_Game_GetNextMap(): String;
117 procedure g_Game_NextLevel();
118 procedure g_Game_Pause(Enable
: Boolean);
119 procedure g_Game_HolmesPause(Enable
: Boolean);
120 procedure g_Game_InGameMenu(Show
: Boolean);
121 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
122 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
123 procedure g_Game_Message(Msg
: String; Time
: Word);
124 procedure g_Game_LoadMapList(FileName
: String);
125 procedure g_Game_PauseAllSounds(Enable
: Boolean);
126 procedure g_Game_StopAllSounds(all
: Boolean);
127 procedure g_Game_UpdateTriggerSounds();
128 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
129 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
130 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
131 procedure g_Game_Announce_KillCombo(Param
: Integer);
132 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
133 procedure g_Game_StartVote(Command
, Initiator
: string);
134 procedure g_Game_CheckVote
;
135 procedure g_TakeScreenShot(Filename
: string = '');
136 procedure g_FatalError(Text: String);
137 procedure g_SimpleError(Text: String);
138 function g_Game_IsTestMap(): Boolean;
139 procedure g_Game_DeleteTestMap();
140 procedure GameCVars(P
: SSArray
);
141 procedure PlayerSettingsCVars(P
: SSArray
);
142 procedure SystemCommands(P
: SSArray
);
143 procedure GameCommands(P
: SSArray
);
144 procedure GameCheats(P
: SSArray
);
145 procedure DebugCommands(P
: SSArray
);
146 procedure g_Game_Process_Params
;
147 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
148 procedure g_Game_StepLoading(Value
: Integer = -1);
149 procedure g_Game_ClearLoading();
150 procedure g_Game_SetDebugMode();
152 function IsActivePlayer(p
: TPlayer
): Boolean;
153 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
154 procedure SortGameStat(var stat
: TPlayerStatArray
);
156 { procedure SetWinPause(Enable: Boolean); }
161 LOADING_SHOW_STEP
= 100;
162 LOADING_INTERLINE
= 20;
177 MESSAGE_DIKEY
= WM_USER
+ 1;
182 EXIT_ENDLEVELSINGLE
= 4;
183 EXIT_ENDLEVELCUSTOM
= 5;
185 GAME_OPTION_RESERVED
= 1;
186 GAME_OPTION_TEAMDAMAGE
= 2;
187 GAME_OPTION_ALLOWEXIT
= 4;
188 GAME_OPTION_WEAPONSTAY
= 8;
189 GAME_OPTION_MONSTERS
= 16;
190 GAME_OPTION_BOTVSPLAYER
= 32;
191 GAME_OPTION_BOTVSMONSTER
= 64;
192 GAME_OPTION_DMKEYS
= 128;
193 GAME_OPTION_TEAMHITTRACE
= 256;
194 GAME_OPTION_TEAMHITPROJECTILE
= 512;
195 GAME_OPTION_TEAMABSORBDAMAGE
= 1024;
196 GAME_OPTION_ALLOWDROPFLAG
= 2048;
197 GAME_OPTION_THROWFLAG
= 4096;
202 STATE_INTERCUSTOM
= 3;
203 STATE_INTERSINGLE
= 4;
209 LMS_RESPAWN_NONE
= 0;
210 LMS_RESPAWN_WARMUP
= 1;
211 LMS_RESPAWN_FINAL
= 2;
228 CONFIG_FILENAME
= 'Doom2DF.cfg';
230 TEST_MAP_NAME
= '$$$_TEST_$$$';
232 STD_PLAYER_MODEL
= 'Doomer';
240 STATFILE_VERSION
= $03;
244 gGameSettings
: TGameSettings
;
245 gPlayer1Settings
: TPlayerSettings
;
246 gPlayer2Settings
: TPlayerSettings
;
248 gPlayerScreenSize
: TDFPoint
;
249 gPlayer1ScreenCoord
: TDFPoint
;
250 gPlayer2ScreenCoord
: TDFPoint
;
251 gPlayer1
: TPlayer
= nil;
252 gPlayer2
: TPlayer
= nil;
253 gPlayerDrawn
: TPlayer
= nil;
255 gLerpFactor
: Single = 1.0;
256 gSwitchGameMode
: Byte = GM_DM
;
257 gHearPoint1
, gHearPoint2
: THearPoint
;
258 gSoundEffectsDF
: Boolean = False;
259 gSoundTriggerTime
: Word = 0;
260 gAnnouncer
: Integer = ANNOUNCE_NONE
;
261 goodsnd
: array[0..3] of TPlayableSound
;
262 killsnd
: array[0..3] of TPlayableSound
;
263 hahasnd
: array[0..2] of TPlayableSound
;
264 sound_get_flag
: array[0..1] of TPlayableSound
;
265 sound_lost_flag
: array[0..1] of TPlayableSound
;
266 sound_ret_flag
: array[0..1] of TPlayableSound
;
267 sound_cap_flag
: array[0..1] of TPlayableSound
;
268 gBodyKillEvent
: Integer = -1;
269 gDefInterTime
: ShortInt = -1;
270 gInterEndTime
: LongWord = 0;
271 gInterTime
: LongWord = 0;
272 gServInterTime
: Byte = 0;
273 gGameStartTime
: LongWord = 0;
274 gTotalMonsters
: Integer = 0;
275 gPauseMain
: Boolean = false;
276 gPauseHolmes
: Boolean = false;
277 gShowTime
: Boolean = False;
278 gShowFPS
: Boolean = False;
279 gShowScore
: Boolean = True;
280 gShowStat
: Boolean = True;
281 gShowPIDs
: Boolean = False;
282 gShowKillMsg
: Boolean = True;
283 gShowLives
: Boolean = True;
284 gShowPing
: Boolean = False;
285 gShowMap
: Boolean = False;
287 gState
: Byte = STATE_NONE
;
289 sWidth
, sHeight
: Word;
290 gSpectMode
: Byte = SPECT_NONE
;
291 gSpectHUD
: Boolean = True;
292 gSpectKeyPress
: Boolean = False;
293 gSpectX
: Integer = 0;
294 gSpectY
: Integer = 0;
295 gSpectStep
: Byte = 8;
296 gSpectViewTwo
: Boolean = False;
297 gSpectPID1
: Integer = -1;
298 gSpectPID2
: Integer = -1;
299 gSpectAuto
: Boolean = False;
300 gSpectAutoNext
: LongWord;
301 gSpectAutoStepX
: Integer;
302 gSpectAutoStepY
: Integer;
303 gMusic
: TMusic
= nil;
304 gLoadGameMode
: Boolean;
305 gCheats
: Boolean = False;
306 gMapOnce
: Boolean = False;
307 gMapToDelete
: String;
308 gTempDelete
: Boolean = False;
309 gLastMap
: Boolean = False;
312 gResolutionChange
: Boolean = False;
313 gRC_Width
, gRC_Height
: Integer;
314 gRC_FullScreen
, gRC_Maximized
: Boolean;
315 gLanguageChange
: Boolean = False;
316 gDebugMode
: Boolean = False;
317 g_debug_Sounds
: Boolean = False;
318 g_debug_Frames
: Boolean = False;
319 g_debug_WinMsgs
: Boolean = False;
320 g_debug_MonsterOff
: Boolean = False;
321 g_debug_BotAIOff
: Byte = 0;
322 g_debug_HealthBar
: Boolean = False;
323 g_Debug_Player
: Boolean = False;
324 gCoopMonstersKilled
: Word = 0;
325 gCoopSecretsFound
: Word = 0;
326 gCoopTotalMonstersKilled
: Word = 0;
327 gCoopTotalSecretsFound
: Word = 0;
328 gCoopTotalMonsters
: Word = 0;
329 gCoopTotalSecrets
: Word = 0;
330 gStatsOff
: Boolean = False;
331 gStatsPressed
: Boolean = False;
332 gExitByTrigger
: Boolean = False;
333 gNextMap
: String = '';
334 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
335 gLMSRespawnTime
: Cardinal = 0;
336 gLMSSoftSpawn
: Boolean = False;
337 gMissionFailed
: Boolean = False;
338 gVoteInProgress
: Boolean = False;
339 gVotePassed
: Boolean = False;
340 gVoteCommand
: string = '';
341 gVoteTimer
: Cardinal = 0;
342 gVoteCmdTimer
: Cardinal = 0;
343 gVoteCount
: Integer = 0;
344 gVoteTimeout
: Cardinal = 30;
345 gVoted
: Boolean = False;
346 gVotesEnabled
: Boolean = True;
347 gEvents
: Array of TGameEvent
;
348 gDelayedEvents
: Array of TDelayedEvent
;
349 gUseChatSounds
: Boolean = True;
350 gChatSounds
: Array of TChatSound
;
351 gWeaponAction
: Array [0..1, WP_FACT
..WP_LACT
] of Boolean; // [player, weapon_action]
352 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
353 gInterReadyCount
: Integer = 0;
354 gMaxBots
: Integer = 127;
356 g_dbg_ignore_bounds
: Boolean = false;
357 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
358 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
360 // move button values:
361 // bits 0-1: l/r state:
362 // 0: neither left, nor right pressed
365 // bits 4-5: l/r state when strafe was pressed
366 P1MoveButton
: Byte = 0;
367 P2MoveButton
: Byte = 0;
369 g_profile_frame_update
: Boolean = false;
370 g_profile_frame_draw
: Boolean = false;
371 g_profile_collision
: Boolean = false;
372 g_profile_los
: Boolean = false;
373 g_profile_history_size
: Integer = 1000;
375 g_rlayer_back
: Boolean = true;
376 g_rlayer_step
: Boolean = true;
377 g_rlayer_wall
: Boolean = true;
378 g_rlayer_door
: Boolean = true;
379 g_rlayer_acid1
: Boolean = true;
380 g_rlayer_acid2
: Boolean = true;
381 g_rlayer_water
: Boolean = true;
382 g_rlayer_fore
: Boolean = true;
385 procedure g_ResetDynlights ();
386 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
387 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
389 function conIsCheatsEnabled (): Boolean; inline;
390 function gPause (): Boolean; inline;
392 type (* private state *)
393 TEndCustomGameStat
= record
394 PlayerStat
: TPlayerStatArray
;
398 Map
, MapName
: String;
401 TEndSingleGameStat
= record
402 PlayerStat
: Array [0..1] of record
408 TotalSecrets
: Integer;
411 TLoadingStat
= record
415 Msgs
: Array of String;
417 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
421 x
, y
, radius
: Integer;
424 exploRadius
: Integer;
427 var (* private state *)
428 CustomStat
: TEndCustomGameStat
;
429 StatShotDone
: Boolean;
430 StatFilename
: string = ''; // used by stat screenshot to save with the same name as the csv
431 SingleStat
: TEndSingleGameStat
;
433 LoadingStat
: TLoadingStat
;
436 EndingGameCounter
: Byte;
438 g_playerLight
: Boolean;
439 g_dynLights
: array of TDynLight
= nil;
440 g_dynLightCount
: Integer = 0;
445 {$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
, r_playermodel
;
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 r_PlayerModel_Initialize
;
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 r_PlayerModel_Finalize
;
2333 g_PlayerModel_FreeData();
2334 g_Texture_DeleteAll();
2335 g_Frames_DeleteAll();
2337 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2340 if NetInitDone
then g_Net_Free
;
2342 // remove map after test
2343 if gMapToDelete
<> '' then
2344 g_Game_DeleteTestMap();
2350 procedure g_Game_FreeData();
2352 if not DataLoaded
then Exit
;
2355 g_Weapon_FreeData();
2356 g_Monsters_FreeData();
2358 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2360 g_Texture_Delete('NOTEXTURE');
2361 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2362 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2363 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2364 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2365 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2366 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2367 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2368 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2369 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2370 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2371 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2372 g_Frames_DeleteByName('FRAMES_TELEPORT');
2373 g_Frames_DeleteByName('FRAMES_PUNCH');
2374 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2375 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2376 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2377 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2378 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2379 g_Sound_Delete('SOUND_GAME_TELEPORT');
2380 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2381 g_Sound_Delete('SOUND_GAME_SECRET');
2382 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2383 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2384 g_Sound_Delete('SOUND_GAME_BULK1');
2385 g_Sound_Delete('SOUND_GAME_BULK2');
2386 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2387 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2388 g_Sound_Delete('SOUND_GAME_BURNING');
2389 g_Sound_Delete('SOUND_GAME_SWITCH1');
2390 g_Sound_Delete('SOUND_GAME_SWITCH0');
2397 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2398 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2399 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2400 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2407 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2408 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2409 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2410 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2416 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2417 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2418 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2420 sound_get_flag
[0].Free();
2421 sound_get_flag
[1].Free();
2422 sound_lost_flag
[0].Free();
2423 sound_lost_flag
[1].Free();
2424 sound_ret_flag
[0].Free();
2425 sound_ret_flag
[1].Free();
2426 sound_cap_flag
[0].Free();
2427 sound_cap_flag
[1].Free();
2429 g_Sound_Delete('SOUND_CTF_GET1');
2430 g_Sound_Delete('SOUND_CTF_GET2');
2431 g_Sound_Delete('SOUND_CTF_LOST1');
2432 g_Sound_Delete('SOUND_CTF_LOST2');
2433 g_Sound_Delete('SOUND_CTF_RETURN1');
2434 g_Sound_Delete('SOUND_CTF_RETURN2');
2435 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2436 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2438 g_Game_FreeChatSounds();
2440 DataLoaded
:= False;
2443 procedure g_FatalError(Text: String);
2445 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
2446 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
2448 gExit
:= EXIT_SIMPLE
;
2449 if gGameOn
then EndGame
;
2452 procedure g_SimpleError(Text: String);
2454 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
2455 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
2458 procedure g_Game_SetupScreenSize();
2460 RES_FACTOR
= 4.0 / 3.0;
2466 // Размер экранов игроков:
2467 gPlayerScreenSize
.X
:= gScreenWidth
-196;
2468 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2469 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
2471 gPlayerScreenSize
.Y
:= gScreenHeight
;
2473 // Размер заднего плана:
2474 if BackID
<> DWORD(-1) then
2477 if (gScreenWidth
*s
> gMapInfo
.Width
) or
2478 (gScreenHeight
*s
> gMapInfo
.Height
) then
2480 gBackSize
.X
:= gScreenWidth
;
2481 gBackSize
.Y
:= gScreenHeight
;
2485 e_GetTextureSize(BackID
, @bw
, @bh
);
2486 rf
:= Single(bw
) / Single(bh
);
2487 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
2488 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
2489 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
2490 if (s
< 1.0) then s
:= 1.0;
2491 gBackSize
.X
:= Round(bw
*s
);
2492 gBackSize
.Y
:= Round(bh
*s
);
2497 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
2499 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
, nowMax
);
2502 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
2504 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2505 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2508 if (gGameSettings
.MaxLives
> 0) and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2511 if gPlayer1
= nil then
2513 if g_Game_IsClient
then
2515 if NetPlrUID1
> -1 then
2516 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2520 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2521 Team
:= gPlayer1Settings
.Team
;
2523 // Создание первого игрока:
2524 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2525 gPlayer1Settings
.Color
,
2527 if gPlayer1
= nil then
2528 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
2531 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2532 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2533 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2534 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2535 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2536 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
2537 if g_Game_IsServer
and g_Game_IsNet
then
2538 MH_SEND_PlayerCreate(gPlayer1
.UID
);
2539 gPlayer1
.Respawn(False, True);
2540 g_Net_Slist_ServerPlayerComes();
2545 if gPlayer2
= nil then
2547 if g_Game_IsClient
then
2549 if NetPlrUID2
> -1 then
2550 gPlayer2
:= g_Player_Get(NetPlrUID2
);
2554 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
2555 Team
:= gPlayer2Settings
.Team
;
2557 // Создание второго игрока:
2558 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2559 gPlayer2Settings
.Color
,
2561 if gPlayer2
= nil then
2562 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
2565 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2566 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2567 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2568 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2569 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2570 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
2571 if g_Game_IsServer
and g_Game_IsNet
then
2572 MH_SEND_PlayerCreate(gPlayer2
.UID
);
2573 gPlayer2
.Respawn(False, True);
2574 g_Net_Slist_ServerPlayerComes();
2581 procedure g_Game_RemovePlayer();
2585 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
2586 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
2591 if g_Game_IsServer
then
2594 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2595 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2596 g_Player_Remove(Pl
.UID
);
2597 g_Net_Slist_ServerPlayerLeaves();
2601 gSpectLatchPID2
:= Pl
.UID
;
2609 if g_Game_IsServer
then
2612 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
2613 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
2614 g_Player_Remove(Pl
.UID
);
2615 g_Net_Slist_ServerPlayerLeaves();
2618 gSpectLatchPID1
:= Pl
.UID
;
2620 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
2624 g_Net_Slist_ServerPlayerLeaves();
2627 procedure g_Game_Spectate();
2629 g_Game_RemovePlayer();
2630 if gPlayer1
<> nil then
2631 g_Game_RemovePlayer();
2634 procedure g_Game_SpectateCenterView();
2636 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
2637 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
2640 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
2647 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
2649 g_Game_ClearLoading();
2652 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
2655 gGameSettings
.GameType
:= GT_SINGLE
;
2656 gGameSettings
.MaxLives
:= 0;
2657 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
2658 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
2659 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
2660 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITPROJECTILE
;
2661 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_TEAMHITTRACE
;
2662 gSwitchGameMode
:= GM_SINGLE
;
2664 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2665 gLMSRespawnTime
:= 0;
2666 gSpectLatchPID1
:= 0;
2667 gSpectLatchPID2
:= 0;
2669 g_Game_ExecuteEvent('ongamestart');
2671 // Установка размеров окон игроков:
2672 g_Game_SetupScreenSize();
2674 // Создание первого игрока:
2675 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2676 gPlayer1Settings
.Color
,
2677 gPlayer1Settings
.Team
, False));
2678 if gPlayer1
= nil then
2680 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2684 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2685 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2686 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2687 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2688 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2691 // Создание второго игрока, если есть:
2694 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2695 gPlayer2Settings
.Color
,
2696 gPlayer2Settings
.Team
, False));
2697 if gPlayer2
= nil then
2699 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2703 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2704 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2705 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2706 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2707 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2711 // Загрузка и запуск карты:
2712 if not g_Game_StartMap(false{asMegawad}, MAP
, True) then
2714 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
2715 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
2719 // Настройки игроков и ботов:
2723 for i
:= nPl
+1 to nPlayers
do
2724 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2727 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
2728 TimeLimit
, ScoreLimit
: Word;
2730 Options
: LongWord; nPlayers
: Byte);
2736 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
2738 g_Game_ClearLoading();
2741 gGameSettings
.GameType
:= GT_CUSTOM
;
2742 gGameSettings
.GameMode
:= GameMode
;
2743 gSwitchGameMode
:= GameMode
;
2744 gGameSettings
.TimeLimit
:= TimeLimit
;
2745 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2746 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2747 gGameSettings
.Options
:= Options
;
2749 gCoopTotalMonstersKilled
:= 0;
2750 gCoopTotalSecretsFound
:= 0;
2751 gCoopTotalMonsters
:= 0;
2752 gCoopTotalSecrets
:= 0;
2756 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2757 gLMSRespawnTime
:= 0;
2758 gSpectLatchPID1
:= 0;
2759 gSpectLatchPID2
:= 0;
2761 g_Game_ExecuteEvent('ongamestart');
2763 // Установка размеров окон игроков:
2764 g_Game_SetupScreenSize();
2766 // Режим наблюдателя:
2767 if nPlayers
= 0 then
2774 if nPlayers
>= 1 then
2776 // Создание первого игрока:
2777 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2778 gPlayer1Settings
.Color
,
2779 gPlayer1Settings
.Team
, False));
2780 if gPlayer1
= nil then
2782 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2786 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2787 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2788 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2789 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2790 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2794 if nPlayers
>= 2 then
2796 // Создание второго игрока:
2797 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2798 gPlayer2Settings
.Color
,
2799 gPlayer2Settings
.Team
, False));
2800 if gPlayer2
= nil then
2802 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2806 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2807 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2808 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2809 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2810 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2814 // Загрузка и запуск карты:
2815 if not g_Game_StartMap(true{asMegawad}, Map
, True) then
2817 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2821 // Нет точек появления:
2822 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2823 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2824 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2825 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2826 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2828 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2832 // Настройки игроков и ботов:
2836 for i
:= nPl
+1 to nPlayers
do
2837 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
2840 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
2841 TimeLimit
, ScoreLimit
: Word; MaxLives
: Byte;
2842 Options
: LongWord; nPlayers
: Byte;
2843 IPAddr
: LongWord; Port
: Word);
2846 g_Net_Slist_ServerClosed();
2848 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
2850 g_Game_ClearLoading();
2855 gGameSettings
.GameType
:= GT_SERVER
;
2856 gGameSettings
.GameMode
:= GameMode
;
2857 gSwitchGameMode
:= GameMode
;
2858 gGameSettings
.TimeLimit
:= TimeLimit
;
2859 gGameSettings
.ScoreLimit
:= ScoreLimit
;
2860 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
2861 gGameSettings
.Options
:= Options
;
2863 gCoopTotalMonstersKilled
:= 0;
2864 gCoopTotalSecretsFound
:= 0;
2865 gCoopTotalMonsters
:= 0;
2866 gCoopTotalSecrets
:= 0;
2870 gLMSRespawn
:= LMS_RESPAWN_NONE
;
2871 gLMSRespawnTime
:= 0;
2872 gSpectLatchPID1
:= 0;
2873 gSpectLatchPID2
:= 0;
2875 g_Game_ExecuteEvent('ongamestart');
2877 // Установка размеров окна игрока
2878 g_Game_SetupScreenSize();
2880 // Режим наблюдателя:
2881 if nPlayers
= 0 then
2887 if nPlayers
>= 1 then
2889 // Создание первого игрока:
2890 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
2891 gPlayer1Settings
.Color
,
2892 gPlayer1Settings
.Team
, False));
2893 if gPlayer1
= nil then
2895 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
2899 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
2900 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
2901 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
2902 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
2903 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
2906 if nPlayers
>= 2 then
2908 // Создание второго игрока:
2909 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
2910 gPlayer2Settings
.Color
,
2911 gPlayer2Settings
.Team
, False));
2912 if gPlayer2
= nil then
2914 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
2918 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
2919 gPlayer2
.WeapSwitchMode
:= gPlayer2Settings
.WeaponSwitch
;
2920 gPlayer2
.setWeaponPrefs(gPlayer2Settings
.WeaponPreferences
);
2921 gPlayer2
.SwitchToEmpty
:= gPlayer2Settings
.SwitchToEmpty
;
2922 gPlayer2
.SkipFist
:= gPlayer2Settings
.SkipFist
;
2925 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
2926 if NetForwardPorts
then
2927 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
2930 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
2932 g_FatalError(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_ERR_HOST
], [Port
]));
2936 g_Net_Slist_Set(NetMasterList
);
2938 g_Net_Slist_ServerStarted();
2940 // Загрузка и запуск карты:
2941 if not g_Game_StartMap(false{asMegawad}, Map
, True) then
2943 g_Net_Slist_ServerClosed();
2944 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
2948 // Нет точек появления:
2949 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
2950 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
2951 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
2952 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
2953 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
2955 g_Net_Slist_ServerClosed();
2956 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
2960 // Настройки игроков и ботов:
2963 g_Net_Slist_ServerMapStarted();
2964 NetState
:= NET_STATE_GAME
;
2967 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
2982 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
2983 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
2985 g_Game_ClearLoading();
2990 gGameSettings
.GameType
:= GT_CLIENT
;
2992 gCoopTotalMonstersKilled
:= 0;
2993 gCoopTotalSecretsFound
:= 0;
2994 gCoopTotalMonsters
:= 0;
2995 gCoopTotalSecrets
:= 0;
2999 g_Game_ExecuteEvent('ongamestart');
3001 // Установка размеров окон игроков:
3002 g_Game_SetupScreenSize();
3004 NetState
:= NET_STATE_AUTH
;
3006 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3008 // create (or update) map/resource databases
3009 g_Res_CreateDatabases(true);
3011 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3012 gLMSRespawnTime
:= 0;
3013 gSpectLatchPID1
:= 0;
3014 gSpectLatchPID2
:= 0;
3017 if not g_Net_Connect(Addr
, Port
) then
3019 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3020 NetState
:= NET_STATE_NONE
;
3024 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3026 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3031 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3032 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3033 // thank you, enet. let's ignore failures altogether then.
3034 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
3036 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3038 Ptr
:= NetEvent
.packet
^.data
;
3039 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3041 enet_packet_destroy(NetEvent
.packet
);
3045 InMsg
.ReadLongWord(); // skip size
3046 MID
:= InMsg
.ReadByte();
3048 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3050 NetMyID
:= InMsg
.ReadByte();
3051 NetPlrUID1
:= InMsg
.ReadWord();
3053 WadName
:= InMsg
.ReadString();
3054 Map
:= InMsg
.ReadString();
3056 gWADHash
:= InMsg
.ReadMD5();
3058 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3059 gSwitchGameMode
:= gGameSettings
.GameMode
;
3060 gGameSettings
.ScoreLimit
:= InMsg
.ReadWord();
3061 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3062 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3063 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3064 T
:= InMsg
.ReadLongWord();
3066 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3067 //if newResPath = '' then
3069 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3070 newResPath
:= g_Res_DownloadMapWAD(ExtractFileName(WadName
), gWADHash
);
3071 if newResPath
= '' then
3073 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3074 enet_packet_destroy(NetEvent
.packet
);
3075 NetState
:= NET_STATE_NONE
;
3078 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
3080 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3083 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3084 gPlayer1Settings
.Color
,
3085 gPlayer1Settings
.Team
, False));
3087 if gPlayer1
= nil then
3089 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3091 enet_packet_destroy(NetEvent
.packet
);
3092 NetState
:= NET_STATE_NONE
;
3096 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3097 gPlayer1
.WeapSwitchMode
:= gPlayer1Settings
.WeaponSwitch
;
3098 gPlayer1
.setWeaponPrefs(gPlayer1Settings
.WeaponPreferences
);
3099 gPlayer1
.SwitchToEmpty
:= gPlayer1Settings
.SwitchToEmpty
;
3100 gPlayer1
.SkipFist
:= gPlayer1Settings
.SkipFist
;
3101 gPlayer1
.UID
:= NetPlrUID1
;
3102 gPlayer1
.Reset(True);
3104 if not g_Game_StartMap(false{asMegawad}, newResPath
+ ':\' + Map
, True) then
3106 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3108 enet_packet_destroy(NetEvent
.packet
);
3109 NetState
:= NET_STATE_NONE
;
3117 enet_packet_destroy(NetEvent
.packet
);
3121 enet_packet_destroy(NetEvent
.packet
);
3125 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3128 if (NetEvent
.data
<= NET_DISC_MAX
) then
3129 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3130 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3137 ProcessLoading(True);
3138 if g_Net_UserRequestExit() then
3147 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3148 NetState
:= NET_STATE_NONE
;
3153 NetState
:= NET_STATE_GAME
;
3154 MC_SEND_FullStateRequest
;
3155 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
3159 lastAsMegaWad
: Boolean = false;
3161 procedure g_Game_ChangeMap(const MapPath
: String);
3165 g_Game_ClearLoading();
3167 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3168 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3169 if gExitByTrigger
then
3172 gExitByTrigger
:= False;
3174 if not g_Game_StartMap(lastAsMegaWad
, MapPath
, Force
) then
3175 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3178 procedure g_Game_Restart();
3182 if g_Game_IsClient
then
3184 map
:= g_ExtractFileName(gMapInfo
.Map
);
3185 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
3189 g_Game_ClearLoading();
3190 g_Game_StartMap(lastAsMegaWad
, Map
, True, gCurrentMapFileName
);
3193 function g_Game_StartMap (asMegawad
: Boolean; Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
3195 NewWAD
, ResName
: String;
3199 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
3200 g_Player_RemoveAllCorpses();
3202 if (not g_Game_IsClient
) and
3203 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3204 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3206 if gSwitchGameMode
= GM_CTF
then
3207 gGameSettings
.MaxLives
:= 0;
3208 gGameSettings
.GameMode
:= gSwitchGameMode
;
3211 gSwitchGameMode
:= gGameSettings
.GameMode
;
3213 g_Player_ResetTeams();
3215 lastAsMegaWad
:= asMegawad
;
3216 if isWadPath(Map
) then
3218 NewWAD
:= g_ExtractWadName(Map
);
3219 ResName
:= g_ExtractFileName(Map
);
3220 if g_Game_IsServer
then
3222 nws
:= findDiskWad(NewWAD
);
3223 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3226 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3227 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3231 if (length(nws
) = 0) then nws
:= e_FindWad(MapDirs
, NewWAD
);
3232 if (length(nws
) = 0) then nws
:= e_FindWad(MegawadDirs
, NewWAD
);
3234 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3235 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3237 if (length(nws
) = 0) then
3239 ResName
:= ''; // failed
3244 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
3245 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3246 g_Game_LoadWAD(NewWAD
);
3251 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3252 NewWAD
:= g_Game_ClientWAD(NewWAD
, gWADHash
);
3257 NewWAD
:= gGameSettings
.WAD
;
3263 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3265 if (ResName
<> '') and (NewWAD
<> '') then
3267 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3268 result
:= g_Map_Load(NewWAD
+':\'+ResName
);
3272 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3274 gState
:= STATE_NONE
;
3275 g_ActiveWindow
:= nil;
3281 if gGameSettings
.GameMode
= GM_CTF
then
3283 g_Map_ResetFlag(FLAG_RED
);
3284 g_Map_ResetFlag(FLAG_BLUE
);
3285 // CTF, а флагов нет:
3286 if not g_Map_HaveFlagPoints() then
3287 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3292 gState
:= STATE_MENU
;
3297 gPauseMain
:= false;
3298 gPauseHolmes
:= false;
3299 NetTimeToUpdate
:= 1;
3300 NetTimeToReliable
:= 0;
3301 NetTimeToMaster
:= NetMasterRate
;
3302 gSpectLatchPID1
:= 0;
3303 gSpectLatchPID2
:= 0;
3304 gMissionFailed
:= False;
3307 gCoopMonstersKilled
:= 0;
3308 gCoopSecretsFound
:= 0;
3310 gVoteInProgress
:= False;
3311 gVotePassed
:= False;
3317 if not gGameOn
then Exit
;
3319 g_Game_SpectateCenterView();
3321 if g_Game_IsServer
then
3323 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
3325 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3326 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3327 gLMSSoftSpawn
:= True;
3328 if g_Game_IsNet
then
3329 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3333 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3334 gLMSRespawnTime
:= 0;
3338 if NetMode
= NET_SERVER
then
3340 // reset full state flags
3341 if NetClients
<> nil then
3342 for I
:= 0 to High(NetClients
) do
3343 NetClients
[I
].FullUpdateSent
:= False;
3345 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
3348 g_Net_Slist_ServerMapStarted();
3350 if NetClients
<> nil then
3351 for I
:= 0 to High(NetClients
) do
3352 if NetClients
[I
].Used
then
3354 NetClients
[I
].Voted
:= False;
3355 if NetClients
[I
].RequestedFullUpdate
then
3357 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
3358 NetClients
[I
].RequestedFullUpdate
:= False;
3362 g_Net_UnbanNonPermHosts();
3367 gCoopTotalMonstersKilled
:= 0;
3368 gCoopTotalSecretsFound
:= 0;
3369 gCoopTotalMonsters
:= 0;
3370 gCoopTotalSecrets
:= 0;
3374 g_Game_ExecuteEvent('onmapstart');
3377 procedure SetFirstLevel
;
3381 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3382 if MapList
= nil then
3385 SortSArray(MapList
);
3386 gNextMap
:= MapList
[Low(MapList
)];
3391 procedure g_Game_ExitLevel(const Map
: AnsiString);
3395 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
3396 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
3397 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
3398 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
3400 // Вышли в выход в Одиночной игре:
3401 if gGameSettings
.GameType
= GT_SINGLE
then
3402 gExit
:= EXIT_ENDLEVELSINGLE
3403 else // Вышли в выход в Своей игре
3405 gExit
:= EXIT_ENDLEVELCUSTOM
;
3406 if gGameSettings
.GameMode
= GM_COOP
then
3407 g_Player_RememberAll
;
3409 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3412 if gGameSettings
.GameMode
= GM_COOP
then
3415 gStatsPressed
:= True;
3416 gNextMap
:= 'MAP01';
3418 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
3421 if g_Game_IsNet
then
3423 MH_SEND_GameStats();
3424 MH_SEND_CoopStats();
3430 procedure g_Game_RestartLevel();
3434 if gGameSettings
.GameMode
= GM_SINGLE
then
3439 gExit
:= EXIT_ENDLEVELCUSTOM
;
3440 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3444 function g_Game_ClientWAD (NewWAD
: String; const WHash
: TMD5Digest
): AnsiString;
3446 gWAD
{, xwad}: String;
3449 if not g_Game_IsClient
then Exit
;
3450 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3452 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
3457 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
3461 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD
, NewWAD
], TMsgType
.Notify
);
3464 g_Game_LoadWAD(NewWAD
);
3468 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3469 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3472 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3473 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3477 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3481 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3482 g_Game_LoadWAD(NewWAD);
3486 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
3488 i
, n
, nb
, nr
: Integer;
3490 if not g_Game_IsServer
then Exit
;
3491 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
3492 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3493 gLMSRespawnTime
:= 0;
3496 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
3498 gMissionFailed
:= True;
3499 g_Game_RestartLevel
;
3503 n
:= 0; nb
:= 0; nr
:= 0;
3504 for i
:= Low(gPlayers
) to High(gPlayers
) do
3505 if (gPlayers
[i
] <> nil) and
3506 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
3507 (gPlayers
[i
] is TBot
)) then
3510 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
3511 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
3514 if (n
< 1) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
3516 // wait a second until the fuckers finally decide to join
3517 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
3518 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
3519 gLMSSoftSpawn
:= NoMapRestart
;
3520 if g_Game_IsNet
then
3521 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3525 g_Player_RemoveAllCorpses
;
3526 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
3527 if g_Game_IsNet
then
3528 MH_SEND_GameEvent(NET_EV_LMS_START
);
3530 for i
:= Low(gPlayers
) to High(gPlayers
) do
3532 if gPlayers
[i
] = nil then continue
;
3533 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
3534 // don't touch normal spectators
3535 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
3537 gPlayers
[i
].FNoRespawn
:= True;
3538 gPlayers
[i
].Lives
:= 0;
3539 if g_Game_IsNet
then
3540 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
3543 gPlayers
[i
].FNoRespawn
:= False;
3544 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
3545 gPlayers
[i
].Respawn(False, True);
3546 if gGameSettings
.GameMode
= GM_COOP
then
3548 gPlayers
[i
].Frags
:= 0;
3549 gPlayers
[i
].RecallState
;
3551 if (gPlayer1
= nil) and (gSpectLatchPID1
> 0) then
3552 gPlayer1
:= g_Player_Get(gSpectLatchPID1
);
3553 if (gPlayer2
= nil) and (gSpectLatchPID2
> 0) then
3554 gPlayer2
:= g_Player_Get(gSpectLatchPID2
);
3557 g_Items_RestartRound();
3559 gLMSSoftSpawn
:= False;
3562 function g_Game_GetFirstMap(WAD
: String): String;
3566 MapList
:= g_Map_GetMapsList(WAD
);
3567 if MapList
= nil then
3570 SortSArray(MapList
);
3571 Result
:= MapList
[Low(MapList
)];
3573 if not g_Map_Exist(WAD
+ ':\' + Result
) then
3579 function g_Game_GetNextMap(): String;
3586 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
3587 if MapList
= nil then
3590 Map
:= g_ExtractFileName(gMapInfo
.Map
);
3592 SortSArray(MapList
);
3594 for I
:= Low(MapList
) to High(MapList
) do
3595 if Map
= MapList
[I
] then
3601 if MapIndex
<> -255 then
3603 if MapIndex
= High(MapList
) then
3604 Result
:= MapList
[Low(MapList
)]
3606 Result
:= MapList
[MapIndex
+ 1];
3608 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
3614 procedure g_Game_NextLevel();
3616 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
3617 gExit
:= EXIT_ENDLEVELCUSTOM
3620 gExit
:= EXIT_ENDLEVELSINGLE
;
3624 if gNextMap
<> '' then Exit
;
3625 gNextMap
:= g_Game_GetNextMap();
3628 function g_Game_IsTestMap(): Boolean;
3630 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
3633 procedure g_Game_DeleteTestMap();
3636 //MapName: AnsiString;
3644 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
3645 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
3646 if (a
= 0) then exit
;
3648 // Выделяем имя wad-файла и имя карты
3649 WadName
:= Copy(gMapToDelete
, 1, a
+3);
3650 Delete(gMapToDelete
, 1, a
+5);
3651 gMapToDelete
:= UpperCase(gMapToDelete
);
3653 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3656 // Имя карты не стандартное тестовое:
3657 if MapName <> TEST_MAP_NAME then
3660 if not gTempDelete then
3662 time := g_GetFileTime(WadName);
3663 WAD := TWADFile.Create();
3666 if not WAD.ReadFile(WadName) then
3667 begin // Нет такого WAD-файла
3672 // Составляем список карт и ищем нужную:
3674 MapList := WAD.GetResourcesList('');
3676 if MapList <> nil then
3677 for a := 0 to High(MapList) do
3678 if MapList[a] = MapName then
3680 // Удаляем и сохраняем:
3681 WAD.RemoveResource('', MapName);
3682 WAD.SaveTo(WadName);
3687 g_SetFileTime(WadName, time);
3690 if gTempDelete
then DeleteFile(WadName
);
3693 procedure GameCVars(P
: SSArray
);
3696 stat
: TPlayerStatArray
;
3699 procedure ParseGameFlag(Flag
: LongWord; OffMsg
, OnMsg
: TStrings_Locale
; OnMapChange
: Boolean = False);
3703 if Length(P
) > 1 then
3708 gsGameFlags
:= gsGameFlags
or Flag
3710 gsGameFlags
:= gsGameFlags
and (not Flag
);
3712 if g_Game_IsServer
then
3715 gGameSettings
.Options
:= gGameSettings
.Options
or Flag
3717 gGameSettings
.Options
:= gGameSettings
.Options
and (not Flag
);
3718 if g_Game_IsNet
then MH_SEND_GameSettings
;
3722 if LongBool(gsGameFlags
and Flag
) then
3723 g_Console_Add(_lc
[OnMsg
])
3725 g_Console_Add(_lc
[OffMsg
]);
3727 if OnMapChange
and g_Game_IsServer
then
3728 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3733 cmd
:= LowerCase(P
[0]);
3735 if cmd
= 'g_gamemode' then
3737 if (Length(P
) > 1) then
3739 a
:= g_Game_TextToMode(P
[1]);
3740 if a
= GM_SINGLE
then a
:= GM_COOP
;
3741 gsGameMode
:= g_Game_ModeToText(a
);
3742 if g_Game_IsServer
then
3744 gSwitchGameMode
:= a
;
3745 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
3746 (gState
= STATE_INTERSINGLE
) then
3747 gSwitchGameMode
:= GM_SINGLE
;
3749 gGameSettings
.GameMode
:= gSwitchGameMode
;
3753 if gSwitchGameMode
= gGameSettings
.GameMode
then
3754 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
3755 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
3757 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
3758 [g_Game_ModeToText(gGameSettings
.GameMode
),
3759 g_Game_ModeToText(gSwitchGameMode
)]));
3761 else if cmd
= 'g_friendlyfire' then
3763 ParseGameFlag(GAME_OPTION_TEAMDAMAGE
, I_MSG_FRIENDLY_FIRE_OFF
, I_MSG_FRIENDLY_FIRE_ON
);
3765 else if cmd
= 'g_friendly_absorb_damage' then
3767 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE
, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF
, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON
);
3769 else if cmd
= 'g_friendly_hit_trace' then
3771 ParseGameFlag(GAME_OPTION_TEAMHITTRACE
, I_MSG_FRIENDLY_HIT_TRACE_OFF
, I_MSG_FRIENDLY_HIT_TRACE_ON
);
3773 else if cmd
= 'g_friendly_hit_projectile' then
3775 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE
, I_MSG_FRIENDLY_PROJECT_TRACE_OFF
, I_MSG_FRIENDLY_PROJECT_TRACE_ON
);
3777 else if cmd
= 'g_weaponstay' then
3779 ParseGameFlag(GAME_OPTION_WEAPONSTAY
, I_MSG_WEAPONSTAY_OFF
, I_MSG_WEAPONSTAY_ON
);
3781 else if cmd
= 'g_allow_exit' then
3783 ParseGameFlag(GAME_OPTION_ALLOWEXIT
, I_MSG_ALLOWEXIT_OFF
, I_MSG_ALLOWEXIT_ON
, True);
3785 else if cmd
= 'g_allow_monsters' then
3787 ParseGameFlag(GAME_OPTION_MONSTERS
, I_MSG_ALLOWMON_OFF
, I_MSG_ALLOWMON_ON
, True);
3789 else if cmd
= 'g_allow_dropflag' then
3791 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG
, I_MSG_ALLOWDROPFLAG_OFF
, I_MSG_ALLOWDROPFLAG_ON
);
3793 else if cmd
= 'g_throw_flag' then
3795 ParseGameFlag(GAME_OPTION_THROWFLAG
, I_MSG_THROWFLAG_OFF
, I_MSG_THROWFLAG_ON
);
3797 else if cmd
= 'g_bot_vsplayers' then
3799 ParseGameFlag(GAME_OPTION_BOTVSPLAYER
, I_MSG_BOTSVSPLAYERS_OFF
, I_MSG_BOTSVSPLAYERS_ON
);
3801 else if cmd
= 'g_bot_vsmonsters' then
3803 ParseGameFlag(GAME_OPTION_BOTVSMONSTER
, I_MSG_BOTSVSMONSTERS_OFF
, I_MSG_BOTSVSMONSTERS_ON
);
3805 else if cmd
= 'g_dm_keys' then
3807 ParseGameFlag(GAME_OPTION_DMKEYS
, I_MSG_DMKEYS_OFF
, I_MSG_DMKEYS_ON
, True);
3809 else if cmd
= 'g_gameflags' then
3811 if Length(P
) > 1 then
3813 gsGameFlags
:= StrToDWordDef(P
[1], gsGameFlags
);
3814 if g_Game_IsServer
then
3816 gGameSettings
.Options
:= gsGameFlags
;
3817 if g_Game_IsNet
then MH_SEND_GameSettings
;
3821 g_Console_Add(Format('%s %u', [cmd
, gsGameFlags
]));
3823 else if cmd
= 'g_warmup_time' then
3825 if Length(P
) > 1 then
3827 gsWarmupTime
:= nclamp(StrToIntDef(P
[1], gsWarmupTime
), 0, $FFFF);
3828 if g_Game_IsServer
then
3830 gGameSettings
.WarmupTime
:= gsWarmupTime
;
3831 // extend warmup if it's already going
3832 if gLMSRespawn
= LMS_RESPAWN_WARMUP
then
3834 gLMSRespawnTime
:= gTime
+ gsWarmupTime
* 1000;
3835 if g_Game_IsNet
then MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
);
3837 if g_Game_IsNet
then MH_SEND_GameSettings
;
3841 g_Console_Add(Format(_lc
[I_MSG_WARMUP
], [Integer(gsWarmupTime
)]));
3842 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3844 else if cmd
= 'g_spawn_invul' then
3846 if Length(P
) > 1 then
3848 gsSpawnInvul
:= nclamp(StrToIntDef(P
[1], gsSpawnInvul
), 0, $FFFF);
3849 if g_Game_IsServer
then
3851 gGameSettings
.SpawnInvul
:= gsSpawnInvul
;
3852 if g_Game_IsNet
then MH_SEND_GameSettings
;
3856 g_Console_Add(Format('%s %d', [cmd
, Integer(gsSpawnInvul
)]));
3858 else if cmd
= 'g_item_respawn_time' then
3860 if Length(P
) > 1 then
3862 gsItemRespawnTime
:= nclamp(StrToIntDef(P
[1], gsItemRespawnTime
), 0, $FFFF);
3863 if g_Game_IsServer
then
3865 gGameSettings
.ItemRespawnTime
:= gsItemRespawnTime
;
3866 if g_Game_IsNet
then MH_SEND_GameSettings
;
3870 g_Console_Add(Format('%s %d', [cmd
, Integer(gsItemRespawnTime
)]));
3871 if g_Game_IsServer
then g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
3873 else if cmd
= 'sv_intertime' then
3875 if (Length(P
) > 1) then
3876 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
3878 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
3880 else if cmd
= 'g_max_particles' then
3882 if Length(p
) = 2 then
3884 a
:= Max(0, StrToIntDef(p
[1], 0));
3887 else if Length(p
) = 1 then
3889 e_LogWritefln('%s', [g_GFX_GetMax()])
3893 e_LogWritefln('usage: %s <n>', [cmd
])
3896 else if cmd
= 'g_max_shells' then
3898 if Length(p
) = 2 then
3900 a
:= Max(0, StrToIntDef(p
[1], 0));
3903 else if Length(p
) = 1 then
3905 e_LogWritefln('%s', [g_Shells_GetMax()])
3909 e_LogWritefln('usage: %s <n>', [cmd
])
3912 else if cmd
= 'g_max_gibs' then
3914 if Length(p
) = 2 then
3916 a
:= Max(0, StrToIntDef(p
[1], 0));
3919 else if Length(p
) = 1 then
3921 e_LogWritefln('%s', [g_Gibs_GetMax()])
3925 e_LogWritefln('usage: %s <n>', [cmd
])
3928 else if cmd
= 'g_max_corpses' then
3930 if Length(p
) = 2 then
3932 a
:= Max(0, StrToIntDef(p
[1], 0));
3935 else if Length(p
) = 1 then
3937 e_LogWritefln('%s', [g_Corpses_GetMax()])
3941 e_LogWritefln('usage: %s <n>', [cmd
])
3944 else if cmd
= 'g_force_model' then
3946 if Length(p
) = 2 then
3948 a
:= StrToIntDef(p
[1], 0);
3949 g_Force_Model_Set(a
);
3950 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
3952 for a
:= Low(gPlayers
) to High(gPlayers
) do
3954 if (gPlayers
[a
] <> nil) then
3956 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
3958 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
3960 gPlayers
[a
].setModel(g_Forced_Model_GetName());
3964 else if (g_Force_Model_Get() = 0) and (gPlayers
<> nil) then
3966 for a
:= Low(gPlayers
) to High(gPlayers
) do
3968 if (gPlayers
[a
] <> nil) then
3970 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
3972 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
3974 gPlayers
[a
].setModel(gPlayers
[a
].FActualModelName
);
3980 else if cmd
= 'g_force_model_name' then
3982 if (Length(P
) > 1) then
3984 cmd
:= b_Text_Unformat(P
[1]);
3985 g_Forced_Model_SetName(cmd
);
3986 if (g_Force_Model_Get() <> 0) and (gPlayers
<> nil) then
3988 for a
:= Low(gPlayers
) to High(gPlayers
) do
3990 if (gPlayers
[a
] <> nil) then
3992 if (gPlayers
[a
].UID
= gPlayer1
.UID
) then
3994 else if (gPlayer2
<> nil) and (gPlayers
[a
].UID
= gPlayer2
.UID
) then
3996 gPlayers
[a
].setModel(g_Forced_Model_GetName());
4002 else if cmd
= 'g_scorelimit' then
4004 if Length(P
) > 1 then
4006 gsScoreLimit
:= nclamp(StrToIntDef(P
[1], gsScoreLimit
), 0, $FFFF);
4008 if g_Game_IsServer
then
4011 if gGameSettings
.GameMode
= GM_DM
then
4013 stat
:= g_Player_GetStats();
4015 for a
:= 0 to High(stat
) do
4016 if stat
[a
].Frags
> b
then
4020 b
:= Max(gTeamStat
[TEAM_RED
].Score
, gTeamStat
[TEAM_BLUE
].Score
);
4022 // if someone has a higher score, set it to that instead
4023 gsScoreLimit
:= max(gsScoreLimit
, b
);
4024 gGameSettings
.ScoreLimit
:= gsScoreLimit
;
4026 if g_Game_IsNet
then MH_SEND_GameSettings
;
4030 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [Integer(gsScoreLimit
)]));
4032 else if cmd
= 'g_timelimit' then
4034 if Length(P
) > 1 then
4036 gsTimeLimit
:= nclamp(StrToIntDef(P
[1], gsTimeLimit
), 0, $FFFF);
4037 if g_Game_IsServer
then
4039 gGameSettings
.TimeLimit
:= gsTimeLimit
;
4040 if g_Game_IsNet
then MH_SEND_GameSettings
;
4043 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4044 [gsTimeLimit
div 3600,
4045 (gsTimeLimit
div 60) mod 60,
4046 gsTimeLimit
mod 60]));
4048 else if cmd
= 'g_max_bots' then
4050 if Length(P
) > 1 then
4051 gMaxBots
:= nclamp(StrToIntDef(P
[1], gMaxBots
), 0, 127);
4052 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots
));
4054 else if cmd
= 'g_maxlives' then
4056 if Length(P
) > 1 then
4058 gsMaxLives
:= nclamp(StrToIntDef(P
[1], gsMaxLives
), 0, $FFFF);
4059 if g_Game_IsServer
then
4061 gGameSettings
.MaxLives
:= gsMaxLives
;
4062 if g_Game_IsNet
then MH_SEND_GameSettings
;
4066 g_Console_Add(Format(_lc
[I_MSG_LIVES
], [Integer(gsMaxLives
)]));
4070 procedure PlayerSettingsCVars(P
: SSArray
);
4075 function ParseTeam(s
: string): Byte;
4079 'red', '1': result
:= TEAM_RED
;
4080 'blue', '2': result
:= TEAM_BLUE
;
4081 else result
:= TEAM_NONE
;
4085 cmd
:= LowerCase(P
[0]);
4089 if (Length(P
) > 1) then
4091 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4092 if g_Game_IsClient
then
4093 MC_SEND_PlayerSettings
4094 else if gGameOn
and (gPlayer1
<> nil) then
4096 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4097 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4103 if (Length(P
) > 1) then
4105 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4106 if g_Game_IsClient
then
4107 MC_SEND_PlayerSettings
4108 else if gGameOn
and (gPlayer2
<> nil) then
4110 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4111 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4117 if Length(P
) > 3 then
4119 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4120 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4121 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4122 if g_Game_IsClient
then
4123 MC_SEND_PlayerSettings
4124 else if gGameOn
and (gPlayer1
<> nil) then
4126 gPlayer1
.SetColor(gPlayer1Settings
.Color
);
4127 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4133 if Length(P
) > 3 then
4135 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4136 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4137 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4138 if g_Game_IsClient
then
4139 MC_SEND_PlayerSettings
4140 else if gGameOn
and (gPlayer2
<> nil) then
4142 gPlayer2
.SetColor(gPlayer2Settings
.Color
);
4143 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4149 if (Length(P
) > 1) then
4151 gPlayer1Settings
.Model
:= P
[1];
4152 if g_Game_IsClient
then
4153 MC_SEND_PlayerSettings
4154 else if gGameOn
and (gPlayer1
<> nil) then
4156 gPlayer1
.FActualModelName
:= gPlayer1Settings
.Model
;
4157 gPlayer1
.SetModel(gPlayer1Settings
.Model
);
4158 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4164 if (Length(P
) > 1) then
4166 gPlayer2Settings
.Model
:= P
[1];
4167 if g_Game_IsClient
then
4168 MC_SEND_PlayerSettings
4169 else if gGameOn
and (gPlayer2
<> nil) then
4171 gPlayer2
.FActualModelName
:= gPlayer2Settings
.Model
;
4172 gPlayer2
.SetModel(gPlayer2Settings
.Model
);
4173 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4179 // TODO: switch teams if in game or store this separately
4180 if (Length(P
) > 1) then
4182 team
:= ParseTeam(P
[1]);
4183 if team
= TEAM_NONE
then
4184 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4185 else if not gGameOn
and not g_Game_IsNet
then
4186 gPlayer1Settings
.Team
:= team
4188 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4193 // TODO: switch teams if in game or store this separately
4194 if (Length(P
) > 1) then
4196 team
:= ParseTeam(P
[1]);
4197 if team
= TEAM_NONE
then
4198 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4199 else if not gGameOn
and not g_Game_IsNet
then
4200 gPlayer2Settings
.Team
:= team
4202 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4207 if (Length(P
) = 2) then
4208 gPlayer1Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4212 if (Length(P
) = 2) then
4213 gPlayer2Settings
.WeaponSwitch
:= EnsureRange(StrTointDef(P
[1], 0), 0, 2);
4217 if (Length(P
) = 2) then
4218 gPlayer1Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4222 if (Length(P
) = 2) then
4223 gPlayer2Settings
.SwitchToEmpty
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4227 if (Length(P
) = 2) then
4228 gPlayer1Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4232 if (Length(P
) = 2) then
4233 gPlayer2Settings
.SkipFist
:= EnsureRange(StrTointDef(P
[1], 0), 0, 1);
4235 'p1_priority_kastet':
4237 if (Length(P
) = 2) then
4238 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4240 'p2_priority_kastet':
4242 if (Length(P
) = 2) then
4243 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4247 if (Length(P
) = 2) then
4248 gPlayer1Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4252 if (Length(P
) = 2) then
4253 gPlayer2Settings
.WeaponPreferences
[WEAPON_SAW
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4255 'p1_priority_pistol':
4257 if (Length(P
) = 2) then
4258 gPlayer1Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4260 'p2_priority_pistol':
4262 if (Length(P
) = 2) then
4263 gPlayer2Settings
.WeaponPreferences
[WEAPON_KASTET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4265 'p1_priority_shotgun1':
4267 if (Length(P
) = 2) then
4268 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4270 'p2_priority_shotgun1':
4272 if (Length(P
) = 2) then
4273 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN1
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4275 'p1_priority_shotgun2':
4277 if (Length(P
) = 2) then
4278 gPlayer1Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4280 'p2_priority_shotgun2':
4282 if (Length(P
) = 2) then
4283 gPlayer2Settings
.WeaponPreferences
[WEAPON_SHOTGUN2
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4285 'p1_priority_chaingun':
4287 if (Length(P
) = 2) then
4288 gPlayer1Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4290 'p2_priority_chaingun':
4292 if (Length(P
) = 2) then
4293 gPlayer2Settings
.WeaponPreferences
[WEAPON_CHAINGUN
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4295 'p1_priority_rocketlauncher':
4297 if (Length(P
) = 2) then
4298 gPlayer1Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4300 'p2_priority_rocketlauncher':
4302 if (Length(P
) = 2) then
4303 gPlayer2Settings
.WeaponPreferences
[WEAPON_ROCKETLAUNCHER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4305 'p1_priority_plasma':
4307 if (Length(P
) = 2) then
4308 gPlayer1Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4310 'p2_priority_plasma':
4312 if (Length(P
) = 2) then
4313 gPlayer2Settings
.WeaponPreferences
[WEAPON_PLASMA
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4317 if (Length(P
) = 2) then
4318 gPlayer1Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4322 if (Length(P
) = 2) then
4323 gPlayer2Settings
.WeaponPreferences
[WEAPON_BFG
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4325 'p1_priority_super':
4327 if (Length(P
) = 2) then
4328 gPlayer1Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4330 'p2_priority_super':
4332 if (Length(P
) = 2) then
4333 gPlayer2Settings
.WeaponPreferences
[WEAPON_SUPERPULEMET
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4335 'p1_priority_flamethrower':
4337 if (Length(P
) = 2) then
4338 gPlayer1Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4340 'p2_priority_flamethrower':
4342 if (Length(P
) = 2) then
4343 gPlayer2Settings
.WeaponPreferences
[WEAPON_FLAMETHROWER
] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4345 'p1_priority_berserk':
4347 if (Length(P
) = 2) then
4348 gPlayer1Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4350 'p2_priority_berserk':
4352 if (Length(P
) = 2) then
4353 gPlayer2Settings
.WeaponPreferences
[WP_LAST
+1] := EnsureRange(StrToIntDef(P
[1], WP_FIRST
), WP_FIRST
, WP_LAST
+1);
4358 procedure PrintHeapStats();
4362 hs
:= GetFPCHeapStatus();
4363 e_LogWriteLn ('v===== heap status =====v');
4364 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
4365 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
4366 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
4367 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
4368 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
4369 e_LogWriteLn ('^=======================^');
4372 procedure DebugCommands(P
: SSArray
);
4379 // Команды отладочного режима:
4380 if {gDebugMode}conIsCheatsEnabled
then
4382 cmd
:= LowerCase(P
[0]);
4383 if cmd
= 'd_window' then
4385 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4386 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
4388 else if cmd
= 'd_sounds' then
4390 if (Length(P
) > 1) and
4391 ((P
[1] = '1') or (P
[1] = '0')) then
4392 g_Debug_Sounds
:= (P
[1][1] = '1');
4394 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
4396 else if cmd
= 'd_frames' then
4398 if (Length(P
) > 1) and
4399 ((P
[1] = '1') or (P
[1] = '0')) then
4400 g_Debug_Frames
:= (P
[1][1] = '1');
4402 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
4404 else if cmd
= 'd_winmsg' then
4406 if (Length(P
) > 1) and
4407 ((P
[1] = '1') or (P
[1] = '0')) then
4408 g_Debug_WinMsgs
:= (P
[1][1] = '1');
4410 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
4412 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
4414 if (Length(P
) > 1) and
4415 ((P
[1] = '1') or (P
[1] = '0')) then
4416 g_Debug_MonsterOff
:= (P
[1][1] = '1');
4418 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
4420 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
4422 if Length(P
) > 1 then
4424 '0': g_debug_BotAIOff
:= 0;
4425 '1': g_debug_BotAIOff
:= 1;
4426 '2': g_debug_BotAIOff
:= 2;
4427 '3': g_debug_BotAIOff
:= 3;
4430 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
4432 else if cmd
= 'd_monster' then
4434 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
4435 if Length(P
) < 2 then
4437 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
4438 g_Console_Add('ID | Name');
4439 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
4440 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
4441 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4444 a
:= StrToIntDef(P
[1], 0);
4445 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4446 a
:= g_Mons_TypeIdByName(P
[1]);
4448 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
4449 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
4452 with gPlayer1
.Obj
do
4454 mon
:= g_Monsters_Create(a
,
4455 X
+ Rect
.X
+ (Rect
.Width
div 2),
4456 Y
+ Rect
.Y
+ Rect
.Height
,
4457 gPlayer1
.Direction
, True);
4459 if (Length(P
) > 2) and (mon
<> nil) then
4461 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
4462 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
4463 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
4464 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
4465 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
4466 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4467 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4468 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
4469 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
4474 else if (cmd
= 'd_health') then
4476 if (Length(P
) > 1) and
4477 ((P
[1] = '1') or (P
[1] = '0')) then
4478 g_debug_HealthBar
:= (P
[1][1] = '1');
4480 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
4482 else if (cmd
= 'd_player') then
4484 if (Length(P
) > 1) and
4485 ((P
[1] = '1') or (P
[1] = '0')) then
4486 g_debug_Player
:= (P
[1][1] = '1');
4488 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
4490 else if (cmd
= 'd_mem') then
4496 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
4500 procedure GameCheats(P
: SSArray
);
4506 if (not gGameOn
) or (not conIsCheatsEnabled
) then
4508 g_Console_Add('not available');
4514 g_Console_Add('where is the player?!');
4517 cmd
:= LowerCase(P
[0]);
4521 plr
.GodMode
:= not plr
.GodMode
;
4522 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4525 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4526 if cmd
= 'give' then
4528 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
4529 for f
:= 1 to High(P
) do
4531 cmd
:= LowerCase(P
[f
]);
4532 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
4533 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
4534 if cmd
= 'exit' then
4536 if gTriggers
<> nil then
4538 for a
:= 0 to High(gTriggers
) do
4540 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
4542 g_Console_Add('player left the map');
4543 gExitByTrigger
:= True;
4544 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4545 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
4553 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
4554 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
4555 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
4556 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
4557 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
4559 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
4560 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
4562 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
4563 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;
4565 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
4566 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
4568 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
4569 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
4571 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
4572 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
4574 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
4575 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
4576 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
4578 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
4579 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
4580 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
4581 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;
4582 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
4583 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
4585 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;
4586 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;
4587 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;
4588 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;
4589 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;
4590 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;
4592 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
4593 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;
4595 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;
4596 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;
4598 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
4600 if cmd
= 'ammo' then
4602 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
4603 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
4604 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
4605 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
4606 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
4607 g_Console_Add('player got some ammo');
4611 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
4612 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
4614 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
4615 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
4617 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
4618 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
4620 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
4621 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
4623 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
4625 if cmd
= 'weapons' then
4627 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
4628 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
4629 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
4630 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
4631 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
4632 plr
.GiveItem(ITEM_WEAPON_BFG
);
4633 g_Console_Add('player got weapons');
4637 if cmd
= 'keys' then
4639 plr
.GiveItem(ITEM_KEY_RED
);
4640 plr
.GiveItem(ITEM_KEY_GREEN
);
4641 plr
.GiveItem(ITEM_KEY_BLUE
);
4642 g_Console_Add('player got all keys');
4646 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
4651 if cmd
= 'open' then
4653 g_Console_Add('player activated sesame');
4654 g_Triggers_OpenAll();
4661 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4665 if cmd
= 'noclip' then
4668 g_Console_Add('wall hardeness adjusted');
4672 if cmd
= 'notarget' then
4674 plr
.NoTarget
:= not plr
.NoTarget
;
4675 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4679 if cmd
= 'noreload' then
4681 plr
.NoReload
:= not plr
.NoReload
;
4682 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4686 if cmd
= 'speedy' then
4688 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
4689 g_Console_Add('speed adjusted');
4693 if cmd
= 'jumpy' then
4695 VEL_JUMP
:= 30-VEL_JUMP
;
4696 g_Console_Add('jump height adjusted');
4700 if cmd
= 'automap' then
4702 gShowMap
:= not gShowMap
;
4703 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4707 if cmd
= 'aimline' then
4709 gAimLine
:= not gAimLine
;
4710 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4715 procedure GameCommands(P
: SSArray
);
4721 pl
: pTNetClient
= nil;
4729 cmd
:= LowerCase(P
[0]);
4731 if cmd
= 'pause' then
4733 if (g_ActiveWindow
= nil) then
4734 g_Game_Pause(not gPauseMain
);
4736 else if cmd
= 'endgame' then
4737 gExit
:= EXIT_SIMPLE
4738 else if cmd
= 'restart' then
4740 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
4742 if g_Game_IsClient
then
4744 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4749 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
4751 else if cmd
= 'kick' then
4753 if g_Game_IsServer
then
4755 if Length(P
) < 2 then
4757 g_Console_Add('kick <name>');
4762 g_Console_Add('kick <name>');
4766 if g_Game_IsNet
then
4767 pl
:= g_Net_Client_ByName(P
[1]);
4770 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4771 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4772 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4773 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4774 g_Net_Slist_ServerPlayerLeaves();
4775 end else if gPlayers
<> nil then
4776 for a
:= Low(gPlayers
) to High(gPlayers
) do
4777 if gPlayers
[a
] <> nil then
4778 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
4780 // Не отключать основных игроков в сингле
4781 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
4783 gPlayers
[a
].Lives
:= 0;
4784 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4785 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
4786 g_Player_Remove(gPlayers
[a
].UID
);
4787 g_Net_Slist_ServerPlayerLeaves();
4788 // Если не перемешать, при добавлении новых ботов появятся старые
4792 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
4794 else if cmd
= 'kick_id' then
4796 if g_Game_IsServer
and g_Game_IsNet
then
4798 if Length(P
) < 2 then
4800 g_Console_Add('kick_id <client ID>');
4805 g_Console_Add('kick_id <client ID>');
4809 a
:= StrToIntDef(P
[1], 0);
4810 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4812 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4814 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4815 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_KICK
);
4816 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4817 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4818 g_Net_Slist_ServerPlayerLeaves();
4822 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4824 else if cmd
= 'kick_pid' then
4826 if g_Game_IsServer
and g_Game_IsNet
then
4828 if Length(P
) < 2 then
4830 g_Console_Add('kick_pid <player ID>');
4835 g_Console_Add('kick_pid <player ID>');
4839 a
:= StrToIntDef(P
[1], 0);
4840 pl
:= g_Net_Client_ByPlayer(a
);
4841 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4843 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4844 g_Net_Host_Kick(pl
^.ID
, NET_DISC_KICK
);
4845 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4846 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4847 g_Net_Slist_ServerPlayerLeaves();
4850 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4852 else if cmd
= 'ban' then
4854 if g_Game_IsServer
and g_Game_IsNet
then
4856 if Length(P
) < 2 then
4858 g_Console_Add('ban <name>');
4863 g_Console_Add('ban <name>');
4867 pl
:= g_Net_Client_ByName(P
[1]);
4870 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4871 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4872 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
4873 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4874 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4875 g_Net_Slist_ServerPlayerLeaves();
4877 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4879 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4881 else if cmd
= 'ban_id' then
4883 if g_Game_IsServer
and g_Game_IsNet
then
4885 if Length(P
) < 2 then
4887 g_Console_Add('ban_id <client ID>');
4892 g_Console_Add('ban_id <client ID>');
4896 a
:= StrToIntDef(P
[1], 0);
4897 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4898 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4900 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4901 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
4902 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_TEMPBAN
);
4903 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4904 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4905 g_Net_Slist_ServerPlayerLeaves();
4908 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4910 else if cmd
= 'ban_pid' then
4912 if g_Game_IsServer
and g_Game_IsNet
then
4914 if Length(P
) < 2 then
4916 g_Console_Add('ban_pid <player ID>');
4921 g_Console_Add('ban_pid <player ID>');
4925 a
:= StrToIntDef(P
[1], 0);
4926 pl
:= g_Net_Client_ByPlayer(a
);
4927 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
4929 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4930 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
4931 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
4932 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4933 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4934 g_Net_Slist_ServerPlayerLeaves();
4937 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4939 else if cmd
= 'permban' then
4941 if g_Game_IsServer
and g_Game_IsNet
then
4943 if Length(P
) < 2 then
4945 g_Console_Add('permban <name>');
4950 g_Console_Add('permban <name>');
4954 pl
:= g_Net_Client_ByName(P
[1]);
4957 s
:= g_Net_ClientName_ByID(pl
^.ID
);
4958 g_Net_BanHost(pl
^.Peer
^.address
.host
);
4959 g_Net_Host_Kick(pl
^.ID
, NET_DISC_BAN
);
4960 g_Net_SaveBanList();
4961 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4962 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4963 g_Net_Slist_ServerPlayerLeaves();
4965 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
4967 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4969 else if cmd
= 'permban_id' then
4971 if g_Game_IsServer
and g_Game_IsNet
then
4973 if Length(P
) < 2 then
4975 g_Console_Add('permban_id <client ID>');
4980 g_Console_Add('permban_id <client ID>');
4984 a
:= StrToIntDef(P
[1], 0);
4985 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
4986 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
4988 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
4989 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
4990 g_Net_Host_Kick(NetClients
[a
].ID
, NET_DISC_BAN
);
4991 g_Net_SaveBanList();
4992 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
4993 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
4994 g_Net_Slist_ServerPlayerLeaves();
4997 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
4999 else if cmd
= 'permban_pid' then
5001 if g_Game_IsServer
and g_Game_IsNet
then
5003 if Length(P
) < 2 then
5005 g_Console_Add('permban_pid <player ID>');
5010 g_Console_Add('permban_pid <player ID>');
5014 a
:= StrToIntDef(P
[1], 0);
5015 pl
:= g_Net_Client_ByPlayer(a
);
5016 if (pl
<> nil) and pl
^.Used
and (pl
^.Peer
<> nil) then
5018 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5019 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5020 g_Net_Host_Kick(pl
^.ID
, NET_DISC_TEMPBAN
);
5021 g_Net_SaveBanList();
5022 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5023 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5024 g_Net_Slist_ServerPlayerLeaves();
5027 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5029 else if cmd
= 'permban_ip' then
5031 if g_Game_IsServer
and g_Game_IsNet
then
5033 if Length(P
) < 2 then
5035 g_Console_Add('permban_ip <IP address>');
5040 g_Console_Add('permban_ip <IP address>');
5044 g_Net_BanHost(P
[1]);
5045 g_Net_SaveBanList();
5046 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [P
[1]]));
5048 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5050 else if cmd
= 'unban' then
5052 if g_Game_IsServer
and g_Game_IsNet
then
5054 if Length(P
) < 2 then
5056 g_Console_Add('unban <IP Address>');
5061 g_Console_Add('unban <IP Address>');
5065 if g_Net_UnbanHost(P
[1]) then
5067 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5068 g_Net_SaveBanList();
5070 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5072 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5074 else if cmd
= 'clientlist' then
5076 if g_Game_IsServer
and g_Game_IsNet
then
5079 if NetClients
<> nil then
5080 for a
:= Low(NetClients
) to High(NetClients
) do
5081 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5083 plr
:= g_Player_Get(NetClients
[a
].Player
);
5084 if plr
= nil then continue
;
5086 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5087 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5090 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5092 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5094 else if cmd
= 'connect' then
5096 if (NetMode
= NET_NONE
) then
5098 if Length(P
) < 2 then
5100 g_Console_Add('connect <IP> [port] [password]');
5105 g_Console_Add('connect <IP> [port] [password]');
5109 if Length(P
) > 2 then
5110 prt
:= StrToIntDef(P
[2], 25666)
5114 if Length(P
) > 3 then
5119 g_Game_StartClient(P
[1], prt
, pw
);
5122 else if cmd
= 'disconnect' then
5124 if (NetMode
= NET_CLIENT
) then
5127 else if cmd
= 'reconnect' then
5129 if (NetMode
= NET_SERVER
) then
5132 if (NetMode
= NET_CLIENT
) then
5135 gExit
:= EXIT_SIMPLE
;
5139 //TODO: Use last successful password to reconnect, instead of ''
5140 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5142 else if (cmd
= 'addbot') or
5143 (cmd
= 'bot_add') then
5145 if Length(P
) > 2 then
5146 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
5147 else if Length(P
) > 1 then
5148 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5150 g_Bot_Add(TEAM_NONE
, 2);
5152 else if cmd
= 'bot_addlist' then
5154 if Length(P
) > 1 then
5156 if Length(P
) = 2 then
5157 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5158 else if Length(P
) = 3 then
5159 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
5161 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5164 else if cmd
= 'bot_removeall' then
5166 else if cmd
= 'chat' then
5168 if g_Game_IsNet
then
5170 if Length(P
) > 1 then
5172 for a
:= 1 to High(P
) do
5173 chstr
:= chstr
+ P
[a
] + ' ';
5175 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5177 if Length(chstr
) < 1 then
5179 g_Console_Add('chat <text>');
5183 chstr
:= b_Text_Format(chstr
);
5184 if g_Game_IsClient
then
5185 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5187 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5190 g_Console_Add('chat <text>');
5192 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5194 else if cmd
= 'teamchat' then
5196 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5198 if Length(P
) > 1 then
5200 for a
:= 1 to High(P
) do
5201 chstr
:= chstr
+ P
[a
] + ' ';
5203 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5205 if Length(chstr
) < 1 then
5207 g_Console_Add('teamchat <text>');
5211 chstr
:= b_Text_Format(chstr
);
5212 if g_Game_IsClient
then
5213 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5215 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5216 gPlayer1Settings
.Team
);
5219 g_Console_Add('teamchat <text>');
5221 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5223 else if (cmd
= 'an') or (cmd
= 'announce') then
5225 if g_Game_IsNet
then
5227 if Length(P
) > 1 then
5229 for a
:= 1 to High(P
) do
5230 chstr
:= chstr
+ P
[a
] + ' ';
5232 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5234 if Length(chstr
) < 1 then
5236 g_Console_Add('announce <text>');
5240 chstr
:= 'centerprint 100 ' + b_Text_Format(chstr
);
5241 if g_Game_IsClient
then
5242 MC_SEND_RCONCommand(chstr
)
5244 g_Console_Process(chstr
, True);
5247 g_Console_Add('announce <text>');
5249 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5251 else if cmd
= 'game' then
5253 if gGameSettings
.GameType
<> GT_NONE
then
5255 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5258 if Length(P
) = 1 then
5260 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5263 // game not started yet, load fist map from some wad
5265 s
:= addWadExtension(P
[1]);
5266 found
:= e_FindResource(AllMapDirs
, s
);
5270 P
[1] := ExpandFileName(P
[1]);
5271 // if map not choosed then set first map
5272 if Length(P
) < 3 then
5275 P
[2] := g_Game_GetFirstMap(P
[1]);
5278 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5280 if g_Map_Exist(s
) then
5284 with gGameSettings
do
5286 Options
:= gsGameFlags
;
5287 GameMode
:= g_Game_TextToMode(gsGameMode
);
5288 if gSwitchGameMode
<> GM_NONE
then
5289 GameMode
:= gSwitchGameMode
;
5290 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5291 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5293 if Length(P
) >= 4 then
5294 b
:= StrToIntDef(P
[3], 1);
5295 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5296 ScoreLimit
, MaxLives
, Options
, b
);
5301 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5303 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
5305 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5307 else if cmd
= 'host' then
5309 if gGameSettings
.GameType
<> GT_NONE
then
5311 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5314 if Length(P
) < 4 then
5316 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5319 if not StrToIp(P
[1], listen
) then
5321 prt
:= StrToIntDef(P
[2], 25666);
5323 s
:= addWadExtension(P
[3]);
5324 found
:= e_FindResource(AllMapDirs
, s
);
5328 // get first map in wad, if not specified
5329 if Length(P
) < 5 then
5332 P
[4] := g_Game_GetFirstMap(P
[1]);
5334 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5335 if g_Map_Exist(s
) then
5339 with gGameSettings
do
5341 Options
:= gsGameFlags
;
5342 GameMode
:= g_Game_TextToMode(gsGameMode
);
5343 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
5344 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5345 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5347 if Length(P
) >= 6 then
5348 b
:= StrToIntDef(P
[5], 0);
5349 g_Game_StartServer(s
, GameMode
, TimeLimit
, ScoreLimit
, MaxLives
, Options
, b
, listen
, prt
)
5355 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5357 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
5362 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
5365 else if cmd
= 'map' then
5367 if Length(P
) = 1 then
5369 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5371 g_Console_Add(cmd
+ ' <MAP>');
5372 g_Console_Add(cmd
+ ' <WAD> [MAP]')
5376 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5381 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5383 if Length(P
) < 3 then
5385 // first param is map or wad
5386 s
:= UpperCase(P
[1]);
5387 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5389 gExitByTrigger
:= False;
5392 // already in game, finish current map
5394 gExit
:= EXIT_ENDLEVELCUSTOM
;
5398 // intermission, so change map immediately
5405 found
:= e_FindResource(AllMapDirs
, s
);
5407 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
5410 // no such map, found wad
5413 P
[1] := ExpandFileName(pw
);
5414 P
[2] := g_Game_GetFirstMap(P
[1]);
5415 s
:= P
[1] + ':\' + P
[2];
5416 if g_Map_Exist(s
) then
5418 gExitByTrigger
:= False;
5421 // already in game, finish current map
5423 gExit
:= EXIT_ENDLEVELCUSTOM
5427 // intermission, so change map immediately
5434 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5436 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5441 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5447 s
:= addWadExtension(P
[1]);
5448 found
:= e_FindResource(AllMapDirs
, s
);
5452 P
[2] := UpperCase(P
[2]);
5453 s
:= P
[1] + ':\' + P
[2];
5454 if g_Map_Exist(s
) then
5456 gExitByTrigger
:= False;
5460 gExit
:= EXIT_ENDLEVELCUSTOM
5469 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5474 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5480 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5484 else if cmd
= 'nextmap' then
5486 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5488 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5493 if Length(P
) = 1 then
5495 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5497 g_Console_Add(cmd
+ ' <MAP>');
5498 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5503 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5509 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5511 if Length(P
) < 3 then
5513 // first param is map or wad
5514 s
:= UpperCase(P
[1]);
5515 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
5518 gExitByTrigger
:= False;
5524 // no such map, found wad
5525 pw
:= addWadExtension(P
[1]);
5526 found
:= e_FindResource(MapDirs
, pw
);
5528 found
:= e_FindResource(WadDirs
, pw
);
5530 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
5533 // map not specified, select first map
5535 P
[2] := g_Game_GetFirstMap(P
[1]);
5536 s
:= P
[1] + ':\' + P
[2];
5537 if g_Map_Exist(s
) then
5539 gExitByTrigger
:= False;
5546 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5548 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5553 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5559 // specified two params wad + map
5560 pw
:= addWadExtension(P
[1]);
5561 found
:= e_FindResource(MapDirs
, pw
);
5563 found
:= e_FindResource(MapDirs
, pw
);
5567 P
[2] := UpperCase(P
[2]);
5568 s
:= P
[1] + ':\' + P
[2];
5569 if g_Map_Exist(s
) then
5571 gExitByTrigger
:= False;
5577 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
5582 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
5588 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5593 if gNextMap
= '' then
5594 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
5596 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
5600 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
5604 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5608 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5610 gExitByTrigger
:= False;
5611 // next map not specified, try to find trigger EXIT
5612 if (gNextMap
= '') and (gTriggers
<> nil) then
5614 for a
:= 0 to High(gTriggers
) do
5616 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5618 gExitByTrigger
:= True;
5619 //gNextMap := gTriggers[a].Data.MapName;
5620 gNextMap
:= gTriggers
[a
].tgcMap
;
5625 if gNextMap
= '' then
5626 gNextMap
:= g_Game_GetNextMap();
5627 if not isWadPath(gNextMap
) then
5628 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
5631 if g_Map_Exist(s
) then
5632 gExit
:= EXIT_ENDLEVELCUSTOM
5634 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
5638 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
5642 else if (cmd
= 'event') then
5644 if (Length(P
) <= 1) then
5646 for a
:= 0 to High(gEvents
) do
5647 if gEvents
[a
].Command
= '' then
5648 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5650 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5653 if (Length(P
) = 2) then
5655 for a
:= 0 to High(gEvents
) do
5656 if gEvents
[a
].Name
= P
[1] then
5657 if gEvents
[a
].Command
= '' then
5658 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
5660 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
5663 for a
:= 0 to High(gEvents
) do
5664 if gEvents
[a
].Name
= P
[1] then
5666 gEvents
[a
].Command
:= '';
5667 for b
:= 2 to High(P
) do
5668 if Pos(' ', P
[b
]) = 0 then
5669 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
5671 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
5672 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
5676 else if cmd
= 'suicide' then
5680 if g_Game_IsClient
then
5681 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
5684 if gPlayer1
<> nil then
5685 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
5686 if gPlayer2
<> nil then
5687 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
5691 else if cmd
= 'screenshot' then
5695 else if (cmd
= 'weapnext') or (cmd
= 'weapprev') then
5697 a
:= 1 - (ord(cmd
[5]) - ord('n'));
5699 gWeaponAction
[0, WP_PREV
] := True;
5701 gWeaponAction
[0, WP_NEXT
] := True;
5703 else if cmd
= 'weapon' then
5705 if Length(p
) = 2 then
5707 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5708 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5709 gSelectWeapon
[0, a
] := True
5712 else if (cmd
= 'p1_weapnext') or (cmd
= 'p1_weapprev')
5713 or (cmd
= 'p2_weapnext') or (cmd
= 'p2_weapprev') then
5715 a
:= 1 - (ord(cmd
[8]) - ord('n'));
5716 b
:= ord(cmd
[2]) - ord('1');
5718 gWeaponAction
[b
, WP_PREV
] := True;
5720 gWeaponAction
[b
, WP_NEXT
] := True;
5722 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
5724 if Length(p
) = 2 then
5726 a
:= WP_FIRST
+ StrToIntDef(p
[1], 0) - 1;
5727 b
:= ord(cmd
[2]) - ord('1');
5728 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
5729 gSelectWeapon
[b
, a
] := True
5732 else if (cmd
= 'p1_weapbest') or (cmd
= 'p2_weapbest') then
5734 b
:= ord(cmd
[2]) - ord('1');
5736 gSelectWeapon
[b
, gPlayer1
.GetMorePrefered()] := True
5738 gSelectWeapon
[b
, gPlayer2
.GetMorePrefered()] := True;
5740 else if (cmd
= 'dropflag') then
5742 if g_Game_IsServer
then
5744 if gPlayer2
<> nil then gPlayer2
.TryDropFlag();
5745 if gPlayer1
<> nil then gPlayer1
.TryDropFlag();
5748 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5750 else if (cmd
= 'p1_dropflag') or (cmd
= 'p2_dropflag') then
5752 b
:= ord(cmd
[2]) - ord('1');
5753 if g_Game_IsServer
then
5755 if (b
= 1) and (gPlayer2
<> nil) then gPlayer2
.TryDropFlag()
5756 else if (b
= 0) and (gPlayer1
<> nil) then gPlayer1
.TryDropFlag();
5759 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG
);
5761 // Команды Своей игры:
5762 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5764 if cmd
= 'bot_addred' then
5766 if Length(P
) > 1 then
5767 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
5769 g_Bot_Add(TEAM_RED
, 2);
5771 else if cmd
= 'bot_addblue' then
5773 if Length(P
) > 1 then
5774 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
5776 g_Bot_Add(TEAM_BLUE
, 2);
5778 else if cmd
= 'spectate' then
5784 else if cmd
= 'say' then
5786 if g_Game_IsServer
and g_Game_IsNet
then
5788 if Length(P
) > 1 then
5791 for a
:= 1 to High(P
) do
5792 chstr
:= chstr
+ P
[a
] + ' ';
5794 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5796 if Length(chstr
) < 1 then
5798 g_Console_Add('say <text>');
5802 chstr
:= b_Text_Format(chstr
);
5803 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
5805 else g_Console_Add('say <text>');
5807 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5809 else if cmd
= 'tell' then
5811 if g_Game_IsServer
and g_Game_IsNet
then
5813 if (Length(P
) > 2) and (P
[1] <> '') then
5816 for a
:= 2 to High(P
) do
5817 chstr
:= chstr
+ P
[a
] + ' ';
5819 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5821 if Length(chstr
) < 1 then
5823 g_Console_Add('tell <playername> <text>');
5827 pl
:= g_Net_Client_ByName(P
[1]);
5829 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
5831 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5833 else g_Console_Add('tell <playername> <text>');
5835 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5837 else if cmd
= 'centerprint' then
5839 if (Length(P
) > 2) and (P
[1] <> '') then
5842 for a
:= 2 to High(P
) do
5843 chstr
:= chstr
+ P
[a
] + ' ';
5845 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5847 if Length(chstr
) < 1 then
5849 g_Console_Add('centerprint <timeout> <text>');
5853 a
:= StrToIntDef(P
[1], 100);
5854 chstr
:= b_Text_Format(chstr
);
5855 g_Game_Message(chstr
, a
);
5856 if g_Game_IsNet
and g_Game_IsServer
then
5857 MH_SEND_GameEvent(NET_EV_BIGTEXT
, a
, chstr
);
5859 else g_Console_Add('centerprint <timeout> <text>');
5861 else if (cmd
= 'overtime') and not g_Game_IsClient
then
5863 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
5865 // Дополнительное время:
5866 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
5868 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5869 [gGameSettings
.TimeLimit
div 3600,
5870 (gGameSettings
.TimeLimit
div 60) mod 60,
5871 gGameSettings
.TimeLimit
mod 60]));
5872 if g_Game_IsNet
then MH_SEND_GameSettings
;
5874 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
5876 if (Length(P
) <= 1) then
5877 g_Console_Add('rcon_password <password>')
5879 MC_SEND_RCONPassword(P
[1]);
5881 else if cmd
= 'rcon' then
5883 if g_Game_IsClient
then
5885 if Length(P
) > 1 then
5888 for a
:= 1 to High(P
) do
5889 chstr
:= chstr
+ P
[a
] + ' ';
5891 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5893 if Length(chstr
) < 1 then
5895 g_Console_Add('rcon <command>');
5899 MC_SEND_RCONCommand(chstr
);
5901 else g_Console_Add('rcon <command>');
5904 else if cmd
= 'ready' then
5906 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
5907 gLMSRespawnTime
:= gTime
+ 100;
5909 else if (cmd
= 'callvote') and g_Game_IsNet
then
5911 if Length(P
) > 1 then
5914 for a
:= 1 to High(P
) do begin
5915 if a
> 1 then chstr
:= chstr
+ ' ';
5916 chstr
:= chstr
+ P
[a
];
5919 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5921 if Length(chstr
) < 1 then
5923 g_Console_Add('callvote <command>');
5927 if g_Game_IsClient
then
5928 MC_SEND_Vote(True, chstr
)
5930 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
5931 g_Console_Process('vote', True);
5934 g_Console_Add('callvote <command>');
5936 else if (cmd
= 'vote') and g_Game_IsNet
then
5938 if g_Game_IsClient
then
5940 else if gVoteInProgress
then
5942 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
5943 a
:= Floor((NetClientCount
+1)/2.0) + 1
5945 a
:= Floor(NetClientCount
/2.0) + 1;
5950 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5951 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5957 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
5958 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
5966 procedure SystemCommands(P
: SSArray
);
5970 cmd
:= LowerCase(P
[0]);
5979 gRC_Width
:= Max(1, gRC_Width
);
5980 gRC_Height
:= Max(1, gRC_Height
);
5981 gBPP
:= Max(1, gBPP
);
5982 if sys_SetDisplayMode(gRC_Width
, gRC_Height
, gBPP
, gRC_FullScreen
, gRC_Maximized
) = True then
5983 e_LogWriteln('resolution changed')
5985 e_LogWriteln('resolution not changed');
5986 sys_EnableVSync(gVSync
);
5990 if Length(p
) = 2 then
5992 gMaxFPS
:= StrToIntDef(p
[1], gMaxFPS
);
5994 gFrameTime
:= 1000 div gMaxFPS
5998 e_LogWritefln('r_maxfps %d', [gMaxFPS
]);
6002 if Length(p
) = 2 then
6004 gAskLanguage
:= true;
6005 gLanguage
:= LANGUAGE_ENGLISH
;
6006 case LowerCase(p
[1]) of
6009 gAskLanguage
:= false;
6010 gLanguage
:= LANGUAGE_ENGLISH
;
6014 gAskLanguage
:= false;
6015 gLanguage
:= LANGUAGE_RUSSIAN
;
6019 gAskLanguage
:= true;
6020 gLanguage
:= LANGUAGE_ENGLISH
;
6023 g_Language_Set(gLanguage
);
6027 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd
]);
6033 procedure g_TakeScreenShot(Filename
: string = '');
6034 var s
: TStream
; t
: TDateTime
; dir
, date
, name
: String;
6036 if e_NoGraphics
then Exit
;
6038 dir
:= e_GetWriteableDir(ScreenshotDirs
);
6040 if Filename
= '' then
6043 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
6044 Filename
:= 'screenshot-' + date
;
6047 name
:= e_CatPath(dir
, Filename
+ '.png');
6048 s
:= createDiskFile(name
);
6050 e_MakeScreenshot(s
, gWinSizeX
, gWinSizeY
);
6052 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
6054 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [name
]));
6059 g_Console_Add('oh shit, i can''t create screenshot!')
6063 procedure g_Game_InGameMenu(Show
: Boolean);
6065 if (g_ActiveWindow
= nil) and Show
then
6067 if gGameSettings
.GameType
= GT_SINGLE
then
6068 g_GUI_ShowWindow('GameSingleMenu')
6071 if g_Game_IsClient
then
6072 g_GUI_ShowWindow('GameClientMenu')
6074 if g_Game_IsNet
then
6075 g_GUI_ShowWindow('GameServerMenu')
6077 g_GUI_ShowWindow('GameCustomMenu');
6079 g_Sound_PlayEx('MENU_OPEN');
6081 // Пауза при меню только в одиночной игре:
6082 if (not g_Game_IsNet
) then
6086 if (g_ActiveWindow
<> nil) and (not Show
) then
6088 // Пауза при меню только в одиночной игре:
6089 if (not g_Game_IsNet
) then
6090 g_Game_Pause(False);
6094 procedure g_Game_Pause (Enable
: Boolean);
6098 if not gGameOn
then exit
;
6100 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6103 gPauseMain
:= Enable
;
6105 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6108 procedure g_Game_HolmesPause (Enable
: Boolean);
6112 if not gGameOn
then exit
;
6113 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6116 gPauseHolmes
:= Enable
;
6118 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6121 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6126 if gTriggers
<> nil then
6127 for i
:= 0 to High(gTriggers
) do
6128 with gTriggers
[i
] do
6129 if (TriggerType
= TRIGGER_SOUND
) and
6131 Sound
.IsPlaying() then
6133 Sound
.Pause(Enable
);
6137 if gPlayers
<> nil then
6138 for i
:= 0 to High(gPlayers
) do
6139 if gPlayers
[i
] <> nil then
6140 gPlayers
[i
].PauseSounds(Enable
);
6143 if gMusic
<> nil then
6144 gMusic
.Pause(Enable
);
6147 procedure g_Game_StopAllSounds(all
: Boolean);
6151 if gTriggers
<> nil then
6152 for i
:= 0 to High(gTriggers
) do
6153 with gTriggers
[i
] do
6154 if (TriggerType
= TRIGGER_SOUND
) and
6158 if gMusic
<> nil then
6165 procedure g_Game_UpdateTriggerSounds
;
6168 if gTriggers
<> nil then
6169 for i
:= 0 to High(gTriggers
) do
6170 with gTriggers
[i
] do
6171 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
6172 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
6175 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6178 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6183 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6188 if gSpectMode
<> SPECT_PLAYERS
then
6190 if gSpectPID1
= UID
then
6195 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6202 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6207 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6212 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6217 if gSpectMode
<> SPECT_PLAYERS
then
6219 Pl
:= g_Player_Get(gSpectPID1
);
6220 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6225 if gSpectViewTwo
then
6227 Pl
:= g_Player_Get(gSpectPID2
);
6228 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6236 procedure g_Game_Message(Msg
: string; Time
: Word);
6238 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
6239 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
6240 MessageTime
:= Time
;
6243 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6245 punct
: Array[0..13] of String =
6246 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6252 function IsPunctuation(S
: String): Boolean;
6257 if Length(S
) <> 1 then
6259 for i
:= Low(punct
) to High(punct
) do
6260 if S
= punct
[i
] then
6266 function FilterPunctuation(S
: String): String;
6270 for i
:= Low(punct
) to High(punct
) do
6271 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
6277 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6279 // remove player name
6280 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6281 // for FullWord check
6282 Text := toLowerCase1251(' ' + Text + ' ');
6283 fpText
:= FilterPunctuation(Text);
6285 for i
:= 0 to Length(gChatSounds
) - 1 do
6288 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6290 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
6291 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6293 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
6299 gChatSounds
[i
].Sound
.Play();
6305 g_Sound_PlayEx('SOUND_GAME_RADIO');
6308 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6317 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6321 if goodsnd
[a
].IsPlaying() then
6324 goodsnd
[Random(4)].Play();
6327 procedure g_Game_Announce_KillCombo(Param
: Integer);
6334 UID
:= Param
and $FFFF;
6339 Pl
:= g_Player_Get(UID
);
6348 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6352 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6356 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6360 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6368 if not g_Game_IsWatchedPlayer(UID
) then
6371 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6375 if killsnd
[n
].IsPlaying() then
6380 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
6388 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6392 if hahasnd
[a
].IsPlaying() then
6395 hahasnd
[Random(3)].Play();
6398 procedure g_Game_StartVote(Command
, Initiator
: string);
6402 if not gVotesEnabled
then Exit
;
6403 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6404 if gVoteInProgress
or gVotePassed
then
6406 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6407 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6410 gVoteInProgress
:= True;
6411 gVotePassed
:= False;
6412 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6415 gVoteCommand
:= Command
;
6417 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6418 Need
:= Floor((NetClientCount
+1)/2.0)+1
6420 Need
:= Floor(NetClientCount
/2.0)+1;
6421 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6422 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6425 procedure g_Game_CheckVote
;
6429 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6430 if not gVoteInProgress
then Exit
;
6432 if (gTime
>= gVoteTimer
) then
6434 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6435 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6437 Need
:= Floor(NetClientCount
/2.0) + 1;
6438 if gVoteCount
>= Need
then
6440 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6441 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6442 gVotePassed
:= True;
6443 gVoteCmdTimer
:= gTime
+ 5000;
6447 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6448 MH_SEND_VoteEvent(NET_VE_FAILED
);
6450 if NetClients
<> nil then
6451 for I
:= Low(NetClients
) to High(NetClients
) do
6452 if NetClients
[i
].Used
then
6453 NetClients
[i
].Voted
:= False;
6454 gVoteInProgress
:= False;
6460 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6461 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6463 Need
:= Floor(NetClientCount
/2.0) + 1;
6464 if gVoteCount
>= Need
then
6466 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6467 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6468 gVoteInProgress
:= False;
6469 gVotePassed
:= True;
6470 gVoteCmdTimer
:= gTime
+ 5000;
6473 if NetClients
<> nil then
6474 for I
:= Low(NetClients
) to High(NetClients
) do
6475 if NetClients
[i
].Used
then
6476 NetClients
[i
].Voted
:= False;
6481 procedure g_Game_LoadMapList(FileName
: string);
6489 if not FileExists(FileName
) then Exit
;
6491 AssignFile(ListFile
, FileName
);
6493 while not EOF(ListFile
) do
6495 ReadLn(ListFile
, s
);
6498 if s
= '' then Continue
;
6500 SetLength(MapList
, Length(MapList
)+1);
6501 MapList
[High(MapList
)] := s
;
6503 CloseFile(ListFile
);
6506 procedure g_Game_SetDebugMode();
6509 // Читы (даже в своей игре):
6513 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6517 if Length(LoadingStat
.Msgs
) = 0 then
6523 begin // Переходим на следующую строку или скроллируем:
6524 if NextMsg
= Length(Msgs
) then
6526 for i
:= 0 to High(Msgs
)-1 do
6527 Msgs
[i
] := Msgs
[i
+1];
6535 Msgs
[NextMsg
-1] := Text;
6539 PBarWasHere
:= false;
6542 g_ActiveWindow
:= nil;
6543 ProcessLoading(True);
6546 procedure g_Game_StepLoading(Value
: Integer = -1);
6558 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
6561 ProcessLoading(False);
6566 procedure g_Game_ClearLoading();
6575 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6576 if len
< 1 then len
:= 1;
6577 SetLength(Msgs
, len
);
6578 for len
:= Low(Msgs
) to High(Msgs
) do
6581 PBarWasHere
:= false;
6585 procedure Parse_Params(var pars
: TParamStrValues
);
6592 while i
<= ParamCount
do
6595 if (Length(s
) > 1) and (s
[1] = '-') then
6597 if (Length(s
) > 2) and (s
[2] = '-') then
6598 begin // Одиночный параметр
6599 SetLength(pars
, Length(pars
) + 1);
6600 with pars
[High(pars
)] do
6602 Name
:= LowerCase(s
);
6607 if (i
< ParamCount
) then
6608 begin // Параметр со значением
6610 SetLength(pars
, Length(pars
) + 1);
6611 with pars
[High(pars
)] do
6613 Name
:= LowerCase(s
);
6614 Value
:= LowerCase(ParamStr(i
));
6623 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6628 for i
:= 0 to High(pars
) do
6629 if pars
[i
].Name
= aName
then
6631 Result
:= pars
[i
].Value
;
6636 procedure g_Game_Process_Params();
6638 pars
: TParamStrValues
;
6641 LimT
, LimS
: Integer;
6652 s
:= Find_Param_Value(pars
, '--debug');
6655 g_Game_SetDebugMode();
6656 s
:= Find_Param_Value(pars
, '--netdump');
6661 // Connect when game loads
6662 ip
:= Find_Param_Value(pars
, '-connect');
6666 s
:= Find_Param_Value(pars
, '-port');
6667 if (s
= '') or not TryStrToInt(s
, Port
) then
6670 s
:= Find_Param_Value(pars
, '-pw');
6672 g_Game_StartClient(ip
, Port
, s
);
6676 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6679 gDefaultMegawadStart
:= s
;
6682 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6683 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6685 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6688 // Start map when game loads:
6689 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6690 if isWadPath(map
) then
6693 s
:= Find_Param_Value(pars
, '-gm');
6694 GMode
:= g_Game_TextToMode(s
);
6695 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6696 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6699 s
:= Find_Param_Value(pars
, '-limt');
6700 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6706 s
:= Find_Param_Value(pars
, '-lims');
6707 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6713 s
:= Find_Param_Value(pars
, '-lives');
6714 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6720 s
:= Find_Param_Value(pars
, '-opt');
6724 Opt
:= StrToIntDef(s
, 0);
6727 s
:= Find_Param_Value(pars
, '--close');
6731 // Override map to test:
6732 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
6735 if e_IsValidResourceName(s
) then
6736 e_FindResource(AllMapDirs
, s
);
6737 gTestMap
:= ExpandFileName(s
);
6740 // Delete test map after play:
6741 s
:= Find_Param_Value(pars
, '--testdelete');
6744 //gMapToDelete := MapsDir + map;
6745 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
6749 // Delete temporary WAD after play:
6750 s
:= Find_Param_Value(pars
, '--tempdelete');
6751 if (s
<> '') and (gTestMap
<> '') then
6753 gMapToDelete
:= gTestMap
;
6754 gTempDelete
:= True;
6757 // Number of players:
6758 s
:= Find_Param_Value(pars
, '-pl');
6760 n
:= DEFAULT_PLAYERS
6762 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
6765 s
:= Find_Param_Value(pars
, '-port');
6766 if (s
= '') or not TryStrToInt(s
, Port
) then
6767 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6769 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6772 // Execute script when game loads:
6773 s
:= Find_Param_Value(pars
, '-exec');
6776 // if not isWadPath(s) then
6777 // s := GameDir + '/' + s;
6782 if IOResult
<> 0 then
6784 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6785 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6789 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
6790 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6795 if IOResult
<> 0 then
6797 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
6798 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6802 if Pos('#', s
) <> 1 then // script comment
6803 g_Console_Process(s
, True);
6814 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
6815 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6816 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
6817 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
6819 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
6820 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6821 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6822 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6824 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
6825 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
6827 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
6828 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
6830 {$IFDEF ENABLE_HOLMES}
6831 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
6834 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
6836 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
6837 conRegVar('r_resolution_scale', @r_pixel_scale
, 0.01, 100.0, 'upscale factor', '', false);
6839 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
6840 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
6842 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6843 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6845 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
6846 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');
6847 conRegVar('r_showping', @gShowPing
, 'show ping', 'show ping');
6848 conRegVar('r_showscore', @gShowScore
, 'show score', 'show score');
6849 conRegVar('r_showkillmsg', @gShowKillMsg
, 'show kill log', 'show kill log');
6850 conRegVar('r_showlives', @gShowLives
, 'show lives', 'show lives');
6851 conRegVar('r_showspect', @gSpectHUD
, 'show spectator hud', 'show spectator hud');
6852 conRegVar('r_showstat', @gShowStat
, 'show stats', 'show stats');
6853 conRegVar('r_showpids', @gShowPIDs
, 'show PIDs', 'show PIDs');