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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 g_basic
, g_player
, e_graphics
, Classes
, g_res_downloader
,
23 SysUtils
, g_sound
, g_gui
, MAPDEF
, wadreader
, md5
, xprofiler
;
26 TGameSettings
= record
42 TDelayedEvent
= record
50 TPlayerSettings
= record
69 function g_Game_IsNet(): Boolean;
70 function g_Game_IsServer(): Boolean;
71 function g_Game_IsClient(): Boolean;
72 procedure g_Game_Init();
73 procedure g_Game_Free (freeTextures
: Boolean=true);
74 procedure g_Game_LoadData();
75 procedure g_Game_FreeData();
76 procedure g_Game_Update();
77 procedure g_Game_Draw();
78 procedure g_Game_Quit();
79 procedure g_Game_SetupScreenSize();
80 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
81 function g_Game_ModeToText(Mode
: Byte): string;
82 function g_Game_TextToMode(Mode
: string): Byte;
83 procedure g_Game_ExecuteEvent(Name
: String);
84 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
85 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
86 procedure g_Game_RemovePlayer();
87 procedure g_Game_Spectate();
88 procedure g_Game_SpectateCenterView();
89 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
90 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
91 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
92 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
93 procedure g_Game_Restart();
94 procedure g_Game_RestartLevel();
95 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
96 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
97 procedure g_Game_SaveOptions();
98 function g_Game_StartMap(Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
99 procedure g_Game_ChangeMap(const MapPath
: String);
100 procedure g_Game_ExitLevel(const Map
: AnsiString);
101 function g_Game_GetFirstMap(WAD
: String): String;
102 function g_Game_GetNextMap(): String;
103 procedure g_Game_NextLevel();
104 procedure g_Game_Pause(Enable
: Boolean);
105 procedure g_Game_InGameMenu(Show
: Boolean);
106 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
107 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
108 procedure g_Game_Message(Msg
: String; Time
: Word);
109 procedure g_Game_LoadMapList(FileName
: String);
110 procedure g_Game_PauseAllSounds(Enable
: Boolean);
111 procedure g_Game_StopAllSounds(all
: Boolean);
112 procedure g_Game_UpdateTriggerSounds();
113 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
114 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
115 procedure g_Game_Announce_KillCombo(Param
: Integer);
116 procedure g_Game_StartVote(Command
, Initiator
: string);
117 procedure g_Game_CheckVote
;
118 procedure g_TakeScreenShot();
119 procedure g_FatalError(Text: String);
120 procedure g_SimpleError(Text: String);
121 function g_Game_IsTestMap(): Boolean;
122 procedure g_Game_DeleteTestMap();
123 procedure GameCVars(P
: SArray
);
124 procedure GameCommands(P
: SArray
);
125 procedure GameCheats(P
: SArray
);
126 procedure DebugCommands(P
: SArray
);
127 procedure g_Game_Process_Params
;
128 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
129 procedure g_Game_StepLoading();
130 procedure g_Game_ClearLoading();
131 procedure g_Game_SetDebugMode();
132 procedure DrawLoadingStat();
134 { procedure SetWinPause(Enable: Boolean); }
139 LOADING_SHOW_STEP
= 100;
140 LOADING_INTERLINE
= 20;
155 MESSAGE_DIKEY
= WM_USER
+ 1;
160 EXIT_ENDLEVELSINGLE
= 4;
161 EXIT_ENDLEVELCUSTOM
= 5;
163 GAME_OPTION_RESERVED
= 1;
164 GAME_OPTION_TEAMDAMAGE
= 2;
165 GAME_OPTION_ALLOWEXIT
= 4;
166 GAME_OPTION_WEAPONSTAY
= 8;
167 GAME_OPTION_MONSTERS
= 16;
168 GAME_OPTION_BOTVSPLAYER
= 32;
169 GAME_OPTION_BOTVSMONSTER
= 64;
174 STATE_INTERCUSTOM
= 3;
175 STATE_INTERSINGLE
= 4;
181 LMS_RESPAWN_NONE
= 0;
182 LMS_RESPAWN_WARMUP
= 1;
183 LMS_RESPAWN_FINAL
= 2;
199 CONFIG_FILENAME
= 'Doom2DF.cfg';
200 LOG_FILENAME
= 'Doom2DF.log';
202 TEST_MAP_NAME
= '$$$_TEST_$$$';
204 STD_PLAYER_MODEL
= 'Doomer';
208 gGameSettings
: TGameSettings
;
209 gPlayer1Settings
: TPlayerSettings
;
210 gPlayer2Settings
: TPlayerSettings
;
212 gPlayerScreenSize
: TDFPoint
;
213 gPlayer1ScreenCoord
: TDFPoint
;
214 gPlayer2ScreenCoord
: TDFPoint
;
215 gPlayer1
: TPlayer
= nil;
216 gPlayer2
: TPlayer
= nil;
217 gPlayerDrawn
: TPlayer
= nil;
219 gSwitchGameMode
: Byte = GM_DM
;
220 gHearPoint1
, gHearPoint2
: THearPoint
;
221 gSoundEffectsDF
: Boolean = False;
222 gSoundTriggerTime
: Word = 0;
223 gAnnouncer
: Byte = ANNOUNCE_NONE
;
224 goodsnd
: array[0..3] of TPlayableSound
;
225 killsnd
: array[0..3] of TPlayableSound
;
226 gDefInterTime
: ShortInt = -1;
227 gInterEndTime
: LongWord = 0;
228 gInterTime
: LongWord = 0;
229 gServInterTime
: Byte = 0;
230 gGameStartTime
: LongWord = 0;
231 gTotalMonsters
: Integer = 0;
233 gShowTime
: Boolean = True;
234 gShowFPS
: Boolean = False;
235 gShowGoals
: Boolean = True;
236 gShowStat
: Boolean = True;
237 gShowKillMsg
: Boolean = True;
238 gShowLives
: Boolean = True;
239 gShowPing
: Boolean = False;
240 gShowMap
: Boolean = False;
242 gState
: Byte = STATE_NONE
;
244 sWidth
, sHeight
: Word;
245 gSpectMode
: Byte = SPECT_NONE
;
246 gSpectHUD
: Boolean = True;
247 gSpectKeyPress
: Boolean = False;
248 gSpectX
: Integer = 0;
249 gSpectY
: Integer = 0;
250 gSpectStep
: Byte = 8;
251 gSpectViewTwo
: Boolean = False;
252 gSpectPID1
: Integer = -1;
253 gSpectPID2
: Integer = -1;
254 gMusic
: TMusic
= nil;
255 gLoadGameMode
: Boolean;
256 gCheats
: Boolean = False;
257 gMapOnce
: Boolean = False;
258 gMapToDelete
: String;
259 gTempDelete
: Boolean = False;
260 gLastMap
: Boolean = False;
261 gWinPosX
, gWinPosY
: Integer;
262 gWinSizeX
, gWinSizeY
: Integer;
263 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
264 gWinActive
: Boolean = True; // by default window is active, lol
265 gResolutionChange
: Boolean = False;
266 gRC_Width
, gRC_Height
: Word;
267 gRC_FullScreen
, gRC_Maximized
: Boolean;
268 gLanguageChange
: Boolean = False;
269 gDebugMode
: Boolean = False;
270 g_debug_Sounds
: Boolean = False;
271 g_debug_Frames
: Boolean = False;
272 g_debug_WinMsgs
: Boolean = False;
273 g_debug_MonsterOff
: Boolean = False;
274 g_debug_BotAIOff
: Byte = 0;
275 g_debug_HealthBar
: Boolean = False;
276 g_Debug_Player
: Boolean = False;
277 gCoopMonstersKilled
: Word = 0;
278 gCoopSecretsFound
: Word = 0;
279 gCoopTotalMonstersKilled
: Word = 0;
280 gCoopTotalSecretsFound
: Word = 0;
281 gCoopTotalMonsters
: Word = 0;
282 gCoopTotalSecrets
: Word = 0;
283 gStatsOff
: Boolean = False;
284 gStatsPressed
: Boolean = False;
285 gExitByTrigger
: Boolean = False;
286 gNextMap
: String = '';
287 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
288 gLMSRespawnTime
: Cardinal = 0;
289 gLMSSoftSpawn
: Boolean = False;
290 gMissionFailed
: Boolean = False;
291 gVoteInProgress
: Boolean = False;
292 gVotePassed
: Boolean = False;
293 gVoteCommand
: string = '';
294 gVoteTimer
: Cardinal = 0;
295 gVoteCmdTimer
: Cardinal = 0;
296 gVoteCount
: Integer = 0;
297 gVoteTimeout
: Cardinal = 30;
298 gVoted
: Boolean = False;
299 gVotesEnabled
: Boolean = True;
300 gEvents
: Array of TGameEvent
;
301 gDelayedEvents
: Array of TDelayedEvent
;
303 // move button values:
304 // bits 0-1: l/r state:
305 // 0: neither left, nor right pressed
308 // bits 4-5: l/r state when strafe was pressed
309 P1MoveButton
: Byte = 0;
310 P2MoveButton
: Byte = 0;
312 g_profile_frame_update
: Boolean = false;
313 g_profile_frame_draw
: Boolean = false;
314 g_profile_collision
: Boolean = false;
315 g_profile_los
: Boolean = false;
316 g_profile_history_size
: Integer = 1000;
318 g_rlayer_back
: Boolean = true;
319 g_rlayer_step
: Boolean = true;
320 g_rlayer_wall
: Boolean = true;
321 g_rlayer_door
: Boolean = true;
322 g_rlayer_acid1
: Boolean = true;
323 g_rlayer_acid2
: Boolean = true;
324 g_rlayer_water
: Boolean = true;
325 g_rlayer_fore
: Boolean = true;
327 g_dbg_scale
: Single = 1.0;
330 procedure g_ResetDynlights ();
331 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
332 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
334 function conIsCheatsEnabled (): Boolean;
340 g_textures
, g_main
, g_window
, g_menu
,
341 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
342 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
343 g_triggers
, g_monsters
, e_sound
, CONFIG
,
344 BinEditor
, g_language
, g_net
, SDL
,
345 ENet
, e_msg
, g_netmsg
, g_netmaster
, GL
, GLExt
,
346 utils
, sfs
, g_holmes
;
349 // ////////////////////////////////////////////////////////////////////////// //
350 function conIsCheatsEnabled (): Boolean;
353 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
354 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then exit
;
359 // ////////////////////////////////////////////////////////////////////////// //
361 profileFrameDraw
: TProfiler
= nil;
364 // ////////////////////////////////////////////////////////////////////////// //
367 x
, y
, radius
: Integer;
370 exploRadius
: Integer;
374 g_dynLights
: array of TDynLight
= nil;
375 g_dynLightCount
: Integer = 0;
376 g_playerLight
: Boolean = false;
378 procedure g_ResetDynlights ();
382 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
384 for idx
:= 0 to g_dynLightCount
-1 do
386 if g_dynLights
[idx
].exploCount
= -666 then
393 Inc(g_dynLights
[idx
].exploCount
);
394 if (g_dynLights
[idx
].exploCount
< 10) then
396 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
397 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
398 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
399 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
404 g_dynLightCount
:= lnum
;
407 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
409 if not gwin_has_stencil
then exit
;
410 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
411 g_dynLights
[g_dynLightCount
].x
:= x
;
412 g_dynLights
[g_dynLightCount
].y
:= y
;
413 g_dynLights
[g_dynLightCount
].radius
:= radius
;
414 g_dynLights
[g_dynLightCount
].r
:= r
;
415 g_dynLights
[g_dynLightCount
].g
:= g
;
416 g_dynLights
[g_dynLightCount
].b
:= b
;
417 g_dynLights
[g_dynLightCount
].a
:= a
;
418 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
419 Inc(g_dynLightCount
);
422 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
424 if not gwin_has_stencil
then exit
;
425 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
426 g_dynLights
[g_dynLightCount
].x
:= x
;
427 g_dynLights
[g_dynLightCount
].y
:= y
;
428 g_dynLights
[g_dynLightCount
].radius
:= 0;
429 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
430 g_dynLights
[g_dynLightCount
].r
:= r
;
431 g_dynLights
[g_dynLightCount
].g
:= g
;
432 g_dynLights
[g_dynLightCount
].b
:= b
;
433 g_dynLights
[g_dynLightCount
].a
:= 0;
434 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
435 Inc(g_dynLightCount
);
439 // ////////////////////////////////////////////////////////////////////////// //
440 function calcProfilesHeight (prof
: TProfiler
): Integer;
443 if (prof
= nil) then exit
;
444 if (length(prof
.bars
) = 0) then exit
;
445 result
:= length(prof
.bars
)*(16+2);
449 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
456 if (prof
= nil) then exit
;
458 if (length(prof
.bars
) = 0) then exit
;
460 hgt
:= calcProfilesHeight(prof
);
461 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
462 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
464 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
465 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
466 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
469 for ii
:= 0 to High(prof
.bars
) do
471 e_TextureFontPrintEx(x
+2+4*prof
.bars
[ii
].level
, yy
, Format('%s: %d', [prof
.bars
[ii
].name
, prof
.bars
[ii
].value
]), gStdFont
, 255, 255, 0, 1, false);
478 // ////////////////////////////////////////////////////////////////////////// //
480 TEndCustomGameStat
= record
481 PlayerStat
: TPlayerStatArray
;
485 Map
, MapName
: String;
488 TEndSingleGameStat
= record
489 PlayerStat
: Array [0..1] of record
495 TotalSecrets
: Integer;
498 TLoadingStat
= record
502 Msgs
: Array of String;
506 TParamStrValue
= record
511 TParamStrValues
= Array of TParamStrValue
;
514 INTER_ACTION_TEXT
= 1;
515 INTER_ACTION_PIC
= 2;
516 INTER_ACTION_MUSIC
= 3;
520 FPSCounter
, UPSCounter
: Word;
521 FPSTime
, UPSTime
: LongWord;
522 DataLoaded
: Boolean = False;
523 LastScreenShot
: Int64;
524 IsDrawStat
: Boolean = False;
525 CustomStat
: TEndCustomGameStat
;
526 SingleStat
: TEndSingleGameStat
;
527 LoadingStat
: TLoadingStat
;
528 EndingGameCounter
: Byte = 0;
531 MapList
: SArray
= nil;
532 MapIndex
: Integer = -1;
538 text: Array of ShortString;
539 anim
: Array of ShortString;
540 pic
: Array of ShortString;
541 mus
: Array of ShortString;
543 triggers
: Array of record
545 actions
: Array of record
546 action
, p1
, p2
: Integer;
549 cur_trigger
: Integer;
562 function Compare(a
, b
: TPlayerStat
): Integer;
564 if a
.Spectator
then Result
:= 1
565 else if b
.Spectator
then Result
:= -1
566 else if a
.Frags
< b
.Frags
then Result
:= 1
567 else if a
.Frags
> b
.Frags
then Result
:= -1
568 else if a
.Deaths
< b
.Deaths
then Result
:= -1
569 else if a
.Deaths
> b
.Deaths
then Result
:= 1
570 else if a
.Kills
< b
.Kills
then Result
:= -1
574 procedure SortGameStat(var stat
: TPlayerStatArray
);
579 if stat
= nil then Exit
;
581 for I
:= High(stat
) downto Low(stat
) do
582 for J
:= Low(stat
) to High(stat
) - 1 do
583 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
586 stat
[J
] := stat
[J
+ 1];
591 function g_Game_ModeToText(Mode
: Byte): string;
595 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
596 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
597 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
598 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
599 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
603 function g_Game_TextToMode(Mode
: string): Byte;
606 Mode
:= UpperCase(Mode
);
607 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
612 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
617 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
622 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
627 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
634 function g_Game_IsNet(): Boolean;
636 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
639 function g_Game_IsServer(): Boolean;
641 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
644 function g_Game_IsClient(): Boolean;
646 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
649 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
656 Result
.name
:= ExtractFileName(WAD
);
657 Result
.description
:= '';
660 w
:= TWADFile
.Create();
663 if not w
.GetResource('INTERSCRIPT', p
, len
) then
669 cfg
:= TConfig
.CreateMem(p
, len
);
670 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
671 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
672 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
673 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
679 procedure g_Game_FreeWAD();
683 for a
:= 0 to High(MegaWAD
.res
.pic
) do
684 if MegaWAD
.res
.pic
[a
] <> '' then
685 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
687 for a
:= 0 to High(MegaWAD
.res
.mus
) do
688 if MegaWAD
.res
.mus
[a
] <> '' then
689 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
691 MegaWAD
.res
.pic
:= nil;
692 MegaWAD
.res
.text := nil;
693 MegaWAD
.res
.anim
:= nil;
694 MegaWAD
.res
.mus
:= nil;
695 MegaWAD
.triggers
:= nil;
697 g_Texture_Delete('TEXTURE_endpic');
698 g_Sound_Delete('MUSIC_endmus');
700 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
701 gGameSettings
.WAD
:= '';
704 procedure g_Game_LoadWAD(WAD
: string);
713 gGameSettings
.WAD
:= WAD
;
714 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
717 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
719 w
:= TWADFile
.Create();
720 w
.ReadFile(MapsDir
+ WAD
);
722 if not w
.GetResource('INTERSCRIPT', p
, len
) then
728 cfg
:= TConfig
.CreateMem(p
, len
);
733 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
734 if s = '' then Break;
737 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
738 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
740 g_Texture_CreateWADEx(s, s);
746 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
747 if s = '' then Break;
750 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
751 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
753 g_Music_CreateWADEx(s, s);
756 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
757 if MegaWAD
.endpic
<> '' then
759 s
:= g_ExtractWadName(MegaWAD
.endpic
);
760 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
761 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
763 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
764 if MegaWAD
.endmus
<> '' then
766 s
:= g_ExtractWadName(MegaWAD
.endmus
);
767 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
768 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
776 {procedure start_trigger(t: string);
780 function next_trigger(): Boolean;
784 procedure DisableCheats();
790 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
791 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
792 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
793 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
795 {$IF DEFINED(D2F_DEBUG)}
796 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
797 gAimLine
:= g_dbg_aimline_on
;
801 procedure g_Game_ExecuteEvent(Name
: String);
807 if gEvents
= nil then
809 for a
:= 0 to High(gEvents
) do
810 if gEvents
[a
].Name
= Name
then
812 if gEvents
[a
].Command
<> '' then
813 g_Console_Process(gEvents
[a
].Command
, True);
818 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
823 if gDelayedEvents
<> nil then
824 for a
:= 0 to High(gDelayedEvents
) do
825 if not gDelayedEvents
[a
].Pending
then
832 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
833 n
:= High(gDelayedEvents
);
835 gDelayedEvents
[n
].Pending
:= True;
836 gDelayedEvents
[n
].DEType
:= DEType
;
837 gDelayedEvents
[n
].DENum
:= Num
;
838 gDelayedEvents
[n
].DEStr
:= Str
;
839 if DEType
= DE_GLOBEVENT
then
840 gDelayedEvents
[n
].Time
:= (GetTimer() {div 1000}) + Time
842 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
851 if g_Game_IsNet
and g_Game_IsServer
then
852 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
858 g_Game_StopAllSounds(False);
863 EndingGameCounter
:= 0;
864 g_ActiveWindow
:= nil;
866 gLMSRespawn
:= LMS_RESPAWN_NONE
;
867 gLMSRespawnTime
:= 0;
870 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
875 begin // Ýòî áûë òåñò
879 begin // Âûõîä â ãëàâíîå ìåíþ
880 gMusic
.SetByName('MUSIC_MENU');
882 if gState
<> STATE_SLIST
then
884 g_GUI_ShowWindow('MainMenu');
885 gState
:= STATE_MENU
;
888 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
889 slReturnPressed
:= True;
890 if g_Net_Slist_Fetch(slCurrent
) then
892 if slCurrent
= nil then
893 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
896 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
899 g_Game_ExecuteEvent('ongameend');
903 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
905 if not g_Game_IsClient
then g_Game_Restart();
908 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
910 // Ñòàòèñòèêà Ñâîåé èãðû:
911 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
913 CustomStat
.GameTime
:= gTime
;
914 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
915 CustomStat
.MapName
:= gMapInfo
.Name
;
916 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
917 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
918 CustomStat
.TeamStat
:= gTeamStat
;
920 CustomStat
.PlayerStat
:= nil;
922 // Ñòàòèñòèêà èãðîêîâ:
923 if gPlayers
<> nil then
925 for a
:= 0 to High(gPlayers
) do
926 if gPlayers
[a
] <> nil then
928 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
929 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
931 Name
:= gPlayers
[a
].Name
;
932 Frags
:= gPlayers
[a
].Frags
;
933 Deaths
:= gPlayers
[a
].Death
;
934 Kills
:= gPlayers
[a
].Kills
;
935 Team
:= gPlayers
[a
].Team
;
936 Color
:= gPlayers
[a
].Model
.Color
;
937 Spectator
:= gPlayers
[a
].FSpectator
;
941 SortGameStat(CustomStat
.PlayerStat
);
944 g_Game_ExecuteEvent('onmapend');
947 EndingGameCounter
:= 255;
948 gState
:= STATE_FOLD
;
950 if gDefInterTime
< 0 then
951 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
953 gInterEndTime
:= gDefInterTime
* 1000;
956 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
958 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
959 SingleStat
.GameTime
:= gTime
;
960 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
961 SingleStat
.TotalSecrets
:= gSecretsCount
;
962 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
963 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
964 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
965 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
966 if SingleStat
.TwoPlayers
then
968 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
969 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
972 g_Game_ExecuteEvent('onmapend');
975 if gNextMap
<> '' then
977 gMusic
.SetByName('MUSIC_INTERMUS');
979 gState
:= STATE_INTERSINGLE
;
981 g_Game_ExecuteEvent('oninter');
983 else // Áîëüøå íåò êàðò
986 EndingGameCounter
:= 255;
987 gState
:= STATE_FOLD
;
992 // Îêîí÷àíèå îáðàáîòàíî:
993 if gExit
<> EXIT_QUIT
then
997 procedure drawTime(X
, Y
: Integer); inline;
999 e_TextureFontPrint(x
, y
,
1000 Format('%d:%.2d:%.2d', [
1001 gTime
div 1000 div 3600,
1002 (gTime
div 1000 div 60) mod 60,
1003 gTime
div 1000 mod 60
1008 procedure DrawStat();
1010 pc
, x
, y
, w
, h
: Integer;
1011 w1
, w2
, w3
, w4
: Integer;
1013 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1016 stat
: TPlayerStatArray
;
1023 pc
:= g_Player_GetCount
;
1024 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1026 w
:= gScreenWidth
-(gScreenWidth
div 5);
1027 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1030 h
:= 40+ch
*5+(ch
+8)*pc
;
1031 x
:= (gScreenWidth
div 2)-(w
div 2);
1032 y
:= (gScreenHeight
div 2)-(h
div 2);
1034 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1035 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1037 drawTime(x
+w
-78, y
+8);
1039 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1040 map
:= g_ExtractFileName(gMapInfo
.Map
);
1041 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1043 case gGameSettings
.GameMode
of
1046 if gGameSettings
.MaxLives
= 0 then
1047 s1
:= _lc
[I_GAME_DM
]
1049 s1
:= _lc
[I_GAME_LMS
];
1050 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1051 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1056 if gGameSettings
.MaxLives
= 0 then
1057 s1
:= _lc
[I_GAME_TDM
]
1059 s1
:= _lc
[I_GAME_TLMS
];
1060 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1061 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1066 s1
:= _lc
[I_GAME_CTF
];
1067 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1068 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1073 if gGameSettings
.MaxLives
= 0 then
1074 s1
:= _lc
[I_GAME_COOP
]
1076 s1
:= _lc
[I_GAME_SURV
];
1077 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1078 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1089 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1091 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1093 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1095 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1096 gStdFont
, 200, 200, 200, 1);
1098 if NetMode
= NET_SERVER
then
1099 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1101 if NetMode
= NET_CLIENT
then
1102 e_TextureFontPrintEx(x
+8, y
+ 8,
1103 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1107 stat
:= g_Player_GetStats();
1110 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1111 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1113 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1115 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1119 for a
:= TEAM_RED
to TEAM_BLUE
do
1121 if a
= TEAM_RED
then
1123 s1
:= _lc
[I_GAME_TEAM_RED
];
1130 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1136 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1137 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1138 gStdFont
, r
, g
, b
, 1);
1140 _y
:= _y
+ch
+(ch
div 4);
1141 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1142 _y
:= _y
+(ch
div 4);
1144 for aa
:= 0 to High(stat
) do
1145 if stat
[aa
].Team
= a
then
1161 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1163 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1165 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1167 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1174 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1177 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1178 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1179 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1180 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1183 for aa
:= 0 to High(stat
) do
1197 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1198 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1200 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1202 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1204 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1206 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1212 procedure g_Game_Init();
1218 gTempDelete
:= False;
1220 sfsGCDisable(); // temporary disable removing of temporary volumes
1223 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1224 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1225 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1226 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1228 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1229 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1230 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1232 g_Game_ClearLoading();
1233 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1234 g_Game_SetLoadingText('', 0, False);
1236 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1239 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1240 g_PlayerModel_LoadData();
1242 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1244 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1245 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1246 until FindNext(SR
) <> 0;
1249 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1251 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1252 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1253 until FindNext(SR
) <> 0;
1256 if FindFirst(ModelsDir
+'*.zip', faAnyFile
, SR
) = 0 then
1258 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1259 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1260 until FindNext(SR
) <> 0;
1266 LastScreenShot
:= 0;
1268 {e_MouseInfo.Accel := 1.0;}
1270 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1273 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1274 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1275 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1276 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1277 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1279 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1282 gMusic
:= TMusic
.Create();
1283 gMusic
.SetByName('MUSIC_MENU');
1286 gGameSettings
.WarmupTime
:= 30;
1288 gState
:= STATE_MENU
;
1290 SetLength(gEvents
, 6);
1291 gEvents
[0].Name
:= 'ongamestart';
1292 gEvents
[1].Name
:= 'ongameend';
1293 gEvents
[2].Name
:= 'onmapstart';
1294 gEvents
[3].Name
:= 'onmapend';
1295 gEvents
[4].Name
:= 'oninter';
1296 gEvents
[5].Name
:= 'onwadend';
1298 sfsGCEnable(); // enable releasing unused volumes
1302 procedure g_Game_Free(freeTextures
: Boolean=true);
1304 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1305 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1307 g_Map_Free(freeTextures
);
1309 g_Player_RemoveAllCorpses();
1311 gGameSettings
.GameType
:= GT_NONE
;
1312 if gGameSettings
.GameMode
= GM_SINGLE
then
1313 gGameSettings
.GameMode
:= GM_DM
;
1314 gSwitchGameMode
:= gGameSettings
.GameMode
;
1317 gExitByTrigger
:= False;
1320 function IsActivePlayer(p
: TPlayer
): Boolean;
1325 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1328 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1335 if gPlayers
= nil then
1337 for a
:= Low(gPlayers
) to High(gPlayers
) do
1338 if IsActivePlayer(gPlayers
[a
]) then
1340 if gPlayers
[a
].UID
<> ID
then
1342 Result
:= gPlayers
[a
];
1347 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1353 if gPlayers
= nil then
1357 for a
:= Low(gPlayers
) to High(gPlayers
) do
1358 if IsActivePlayer(gPlayers
[a
]) then
1360 SetLength(ids
, Length(ids
) + 1);
1361 ids
[High(ids
)] := gPlayers
[a
].UID
;
1362 if gPlayers
[a
].UID
= Skip
then
1365 if Length(ids
) = 0 then
1370 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1373 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1379 if gPlayers
= nil then
1383 for a
:= Low(gPlayers
) to High(gPlayers
) do
1384 if IsActivePlayer(gPlayers
[a
]) then
1386 SetLength(ids
, Length(ids
) + 1);
1387 ids
[High(ids
)] := gPlayers
[a
].UID
;
1388 if gPlayers
[a
].UID
= Skip
then
1391 if Length(ids
) = 0 then
1394 Result
:= ids
[Length(ids
) - 1]
1396 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1399 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
1401 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
1402 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
1406 procedure processPlayerControls (plr
: TPlayer
; var ctrl
: TPlayerControl
; var MoveButton
: Byte; p2hack
: Boolean=false);
1412 if (plr
= nil) then exit
;
1413 if (p2hack
) then time
:= 1000 else time
:= 1;
1414 strafeDir
:= MoveButton
shr 4;
1415 MoveButton
:= MoveButton
and $0F;
1418 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1419 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1420 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1422 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1423 if MoveButton
= 1 then plr
.PressKey(KEY_LEFT
, time
)
1424 else if MoveButton
= 2 then plr
.PressKey(KEY_RIGHT
, time
);
1426 // if we have "strafe" key, turn off old strafe mechanics
1427 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
1429 // new strafe mechanics
1430 if (strafeDir
= 0) then strafeDir
:= MoveButton
; // start strafing
1431 // now set direction according to strafe (reversed)
1432 if (strafeDir
= 2) then plr
.SetDirection(D_LEFT
)
1433 else if (strafeDir
= 1) then plr
.SetDirection(D_RIGHT
);
1437 strafeDir
:= 0; // not strafing anymore
1438 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1439 if (MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then plr
.SetDirection(D_LEFT
)
1440 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1441 else if (MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then plr
.SetDirection(D_RIGHT
)
1442 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1443 else if MoveButton
<> 0 then plr
.SetDirection(TDirection(MoveButton
-1));
1446 // fix movebutton state
1447 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1449 // Îñòàëüíûå êëàâèøè:
1450 if isKeyPressed(KeyJump
, KeyJump2
) then plr
.PressKey(KEY_JUMP
, time
);
1451 if isKeyPressed(KeyUp
, KeyUp2
) then plr
.PressKey(KEY_UP
, time
);
1452 if isKeyPressed(KeyDown
, KeyDown2
) then plr
.PressKey(KEY_DOWN
, time
);
1453 if isKeyPressed(KeyFire
, KeyFire2
) then plr
.PressKey(KEY_FIRE
);
1454 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then plr
.PressKey(KEY_NEXTWEAPON
);
1455 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then plr
.PressKey(KEY_PREVWEAPON
);
1456 if isKeyPressed(KeyOpen
, KeyOpen2
) then plr
.PressKey(KEY_OPEN
);
1458 for i
:= 0 to High(KeyWeapon
) do
1459 if isKeyPressed(KeyWeapon
[i
], KeyWeapon2
[i
]) then
1460 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1463 // HACK: add dynlight here
1464 if gwin_k8_enable_light_experiments
then
1466 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1468 g_playerLight
:= true;
1470 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1472 g_playerLight
:= false;
1476 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1479 procedure g_Game_Update();
1481 Msg
: g_gui
.TMessage
;
1487 function sendMonsPos (mon
: TMonster
): Boolean;
1489 result
:= false; // don't stop
1490 // this will also reset "need-send" flag
1491 if mon
.gncNeedSend
then
1493 MH_SEND_MonsterPos(mon
.UID
);
1495 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1497 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1499 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1501 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1505 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1507 result
:= false; // don't stop
1508 // this will also reset "need-send" flag
1509 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1513 reliableUpdate
: Boolean;
1516 // Ïîðà âûêëþ÷àòü èãðó:
1517 if gExit
= EXIT_QUIT
then
1519 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1523 if gExit
= EXIT_QUIT
then
1527 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
1530 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1533 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1535 gExit
:= EXIT_SIMPLE
;
1541 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1542 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1543 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1544 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1546 if g_Game_IsNet
and g_Game_IsServer
then
1548 gInterTime
:= gInterTime
+ GAME_TICK
;
1549 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1550 if a
<> gServInterTime
then
1552 gServInterTime
:= a
;
1553 MH_SEND_TimeSync(gServInterTime
);
1557 if (not g_Game_IsClient
) and
1560 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1561 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1562 and (g_ActiveWindow
= nil)
1564 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1567 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1568 g_Game_StopAllSounds(True);
1570 if gMapOnce
then // Ýòî áûë òåñò
1571 gExit
:= EXIT_SIMPLE
1573 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1574 g_Game_ChangeMap(gNextMap
)
1575 else // Ñëåäóþùåé êàðòû íåò
1577 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1579 // Âûõîä â ãëàâíîå ìåíþ:
1581 g_GUI_ShowWindow('MainMenu');
1582 gMusic
.SetByName('MUSIC_MENU');
1584 gState
:= STATE_MENU
;
1587 // Ôèíàëüíàÿ êàðòèíêà:
1588 g_Game_ExecuteEvent('onwadend');
1590 if not gMusic
.SetByName('MUSIC_endmus') then
1591 gMusic
.SetByName('MUSIC_STDENDMUS');
1593 gState
:= STATE_ENDPIC
;
1595 g_Game_ExecuteEvent('ongameend');
1601 if gState
= STATE_INTERTEXT
then
1602 if InterText
.counter
> 0 then
1603 InterText
.counter
:= InterText
.counter
- 1;
1606 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1608 if EndingGameCounter
= 0 then
1610 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1611 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1613 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1615 g_Game_ExecuteEvent('onwadend');
1616 if not gMusic
.SetByName('MUSIC_endmus') then
1617 gMusic
.SetByName('MUSIC_STDENDMUS');
1620 gMusic
.SetByName('MUSIC_ROUNDMUS');
1623 gState
:= STATE_INTERCUSTOM
;
1625 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1627 gMusic
.SetByName('MUSIC_INTERMUS');
1629 gState
:= STATE_INTERSINGLE
;
1631 g_Game_ExecuteEvent('oninter');
1634 DecMin(EndingGameCounter
, 6, 0);
1637 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1639 if gMapOnce
then // Ýòî áûë òåñò
1641 gExit
:= EXIT_SIMPLE
;
1647 g_Serverlist_Control(slCurrent
);
1650 if g_Game_IsNet
then
1651 if not gConsoleShow
then
1652 if not gChatShow
then
1654 if g_ActiveWindow
= nil then
1656 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1657 g_Console_Chat_Switch(False)
1658 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1659 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1660 g_Console_Chat_Switch(True);
1663 if not gChatEnter
then
1664 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1665 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1668 // Ñòàòèñòèêà ïî Tab:
1670 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1671 (gGameSettings
.GameType
<> GT_SINGLE
) and
1672 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1675 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1677 // Âðåìÿ += 28 ìèëëèñåêóíä:
1678 gTime
:= gTime
+ GAME_TICK
;
1680 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1681 if MessageTime
= 0 then
1683 if MessageTime
> 0 then
1684 MessageTime
:= MessageTime
- 1;
1686 if (g_Game_IsServer
) then
1688 // Áûë çàäàí ëèìèò âðåìåíè:
1689 if (gGameSettings
.TimeLimit
> 0) then
1690 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1691 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1696 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1697 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1698 g_Game_RestartRound(gLMSSoftSpawn
);
1700 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1701 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1703 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1705 g_Console_Process(gVoteCommand
);
1707 gVotePassed
:= False;
1710 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1711 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1712 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1713 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1714 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1716 // Áûë çàäàí ëèìèò ïîáåä:
1717 if (gGameSettings
.GoalLimit
> 0) then
1721 if gGameSettings
.GameMode
= GM_DM
then
1722 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1723 for i
:= 0 to High(gPlayers
) do
1724 if gPlayers
[i
] <> nil then
1725 if gPlayers
[i
].Frags
> b
then
1726 b
:= gPlayers
[i
].Frags
;
1729 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1730 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1731 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1734 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1735 if b
>= gGameSettings
.GoalLimit
then
1742 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1743 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1744 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1745 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1747 processPlayerControls(gPlayer1
, gGameControls
.P1Control
, P1MoveButton
);
1748 processPlayerControls(gPlayer2
, gGameControls
.P2Control
, P2MoveButton
, true);
1749 end // if not console
1752 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1754 // process weapon switch queue
1758 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1759 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1761 if not gSpectKeyPress
then
1763 if isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
) then
1765 // switch spect mode
1767 SPECT_NONE
: ; // not spectator
1769 SPECT_MAPVIEW
: Inc(gSpectMode
);
1770 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1772 gSpectKeyPress
:= True;
1774 if gSpectMode
= SPECT_MAPVIEW
then
1776 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1777 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1778 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1779 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1780 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1781 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1782 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1783 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1784 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1787 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1788 gSpectKeyPress
:= True;
1790 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1793 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1794 gSpectKeyPress
:= True;
1797 if gSpectMode
= SPECT_PLAYERS
then
1799 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1802 gSpectViewTwo
:= True;
1803 gSpectKeyPress
:= True;
1805 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1807 // remove second view
1808 gSpectViewTwo
:= False;
1809 gSpectKeyPress
:= True;
1811 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1813 // prev player (view 1)
1814 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1815 gSpectKeyPress
:= True;
1817 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1819 // next player (view 1)
1820 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1821 gSpectKeyPress
:= True;
1823 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1825 // prev player (view 2)
1826 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1827 gSpectKeyPress
:= True;
1829 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1831 // next player (view 2)
1832 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1833 gSpectKeyPress
:= True;
1838 if (not isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)) and
1839 (not isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
)) and
1840 (not isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
)) and
1841 (not isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
)) and
1842 (not isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
)) and
1843 (not isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
)) and
1844 (not isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
)) then
1845 gSpectKeyPress
:= False;
1848 // Îáíîâëÿåì âñå îñòàëüíîå:
1851 g_Triggers_Update();
1853 g_Monsters_Update();
1855 g_Player_UpdateAll();
1856 g_Player_UpdatePhysicalObjects();
1858 // server: send newly spawned monsters unconditionally
1859 if (gGameSettings
.GameType
= GT_SERVER
) then
1861 if (Length(gMonstersSpawned
) > 0) then
1863 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1864 SetLength(gMonstersSpawned
, 0);
1868 if (gSoundTriggerTime
> 8) then
1870 g_Game_UpdateTriggerSounds();
1871 gSoundTriggerTime
:= 0;
1875 Inc(gSoundTriggerTime
);
1878 if (NetMode
= NET_SERVER
) then
1880 Inc(NetTimeToUpdate
);
1881 Inc(NetTimeToReliable
);
1883 // send monster updates
1884 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
1886 // send all monsters (periodic sync)
1887 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
1889 for I
:= 0 to High(gPlayers
) do
1891 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
1894 g_Mons_ForEach(sendMonsPos
);
1896 if reliableUpdate
then
1898 NetTimeToReliable
:= 0;
1899 NetTimeToUpdate
:= NetUpdateRate
;
1903 NetTimeToUpdate
:= 0;
1908 // send only mosters with some unexpected changes
1909 g_Mons_ForEach(sendMonsPosUnexpected
);
1912 // send unexpected platform changes
1913 g_Map_NetSendInterestingPanels();
1915 if NetUseMaster
then
1917 if gTime
>= NetTimeToMaster
then
1919 if (NetMHost
= nil) or (NetMPeer
= nil) then
1921 if not g_Net_Slist_Connect
then g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1925 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1929 else if (NetMode
= NET_CLIENT
) then
1931 MC_SEND_PlayerPos();
1933 end; // if gameOn ...
1935 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1936 if g_ActiveWindow
<> nil then
1938 w
:= e_GetFirstKeyPressed();
1940 if (w
<> IK_INVALID
) then
1942 Msg
.Msg
:= MESSAGE_DIKEY
;
1944 g_ActiveWindow
.OnMessage(Msg
);
1947 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1948 if g_ActiveWindow
<> nil then
1949 g_ActiveWindow
.Update();
1951 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1952 if gResolutionChange
then
1954 e_WriteLog('Changing resolution', MSG_NOTIFY
);
1955 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1956 gResolutionChange
:= False;
1959 // Íóæíî ñìåíèòü ÿçûê:
1960 if gLanguageChange
then
1962 //e_WriteLog('Read language file', MSG_NOTIFY);
1963 //g_Language_Load(DataDir + gLanguage + '.txt');
1964 g_Language_Set(gLanguage
);
1966 gLanguageChange
:= False;
1970 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1971 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
1972 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
1975 LastScreenShot
:= GetTimer();
1978 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
1979 if e_KeyPressed(IK_F10
) and
1981 (not gConsoleShow
) and
1982 (g_ActiveWindow
= nil) then
1987 Time
:= GetTimer() {div 1000};
1989 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
1990 if gDelayedEvents
<> nil then
1991 for a
:= 0 to High(gDelayedEvents
) do
1992 if gDelayedEvents
[a
].Pending
and
1994 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
1995 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
1998 case gDelayedEvents
[a
].DEType
of
2000 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2003 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2007 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2008 if g_Game_IsNet
and g_Game_IsServer
then
2009 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2012 gDelayedEvents
[a
].Pending
:= False;
2015 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2016 UPSCounter
:= UPSCounter
+ 1;
2017 if Time
- UPSTime
>= 1000 then
2026 g_Weapon_AddDynLights();
2027 g_Items_AddDynLights();
2031 procedure g_Game_LoadData();
2033 if DataLoaded
then Exit
;
2035 e_WriteLog('Loading game data...', MSG_NOTIFY
);
2037 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2038 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2039 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2040 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2041 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2042 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2043 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_RB', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2044 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_RS', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2045 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_RD', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2046 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_BB', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2047 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_BS', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2048 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_BD', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2049 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2050 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2051 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2052 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2053 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2054 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2055 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2056 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2057 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2058 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2059 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2060 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2061 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2062 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2063 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2064 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2065 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2066 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2067 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2068 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2069 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2070 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2072 goodsnd
[0] := TPlayableSound
.Create();
2073 goodsnd
[1] := TPlayableSound
.Create();
2074 goodsnd
[2] := TPlayableSound
.Create();
2075 goodsnd
[3] := TPlayableSound
.Create();
2077 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2078 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2079 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2080 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2082 killsnd
[0] := TPlayableSound
.Create();
2083 killsnd
[1] := TPlayableSound
.Create();
2084 killsnd
[2] := TPlayableSound
.Create();
2085 killsnd
[3] := TPlayableSound
.Create();
2087 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2088 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2089 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2090 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2092 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2095 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2096 g_Weapon_LoadData();
2098 g_Monsters_LoadData();
2103 procedure g_Game_FreeData();
2105 if not DataLoaded
then Exit
;
2108 g_Weapon_FreeData();
2109 g_Monsters_FreeData();
2111 e_WriteLog('Releasing game data...', MSG_NOTIFY
);
2113 g_Texture_Delete('NOTEXTURE');
2114 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2115 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2116 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2117 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2118 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2119 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2120 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2121 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2122 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2123 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2124 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2125 g_Frames_DeleteByName('FRAMES_TELEPORT');
2126 g_Sound_Delete('SOUND_GAME_TELEPORT');
2127 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2128 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2129 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2130 g_Sound_Delete('SOUND_GAME_BULK1');
2131 g_Sound_Delete('SOUND_GAME_BULK2');
2132 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2133 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2134 g_Sound_Delete('SOUND_GAME_SWITCH1');
2135 g_Sound_Delete('SOUND_GAME_SWITCH0');
2142 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2143 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2144 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2145 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2152 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2153 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2154 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2155 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2157 DataLoaded
:= False;
2160 procedure DrawCustomStat();
2166 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2167 s1
, s2
, topstr
: String;
2169 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2172 if e_KeyPressed(IK_TAB
) then
2174 if not gStatsPressed
then
2176 gStatsOff
:= not gStatsOff
;
2177 gStatsPressed
:= True;
2181 gStatsPressed
:= False;
2185 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2186 w
:= (Length(s1
) * ww2
) div 2;
2187 x
:= gScreenWidth
div 2 - w
;
2189 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2193 if (gGameSettings
.GameMode
= GM_COOP
) then
2195 if gMissionFailed
then
2196 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2198 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2201 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2203 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2204 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2206 if g_Game_IsNet
then
2208 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2209 if not gChatShow
then
2210 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2211 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2214 if g_Game_IsClient
then
2215 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2217 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2218 if not gChatShow
then
2219 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2220 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2225 w
:= gScreenWidth
-x
*2;
2231 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2232 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2234 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2236 case CustomStat
.GameMode
of
2239 if gGameSettings
.MaxLives
= 0 then
2240 s1
:= _lc
[I_GAME_DM
]
2242 s1
:= _lc
[I_GAME_LMS
];
2246 if gGameSettings
.MaxLives
= 0 then
2247 s1
:= _lc
[I_GAME_TDM
]
2249 s1
:= _lc
[I_GAME_TLMS
];
2251 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2254 if gGameSettings
.MaxLives
= 0 then
2255 s1
:= _lc
[I_GAME_COOP
]
2257 s1
:= _lc
[I_GAME_SURV
];
2263 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2267 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2268 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2271 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2272 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2273 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2274 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2276 pc
:= Length(CustomStat
.PlayerStat
);
2277 if pc
= 0 then Exit
;
2279 if CustomStat
.GameMode
= GM_COOP
then
2281 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2283 s2
:= _lc
[I_GAME_MONSTERS
];
2284 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2285 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2287 s2
:= _lc
[I_GAME_SECRETS
];
2288 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2289 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2292 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2294 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2295 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2296 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2298 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2299 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2300 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2304 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2309 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2310 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2311 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2313 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2316 for t
:= TEAM_RED
to TEAM_BLUE
do
2318 if t
= TEAM_RED
then
2320 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2321 gStdFont
, 255, 0, 0, 1);
2322 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2323 gStdFont
, 255, 0, 0, 1);
2330 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2331 gStdFont
, 0, 0, 255, 1);
2332 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2333 gStdFont
, 0, 0, 255, 1);
2339 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2342 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2343 if CustomStat
.PlayerStat
[p
].Team
= t
then
2344 with CustomStat
.PlayerStat
[p
] do
2358 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2359 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2360 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2367 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2370 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2371 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2372 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2375 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2376 with CustomStat
.PlayerStat
[p
] do
2378 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2385 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2386 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2387 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2393 procedure DrawSingleStat();
2395 tm
, key_x
, val_x
, y
: Integer;
2399 procedure player_stat(n
: Integer);
2405 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2406 s2
:= Format(' %d', [gTotalMonsters
]);
2408 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2409 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2410 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2411 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2413 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2414 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2416 // "Kills-per-minute: ##.#":
2417 s1
:= _lc
[I_MENU_INTER_KPM
];
2419 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2421 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2422 s2
:= Format(' %.1f', [kpm
]);
2424 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2425 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2427 // "Secrets found: # / #":
2428 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2429 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2431 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2432 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2433 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2434 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2436 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2437 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2441 // "Level Complete":
2442 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2443 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2445 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2446 s1
:= _lc
[I_MENU_INTER_KPM
];
2447 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2450 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2452 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2453 val_x
:= key_x
+ w1
;
2456 tm
:= SingleStat
.GameTime
div 1000;
2457 s1
:= _lc
[I_MENU_INTER_TIME
];
2458 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2460 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2461 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2463 if SingleStat
.TwoPlayers
then
2466 s1
:= _lc
[I_MENU_PLAYER_1
];
2467 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2468 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2470 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2475 s1
:= _lc
[I_MENU_PLAYER_2
];
2476 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2477 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2479 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2485 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2491 procedure DrawLoadingStat();
2497 if Length(LoadingStat
.Msgs
) = 0 then
2500 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2501 yy
:= (gScreenHeight
div 3);
2502 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2503 xx
:= (gScreenWidth
div 3);
2506 for i
:= 0 to NextMsg
-1 do
2508 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2509 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2513 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2514 yy
:= yy
+ LOADING_INTERLINE
;
2518 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2520 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2522 function monDraw (mon
: TMonster
): Boolean;
2524 result
:= false; // don't stop
2529 // Ëåâûé âåðõíèé óãîë
2530 aX
:= Obj
.X
div ScaleSz
+ 1;
2531 aY
:= Obj
.Y
div ScaleSz
+ 1;
2533 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2534 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2535 // Ïðàâûé íèæíèé óãîë
2536 aX2
:= aX
+ aX2
- 1;
2537 aY2
:= aY
+ aY2
- 1;
2538 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2544 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2545 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2548 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2549 ScaleSz
:= 16 div Scale
;
2550 // Ðàçìåðû ìèíè-êàðòû:
2551 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2552 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2554 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2556 if gWalls
<> nil then
2559 for a
:= 0 to High(gWalls
) do
2561 if PanelType
<> 0 then
2563 // Ëåâûé âåðõíèé óãîë:
2564 aX
:= X
div ScaleSz
;
2565 aY
:= Y
div ScaleSz
;
2567 aX2
:= max(Width
div ScaleSz
, 1);
2568 aY2
:= max(Height
div ScaleSz
, 1);
2569 // Ïðàâûé íèæíèé óãîë:
2570 aX2
:= aX
+ aX2
- 1;
2571 aY2
:= aY
+ aY2
- 1;
2574 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2575 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2576 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2580 if gSteps
<> nil then
2583 for a
:= 0 to High(gSteps
) do
2585 if PanelType
<> 0 then
2587 // Ëåâûé âåðõíèé óãîë:
2588 aX
:= X
div ScaleSz
;
2589 aY
:= Y
div ScaleSz
;
2591 aX2
:= max(Width
div ScaleSz
, 1);
2592 aY2
:= max(Height
div ScaleSz
, 1);
2593 // Ïðàâûé íèæíèé óãîë:
2594 aX2
:= aX
+ aX2
- 1;
2595 aY2
:= aY
+ aY2
- 1;
2597 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2600 if gLifts
<> nil then
2603 for a
:= 0 to High(gLifts
) do
2605 if PanelType
<> 0 then
2607 // Ëåâûé âåðõíèé óãîë:
2608 aX
:= X
div ScaleSz
;
2609 aY
:= Y
div ScaleSz
;
2611 aX2
:= max(Width
div ScaleSz
, 1);
2612 aY2
:= max(Height
div ScaleSz
, 1);
2613 // Ïðàâûé íèæíèé óãîë:
2614 aX2
:= aX
+ aX2
- 1;
2615 aY2
:= aY
+ aY2
- 1;
2618 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2619 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2620 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2621 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2625 if gWater
<> nil then
2628 for a
:= 0 to High(gWater
) do
2630 if PanelType
<> 0 then
2632 // Ëåâûé âåðõíèé óãîë:
2633 aX
:= X
div ScaleSz
;
2634 aY
:= Y
div ScaleSz
;
2636 aX2
:= max(Width
div ScaleSz
, 1);
2637 aY2
:= max(Height
div ScaleSz
, 1);
2638 // Ïðàâûé íèæíèé óãîë:
2639 aX2
:= aX
+ aX2
- 1;
2640 aY2
:= aY
+ aY2
- 1;
2642 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2645 if gAcid1
<> nil then
2647 // Ðèñóåì êèñëîòó 1:
2648 for a
:= 0 to High(gAcid1
) do
2650 if PanelType
<> 0 then
2652 // Ëåâûé âåðõíèé óãîë:
2653 aX
:= X
div ScaleSz
;
2654 aY
:= Y
div ScaleSz
;
2656 aX2
:= max(Width
div ScaleSz
, 1);
2657 aY2
:= max(Height
div ScaleSz
, 1);
2658 // Ïðàâûé íèæíèé óãîë:
2659 aX2
:= aX
+ aX2
- 1;
2660 aY2
:= aY
+ aY2
- 1;
2662 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2665 if gAcid2
<> nil then
2667 // Ðèñóåì êèñëîòó 2:
2668 for a
:= 0 to High(gAcid2
) do
2670 if PanelType
<> 0 then
2672 // Ëåâûé âåðõíèé óãîë:
2673 aX
:= X
div ScaleSz
;
2674 aY
:= Y
div ScaleSz
;
2676 aX2
:= max(Width
div ScaleSz
, 1);
2677 aY2
:= max(Height
div ScaleSz
, 1);
2678 // Ïðàâûé íèæíèé óãîë:
2679 aX2
:= aX
+ aX2
- 1;
2680 aY2
:= aY
+ aY2
- 1;
2682 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2685 if gPlayers
<> nil then
2688 for a
:= 0 to High(gPlayers
) do
2689 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2691 // Ëåâûé âåðõíèé óãîë:
2692 aX
:= Obj
.X
div ScaleSz
+ 1;
2693 aY
:= Obj
.Y
div ScaleSz
+ 1;
2695 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2696 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2697 // Ïðàâûé íèæíèé óãîë:
2698 aX2
:= aX
+ aX2
- 1;
2699 aY2
:= aY
+ aY2
- 1;
2701 if gPlayers
[a
] = p
then
2702 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2705 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2706 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2707 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2712 g_Mons_ForEach(monDraw
);
2717 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
2719 if not hasAmbient
then exit
;
2720 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
2724 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
2725 //FIXME: broken for splitscreen mode
2726 procedure renderDynLightsInternal ();
2728 //hasAmbient: Boolean;
2729 //ambColor: TDFColor;
2731 lx
, ly
, lrad
: Integer;
2732 scxywh
: array[0..3] of GLint
;
2735 if e_NoGraphics
then exit
;
2737 //TODO: lights should be in separate grid, i think
2738 // but on the other side: grid may be slower for dynlights, as their lifetime is short
2739 if (not g_playerLight
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
2742 //ambColor := gCurrentMap['light_ambient'].rgba;
2743 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
2745 { // this will multiply incoming color to alpha from framebuffer
2747 glBlendFunc(GL_DST_ALPHA, GL_ONE);
2751 * light rendering: (INVALID!)
2752 * glStencilFunc(GL_EQUAL, 0, $ff);
2754 * glClear(GL_STENCIL_BUFFER_BIT);
2755 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
2756 * draw shadow volume into stencil buffer
2757 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
2758 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
2760 * draw color-less quad with light alpha (WARNING! don't touch color!)
2761 * glEnable(GL_BLEND);
2762 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
2763 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
2766 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
2767 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
2769 // setup OpenGL parameters
2770 glStencilMask($FFFFFFFF);
2771 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
2772 glEnable(GL_STENCIL_TEST
);
2773 glEnable(GL_SCISSOR_TEST
);
2774 glClear(GL_STENCIL_BUFFER_BIT
);
2775 glStencilFunc(GL_EQUAL
, 0, $ff);
2777 for lln
:= 0 to g_dynLightCount
-1 do
2779 lx
:= g_dynLights
[lln
].x
;
2780 ly
:= g_dynLights
[lln
].y
;
2781 lrad
:= g_dynLights
[lln
].radius
;
2782 if (lrad
< 3) then continue
;
2784 if (lx
-sX
+lrad
< 0) then continue
;
2785 if (ly
-sY
+lrad
< 0) then continue
;
2786 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
2787 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
2789 // set scissor to optimize drawing
2790 if (g_dbg_scale
= 1.0) then
2792 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
2796 glScissor(0, 0, gWinSizeX
, gWinSizeY
);
2798 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
2799 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
2800 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
2801 // draw extruded panels
2802 glDisable(GL_TEXTURE_2D
);
2803 glDisable(GL_BLEND
);
2804 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
2805 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
2806 // render light texture
2807 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
2808 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
2811 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
2812 glEnable(GL_TEXTURE_2D
);
2813 // color and opacity
2814 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
2815 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
2817 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
2818 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
2819 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
2820 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
2825 glDisable(GL_STENCIL_TEST
);
2826 glDisable(GL_BLEND
);
2827 glDisable(GL_SCISSOR_TEST
);
2828 //glScissor(0, 0, sWidth, sHeight);
2830 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
2831 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
2835 function fixViewportForScale (): Boolean;
2837 nx0
, ny0
, nw
, nh
: Integer;
2840 if (g_dbg_scale
<> 1.0) then
2843 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
2844 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
2845 nw
:= round(sWidth
/g_dbg_scale
);
2846 nh
:= round(sHeight
/g_dbg_scale
);
2855 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
2856 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
2857 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
2859 TDrawCB
= procedure ();
2862 hasAmbient
: Boolean;
2864 doAmbient
: Boolean = false;
2866 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
2871 profileFrameDraw
.sectionBegin(profname
);
2872 if gdbg_map_use_accel_render
then
2874 tagmask
:= panelTypeToTag(panType
);
2875 while (gDrawPanelList
.count
> 0) do
2877 pan
:= TPanel(gDrawPanelList
.front());
2878 if ((pan
.tag
and tagmask
) = 0) then break
;
2879 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
2880 gDrawPanelList
.popFront();
2885 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
2887 profileFrameDraw
.sectionEnd();
2890 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
2892 profileFrameDraw
.sectionBegin(profname
);
2893 if assigned(cb
) then cb();
2894 profileFrameDraw
.sectionEnd();
2898 profileFrameDraw
.sectionBegin('total');
2900 // our accelerated renderer will collect all panels to gDrawPanelList
2901 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
2902 profileFrameDraw
.sectionBegin('collect');
2903 if gdbg_map_use_accel_render
then
2905 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
2907 profileFrameDraw
.sectionEnd();
2909 profileFrameDraw
.sectionBegin('skyback');
2910 g_Map_DrawBack(backXOfs
, backYOfs
);
2911 profileFrameDraw
.sectionEnd();
2913 if setTransMatrix
then
2915 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
2916 glTranslatef(-sX
, -sY
, 0);
2920 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
2921 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
2926 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
2927 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
2928 glClear(GL_COLOR_BUFFER_BIT);
2931 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
2934 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
2935 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
2936 drawOther('items', @g_Items_Draw
);
2937 drawOther('weapons', @g_Weapon_Draw
);
2938 drawOther('shells', @g_Player_DrawShells
);
2939 drawOther('drawall', @g_Player_DrawAll
);
2940 drawOther('corpses', @g_Player_DrawCorpses
);
2941 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
2942 drawOther('monsters', @g_Monsters_Draw
);
2943 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
2944 drawOther('gfx', @g_GFX_Draw
);
2945 drawOther('flags', @g_Map_DrawFlags
);
2946 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
2947 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
2948 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
2949 drawOther('dynlights', @renderDynLightsInternal
);
2951 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
2953 renderAmbientQuad(hasAmbient
, ambColor
);
2957 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
2960 if g_debug_HealthBar
then
2962 g_Monsters_DrawHealth();
2963 g_Player_DrawHealth();
2966 profileFrameDraw
.mainEnd(); // map rendering
2970 procedure DrawMapView(x
, y
, w
, h
: Integer);
2977 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
2978 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
2985 fixViewportForScale();
2986 renderMapInternal(-bx
, -by
, true);
2992 procedure DrawPlayer(p
: TPlayer
);
2994 px
, py
, a
, b
, c
, d
: Integer;
2997 if (p
= nil) or (p
.FDummy
) then
3000 g_Map_DrawBack(0, 0);
3005 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3006 profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3012 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3013 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3015 if (g_dbg_scale
= 1.0) then
3017 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3018 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3020 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3021 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3023 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3024 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3027 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3030 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3031 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3034 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3039 // scaled, ignore level bounds
3040 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3041 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3044 if p
.IncCam
<> 0 then
3046 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
3048 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
3050 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
3054 if py
< gPlayerScreenSize
.Y
div 2 then
3056 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
3058 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
3062 if p
.IncCam
< 0 then
3064 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
3067 if p
.IncCam
> 0 then
3069 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
3073 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
3074 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
3075 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
3077 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
3078 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
3079 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
3082 sY
:= -(b
+p
.IncCam
);
3083 sWidth
:= gPlayerScreenSize
.X
;
3084 sHeight
:= gPlayerScreenSize
.Y
;
3086 //glTranslatef(a, b+p.IncCam, 0);
3088 if (p
= gPlayer1
) then g_Holmes_plrViewSize(sWidth
, sHeight
);
3090 fixViewportForScale();
3093 p
.viewPortW
:= sWidth
;
3094 p
.viewPortH
:= sHeight
;
3096 if (p
= gPlayer1
) then g_Holmes_plrViewPos(sX
, sY
);
3098 renderMapInternal(-c
, -d
, true);
3100 if p
.FSpectator
then
3101 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3102 p
.GameY
+ PLAYER_RECT_CY
- 4,
3103 'X', gStdFont
, 255, 255, 255, 1, True);
3105 for a := 0 to High(gCollideMap) do
3106 for b := 0 to High(gCollideMap[a]) do
3109 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3111 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3115 1: e_DrawPoint(1, b, a, 200, 200, 200);
3116 2: e_DrawPoint(1, b, a, 64, 64, 255);
3117 3: e_DrawPoint(1, b, a, 255, 0, 255);
3127 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3128 if g_Debug_Player
then
3129 g_Player_DrawDebug(p
);
3133 procedure drawProfilers ();
3138 if g_profile_frame_draw
then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3139 if g_profile_collision
then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3140 if g_profile_los
then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3143 procedure g_Game_Draw();
3150 plView1
, plView2
: TPlayer
;
3153 if gExit
= EXIT_QUIT
then Exit
;
3155 Time
:= GetTimer() {div 1000};
3156 FPSCounter
:= FPSCounter
+1;
3157 if Time
- FPSTime
>= 1000 then
3164 if gGameOn
or (gState
= STATE_FOLD
) then
3166 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3168 gSpectMode
:= SPECT_NONE
;
3169 if not gRevertPlayers
then
3171 plView1
:= gPlayer1
;
3172 plView2
:= gPlayer2
;
3176 plView1
:= gPlayer2
;
3177 plView2
:= gPlayer1
;
3181 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3183 gSpectMode
:= SPECT_NONE
;
3184 if gPlayer2
= nil then
3187 plView1
:= gPlayer2
;
3196 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3197 gSpectMode
:= SPECT_STATS
;
3199 if gSpectMode
= SPECT_PLAYERS
then
3200 if gPlayers
<> nil then
3202 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3203 if plView1
= nil then
3205 gSpectPID1
:= GetActivePlayerID_Next();
3206 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3208 if gSpectViewTwo
then
3210 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3211 if plView2
= nil then
3213 gSpectPID2
:= GetActivePlayerID_Next();
3214 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3219 if gSpectMode
= SPECT_MAPVIEW
then
3221 // Ðåæèì ïðîñìîòðà êàðòû
3223 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3224 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3225 gHearPoint1
.Active
:= True;
3226 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3227 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3228 gHearPoint2
.Active
:= False;
3232 Split
:= (plView1
<> nil) and (plView2
<> nil);
3234 // Òî÷êè ñëóõà èãðîêîâ
3235 if plView1
<> nil then
3237 gHearPoint1
.Active
:= True;
3238 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
3239 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
3241 gHearPoint1
.Active
:= False;
3242 if plView2
<> nil then
3244 gHearPoint2
.Active
:= True;
3245 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
3246 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
3248 gHearPoint2
.Active
:= False;
3250 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3251 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3254 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3255 if gScreenHeight
mod 2 = 0 then
3256 Dec(gPlayerScreenSize
.Y
);
3259 gPlayerScreenSize
.Y
:= gScreenHeight
;
3262 if gScreenHeight
mod 2 = 0 then
3263 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3265 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3267 DrawPlayer(plView1
);
3268 gPlayer1ScreenCoord
.X
:= sX
;
3269 gPlayer1ScreenCoord
.Y
:= sY
;
3273 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3275 DrawPlayer(plView2
);
3276 gPlayer2ScreenCoord
.X
:= sX
;
3277 gPlayer2ScreenCoord
.Y
:= sY
;
3280 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3283 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3286 if MessageText
<> '' then
3290 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3292 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3293 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3295 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3296 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3299 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3301 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
3303 // Draw spectator GUI
3306 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3309 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3311 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3313 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3315 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3316 if gSpectMode
= SPECT_MAPVIEW
then
3318 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
3319 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
3320 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
3321 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
3322 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
3324 if gSpectMode
= SPECT_PLAYERS
then
3326 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
3327 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
3328 if gSpectViewTwo
then
3330 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
3331 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
3332 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3333 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3337 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3338 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3344 if gPause
and gGameOn
and (g_ActiveWindow
= nil) then
3346 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3347 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3349 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
3350 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3351 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
3356 if (gState
= STATE_MENU
) then
3358 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then
3360 if g_Texture_Get('MENU_BACKGROUND', ID
) then e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3361 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3363 // F3 at menu will show game loading dialog
3364 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
3365 if (g_ActiveWindow
<> nil) then
3367 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3368 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3372 // F3 at titlepic will show game loading dialog
3373 if e_KeyPressed(IK_F3
) then
3375 g_Menu_Show_LoadMenu(true);
3376 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3381 if gState
= STATE_FOLD
then
3383 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3386 if gState
= STATE_INTERCUSTOM
then
3388 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
3390 back
:= 'TEXTURE_endpic';
3391 if not g_Texture_Get(back
, ID
) then
3392 back
:= _lc
[I_TEXTURE_ENDPIC
];
3397 if g_Texture_Get(back
, ID
) then
3398 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3400 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3404 if g_ActiveWindow
<> nil then
3406 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3407 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3411 if gState
= STATE_INTERSINGLE
then
3413 if EndingGameCounter
> 0 then
3415 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3421 if g_Texture_Get(back
, ID
) then
3422 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3424 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3428 if g_ActiveWindow
<> nil then
3430 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3431 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3436 if gState
= STATE_ENDPIC
then
3439 if not g_Texture_Get('TEXTURE_endpic', ID
) then
3440 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
3442 if ID
<> DWORD(-1) then
3443 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3445 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3447 if g_ActiveWindow
<> nil then
3449 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3450 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3454 if gState
= STATE_SLIST
then
3456 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3458 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
3459 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3460 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3462 g_Serverlist_Draw(slCurrent
);
3466 if g_ActiveWindow
<> nil then
3470 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3471 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3473 g_ActiveWindow
.Draw();
3477 if (g_holmes_enabled
) then g_Holmes_Draw();
3481 if g_debug_Sounds
and gGameOn
then
3483 for w
:= 0 to High(e_SoundsArray
) do
3484 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
3485 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
3490 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3491 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3494 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3495 drawTime(gScreenWidth
-72, gScreenHeight
-16);
3497 if gGameOn
then drawProfilers();
3502 procedure g_Game_Quit();
3504 g_Game_StopAllSounds(True);
3506 g_Game_SaveOptions();
3508 g_PlayerModel_FreeData();
3509 g_Texture_DeleteAll();
3510 g_Frames_DeleteAll();
3513 if NetInitDone
then g_Net_Free
;
3515 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3516 if gMapToDelete
<> '' then
3517 g_Game_DeleteTestMap();
3523 procedure g_FatalError(Text: String);
3525 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3526 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), MSG_WARNING
);
3528 gExit
:= EXIT_SIMPLE
;
3531 procedure g_SimpleError(Text: String);
3533 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3534 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), MSG_WARNING
);
3537 procedure g_Game_SetupScreenSize();
3539 RES_FACTOR
= 4.0 / 3.0;
3545 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3546 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3547 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3548 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3550 gPlayerScreenSize
.Y
:= gScreenHeight
;
3552 // Ðàçìåð çàäíåãî ïëàíà:
3553 if BackID
<> DWORD(-1) then
3556 if (gScreenWidth
*s
> gMapInfo
.Width
) or
3557 (gScreenHeight
*s
> gMapInfo
.Height
) then
3559 gBackSize
.X
:= gScreenWidth
;
3560 gBackSize
.Y
:= gScreenHeight
;
3564 e_GetTextureSize(BackID
, @bw
, @bh
);
3565 rf
:= Single(bw
) / Single(bh
);
3566 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
3567 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
3568 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
3569 if (s
< 1.0) then s
:= 1.0;
3570 gBackSize
.X
:= Round(bw
*s
);
3571 gBackSize
.Y
:= Round(bh
*s
);
3576 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3578 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3581 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3583 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3584 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3586 if gPlayer1
= nil then
3588 if g_Game_IsClient
then
3590 if NetPlrUID1
> -1 then
3592 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3593 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3598 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3599 Team
:= gPlayer1Settings
.Team
;
3601 // Ñîçäàíèå ïåðâîãî èãðîêà:
3602 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3603 gPlayer1Settings
.Color
,
3605 if gPlayer1
= nil then
3606 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3609 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3610 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3611 if g_Game_IsServer
and g_Game_IsNet
then
3612 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3613 gPlayer1
.Respawn(False, True);
3615 if g_Game_IsNet
and NetUseMaster
then
3621 if gPlayer2
= nil then
3623 if g_Game_IsClient
then
3625 if NetPlrUID2
> -1 then
3626 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3630 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3631 Team
:= gPlayer2Settings
.Team
;
3633 // Ñîçäàíèå âòîðîãî èãðîêà:
3634 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3635 gPlayer2Settings
.Color
,
3637 if gPlayer2
= nil then
3638 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3641 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3642 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3643 if g_Game_IsServer
and g_Game_IsNet
then
3644 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3645 gPlayer2
.Respawn(False, True);
3647 if g_Game_IsNet
and NetUseMaster
then
3655 procedure g_Game_RemovePlayer();
3659 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3660 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3665 if g_Game_IsServer
then
3668 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3669 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3670 g_Player_Remove(Pl
.UID
);
3672 if g_Game_IsNet
and NetUseMaster
then
3681 if g_Game_IsServer
then
3684 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3685 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3686 g_Player_Remove(Pl
.UID
);
3688 if g_Game_IsNet
and NetUseMaster
then
3693 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3699 procedure g_Game_Spectate();
3701 g_Game_RemovePlayer();
3702 if gPlayer1
<> nil then
3703 g_Game_RemovePlayer();
3706 procedure g_Game_SpectateCenterView();
3708 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3709 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3712 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3718 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY
);
3720 g_Game_ClearLoading();
3723 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3726 gGameSettings
.GameType
:= GT_SINGLE
;
3727 gGameSettings
.MaxLives
:= 0;
3728 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3729 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3730 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3731 gSwitchGameMode
:= GM_SINGLE
;
3733 g_Game_ExecuteEvent('ongamestart');
3735 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3736 g_Game_SetupScreenSize();
3738 // Ñîçäàíèå ïåðâîãî èãðîêà:
3739 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3740 gPlayer1Settings
.Color
,
3741 gPlayer1Settings
.Team
, False));
3742 if gPlayer1
= nil then
3744 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3748 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3751 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3754 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3755 gPlayer2Settings
.Color
,
3756 gPlayer2Settings
.Team
, False));
3757 if gPlayer2
= nil then
3759 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3763 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3767 // Çàãðóçêà è çàïóñê êàðòû:
3768 if not g_Game_StartMap(MAP
, True) then
3770 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + MAP
]));
3774 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3778 for i
:= nPl
+1 to nPlayers
do
3779 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3782 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3783 TimeLimit
, GoalLimit
: Word;
3785 Options
: LongWord; nPlayers
: Byte);
3791 e_WriteLog('Starting custom game...', MSG_NOTIFY
);
3793 g_Game_ClearLoading();
3796 gGameSettings
.GameType
:= GT_CUSTOM
;
3797 gGameSettings
.GameMode
:= GameMode
;
3798 gSwitchGameMode
:= GameMode
;
3799 gGameSettings
.TimeLimit
:= TimeLimit
;
3800 gGameSettings
.GoalLimit
:= GoalLimit
;
3801 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3802 gGameSettings
.Options
:= Options
;
3804 gCoopTotalMonstersKilled
:= 0;
3805 gCoopTotalSecretsFound
:= 0;
3806 gCoopTotalMonsters
:= 0;
3807 gCoopTotalSecrets
:= 0;
3811 g_Game_ExecuteEvent('ongamestart');
3813 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3814 g_Game_SetupScreenSize();
3816 // Ðåæèì íàáëþäàòåëÿ:
3817 if nPlayers
= 0 then
3824 if nPlayers
>= 1 then
3826 // Ñîçäàíèå ïåðâîãî èãðîêà:
3827 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3828 gPlayer1Settings
.Color
,
3829 gPlayer1Settings
.Team
, False));
3830 if gPlayer1
= nil then
3832 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3836 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3840 if nPlayers
>= 2 then
3842 // Ñîçäàíèå âòîðîãî èãðîêà:
3843 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3844 gPlayer2Settings
.Color
,
3845 gPlayer2Settings
.Team
, False));
3846 if gPlayer2
= nil then
3848 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3852 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3856 // Çàãðóçêà è çàïóñê êàðòû:
3857 if not g_Game_StartMap(Map
, True) then
3859 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3863 // Íåò òî÷åê ïîÿâëåíèÿ:
3864 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3865 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3866 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3867 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3868 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3870 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3874 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3878 for i
:= nPl
+1 to nPlayers
do
3879 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3882 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3883 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3884 Options
: LongWord; nPlayers
: Byte;
3885 IPAddr
: LongWord; Port
: Word);
3889 e_WriteLog('Starting net game (server)...', MSG_NOTIFY
);
3891 g_Game_ClearLoading();
3894 gGameSettings
.GameType
:= GT_SERVER
;
3895 gGameSettings
.GameMode
:= GameMode
;
3896 gSwitchGameMode
:= GameMode
;
3897 gGameSettings
.TimeLimit
:= TimeLimit
;
3898 gGameSettings
.GoalLimit
:= GoalLimit
;
3899 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3900 gGameSettings
.Options
:= Options
;
3902 gCoopTotalMonstersKilled
:= 0;
3903 gCoopTotalSecretsFound
:= 0;
3904 gCoopTotalMonsters
:= 0;
3905 gCoopTotalSecrets
:= 0;
3909 g_Game_ExecuteEvent('ongamestart');
3911 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3912 g_Game_SetupScreenSize();
3914 // Ðåæèì íàáëþäàòåëÿ:
3915 if nPlayers
= 0 then
3921 if nPlayers
>= 1 then
3923 // Ñîçäàíèå ïåðâîãî èãðîêà:
3924 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3925 gPlayer1Settings
.Color
,
3926 gPlayer1Settings
.Team
, False));
3927 if gPlayer1
= nil then
3929 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3933 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3936 if nPlayers
>= 2 then
3938 // Ñîçäàíèå âòîðîãî èãðîêà:
3939 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3940 gPlayer2Settings
.Color
,
3941 gPlayer2Settings
.Team
, False));
3942 if gPlayer2
= nil then
3944 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3948 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3952 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3954 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
3958 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
3960 // Çàãðóçêà è çàïóñê êàðòû:
3961 if not g_Game_StartMap(Map
, True) then
3963 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3967 // Íåò òî÷åê ïîÿâëåíèÿ:
3968 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3969 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3970 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3971 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3972 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3974 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3978 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3981 NetState
:= NET_STATE_GAME
;
3984 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3999 e_WriteLog('Starting net game (client)...', MSG_NOTIFY
);
4000 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', MSG_NOTIFY
);
4002 g_Game_ClearLoading();
4005 gGameSettings
.GameType
:= GT_CLIENT
;
4007 gCoopTotalMonstersKilled
:= 0;
4008 gCoopTotalSecretsFound
:= 0;
4009 gCoopTotalMonsters
:= 0;
4010 gCoopTotalSecrets
:= 0;
4014 g_Game_ExecuteEvent('ongamestart');
4016 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4017 g_Game_SetupScreenSize();
4019 NetState
:= NET_STATE_AUTH
;
4021 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4023 if not g_Net_Connect(Addr
, Port
) then
4025 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4026 NetState
:= NET_STATE_NONE
;
4030 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4032 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4037 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
4039 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4041 Ptr
:= NetEvent
.packet
^.data
;
4042 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4045 MID
:= InMsg
.ReadByte();
4047 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4049 NetMyID
:= InMsg
.ReadByte();
4050 NetPlrUID1
:= InMsg
.ReadWord();
4052 WadName
:= InMsg
.ReadString();
4053 Map
:= InMsg
.ReadString();
4055 gWADHash
:= InMsg
.ReadMD5();
4057 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4058 gSwitchGameMode
:= gGameSettings
.GameMode
;
4059 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4060 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4061 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4062 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4063 T
:= InMsg
.ReadLongWord();
4065 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
4066 if newResPath
= '' then
4068 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4069 newResPath
:= g_Res_DownloadWAD(WadName
);
4070 if newResPath
= '' then
4072 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4073 enet_packet_destroy(NetEvent
.packet
);
4074 NetState
:= NET_STATE_NONE
;
4078 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
4080 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4081 gPlayer1Settings
.Color
,
4082 gPlayer1Settings
.Team
, False));
4084 if gPlayer1
= nil then
4086 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4088 enet_packet_destroy(NetEvent
.packet
);
4089 NetState
:= NET_STATE_NONE
;
4093 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4094 gPlayer1
.UID
:= NetPlrUID1
;
4095 gPlayer1
.Reset(True);
4097 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
4099 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4101 enet_packet_destroy(NetEvent
.packet
);
4102 NetState
:= NET_STATE_NONE
;
4110 enet_packet_destroy(NetEvent
.packet
);
4114 enet_packet_destroy(NetEvent
.packet
);
4117 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4120 if (NetEvent
.data
<= NET_DISC_MAX
) then
4121 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4122 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4128 ProcessLoading(true);
4132 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
4141 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4142 NetState
:= NET_STATE_NONE
;
4146 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4147 gLMSRespawnTime
:= 0;
4150 NetState
:= NET_STATE_GAME
;
4151 MC_SEND_FullStateRequest
;
4152 e_WriteLog('NET: Connection successful.', MSG_NOTIFY
);
4155 procedure g_Game_SaveOptions();
4157 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
4160 procedure g_Game_ChangeMap(const MapPath
: String);
4164 g_Game_ClearLoading();
4166 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4167 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4168 if gExitByTrigger
then
4171 gExitByTrigger
:= False;
4173 if not g_Game_StartMap(MapPath
, Force
) then
4174 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4177 procedure g_Game_Restart();
4181 if g_Game_IsClient
then
4183 map
:= g_ExtractFileName(gMapInfo
.Map
);
4187 g_Game_ClearLoading();
4188 g_Game_StartMap(Map
, True, gCurrentMapFileName
);
4191 function g_Game_StartMap(Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4193 NewWAD
, ResName
: String;
4196 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4197 g_Player_RemoveAllCorpses();
4199 if (not g_Game_IsClient
) and
4200 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4201 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4203 if gSwitchGameMode
= GM_CTF
then
4204 gGameSettings
.MaxLives
:= 0;
4205 gGameSettings
.GameMode
:= gSwitchGameMode
;
4208 gSwitchGameMode
:= gGameSettings
.GameMode
;
4210 g_Player_ResetTeams();
4212 if isWadPath(Map
) then
4214 NewWAD
:= g_ExtractWadName(Map
);
4215 ResName
:= g_ExtractFileName(Map
);
4216 if g_Game_IsServer
then
4218 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
4219 g_Game_LoadWAD(NewWAD
);
4221 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
4222 g_Game_ClientWAD(NewWAD
, gWADHash
);
4226 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
4229 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4231 gState
:= STATE_NONE
;
4232 g_ActiveWindow
:= nil;
4238 if gGameSettings
.GameMode
= GM_CTF
then
4240 g_Map_ResetFlag(FLAG_RED
);
4241 g_Map_ResetFlag(FLAG_BLUE
);
4242 // CTF, à ôëàãîâ íåò:
4243 if not g_Map_HaveFlagPoints() then
4244 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4249 gState
:= STATE_MENU
;
4256 NetTimeToUpdate
:= 1;
4257 NetTimeToReliable
:= 0;
4258 NetTimeToMaster
:= NetMasterRate
;
4259 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4260 gLMSRespawnTime
:= 0;
4261 gMissionFailed
:= False;
4264 gCoopMonstersKilled
:= 0;
4265 gCoopSecretsFound
:= 0;
4267 gVoteInProgress
:= False;
4268 gVotePassed
:= False;
4274 if not gGameOn
then Exit
;
4276 g_Game_SpectateCenterView();
4278 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
4280 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4281 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
4282 gLMSSoftSpawn
:= True;
4283 if NetMode
= NET_SERVER
then
4284 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
4286 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
4289 if NetMode
= NET_SERVER
then
4291 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
4294 if NetUseMaster
then
4296 if (NetMHost
= nil) or (NetMPeer
= nil) then
4297 if not g_Net_Slist_Connect
then
4298 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4303 if NetClients
<> nil then
4304 for I
:= 0 to High(NetClients
) do
4305 if NetClients
[I
].Used
then
4307 NetClients
[I
].Voted
:= False;
4308 if NetClients
[I
].RequestedFullUpdate
then
4310 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
4311 NetClients
[I
].RequestedFullUpdate
:= False;
4315 g_Net_UnbanNonPermHosts();
4320 gCoopTotalMonstersKilled
:= 0;
4321 gCoopTotalSecretsFound
:= 0;
4322 gCoopTotalMonsters
:= 0;
4323 gCoopTotalSecrets
:= 0;
4327 g_Game_ExecuteEvent('onmapstart');
4330 procedure SetFirstLevel();
4334 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4335 if MapList
= nil then
4338 SortSArray(MapList
);
4339 gNextMap
:= MapList
[Low(MapList
)];
4344 procedure g_Game_ExitLevel(const Map
: AnsiString);
4348 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
4349 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
4350 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
4351 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
4353 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4354 if gGameSettings
.GameType
= GT_SINGLE
then
4355 gExit
:= EXIT_ENDLEVELSINGLE
4356 else // Âûøëè â âûõîä â Ñâîåé èãðå
4358 gExit
:= EXIT_ENDLEVELCUSTOM
;
4359 if gGameSettings
.GameMode
= GM_COOP
then
4360 g_Player_RememberAll
;
4362 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4365 if gGameSettings
.GameMode
= GM_COOP
then
4368 gStatsPressed
:= True;
4369 gNextMap
:= 'MAP01';
4371 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4374 if g_Game_IsNet
then
4376 MH_SEND_GameStats();
4377 MH_SEND_CoopStats();
4383 procedure g_Game_RestartLevel();
4387 if gGameSettings
.GameMode
= GM_SINGLE
then
4392 gExit
:= EXIT_ENDLEVELCUSTOM
;
4393 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4397 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
4401 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
4403 if not g_Game_IsClient
then
4405 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
4408 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4409 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
4413 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
4417 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
4418 g_Game_LoadWAD(NewWAD
);
4421 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
4423 i
, n
, nb
, nr
: Integer;
4425 function monRespawn (mon
: TMonster
): Boolean;
4427 result
:= false; // don't stop
4428 if not mon
.FNoRespawn
then mon
.Respawn();
4432 if not g_Game_IsServer
then Exit
;
4433 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
4434 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4435 gLMSRespawnTime
:= 0;
4438 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
4440 gMissionFailed
:= True;
4441 g_Game_RestartLevel
;
4445 n
:= 0; nb
:= 0; nr
:= 0;
4446 for i
:= Low(gPlayers
) to High(gPlayers
) do
4447 if (gPlayers
[i
] <> nil) and
4448 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
4449 (gPlayers
[i
] is TBot
)) then
4452 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
4453 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
4456 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
4458 // wait a second until the fuckers finally decide to join
4459 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4460 gLMSRespawnTime
:= gTime
+ 1000;
4461 gLMSSoftSpawn
:= NoMapRestart
;
4465 g_Player_RemoveAllCorpses
;
4466 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
4467 if g_Game_IsNet
then
4468 MH_SEND_GameEvent(NET_EV_LMS_START
);
4470 for i
:= Low(gPlayers
) to High(gPlayers
) do
4472 if gPlayers
[i
] = nil then continue
;
4473 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
4474 // don't touch normal spectators
4475 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
4477 gPlayers
[i
].FNoRespawn
:= True;
4478 gPlayers
[i
].Lives
:= 0;
4479 if g_Game_IsNet
then
4480 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
4483 gPlayers
[i
].FNoRespawn
:= False;
4484 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
4485 gPlayers
[i
].Respawn(False, True);
4486 if gGameSettings
.GameMode
= GM_COOP
then
4488 gPlayers
[i
].Frags
:= 0;
4489 gPlayers
[i
].RecallState
;
4491 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
4492 gPlayer1
:= g_Player_Get(gLMSPID1
);
4493 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
4494 gPlayer2
:= g_Player_Get(gLMSPID2
);
4497 g_Items_RestartRound();
4500 g_Mons_ForEach(monRespawn
);
4502 gLMSSoftSpawn
:= False;
4505 function g_Game_GetFirstMap(WAD
: String): String;
4509 MapList
:= g_Map_GetMapsList(WAD
);
4510 if MapList
= nil then
4513 SortSArray(MapList
);
4514 Result
:= MapList
[Low(MapList
)];
4516 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4522 function g_Game_GetNextMap(): String;
4529 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4530 if MapList
= nil then
4533 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4535 SortSArray(MapList
);
4537 for I
:= Low(MapList
) to High(MapList
) do
4538 if Map
= MapList
[I
] then
4544 if MapIndex
<> -255 then
4546 if MapIndex
= High(MapList
) then
4547 Result
:= MapList
[Low(MapList
)]
4549 Result
:= MapList
[MapIndex
+ 1];
4551 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4557 procedure g_Game_NextLevel();
4559 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4560 gExit
:= EXIT_ENDLEVELCUSTOM
4563 gExit
:= EXIT_ENDLEVELSINGLE
;
4567 if gNextMap
<> '' then Exit
;
4568 gNextMap
:= g_Game_GetNextMap();
4571 function g_Game_IsTestMap(): Boolean;
4573 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4576 procedure g_Game_DeleteTestMap();
4579 //MapName: AnsiString;
4587 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
4588 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
4589 if (a
= 0) then exit
;
4591 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
4592 WadName
:= Copy(gMapToDelete
, 1, a
+3);
4593 Delete(gMapToDelete
, 1, a
+5);
4594 gMapToDelete
:= UpperCase(gMapToDelete
);
4596 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
4599 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4600 if MapName <> TEST_MAP_NAME then
4603 if not gTempDelete then
4605 time := g_GetFileTime(WadName);
4606 WAD := TWADFile.Create();
4609 if not WAD.ReadFile(WadName) then
4610 begin // Íåò òàêîãî WAD-ôàéëà
4615 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4617 MapList := WAD.GetResourcesList('');
4619 if MapList <> nil then
4620 for a := 0 to High(MapList) do
4621 if MapList[a] = MapName then
4623 // Óäàëÿåì è ñîõðàíÿåì:
4624 WAD.RemoveResource('', MapName);
4625 WAD.SaveTo(WadName);
4630 g_SetFileTime(WadName, time);
4633 if gTempDelete
then DeleteFile(WadName
);
4636 procedure GameCVars(P
: SArray
);
4639 stat
: TPlayerStatArray
;
4644 cmd
:= LowerCase(P
[0]);
4645 if cmd
= 'r_showfps' then
4647 if (Length(P
) > 1) and
4648 ((P
[1] = '1') or (P
[1] = '0')) then
4649 gShowFPS
:= (P
[1][1] = '1');
4652 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4654 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4656 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4658 with gGameSettings
do
4660 if (Length(P
) > 1) and
4661 ((P
[1] = '1') or (P
[1] = '0')) then
4663 if (P
[1][1] = '1') then
4664 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4666 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4669 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4670 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4672 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4674 if g_Game_IsNet
then MH_SEND_GameSettings
;
4677 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4679 with gGameSettings
do
4681 if (Length(P
) > 1) and
4682 ((P
[1] = '1') or (P
[1] = '0')) then
4684 if (P
[1][1] = '1') then
4685 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4687 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4690 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4691 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4693 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4695 if g_Game_IsNet
then MH_SEND_GameSettings
;
4698 else if cmd
= 'g_gamemode' then
4700 a
:= g_Game_TextToMode(P
[1]);
4701 if a
= GM_SINGLE
then a
:= GM_COOP
;
4702 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4704 gSwitchGameMode
:= a
;
4705 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4706 (gState
= STATE_INTERSINGLE
) then
4707 gSwitchGameMode
:= GM_SINGLE
;
4709 gGameSettings
.GameMode
:= gSwitchGameMode
;
4711 if gSwitchGameMode
= gGameSettings
.GameMode
then
4712 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4713 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4715 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4716 [g_Game_ModeToText(gGameSettings
.GameMode
),
4717 g_Game_ModeToText(gSwitchGameMode
)]));
4719 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4721 with gGameSettings
do
4723 if (Length(P
) > 1) and
4724 ((P
[1] = '1') or (P
[1] = '0')) then
4726 if (P
[1][1] = '1') then
4727 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4729 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4732 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4733 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4735 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4736 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4738 if g_Game_IsNet
then MH_SEND_GameSettings
;
4741 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4743 with gGameSettings
do
4745 if (Length(P
) > 1) and
4746 ((P
[1] = '1') or (P
[1] = '0')) then
4748 if (P
[1][1] = '1') then
4749 Options
:= Options
or GAME_OPTION_MONSTERS
4751 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4754 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4755 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4757 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
4758 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4760 if g_Game_IsNet
then MH_SEND_GameSettings
;
4763 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
4765 with gGameSettings
do
4767 if (Length(P
) > 1) and
4768 ((P
[1] = '1') or (P
[1] = '0')) then
4770 if (P
[1][1] = '1') then
4771 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
4773 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
4776 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
4777 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
4779 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
4781 if g_Game_IsNet
then MH_SEND_GameSettings
;
4784 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
4786 with gGameSettings
do
4788 if (Length(P
) > 1) and
4789 ((P
[1] = '1') or (P
[1] = '0')) then
4791 if (P
[1][1] = '1') then
4792 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
4794 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
4797 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
4798 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
4800 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
4802 if g_Game_IsNet
then MH_SEND_GameSettings
;
4805 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
4807 if Length(P
) > 1 then
4809 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
4810 gGameSettings
.WarmupTime
:= 30
4812 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
4815 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
4816 [gGameSettings
.WarmupTime
]));
4817 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4819 else if cmd
= 'net_interp' then
4821 if (Length(P
) > 1) then
4822 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
4824 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
4825 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4826 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
4827 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4830 else if cmd
= 'net_forceplayerupdate' then
4832 if (Length(P
) > 1) and
4833 ((P
[1] = '1') or (P
[1] = '0')) then
4834 NetForcePlayerUpdate
:= (P
[1][1] = '1');
4836 if NetForcePlayerUpdate
then
4837 g_Console_Add('net_forceplayerupdate = 1')
4839 g_Console_Add('net_forceplayerupdate = 0');
4840 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4841 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
4842 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4845 else if cmd
= 'net_predictself' then
4847 if (Length(P
) > 1) and
4848 ((P
[1] = '1') or (P
[1] = '0')) then
4849 NetPredictSelf
:= (P
[1][1] = '1');
4851 if NetPredictSelf
then
4852 g_Console_Add('net_predictself = 1')
4854 g_Console_Add('net_predictself = 0');
4855 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4856 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
4857 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4860 else if cmd
= 'sv_name' then
4862 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4864 NetServerName
:= P
[1];
4865 if Length(NetServerName
) > 64 then
4866 SetLength(NetServerName
, 64);
4867 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4871 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
4873 else if cmd
= 'sv_passwd' then
4875 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4877 NetPassword
:= P
[1];
4878 if Length(NetPassword
) > 24 then
4879 SetLength(NetPassword
, 24);
4880 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4884 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
4886 else if cmd
= 'sv_maxplrs' then
4888 if (Length(P
) > 1) then
4890 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
4891 if g_Game_IsServer
and g_Game_IsNet
then
4894 for a
:= 0 to High(NetClients
) do
4895 if NetClients
[a
].Used
then
4898 if b
> NetMaxClients
then
4900 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
4901 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
4902 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4903 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4906 if NetUseMaster
then
4911 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
4913 else if cmd
= 'sv_public' then
4915 if (Length(P
) > 1) then
4917 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
4918 if g_Game_IsServer
and g_Game_IsNet
then
4919 if NetUseMaster
then
4921 if NetMPeer
= nil then
4922 if not g_Net_Slist_Connect() then
4923 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4924 g_Net_Slist_Update();
4927 if NetMPeer
<> nil then
4928 g_Net_Slist_Disconnect();
4931 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
4933 else if cmd
= 'sv_intertime' then
4935 if (Length(P
) > 1) then
4936 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4938 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4940 else if cmd
= 'p1_name' then
4942 if (Length(P
) > 1) and gGameOn
then
4944 if g_Game_IsClient
then
4946 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4947 MC_SEND_PlayerSettings
;
4950 if gPlayer1
<> nil then
4952 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4953 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4956 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4959 else if cmd
= 'p2_name' then
4961 if (Length(P
) > 1) and gGameOn
then
4963 if g_Game_IsClient
then
4965 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4966 MC_SEND_PlayerSettings
;
4969 if gPlayer2
<> nil then
4971 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4972 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4975 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4978 else if cmd
= 'p1_color' then
4980 if Length(P
) > 3 then
4981 if g_Game_IsClient
then
4983 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4984 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4985 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4986 MC_SEND_PlayerSettings
;
4989 if gPlayer1
<> nil then
4991 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4992 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4993 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4994 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4997 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4998 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4999 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5001 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5003 if Length(P
) > 3 then
5004 if g_Game_IsClient
then
5006 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5007 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5008 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5009 MC_SEND_PlayerSettings
;
5012 if gPlayer2
<> nil then
5014 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5015 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5016 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5017 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5020 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5021 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5022 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5024 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5026 if cmd
= 'r_showtime' then
5028 if (Length(P
) > 1) and
5029 ((P
[1] = '1') or (P
[1] = '0')) then
5030 gShowTime
:= (P
[1][1] = '1');
5033 g_Console_Add(_lc
[I_MSG_TIME_ON
])
5035 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
5037 else if cmd
= 'r_showscore' then
5039 if (Length(P
) > 1) and
5040 ((P
[1] = '1') or (P
[1] = '0')) then
5041 gShowGoals
:= (P
[1][1] = '1');
5044 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5046 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5048 else if cmd
= 'r_showstat' then
5050 if (Length(P
) > 1) and
5051 ((P
[1] = '1') or (P
[1] = '0')) then
5052 gShowStat
:= (P
[1][1] = '1');
5055 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5057 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5059 else if cmd
= 'r_showkillmsg' then
5061 if (Length(P
) > 1) and
5062 ((P
[1] = '1') or (P
[1] = '0')) then
5063 gShowKillMsg
:= (P
[1][1] = '1');
5065 if gShowKillMsg
then
5066 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5068 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5070 else if cmd
= 'r_showlives' then
5072 if (Length(P
) > 1) and
5073 ((P
[1] = '1') or (P
[1] = '0')) then
5074 gShowLives
:= (P
[1][1] = '1');
5077 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5079 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5081 else if cmd
= 'r_showspect' then
5083 if (Length(P
) > 1) and
5084 ((P
[1] = '1') or (P
[1] = '0')) then
5085 gSpectHUD
:= (P
[1][1] = '1');
5088 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5090 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5092 else if cmd
= 'r_showping' then
5094 if (Length(P
) > 1) and
5095 ((P
[1] = '1') or (P
[1] = '0')) then
5096 gShowPing
:= (P
[1][1] = '1');
5099 g_Console_Add(_lc
[I_MSG_PING_ON
])
5101 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5103 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5105 if Length(P
) > 1 then
5107 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5108 gGameSettings
.GoalLimit
:= 0
5113 if gGameSettings
.GameMode
= GM_DM
then
5115 stat
:= g_Player_GetStats();
5117 for a
:= 0 to High(stat
) do
5118 if stat
[a
].Frags
> b
then
5122 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5124 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5127 if g_Game_IsNet
then MH_SEND_GameSettings
;
5130 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5132 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5134 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5135 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5137 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5138 [gGameSettings
.TimeLimit
div 3600,
5139 (gGameSettings
.TimeLimit
div 60) mod 60,
5140 gGameSettings
.TimeLimit
mod 60]));
5141 if g_Game_IsNet
then MH_SEND_GameSettings
;
5143 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5145 if Length(P
) > 1 then
5147 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5148 gGameSettings
.MaxLives
:= 0
5152 stat
:= g_Player_GetStats();
5154 for a
:= 0 to High(stat
) do
5155 if stat
[a
].Lives
> b
then
5157 gGameSettings
.MaxLives
:=
5158 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5162 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5163 [gGameSettings
.MaxLives
]));
5164 if g_Game_IsNet
then MH_SEND_GameSettings
;
5170 procedure DebugCommands(P
: SArray
);
5177 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5180 cmd
:= LowerCase(P
[0]);
5181 if cmd
= 'd_window' then
5183 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
5184 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
5185 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5186 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5187 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
5189 else if cmd
= 'd_sounds' then
5191 if (Length(P
) > 1) and
5192 ((P
[1] = '1') or (P
[1] = '0')) then
5193 g_Debug_Sounds
:= (P
[1][1] = '1');
5195 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5197 else if cmd
= 'd_frames' then
5199 if (Length(P
) > 1) and
5200 ((P
[1] = '1') or (P
[1] = '0')) then
5201 g_Debug_Frames
:= (P
[1][1] = '1');
5203 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5205 else if cmd
= 'd_winmsg' then
5207 if (Length(P
) > 1) and
5208 ((P
[1] = '1') or (P
[1] = '0')) then
5209 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5211 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5213 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5215 if (Length(P
) > 1) and
5216 ((P
[1] = '1') or (P
[1] = '0')) then
5217 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5219 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5221 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5223 if Length(P
) > 1 then
5225 '0': g_debug_BotAIOff
:= 0;
5226 '1': g_debug_BotAIOff
:= 1;
5227 '2': g_debug_BotAIOff
:= 2;
5228 '3': g_debug_BotAIOff
:= 3;
5231 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5233 else if cmd
= 'd_monster' then
5235 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5236 if Length(P
) < 2 then
5238 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5239 g_Console_Add('ID | Name');
5240 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5241 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5244 a
:= StrToIntDef(P
[1], 0);
5245 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5246 a
:= g_Mons_TypeIdByName(P
[1]);
5248 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5249 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5252 with gPlayer1
.Obj
do
5254 mon
:= g_Monsters_Create(a
,
5255 X
+ Rect
.X
+ (Rect
.Width
div 2),
5256 Y
+ Rect
.Y
+ Rect
.Height
,
5257 gPlayer1
.Direction
, True);
5259 if (Length(P
) > 2) and (mon
<> nil) then
5260 mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5264 else if (cmd
= 'd_health') then
5266 if (Length(P
) > 1) and
5267 ((P
[1] = '1') or (P
[1] = '0')) then
5268 g_debug_HealthBar
:= (P
[1][1] = '1');
5270 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5272 else if (cmd
= 'd_player') then
5274 if (Length(P
) > 1) and
5275 ((P
[1] = '1') or (P
[1] = '0')) then
5276 g_debug_Player
:= (P
[1][1] = '1');
5278 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5280 else if (cmd
= 'd_joy') then
5283 g_Console_Add(e_JoystickStateToString(a
));
5287 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5291 procedure GameCheats(P
: SArray
);
5297 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
5298 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then
5300 g_Console_Add('not available');
5306 g_Console_Add('where is the player?!');
5309 cmd
:= LowerCase(P
[0]);
5313 plr
.GodMode
:= not plr
.GodMode
;
5314 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5317 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5318 if cmd
= 'give' then
5320 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
5321 for f
:= 1 to High(P
) do
5323 cmd
:= LowerCase(P
[f
]);
5324 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
5325 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
5326 if cmd
= 'exit' then
5328 if gTriggers
<> nil then
5330 for a
:= 0 to High(gTriggers
) do
5332 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5334 g_Console_Add('player left the map');
5335 gExitByTrigger
:= True;
5336 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
5337 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
5345 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
5346 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
5347 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
5348 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
5349 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
5351 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
5352 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
5354 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
5355 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;
5357 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
5358 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
5360 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
5361 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
5363 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
5364 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
5366 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
5367 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
5368 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
5370 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
5371 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
5372 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
5373 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;
5374 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
5375 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
5377 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;
5378 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;
5379 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;
5380 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;
5381 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;
5382 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;
5384 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
5385 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;
5387 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;
5388 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;
5390 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
5392 if cmd
= 'ammo' then
5394 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
5395 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
5396 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
5397 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
5398 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
5399 g_Console_Add('player got some ammo');
5403 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
5404 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
5406 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
5407 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
5409 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
5410 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
5412 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
5413 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
5415 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
5417 if cmd
= 'weapons' then
5419 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
5420 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
5421 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
5422 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
5423 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
5424 plr
.GiveItem(ITEM_WEAPON_BFG
);
5425 g_Console_Add('player got weapons');
5429 if cmd
= 'keys' then
5431 plr
.GiveItem(ITEM_KEY_RED
);
5432 plr
.GiveItem(ITEM_KEY_GREEN
);
5433 plr
.GiveItem(ITEM_KEY_BLUE
);
5434 g_Console_Add('player got all keys');
5438 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
5443 if cmd
= 'open' then
5445 g_Console_Add('player activated sesame');
5446 g_Triggers_OpenAll();
5453 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
5457 if cmd
= 'noclip' then
5460 g_Console_Add('wall hardeness adjusted');
5464 if cmd
= 'notarget' then
5466 plr
.NoTarget
:= not plr
.NoTarget
;
5467 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
5471 if cmd
= 'noreload' then
5473 plr
.NoReload
:= not plr
.NoReload
;
5474 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
5478 if cmd
= 'speedy' then
5480 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
5481 g_Console_Add('speed adjusted');
5485 if cmd
= 'jumpy' then
5487 VEL_JUMP
:= 30-VEL_JUMP
;
5488 g_Console_Add('jump height adjusted');
5492 if cmd
= 'automap' then
5494 gShowMap
:= not gShowMap
;
5495 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
5499 if cmd
= 'aimline' then
5501 gAimLine
:= not gAimLine
;
5502 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
5507 procedure GameCommands(P
: SArray
);
5513 pl
: pTNetClient
= nil;
5520 cmd
:= LowerCase(P
[0]);
5522 if (cmd
= 'quit') or
5529 else if cmd
= 'pause' then
5531 if (g_ActiveWindow
= nil) then
5532 g_Game_Pause(not gPause
);
5534 else if cmd
= 'endgame' then
5535 gExit
:= EXIT_SIMPLE
5536 else if cmd
= 'restart' then
5538 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5540 if g_Game_IsClient
then
5542 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5547 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5549 else if cmd
= 'kick' then
5551 if g_Game_IsServer
then
5553 if Length(P
) < 2 then
5555 g_Console_Add('kick <name>');
5560 g_Console_Add('kick <name>');
5564 if g_Game_IsNet
then
5565 pl
:= g_Net_Client_ByName(P
[1]);
5568 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5569 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
5570 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5571 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5572 if NetUseMaster
then
5574 end else if gPlayers
<> nil then
5575 for a
:= Low(gPlayers
) to High(gPlayers
) do
5576 if gPlayers
[a
] <> nil then
5577 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5579 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
5580 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5582 gPlayers
[a
].Lives
:= 0;
5583 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5584 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5585 g_Player_Remove(gPlayers
[a
].UID
);
5586 if NetUseMaster
then
5588 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
5592 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5594 else if cmd
= 'kick_id' then
5596 if g_Game_IsServer
and g_Game_IsNet
then
5598 if Length(P
) < 2 then
5600 g_Console_Add('kick_id <client ID>');
5605 g_Console_Add('kick_id <client ID>');
5609 a
:= StrToIntDef(P
[1], 0);
5610 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5612 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5614 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5615 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5616 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5617 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5618 if NetUseMaster
then
5623 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5625 else if cmd
= 'ban' then
5627 if g_Game_IsServer
and g_Game_IsNet
then
5629 if Length(P
) < 2 then
5631 g_Console_Add('ban <name>');
5636 g_Console_Add('ban <name>');
5640 pl
:= g_Net_Client_ByName(P
[1]);
5643 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5644 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5645 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5646 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5647 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5648 if NetUseMaster
then
5651 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5653 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5655 else if cmd
= 'ban_id' then
5657 if g_Game_IsServer
and g_Game_IsNet
then
5659 if Length(P
) < 2 then
5661 g_Console_Add('ban_id <client ID>');
5666 g_Console_Add('ban_id <client ID>');
5670 a
:= StrToIntDef(P
[1], 0);
5671 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5672 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5674 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5675 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5676 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5677 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5678 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5679 if NetUseMaster
then
5683 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5685 else if cmd
= 'permban' then
5687 if g_Game_IsServer
and g_Game_IsNet
then
5689 if Length(P
) < 2 then
5691 g_Console_Add('permban <name>');
5696 g_Console_Add('permban <name>');
5700 pl
:= g_Net_Client_ByName(P
[1]);
5703 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5704 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5705 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5706 g_Net_SaveBanList();
5707 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5708 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5709 if NetUseMaster
then
5712 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5714 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5716 else if cmd
= 'permban_id' then
5718 if g_Game_IsServer
and g_Game_IsNet
then
5720 if Length(P
) < 2 then
5722 g_Console_Add('permban_id <client ID>');
5727 g_Console_Add('permban_id <client ID>');
5731 a
:= StrToIntDef(P
[1], 0);
5732 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5733 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5735 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5736 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5737 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5738 g_Net_SaveBanList();
5739 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5740 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5741 if NetUseMaster
then
5745 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5747 else if cmd
= 'unban' then
5749 if g_Game_IsServer
and g_Game_IsNet
then
5751 if Length(P
) < 2 then
5753 g_Console_Add('unban <IP Address>');
5758 g_Console_Add('unban <IP Address>');
5762 if g_Net_UnbanHost(P
[1]) then
5764 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5765 g_Net_SaveBanList();
5767 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5769 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5771 else if cmd
= 'clientlist' then
5773 if g_Game_IsServer
and g_Game_IsNet
then
5776 if NetClients
<> nil then
5777 for a
:= Low(NetClients
) to High(NetClients
) do
5778 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5780 plr
:= g_Player_Get(NetClients
[a
].Player
);
5781 if plr
= nil then continue
;
5783 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5784 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5787 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5789 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5791 else if cmd
= 'connect' then
5793 if (NetMode
= NET_NONE
) then
5795 if Length(P
) < 2 then
5797 g_Console_Add('connect <IP> [port] [password]');
5802 g_Console_Add('connect <IP> [port] [password]');
5806 if Length(P
) > 2 then
5807 prt
:= StrToIntDef(P
[2], 25666)
5811 if Length(P
) > 3 then
5816 g_Game_StartClient(P
[1], prt
, pw
);
5819 else if cmd
= 'disconnect' then
5821 if (NetMode
= NET_CLIENT
) then
5824 else if cmd
= 'reconnect' then
5826 if (NetMode
= NET_SERVER
) then
5829 if (NetMode
= NET_CLIENT
) then
5832 gExit
:= EXIT_SIMPLE
;
5836 //TODO: Use last successful password to reconnect, instead of ''
5837 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5839 else if (cmd
= 'addbot') or
5840 (cmd
= 'bot_add') then
5842 if Length(P
) > 1 then
5843 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5845 g_Bot_Add(TEAM_NONE
, 2);
5847 else if cmd
= 'bot_addlist' then
5849 if Length(P
) > 1 then
5850 if Length(P
) = 2 then
5851 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5853 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5855 else if cmd
= 'bot_removeall' then
5857 else if cmd
= 'chat' then
5859 if g_Game_IsNet
then
5861 if Length(P
) > 1 then
5863 for a
:= 1 to High(P
) do
5864 chstr
:= chstr
+ P
[a
] + ' ';
5866 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5868 if Length(chstr
) < 1 then
5870 g_Console_Add('chat <text>');
5874 chstr
:= b_Text_Format(chstr
);
5875 if g_Game_IsClient
then
5876 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5878 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5881 g_Console_Add('chat <text>');
5883 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5885 else if cmd
= 'teamchat' then
5887 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5889 if Length(P
) > 1 then
5891 for a
:= 1 to High(P
) do
5892 chstr
:= chstr
+ P
[a
] + ' ';
5894 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5896 if Length(chstr
) < 1 then
5898 g_Console_Add('teamchat <text>');
5902 chstr
:= b_Text_Format(chstr
);
5903 if g_Game_IsClient
then
5904 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5906 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5907 gPlayer1Settings
.Team
);
5910 g_Console_Add('teamchat <text>');
5912 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5914 else if cmd
= 'game' then
5916 if gGameSettings
.GameType
<> GT_NONE
then
5918 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5921 if Length(P
) = 1 then
5923 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5926 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5927 P
[1] := addWadExtension(P
[1]);
5928 if FileExists(MapsDir
+ P
[1]) then
5930 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5931 if Length(P
) < 3 then
5934 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5937 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5939 if g_Map_Exist(MapsDir
+ s
) then
5941 // Çàïóñêàåì ñâîþ èãðó
5943 with gGameSettings
do
5945 GameMode
:= g_Game_TextToMode(gcGameMode
);
5946 if gSwitchGameMode
<> GM_NONE
then
5947 GameMode
:= gSwitchGameMode
;
5948 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5949 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5951 if Length(P
) >= 4 then
5952 b
:= StrToIntDef(P
[3], 1);
5953 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5954 GoalLimit
, MaxLives
, Options
, b
);
5959 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5961 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[2])]));
5963 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5965 else if cmd
= 'host' then
5967 if gGameSettings
.GameType
<> GT_NONE
then
5969 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5972 if Length(P
) < 4 then
5974 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5977 if not StrToIp(P
[1], listen
) then
5979 prt
:= StrToIntDef(P
[2], 25666);
5981 P
[3] := addWadExtension(P
[3]);
5982 if FileExists(MapsDir
+ P
[3]) then
5984 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5985 if Length(P
) < 5 then
5988 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5991 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5993 if g_Map_Exist(MapsDir
+ s
) then
5995 // Çàïóñêàåì ñâîþ èãðó
5997 with gGameSettings
do
5999 GameMode
:= g_Game_TextToMode(gcGameMode
);
6000 if gSwitchGameMode
<> GM_NONE
then
6001 GameMode
:= gSwitchGameMode
;
6002 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6003 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6005 if Length(P
) >= 6 then
6006 b
:= StrToIntDef(P
[5], 0);
6007 g_Game_StartServer(s
, GameMode
, TimeLimit
,
6008 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
6013 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6015 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[4])]));
6017 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
6019 else if cmd
= 'map' then
6021 if Length(P
) = 1 then
6023 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6025 g_Console_Add(cmd
+ ' <MAP>');
6026 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6028 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6030 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6032 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
6033 if Length(P
) < 3 then
6035 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6036 s
:= UpperCase(P
[1]);
6037 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6038 begin // Êàðòà íàøëàñü
6039 gExitByTrigger
:= False;
6041 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6043 gExit
:= EXIT_ENDLEVELCUSTOM
;
6045 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6046 g_Game_ChangeMap(s
);
6049 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
6050 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6051 P
[1] := addWadExtension(P
[1]);
6052 if FileExists(MapsDir
+ P
[1]) then
6054 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6056 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6058 s
:= P
[1] + ':\' + P
[2];
6060 if g_Map_Exist(MapsDir
+ s
) then
6062 gExitByTrigger
:= False;
6064 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6066 gExit
:= EXIT_ENDLEVELCUSTOM
;
6068 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6069 g_Game_ChangeMap(s
);
6072 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6074 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6076 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6080 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6081 P
[1] := addWadExtension(P
[1]);
6082 if FileExists(MapsDir
+ P
[1]) then
6085 P
[2] := UpperCase(P
[2]);
6086 s
:= P
[1] + ':\' + P
[2];
6088 if g_Map_Exist(MapsDir
+ s
) then
6089 begin // Íàøëè êàðòó
6090 gExitByTrigger
:= False;
6092 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6094 gExit
:= EXIT_ENDLEVELCUSTOM
;
6096 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6097 g_Game_ChangeMap(s
);
6099 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6101 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6104 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6106 else if cmd
= 'nextmap' then
6108 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6109 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6112 if Length(P
) = 1 then
6114 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6116 g_Console_Add(cmd
+ ' <MAP>');
6117 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6120 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6125 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6127 if Length(P
) < 3 then
6129 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6130 s
:= UpperCase(P
[1]);
6131 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6132 begin // Êàðòà íàøëàñü
6133 gExitByTrigger
:= False;
6138 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
6139 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6140 P
[1] := addWadExtension(P
[1]);
6141 if FileExists(MapsDir
+ P
[1]) then
6143 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6145 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6147 s
:= P
[1] + ':\' + P
[2];
6149 if g_Map_Exist(MapsDir
+ s
) then
6150 begin // Óñòàíàâëèâàåì êàðòó
6151 gExitByTrigger
:= False;
6156 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6158 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6160 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6164 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6165 P
[1] := addWadExtension(P
[1]);
6166 if FileExists(MapsDir
+ P
[1]) then
6169 P
[2] := UpperCase(P
[2]);
6170 s
:= P
[1] + ':\' + P
[2];
6172 if g_Map_Exist(MapsDir
+ s
) then
6173 begin // Íàøëè êàðòó
6174 gExitByTrigger
:= False;
6178 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6180 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6183 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6186 if gNextMap
= '' then
6187 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
6189 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
6192 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
6195 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6197 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6199 gExitByTrigger
:= False;
6200 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6201 if (gNextMap
= '') and (gTriggers
<> nil) then
6202 for a
:= 0 to High(gTriggers
) do
6203 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6205 gExitByTrigger
:= True;
6206 //gNextMap := gTriggers[a].Data.MapName;
6207 gNextMap
:= gTriggers
[a
].tgcMap
;
6210 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6211 if gNextMap
= '' then
6212 gNextMap
:= g_Game_GetNextMap();
6213 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6214 if not isWadPath(gNextMap
) then
6215 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
6218 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6219 if g_Map_Exist(MapsDir
+ s
) then
6220 gExit
:= EXIT_ENDLEVELCUSTOM
6222 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
6224 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6226 else if (cmd
= 'event') then
6228 if (Length(P
) <= 1) then
6230 for a
:= 0 to High(gEvents
) do
6231 if gEvents
[a
].Command
= '' then
6232 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6234 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6237 if (Length(P
) = 2) then
6239 for a
:= 0 to High(gEvents
) do
6240 if gEvents
[a
].Name
= P
[1] then
6241 if gEvents
[a
].Command
= '' then
6242 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6244 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6247 for a
:= 0 to High(gEvents
) do
6248 if gEvents
[a
].Name
= P
[1] then
6250 gEvents
[a
].Command
:= '';
6251 for b
:= 2 to High(P
) do
6252 if Pos(' ', P
[b
]) = 0 then
6253 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6255 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6256 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6260 else if cmd
= 'suicide' then
6264 if g_Game_IsClient
then
6265 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6268 if gPlayer1
<> nil then
6269 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6270 if gPlayer2
<> nil then
6271 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6275 // Êîìàíäû Ñâîåé èãðû:
6276 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6278 if cmd
= 'bot_addred' then
6280 if Length(P
) > 1 then
6281 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6283 g_Bot_Add(TEAM_RED
, 2);
6285 else if cmd
= 'bot_addblue' then
6287 if Length(P
) > 1 then
6288 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6290 g_Bot_Add(TEAM_BLUE
, 2);
6292 else if cmd
= 'spectate' then
6298 else if cmd
= 'say' then
6300 if g_Game_IsServer
and g_Game_IsNet
then
6302 if Length(P
) > 1 then
6305 for a
:= 1 to High(P
) do
6306 chstr
:= chstr
+ P
[a
] + ' ';
6308 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6310 if Length(chstr
) < 1 then
6312 g_Console_Add('say <text>');
6316 chstr
:= b_Text_Format(chstr
);
6317 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6319 else g_Console_Add('say <text>');
6321 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6323 else if cmd
= 'tell' then
6325 if g_Game_IsServer
and g_Game_IsNet
then
6327 if (Length(P
) > 2) and (P
[1] <> '') then
6330 for a
:= 2 to High(P
) do
6331 chstr
:= chstr
+ P
[a
] + ' ';
6333 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6335 if Length(chstr
) < 1 then
6337 g_Console_Add('tell <playername> <text>');
6341 pl
:= g_Net_Client_ByName(P
[1]);
6343 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6345 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6347 else g_Console_Add('tell <playername> <text>');
6349 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6351 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6353 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6355 // Äîïîëíèòåëüíîå âðåìÿ:
6356 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6358 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6359 [gGameSettings
.TimeLimit
div 3600,
6360 (gGameSettings
.TimeLimit
div 60) mod 60,
6361 gGameSettings
.TimeLimit
mod 60]));
6362 if g_Game_IsNet
then MH_SEND_GameSettings
;
6364 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6366 if (Length(P
) <= 1) then
6367 g_Console_Add('rcon_password <password>')
6369 MC_SEND_RCONPassword(P
[1]);
6371 else if cmd
= 'rcon' then
6373 if g_Game_IsClient
then
6375 if Length(P
) > 1 then
6378 for a
:= 1 to High(P
) do
6379 chstr
:= chstr
+ P
[a
] + ' ';
6381 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6383 if Length(chstr
) < 1 then
6385 g_Console_Add('rcon <command>');
6389 MC_SEND_RCONCommand(chstr
);
6391 else g_Console_Add('rcon <command>');
6394 else if cmd
= 'ready' then
6396 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6397 gLMSRespawnTime
:= gTime
+ 100;
6399 else if (cmd
= 'callvote') and g_Game_IsNet
then
6401 if Length(P
) > 1 then
6404 for a
:= 1 to High(P
) do begin
6405 if a
> 1 then chstr
:= chstr
+ ' ';
6406 chstr
:= chstr
+ P
[a
];
6409 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6411 if Length(chstr
) < 1 then
6413 g_Console_Add('callvote <command>');
6417 if g_Game_IsClient
then
6418 MC_SEND_Vote(True, chstr
)
6420 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6421 g_Console_Process('vote', True);
6424 g_Console_Add('callvote <command>');
6426 else if (cmd
= 'vote') and g_Game_IsNet
then
6428 if g_Game_IsClient
then
6430 else if gVoteInProgress
then
6432 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6433 a
:= Floor((NetClientCount
+1)/2.0) + 1
6435 a
:= Floor(NetClientCount
/2.0) + 1;
6440 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6441 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6447 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6448 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6456 procedure g_TakeScreenShot();
6464 if e_NoGraphics
then Exit
;
6465 ssdir
:= GameDir
+'/screenshots';
6466 if not findFileCI(ssdir
, true) then
6468 // try to create dir
6473 if not findFileCI(ssdir
, true) then exit
; // alas
6476 for a
:= 1 to High(Word) do
6478 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
6480 if findFileCI(t
, true) then continue
;
6481 if not findFileCI(FileName
) then
6484 st
:= createDiskFile(FileName
);
6486 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
6491 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
6499 procedure g_Game_InGameMenu(Show
: Boolean);
6501 if (g_ActiveWindow
= nil) and Show
then
6503 if gGameSettings
.GameType
= GT_SINGLE
then
6504 g_GUI_ShowWindow('GameSingleMenu')
6507 if g_Game_IsClient
then
6508 g_GUI_ShowWindow('GameClientMenu')
6510 if g_Game_IsNet
then
6511 g_GUI_ShowWindow('GameServerMenu')
6513 g_GUI_ShowWindow('GameCustomMenu');
6515 g_Sound_PlayEx('MENU_OPEN');
6517 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6518 if (not g_Game_IsNet
) then
6522 if (g_ActiveWindow
<> nil) and (not Show
) then
6524 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6525 if (not g_Game_IsNet
) then
6526 g_Game_Pause(False);
6530 procedure g_Game_Pause(Enable
: Boolean);
6535 if gPause
= Enable
then
6538 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then
6542 g_Game_PauseAllSounds(Enable
);
6545 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6550 if gTriggers
<> nil then
6551 for i
:= 0 to High(gTriggers
) do
6552 with gTriggers
[i
] do
6553 if (TriggerType
= TRIGGER_SOUND
) and
6555 Sound
.IsPlaying() then
6557 Sound
.Pause(Enable
);
6561 if gPlayers
<> nil then
6562 for i
:= 0 to High(gPlayers
) do
6563 if gPlayers
[i
] <> nil then
6564 gPlayers
[i
].PauseSounds(Enable
);
6567 if gMusic
<> nil then
6568 gMusic
.Pause(Enable
);
6571 procedure g_Game_StopAllSounds(all
: Boolean);
6575 if gTriggers
<> nil then
6576 for i
:= 0 to High(gTriggers
) do
6577 with gTriggers
[i
] do
6578 if (TriggerType
= TRIGGER_SOUND
) and
6582 if gMusic
<> nil then
6589 procedure g_Game_UpdateTriggerSounds();
6593 if gTriggers
<> nil then
6594 for i
:= 0 to High(gTriggers
) do
6595 with gTriggers
[i
] do
6596 if (TriggerType
= TRIGGER_SOUND
) and
6599 Sound
.IsPlaying() then
6601 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
6602 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
6604 Sound
.SetPan(0.5 - tgcPan
/255.0);
6605 Sound
.SetVolume(tgcVolume
/255.0);
6608 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0);
6612 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6615 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6620 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6625 if gSpectMode
<> SPECT_PLAYERS
then
6627 if gSpectPID1
= UID
then
6632 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6639 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6644 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6649 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6654 if gSpectMode
<> SPECT_PLAYERS
then
6656 Pl
:= g_Player_Get(gSpectPID1
);
6657 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6662 if gSpectViewTwo
then
6664 Pl
:= g_Player_Get(gSpectPID2
);
6665 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6673 procedure g_Game_Message(Msg
: string; Time
: Word);
6675 MessageText
:= b_Text_Format(Msg
);
6676 MessageTime
:= Time
;
6679 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6688 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6692 if goodsnd
[a
].IsPlaying() then
6695 goodsnd
[Random(4)].Play();
6698 procedure g_Game_Announce_KillCombo(Param
: Integer);
6705 UID
:= Param
and $FFFF;
6710 Pl
:= g_Player_Get(UID
);
6719 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6723 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6727 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6731 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6739 if not g_Game_IsWatchedPlayer(UID
) then
6742 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6746 if killsnd
[n
].IsPlaying() then
6751 procedure g_Game_StartVote(Command
, Initiator
: string);
6755 if not gVotesEnabled
then Exit
;
6756 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6757 if gVoteInProgress
or gVotePassed
then
6759 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6760 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6763 gVoteInProgress
:= True;
6764 gVotePassed
:= False;
6765 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6768 gVoteCommand
:= Command
;
6770 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6771 Need
:= Floor((NetClientCount
+1)/2.0)+1
6773 Need
:= Floor(NetClientCount
/2.0)+1;
6774 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6775 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6778 procedure g_Game_CheckVote
;
6782 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6783 if not gVoteInProgress
then Exit
;
6785 if (gTime
>= gVoteTimer
) then
6787 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6788 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6790 Need
:= Floor(NetClientCount
/2.0) + 1;
6791 if gVoteCount
>= Need
then
6793 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6794 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6795 gVotePassed
:= True;
6796 gVoteCmdTimer
:= gTime
+ 5000;
6800 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6801 MH_SEND_VoteEvent(NET_VE_FAILED
);
6803 if NetClients
<> nil then
6804 for I
:= Low(NetClients
) to High(NetClients
) do
6805 if NetClients
[i
].Used
then
6806 NetClients
[i
].Voted
:= False;
6807 gVoteInProgress
:= False;
6813 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6814 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6816 Need
:= Floor(NetClientCount
/2.0) + 1;
6817 if gVoteCount
>= Need
then
6819 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6820 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6821 gVoteInProgress
:= False;
6822 gVotePassed
:= True;
6823 gVoteCmdTimer
:= gTime
+ 5000;
6826 if NetClients
<> nil then
6827 for I
:= Low(NetClients
) to High(NetClients
) do
6828 if NetClients
[i
].Used
then
6829 NetClients
[i
].Voted
:= False;
6834 procedure g_Game_LoadMapList(FileName
: string);
6842 if not FileExists(FileName
) then Exit
;
6844 AssignFile(ListFile
, FileName
);
6846 while not EOF(ListFile
) do
6848 ReadLn(ListFile
, s
);
6851 if s
= '' then Continue
;
6853 SetLength(MapList
, Length(MapList
)+1);
6854 MapList
[High(MapList
)] := s
;
6856 CloseFile(ListFile
);
6859 procedure g_Game_SetDebugMode();
6862 // ×èòû (äàæå â ñâîåé èãðå):
6866 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6870 if Length(LoadingStat
.Msgs
) = 0 then
6876 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6877 if NextMsg
= Length(Msgs
) then
6879 for i
:= 0 to High(Msgs
)-1 do
6880 Msgs
[i
] := Msgs
[i
+1];
6888 Msgs
[NextMsg
-1] := Text;
6894 g_ActiveWindow
:= nil;
6896 ProcessLoading(true);
6899 procedure g_Game_StepLoading();
6905 if (ShowCount
> LOADING_SHOW_STEP
) then
6913 procedure g_Game_ClearLoading();
6922 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6923 if len
< 1 then len
:= 1;
6924 SetLength(Msgs
, len
);
6925 for len
:= Low(Msgs
) to High(Msgs
) do
6931 procedure Parse_Params(var pars
: TParamStrValues
);
6938 while i
<= ParamCount
do
6941 if (s
[1] = '-') and (Length(s
) > 1) then
6943 if (s
[2] = '-') and (Length(s
) > 2) then
6944 begin // Îäèíî÷íûé ïàðàìåòð
6945 SetLength(pars
, Length(pars
) + 1);
6946 with pars
[High(pars
)] do
6948 Name
:= LowerCase(s
);
6953 if (i
< ParamCount
) then
6954 begin // Ïàðàìåòð ñî çíà÷åíèåì
6956 SetLength(pars
, Length(pars
) + 1);
6957 with pars
[High(pars
)] do
6959 Name
:= LowerCase(s
);
6960 Value
:= LowerCase(ParamStr(i
));
6969 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6974 for i
:= 0 to High(pars
) do
6975 if pars
[i
].Name
= aName
then
6977 Result
:= pars
[i
].Value
;
6982 procedure g_Game_Process_Params();
6984 pars
: TParamStrValues
;
6987 LimT
, LimS
: Integer;
6998 s
:= Find_Param_Value(pars
, '--debug');
7001 g_Game_SetDebugMode();
7002 s
:= Find_Param_Value(pars
, '--netdump');
7007 // Connect when game loads
7008 ip
:= Find_Param_Value(pars
, '-connect');
7012 s
:= Find_Param_Value(pars
, '-port');
7013 if (s
= '') or not TryStrToInt(s
, Port
) then
7016 s
:= Find_Param_Value(pars
, '-pw');
7018 g_Game_StartClient(ip
, Port
, s
);
7022 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
7025 gDefaultMegawadStart
:= s
;
7028 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
7029 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
7031 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
7034 // Start map when game loads:
7035 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
7036 if isWadPath(map
) then
7039 s
:= Find_Param_Value(pars
, '-gm');
7040 GMode
:= g_Game_TextToMode(s
);
7041 if GMode
= GM_NONE
then GMode
:= GM_DM
;
7042 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
7045 s
:= Find_Param_Value(pars
, '-limt');
7046 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
7052 s
:= Find_Param_Value(pars
, '-lims');
7053 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
7059 s
:= Find_Param_Value(pars
, '-lives');
7060 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
7066 s
:= Find_Param_Value(pars
, '-opt');
7068 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
7070 Opt
:= StrToIntDef(s
, 0);
7072 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
7075 s
:= Find_Param_Value(pars
, '--close');
7079 // Delete test map after play:
7080 s
:= Find_Param_Value(pars
, '--testdelete');
7083 gMapToDelete
:= MapsDir
+ map
;
7084 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR
);
7088 // Delete temporary WAD after play:
7089 s
:= Find_Param_Value(pars
, '--tempdelete');
7092 gMapToDelete
:= MapsDir
+ map
;
7093 gTempDelete
:= True;
7096 // Number of players:
7097 s
:= Find_Param_Value(pars
, '-pl');
7101 n
:= StrToIntDef(s
, 1);
7104 s
:= Find_Param_Value(pars
, '-port');
7105 if (s
= '') or not TryStrToInt(s
, Port
) then
7106 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
7108 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
7111 // Execute script when game loads:
7112 s
:= Find_Param_Value(pars
, '-exec');
7115 if not isWadPath(s
) then
7116 s
:= GameDir
+ '/' + s
;
7121 if IOResult
<> 0 then
7123 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
7124 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7128 e_WriteLog('Executing script: ' + s
, MSG_NOTIFY
);
7129 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7134 if IOResult
<> 0 then
7136 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
7137 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7141 if Pos('#', s
) <> 1 then // script comment
7142 g_Console_Process(s
, True);
7153 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7154 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7155 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7156 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7158 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7159 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7160 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7161 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7163 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7164 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7166 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7167 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7169 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7171 conRegVar('dbg_scale', @g_dbg_scale
, 0.01, 5.0, 'experimental deBUG scale mode', '', true);