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}
24 g_basic
, g_player
, e_graphics
, g_res_downloader
,
25 g_sound
, g_gui
, utils
, md5
, xprofiler
;
28 TGameSettings
= record
44 TDelayedEvent
= record
53 Sound
: TPlayableSound
;
54 Tags
: Array of String;
58 TPlayerSettings
= record
77 function g_Game_IsNet(): Boolean;
78 function g_Game_IsServer(): Boolean;
79 function g_Game_IsClient(): Boolean;
80 procedure g_Game_Init();
81 procedure g_Game_Free (freeTextures
: Boolean=true);
82 procedure g_Game_LoadData();
83 procedure g_Game_FreeData();
84 procedure g_Game_Update();
85 procedure g_Game_Draw();
86 procedure g_Game_Quit();
87 procedure g_Game_SetupScreenSize();
88 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
89 function g_Game_ModeToText(Mode
: Byte): string;
90 function g_Game_TextToMode(Mode
: string): Byte;
91 procedure g_Game_ExecuteEvent(Name
: String);
92 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
93 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
94 procedure g_Game_RemovePlayer();
95 procedure g_Game_Spectate();
96 procedure g_Game_SpectateCenterView();
97 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
98 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
99 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
100 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
101 procedure g_Game_Restart();
102 procedure g_Game_RestartLevel();
103 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
104 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
105 procedure g_Game_SaveOptions();
106 function g_Game_StartMap(Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
107 procedure g_Game_ChangeMap(const MapPath
: String);
108 procedure g_Game_ExitLevel(const Map
: AnsiString);
109 function g_Game_GetFirstMap(WAD
: String): String;
110 function g_Game_GetNextMap(): String;
111 procedure g_Game_NextLevel();
112 procedure g_Game_Pause(Enable
: Boolean);
113 procedure g_Game_HolmesPause(Enable
: Boolean);
114 procedure g_Game_InGameMenu(Show
: Boolean);
115 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
116 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
117 procedure g_Game_Message(Msg
: String; Time
: Word);
118 procedure g_Game_LoadMapList(FileName
: String);
119 procedure g_Game_PauseAllSounds(Enable
: Boolean);
120 procedure g_Game_StopAllSounds(all
: Boolean);
121 procedure g_Game_UpdateTriggerSounds();
122 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
123 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
124 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
125 procedure g_Game_Announce_KillCombo(Param
: Integer);
126 procedure g_Game_StartVote(Command
, Initiator
: string);
127 procedure g_Game_CheckVote
;
128 procedure g_TakeScreenShot();
129 procedure g_FatalError(Text: String);
130 procedure g_SimpleError(Text: String);
131 function g_Game_IsTestMap(): Boolean;
132 procedure g_Game_DeleteTestMap();
133 procedure GameCVars(P
: SSArray
);
134 procedure GameCommands(P
: SSArray
);
135 procedure GameCheats(P
: SSArray
);
136 procedure DebugCommands(P
: SSArray
);
137 procedure g_Game_Process_Params
;
138 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
139 procedure g_Game_StepLoading();
140 procedure g_Game_ClearLoading();
141 procedure g_Game_SetDebugMode();
142 procedure DrawLoadingStat();
144 { procedure SetWinPause(Enable: Boolean); }
149 LOADING_SHOW_STEP
= 100;
150 LOADING_INTERLINE
= 20;
165 MESSAGE_DIKEY
= WM_USER
+ 1;
170 EXIT_ENDLEVELSINGLE
= 4;
171 EXIT_ENDLEVELCUSTOM
= 5;
173 GAME_OPTION_RESERVED
= 1;
174 GAME_OPTION_TEAMDAMAGE
= 2;
175 GAME_OPTION_ALLOWEXIT
= 4;
176 GAME_OPTION_WEAPONSTAY
= 8;
177 GAME_OPTION_MONSTERS
= 16;
178 GAME_OPTION_BOTVSPLAYER
= 32;
179 GAME_OPTION_BOTVSMONSTER
= 64;
184 STATE_INTERCUSTOM
= 3;
185 STATE_INTERSINGLE
= 4;
191 LMS_RESPAWN_NONE
= 0;
192 LMS_RESPAWN_WARMUP
= 1;
193 LMS_RESPAWN_FINAL
= 2;
209 CONFIG_FILENAME
= 'Doom2DF.cfg';
210 LOG_FILENAME
= 'Doom2DF.log';
212 TEST_MAP_NAME
= '$$$_TEST_$$$';
214 STD_PLAYER_MODEL
= 'Doomer';
218 gGameSettings
: TGameSettings
;
219 gPlayer1Settings
: TPlayerSettings
;
220 gPlayer2Settings
: TPlayerSettings
;
222 gPlayerScreenSize
: TDFPoint
;
223 gPlayer1ScreenCoord
: TDFPoint
;
224 gPlayer2ScreenCoord
: TDFPoint
;
225 gPlayer1
: TPlayer
= nil;
226 gPlayer2
: TPlayer
= nil;
227 gPlayerDrawn
: TPlayer
= nil;
229 gSwitchGameMode
: Byte = GM_DM
;
230 gHearPoint1
, gHearPoint2
: THearPoint
;
231 gSoundEffectsDF
: Boolean = False;
232 gSoundTriggerTime
: Word = 0;
233 gAnnouncer
: Byte = ANNOUNCE_NONE
;
234 goodsnd
: array[0..3] of TPlayableSound
;
235 killsnd
: array[0..3] of TPlayableSound
;
236 gDefInterTime
: ShortInt = -1;
237 gInterEndTime
: LongWord = 0;
238 gInterTime
: LongWord = 0;
239 gServInterTime
: Byte = 0;
240 gGameStartTime
: LongWord = 0;
241 gTotalMonsters
: Integer = 0;
242 gPauseMain
: Boolean = false;
243 gPauseHolmes
: Boolean = false;
244 gShowTime
: Boolean = True;
245 gShowFPS
: Boolean = False;
246 gShowGoals
: Boolean = True;
247 gShowStat
: Boolean = True;
248 gShowKillMsg
: Boolean = True;
249 gShowLives
: Boolean = True;
250 gShowPing
: Boolean = False;
251 gShowMap
: Boolean = False;
253 gState
: Byte = STATE_NONE
;
255 sWidth
, sHeight
: Word;
256 gSpectMode
: Byte = SPECT_NONE
;
257 gSpectHUD
: Boolean = True;
258 gSpectKeyPress
: Boolean = False;
259 gSpectX
: Integer = 0;
260 gSpectY
: Integer = 0;
261 gSpectStep
: Byte = 8;
262 gSpectViewTwo
: Boolean = False;
263 gSpectPID1
: Integer = -1;
264 gSpectPID2
: Integer = -1;
265 gMusic
: TMusic
= nil;
266 gLoadGameMode
: Boolean;
267 gCheats
: Boolean = False;
268 gMapOnce
: Boolean = False;
269 gMapToDelete
: String;
270 gTempDelete
: Boolean = False;
271 gLastMap
: Boolean = False;
272 gWinPosX
, gWinPosY
: Integer;
273 gWinSizeX
, gWinSizeY
: Integer;
274 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
275 gWinActive
: Boolean = True; // by default window is active, lol
276 gResolutionChange
: Boolean = False;
277 gRC_Width
, gRC_Height
: Word;
278 gRC_FullScreen
, gRC_Maximized
: Boolean;
279 gLanguageChange
: Boolean = False;
280 gDebugMode
: Boolean = False;
281 g_debug_Sounds
: Boolean = False;
282 g_debug_Frames
: Boolean = False;
283 g_debug_WinMsgs
: Boolean = False;
284 g_debug_MonsterOff
: Boolean = False;
285 g_debug_BotAIOff
: Byte = 0;
286 g_debug_HealthBar
: Boolean = False;
287 g_Debug_Player
: Boolean = False;
288 gCoopMonstersKilled
: Word = 0;
289 gCoopSecretsFound
: Word = 0;
290 gCoopTotalMonstersKilled
: Word = 0;
291 gCoopTotalSecretsFound
: Word = 0;
292 gCoopTotalMonsters
: Word = 0;
293 gCoopTotalSecrets
: Word = 0;
294 gStatsOff
: Boolean = False;
295 gStatsPressed
: Boolean = False;
296 gExitByTrigger
: Boolean = False;
297 gNextMap
: String = '';
298 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
299 gLMSRespawnTime
: Cardinal = 0;
300 gLMSSoftSpawn
: Boolean = False;
301 gMissionFailed
: Boolean = False;
302 gVoteInProgress
: Boolean = False;
303 gVotePassed
: Boolean = False;
304 gVoteCommand
: string = '';
305 gVoteTimer
: Cardinal = 0;
306 gVoteCmdTimer
: Cardinal = 0;
307 gVoteCount
: Integer = 0;
308 gVoteTimeout
: Cardinal = 30;
309 gVoted
: Boolean = False;
310 gVotesEnabled
: Boolean = True;
311 gEvents
: Array of TGameEvent
;
312 gDelayedEvents
: Array of TDelayedEvent
;
313 gChatSounds
: Array of TChatSound
;
315 // move button values:
316 // bits 0-1: l/r state:
317 // 0: neither left, nor right pressed
320 // bits 4-5: l/r state when strafe was pressed
321 P1MoveButton
: Byte = 0;
322 P2MoveButton
: Byte = 0;
324 g_profile_frame_update
: Boolean = false;
325 g_profile_frame_draw
: Boolean = false;
326 g_profile_collision
: Boolean = false;
327 g_profile_los
: Boolean = false;
328 g_profile_history_size
: Integer = 1000;
330 g_rlayer_back
: Boolean = true;
331 g_rlayer_step
: Boolean = true;
332 g_rlayer_wall
: Boolean = true;
333 g_rlayer_door
: Boolean = true;
334 g_rlayer_acid1
: Boolean = true;
335 g_rlayer_acid2
: Boolean = true;
336 g_rlayer_water
: Boolean = true;
337 g_rlayer_fore
: Boolean = true;
340 procedure g_ResetDynlights ();
341 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
342 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
344 function conIsCheatsEnabled (): Boolean; inline;
345 function gPause (): Boolean; inline;
351 e_texture
, g_textures
, g_main
, g_window
, g_menu
,
352 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
353 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
354 g_triggers
, g_monsters
, e_sound
, CONFIG
,
356 ENet
, e_msg
, g_netmsg
, g_netmaster
, GL
, GLExt
,
357 sfs
, wadreader
, g_holmes
;
361 hasPBarGfx
: Boolean = false;
364 // ////////////////////////////////////////////////////////////////////////// //
365 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
368 // ////////////////////////////////////////////////////////////////////////// //
369 function conIsCheatsEnabled (): Boolean; inline;
372 if g_Game_IsNet
then exit
;
373 if not gDebugMode
then
375 //if not gCheats then exit;
376 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
377 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
383 // ////////////////////////////////////////////////////////////////////////// //
385 profileFrameDraw
: TProfiler
= nil;
388 // ////////////////////////////////////////////////////////////////////////// //
391 x
, y
, radius
: Integer;
394 exploRadius
: Integer;
398 g_dynLights
: array of TDynLight
= nil;
399 g_dynLightCount
: Integer = 0;
400 g_playerLight
: Boolean = false;
402 procedure g_ResetDynlights ();
406 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
408 for idx
:= 0 to g_dynLightCount
-1 do
410 if g_dynLights
[idx
].exploCount
= -666 then
417 Inc(g_dynLights
[idx
].exploCount
);
418 if (g_dynLights
[idx
].exploCount
< 10) then
420 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
421 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
422 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
423 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
428 g_dynLightCount
:= lnum
;
431 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
433 if not gwin_has_stencil
then exit
;
434 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
435 g_dynLights
[g_dynLightCount
].x
:= x
;
436 g_dynLights
[g_dynLightCount
].y
:= y
;
437 g_dynLights
[g_dynLightCount
].radius
:= radius
;
438 g_dynLights
[g_dynLightCount
].r
:= r
;
439 g_dynLights
[g_dynLightCount
].g
:= g
;
440 g_dynLights
[g_dynLightCount
].b
:= b
;
441 g_dynLights
[g_dynLightCount
].a
:= a
;
442 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
443 Inc(g_dynLightCount
);
446 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
448 if not gwin_has_stencil
then exit
;
449 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
450 g_dynLights
[g_dynLightCount
].x
:= x
;
451 g_dynLights
[g_dynLightCount
].y
:= y
;
452 g_dynLights
[g_dynLightCount
].radius
:= 0;
453 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
454 g_dynLights
[g_dynLightCount
].r
:= r
;
455 g_dynLights
[g_dynLightCount
].g
:= g
;
456 g_dynLights
[g_dynLightCount
].b
:= b
;
457 g_dynLights
[g_dynLightCount
].a
:= 0;
458 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
459 Inc(g_dynLightCount
);
463 // ////////////////////////////////////////////////////////////////////////// //
464 function calcProfilesHeight (prof
: TProfiler
): Integer;
467 if (prof
= nil) then exit
;
468 if (length(prof
.bars
) = 0) then exit
;
469 result
:= length(prof
.bars
)*(16+2);
473 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
480 if (prof
= nil) then exit
;
482 if (length(prof
.bars
) = 0) then exit
;
484 hgt
:= calcProfilesHeight(prof
);
485 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
486 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
488 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
489 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
490 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
493 for ii
:= 0 to High(prof
.bars
) do
495 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);
502 // ////////////////////////////////////////////////////////////////////////// //
504 TEndCustomGameStat
= record
505 PlayerStat
: TPlayerStatArray
;
509 Map
, MapName
: String;
512 TEndSingleGameStat
= record
513 PlayerStat
: Array [0..1] of record
519 TotalSecrets
: Integer;
522 TLoadingStat
= record
526 Msgs
: Array of String;
528 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
531 TParamStrValue
= record
536 TParamStrValues
= Array of TParamStrValue
;
539 INTER_ACTION_TEXT
= 1;
540 INTER_ACTION_PIC
= 2;
541 INTER_ACTION_MUSIC
= 3;
545 FPSCounter
, UPSCounter
: Word;
546 FPSTime
, UPSTime
: LongWord;
547 DataLoaded
: Boolean = False;
548 LastScreenShot
: Int64;
549 IsDrawStat
: Boolean = False;
550 CustomStat
: TEndCustomGameStat
;
551 SingleStat
: TEndSingleGameStat
;
552 LoadingStat
: TLoadingStat
;
553 EndingGameCounter
: Byte = 0;
556 MapList
: SSArray
= nil;
557 MapIndex
: Integer = -1;
563 text: Array of ShortString;
564 anim
: Array of ShortString;
565 pic
: Array of ShortString;
566 mus
: Array of ShortString;
568 triggers
: Array of record
570 actions
: Array of record
571 action
, p1
, p2
: Integer;
574 cur_trigger
: Integer;
587 function Compare(a
, b
: TPlayerStat
): Integer;
589 if a
.Spectator
then Result
:= 1
590 else if b
.Spectator
then Result
:= -1
591 else if a
.Frags
< b
.Frags
then Result
:= 1
592 else if a
.Frags
> b
.Frags
then Result
:= -1
593 else if a
.Deaths
< b
.Deaths
then Result
:= -1
594 else if a
.Deaths
> b
.Deaths
then Result
:= 1
595 else if a
.Kills
< b
.Kills
then Result
:= -1
599 procedure SortGameStat(var stat
: TPlayerStatArray
);
604 if stat
= nil then Exit
;
606 for I
:= High(stat
) downto Low(stat
) do
607 for J
:= Low(stat
) to High(stat
) - 1 do
608 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
611 stat
[J
] := stat
[J
+ 1];
616 function g_Game_ModeToText(Mode
: Byte): string;
620 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
621 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
622 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
623 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
624 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
628 function g_Game_TextToMode(Mode
: string): Byte;
631 Mode
:= UpperCase(Mode
);
632 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
637 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
642 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
647 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
652 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
659 function g_Game_IsNet(): Boolean;
661 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
664 function g_Game_IsServer(): Boolean;
666 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
669 function g_Game_IsClient(): Boolean;
671 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
674 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
681 Result
.name
:= ExtractFileName(WAD
);
682 Result
.description
:= '';
685 w
:= TWADFile
.Create();
688 if not w
.GetResource('INTERSCRIPT', p
, len
) then
694 cfg
:= TConfig
.CreateMem(p
, len
);
695 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
696 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
697 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
698 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
704 procedure g_Game_FreeWAD();
708 for a
:= 0 to High(MegaWAD
.res
.pic
) do
709 if MegaWAD
.res
.pic
[a
] <> '' then
710 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
712 for a
:= 0 to High(MegaWAD
.res
.mus
) do
713 if MegaWAD
.res
.mus
[a
] <> '' then
714 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
716 MegaWAD
.res
.pic
:= nil;
717 MegaWAD
.res
.text := nil;
718 MegaWAD
.res
.anim
:= nil;
719 MegaWAD
.res
.mus
:= nil;
720 MegaWAD
.triggers
:= nil;
722 g_Texture_Delete('TEXTURE_endpic');
723 g_Sound_Delete('MUSIC_endmus');
725 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
726 gGameSettings
.WAD
:= '';
729 procedure g_Game_LoadWAD(WAD
: string);
738 gGameSettings
.WAD
:= WAD
;
739 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
742 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
744 w
:= TWADFile
.Create();
745 w
.ReadFile(MapsDir
+ WAD
);
747 if not w
.GetResource('INTERSCRIPT', p
, len
) then
753 cfg
:= TConfig
.CreateMem(p
, len
);
758 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
759 if s = '' then Break;
762 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
763 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
765 g_Texture_CreateWADEx(s, s);
771 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
772 if s = '' then Break;
775 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
776 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
778 g_Music_CreateWADEx(s, s);
781 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
782 if MegaWAD
.endpic
<> '' then
784 s
:= g_ExtractWadName(MegaWAD
.endpic
);
785 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
786 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
788 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
789 if MegaWAD
.endmus
<> '' then
791 s
:= g_ExtractWadName(MegaWAD
.endmus
);
792 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
793 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
801 {procedure start_trigger(t: string);
805 function next_trigger(): Boolean;
809 procedure DisableCheats();
815 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
816 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
817 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
818 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
820 {$IF DEFINED(D2F_DEBUG)}
821 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
822 gAimLine
:= g_dbg_aimline_on
;
826 procedure g_Game_ExecuteEvent(Name
: String);
832 if gEvents
= nil then
834 for a
:= 0 to High(gEvents
) do
835 if gEvents
[a
].Name
= Name
then
837 if gEvents
[a
].Command
<> '' then
838 g_Console_Process(gEvents
[a
].Command
, True);
843 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
848 if gDelayedEvents
<> nil then
849 for a
:= 0 to High(gDelayedEvents
) do
850 if not gDelayedEvents
[a
].Pending
then
857 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
858 n
:= High(gDelayedEvents
);
860 gDelayedEvents
[n
].Pending
:= True;
861 gDelayedEvents
[n
].DEType
:= DEType
;
862 gDelayedEvents
[n
].DENum
:= Num
;
863 gDelayedEvents
[n
].DEStr
:= Str
;
864 if DEType
= DE_GLOBEVENT
then
865 gDelayedEvents
[n
].Time
:= (GetTimer() {div 1000}) + Time
867 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
876 if g_Game_IsNet
and g_Game_IsServer
then
877 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
881 gPauseHolmes
:= false;
884 g_Game_StopAllSounds(False);
889 EndingGameCounter
:= 0;
890 g_ActiveWindow
:= nil;
892 gLMSRespawn
:= LMS_RESPAWN_NONE
;
893 gLMSRespawnTime
:= 0;
896 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
901 begin // Ýòî áûë òåñò
905 begin // Âûõîä â ãëàâíîå ìåíþ
906 gMusic
.SetByName('MUSIC_MENU');
908 if gState
<> STATE_SLIST
then
910 g_GUI_ShowWindow('MainMenu');
911 gState
:= STATE_MENU
;
914 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
915 slReturnPressed
:= True;
916 if g_Net_Slist_Fetch(slCurrent
) then
918 if slCurrent
= nil then
919 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
922 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
925 g_Game_ExecuteEvent('ongameend');
929 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
931 if not g_Game_IsClient
then g_Game_Restart();
934 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
936 // Ñòàòèñòèêà Ñâîåé èãðû:
937 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
939 CustomStat
.GameTime
:= gTime
;
940 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
941 CustomStat
.MapName
:= gMapInfo
.Name
;
942 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
943 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
944 CustomStat
.TeamStat
:= gTeamStat
;
946 CustomStat
.PlayerStat
:= nil;
948 // Ñòàòèñòèêà èãðîêîâ:
949 if gPlayers
<> nil then
951 for a
:= 0 to High(gPlayers
) do
952 if gPlayers
[a
] <> nil then
954 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
955 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
957 Name
:= gPlayers
[a
].Name
;
958 Frags
:= gPlayers
[a
].Frags
;
959 Deaths
:= gPlayers
[a
].Death
;
960 Kills
:= gPlayers
[a
].Kills
;
961 Team
:= gPlayers
[a
].Team
;
962 Color
:= gPlayers
[a
].Model
.Color
;
963 Spectator
:= gPlayers
[a
].FSpectator
;
967 SortGameStat(CustomStat
.PlayerStat
);
970 g_Game_ExecuteEvent('onmapend');
973 EndingGameCounter
:= 255;
974 gState
:= STATE_FOLD
;
976 if gDefInterTime
< 0 then
977 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
979 gInterEndTime
:= gDefInterTime
* 1000;
982 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
984 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
985 SingleStat
.GameTime
:= gTime
;
986 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
987 SingleStat
.TotalSecrets
:= gSecretsCount
;
988 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
989 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
990 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
991 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
992 if SingleStat
.TwoPlayers
then
994 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
995 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
998 g_Game_ExecuteEvent('onmapend');
1001 if gNextMap
<> '' then
1003 gMusic
.SetByName('MUSIC_INTERMUS');
1005 gState
:= STATE_INTERSINGLE
;
1007 g_Game_ExecuteEvent('oninter');
1009 else // Áîëüøå íåò êàðò
1011 // Çàòóõàþùèé ýêðàí:
1012 EndingGameCounter
:= 255;
1013 gState
:= STATE_FOLD
;
1018 // Îêîí÷àíèå îáðàáîòàíî:
1019 if gExit
<> EXIT_QUIT
then
1023 procedure drawTime(X
, Y
: Integer); inline;
1025 e_TextureFontPrint(x
, y
,
1026 Format('%d:%.2d:%.2d', [
1027 gTime
div 1000 div 3600,
1028 (gTime
div 1000 div 60) mod 60,
1029 gTime
div 1000 mod 60
1034 procedure DrawStat();
1036 pc
, x
, y
, w
, h
: Integer;
1037 w1
, w2
, w3
, w4
: Integer;
1039 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1042 stat
: TPlayerStatArray
;
1049 pc
:= g_Player_GetCount
;
1050 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1052 w
:= gScreenWidth
-(gScreenWidth
div 5);
1053 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1056 h
:= 40+ch
*5+(ch
+8)*pc
;
1057 x
:= (gScreenWidth
div 2)-(w
div 2);
1058 y
:= (gScreenHeight
div 2)-(h
div 2);
1060 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1061 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1063 drawTime(x
+w
-78, y
+8);
1065 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1066 map
:= g_ExtractFileName(gMapInfo
.Map
);
1067 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1069 case gGameSettings
.GameMode
of
1072 if gGameSettings
.MaxLives
= 0 then
1073 s1
:= _lc
[I_GAME_DM
]
1075 s1
:= _lc
[I_GAME_LMS
];
1076 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1077 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1082 if gGameSettings
.MaxLives
= 0 then
1083 s1
:= _lc
[I_GAME_TDM
]
1085 s1
:= _lc
[I_GAME_TLMS
];
1086 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1087 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1092 s1
:= _lc
[I_GAME_CTF
];
1093 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1094 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1099 if gGameSettings
.MaxLives
= 0 then
1100 s1
:= _lc
[I_GAME_COOP
]
1102 s1
:= _lc
[I_GAME_SURV
];
1103 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1104 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1115 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1117 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1119 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1121 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1122 gStdFont
, 200, 200, 200, 1);
1124 if NetMode
= NET_SERVER
then
1125 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1127 if NetMode
= NET_CLIENT
then
1128 e_TextureFontPrintEx(x
+8, y
+ 8,
1129 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1133 stat
:= g_Player_GetStats();
1136 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1137 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1139 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1141 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1145 for a
:= TEAM_RED
to TEAM_BLUE
do
1147 if a
= TEAM_RED
then
1149 s1
:= _lc
[I_GAME_TEAM_RED
];
1156 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1162 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1163 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1164 gStdFont
, r
, g
, b
, 1);
1166 _y
:= _y
+ch
+(ch
div 4);
1167 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1168 _y
:= _y
+(ch
div 4);
1170 for aa
:= 0 to High(stat
) do
1171 if stat
[aa
].Team
= a
then
1187 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1189 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1191 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1193 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1200 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1203 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1204 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1205 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1206 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1209 for aa
:= 0 to High(stat
) do
1223 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1224 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1226 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1228 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1230 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1232 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1238 procedure g_Game_Init();
1244 gTempDelete
:= False;
1246 sfsGCDisable(); // temporary disable removing of temporary volumes
1249 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1250 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1251 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1252 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1254 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1255 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1256 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1258 g_Game_ClearLoading();
1259 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1260 g_Game_SetLoadingText('', 0, False);
1262 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1265 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1266 g_PlayerModel_LoadData();
1268 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1270 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1271 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1272 until FindNext(SR
) <> 0;
1275 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1277 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1278 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1279 until FindNext(SR
) <> 0;
1282 if FindFirst(ModelsDir
+'*.zip', faAnyFile
, SR
) = 0 then
1284 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1285 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1286 until FindNext(SR
) <> 0;
1290 gPauseMain
:= false;
1291 gPauseHolmes
:= false;
1293 LastScreenShot
:= 0;
1295 {e_MouseInfo.Accel := 1.0;}
1297 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1300 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1301 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1302 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1303 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1304 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1306 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1309 gMusic
:= TMusic
.Create();
1310 gMusic
.SetByName('MUSIC_MENU');
1313 gGameSettings
.WarmupTime
:= 30;
1315 gState
:= STATE_MENU
;
1317 SetLength(gEvents
, 6);
1318 gEvents
[0].Name
:= 'ongamestart';
1319 gEvents
[1].Name
:= 'ongameend';
1320 gEvents
[2].Name
:= 'onmapstart';
1321 gEvents
[3].Name
:= 'onmapend';
1322 gEvents
[4].Name
:= 'oninter';
1323 gEvents
[5].Name
:= 'onwadend';
1325 sfsGCEnable(); // enable releasing unused volumes
1329 procedure g_Game_Free(freeTextures
: Boolean=true);
1331 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1332 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1334 g_Map_Free(freeTextures
);
1336 g_Player_RemoveAllCorpses();
1338 gGameSettings
.GameType
:= GT_NONE
;
1339 if gGameSettings
.GameMode
= GM_SINGLE
then
1340 gGameSettings
.GameMode
:= GM_DM
;
1341 gSwitchGameMode
:= gGameSettings
.GameMode
;
1344 gExitByTrigger
:= False;
1347 function IsActivePlayer(p
: TPlayer
): Boolean;
1352 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1355 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1362 if gPlayers
= nil then
1364 for a
:= Low(gPlayers
) to High(gPlayers
) do
1365 if IsActivePlayer(gPlayers
[a
]) then
1367 if gPlayers
[a
].UID
<> ID
then
1369 Result
:= gPlayers
[a
];
1374 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1380 if gPlayers
= nil then
1384 for a
:= Low(gPlayers
) to High(gPlayers
) do
1385 if IsActivePlayer(gPlayers
[a
]) then
1387 SetLength(ids
, Length(ids
) + 1);
1388 ids
[High(ids
)] := gPlayers
[a
].UID
;
1389 if gPlayers
[a
].UID
= Skip
then
1392 if Length(ids
) = 0 then
1397 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1400 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1406 if gPlayers
= nil then
1410 for a
:= Low(gPlayers
) to High(gPlayers
) do
1411 if IsActivePlayer(gPlayers
[a
]) then
1413 SetLength(ids
, Length(ids
) + 1);
1414 ids
[High(ids
)] := gPlayers
[a
].UID
;
1415 if gPlayers
[a
].UID
= Skip
then
1418 if Length(ids
) = 0 then
1421 Result
:= ids
[Length(ids
) - 1]
1423 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1426 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
1428 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
1429 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
1433 procedure processPlayerControls (plr
: TPlayer
; var ctrl
: TPlayerControl
; var MoveButton
: Byte; p2hack
: Boolean=false);
1439 if (plr
= nil) then exit
;
1440 if (p2hack
) then time
:= 1000 else time
:= 1;
1441 strafeDir
:= MoveButton
shr 4;
1442 MoveButton
:= MoveButton
and $0F;
1445 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1446 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1447 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1449 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1450 if MoveButton
= 1 then plr
.PressKey(KEY_LEFT
, time
)
1451 else if MoveButton
= 2 then plr
.PressKey(KEY_RIGHT
, time
);
1453 // if we have "strafe" key, turn off old strafe mechanics
1454 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
1456 // new strafe mechanics
1457 if (strafeDir
= 0) then strafeDir
:= MoveButton
; // start strafing
1458 // now set direction according to strafe (reversed)
1459 if (strafeDir
= 2) then plr
.SetDirection(TDirection
.D_LEFT
)
1460 else if (strafeDir
= 1) then plr
.SetDirection(TDirection
.D_RIGHT
);
1464 strafeDir
:= 0; // not strafing anymore
1465 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1466 if (MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then plr
.SetDirection(TDirection
.D_LEFT
)
1467 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1468 else if (MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then plr
.SetDirection(TDirection
.D_RIGHT
)
1469 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1470 else if MoveButton
<> 0 then plr
.SetDirection(TDirection(MoveButton
-1));
1473 // fix movebutton state
1474 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1476 // Îñòàëüíûå êëàâèøè:
1477 if isKeyPressed(KeyJump
, KeyJump2
) then plr
.PressKey(KEY_JUMP
, time
);
1478 if isKeyPressed(KeyUp
, KeyUp2
) then plr
.PressKey(KEY_UP
, time
);
1479 if isKeyPressed(KeyDown
, KeyDown2
) then plr
.PressKey(KEY_DOWN
, time
);
1480 if isKeyPressed(KeyFire
, KeyFire2
) then plr
.PressKey(KEY_FIRE
);
1481 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then plr
.PressKey(KEY_NEXTWEAPON
);
1482 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then plr
.PressKey(KEY_PREVWEAPON
);
1483 if isKeyPressed(KeyOpen
, KeyOpen2
) then plr
.PressKey(KEY_OPEN
);
1485 for i
:= 0 to High(KeyWeapon
) do
1486 if isKeyPressed(KeyWeapon
[i
], KeyWeapon2
[i
]) then
1487 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1490 // HACK: add dynlight here
1491 if gwin_k8_enable_light_experiments
then
1493 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1495 g_playerLight
:= true;
1497 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1499 g_playerLight
:= false;
1503 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1506 procedure g_Game_Update();
1508 Msg
: g_gui
.TMessage
;
1514 function sendMonsPos (mon
: TMonster
): Boolean;
1516 result
:= false; // don't stop
1517 // this will also reset "need-send" flag
1518 if mon
.gncNeedSend
then
1520 MH_SEND_MonsterPos(mon
.UID
);
1522 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1524 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1526 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1528 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1532 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1534 result
:= false; // don't stop
1535 // this will also reset "need-send" flag
1536 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1540 reliableUpdate
: Boolean;
1543 // Ïîðà âûêëþ÷àòü èãðó:
1544 if gExit
= EXIT_QUIT
then
1546 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1550 if gExit
= EXIT_QUIT
then
1554 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1555 // no need to, as we'll do it in event handler
1557 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1560 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1562 gExit
:= EXIT_SIMPLE
;
1568 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1569 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1570 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1571 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1573 if g_Game_IsNet
and g_Game_IsServer
then
1575 gInterTime
:= gInterTime
+ GAME_TICK
;
1576 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1577 if a
<> gServInterTime
then
1579 gServInterTime
:= a
;
1580 MH_SEND_TimeSync(gServInterTime
);
1584 if (not g_Game_IsClient
) and
1587 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1588 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1589 and (g_ActiveWindow
= nil)
1591 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1594 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1595 g_Game_StopAllSounds(True);
1597 if gMapOnce
then // Ýòî áûë òåñò
1598 gExit
:= EXIT_SIMPLE
1600 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1601 g_Game_ChangeMap(gNextMap
)
1602 else // Ñëåäóþùåé êàðòû íåò
1604 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1606 // Âûõîä â ãëàâíîå ìåíþ:
1608 g_GUI_ShowWindow('MainMenu');
1609 gMusic
.SetByName('MUSIC_MENU');
1611 gState
:= STATE_MENU
;
1614 // Ôèíàëüíàÿ êàðòèíêà:
1615 g_Game_ExecuteEvent('onwadend');
1617 if not gMusic
.SetByName('MUSIC_endmus') then
1618 gMusic
.SetByName('MUSIC_STDENDMUS');
1620 gState
:= STATE_ENDPIC
;
1622 g_Game_ExecuteEvent('ongameend');
1628 if gState
= STATE_INTERTEXT
then
1629 if InterText
.counter
> 0 then
1630 InterText
.counter
:= InterText
.counter
- 1;
1633 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1635 if EndingGameCounter
= 0 then
1637 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1638 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1640 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1642 g_Game_ExecuteEvent('onwadend');
1643 if not gMusic
.SetByName('MUSIC_endmus') then
1644 gMusic
.SetByName('MUSIC_STDENDMUS');
1647 gMusic
.SetByName('MUSIC_ROUNDMUS');
1650 gState
:= STATE_INTERCUSTOM
;
1652 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1654 gMusic
.SetByName('MUSIC_INTERMUS');
1656 gState
:= STATE_INTERSINGLE
;
1658 g_Game_ExecuteEvent('oninter');
1661 DecMin(EndingGameCounter
, 6, 0);
1664 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1666 if gMapOnce
then // Ýòî áûë òåñò
1668 gExit
:= EXIT_SIMPLE
;
1674 g_Serverlist_Control(slCurrent
);
1677 if g_Game_IsNet
then
1678 if not gConsoleShow
then
1679 if not gChatShow
then
1681 if g_ActiveWindow
= nil then
1683 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1684 g_Console_Chat_Switch(False)
1685 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1686 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1687 g_Console_Chat_Switch(True);
1690 if not gChatEnter
then
1691 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1692 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1695 // Ñòàòèñòèêà ïî Tab:
1697 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1698 (gGameSettings
.GameType
<> GT_SINGLE
) and
1699 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1702 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1704 // Âðåìÿ += 28 ìèëëèñåêóíä:
1705 gTime
:= gTime
+ GAME_TICK
;
1707 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1708 if MessageTime
= 0 then
1710 if MessageTime
> 0 then
1711 MessageTime
:= MessageTime
- 1;
1713 if (g_Game_IsServer
) then
1715 // Áûë çàäàí ëèìèò âðåìåíè:
1716 if (gGameSettings
.TimeLimit
> 0) then
1717 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1718 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1723 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1724 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1725 g_Game_RestartRound(gLMSSoftSpawn
);
1727 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1728 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1730 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1732 g_Console_Process(gVoteCommand
);
1734 gVotePassed
:= False;
1737 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1738 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1739 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1740 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1741 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1743 // Áûë çàäàí ëèìèò ïîáåä:
1744 if (gGameSettings
.GoalLimit
> 0) then
1748 if gGameSettings
.GameMode
= GM_DM
then
1749 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1750 for i
:= 0 to High(gPlayers
) do
1751 if gPlayers
[i
] <> nil then
1752 if gPlayers
[i
].Frags
> b
then
1753 b
:= gPlayers
[i
].Frags
;
1756 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1757 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1758 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1761 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1762 if b
>= gGameSettings
.GoalLimit
then
1769 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1770 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1771 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1772 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1774 processPlayerControls(gPlayer1
, gGameControls
.P1Control
, P1MoveButton
);
1775 processPlayerControls(gPlayer2
, gGameControls
.P2Control
, P2MoveButton
, true);
1776 end // if not console
1779 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1781 // process weapon switch queue
1785 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1786 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1788 if not gSpectKeyPress
then
1790 if isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
) then
1792 // switch spect mode
1794 SPECT_NONE
: ; // not spectator
1796 SPECT_MAPVIEW
: Inc(gSpectMode
);
1797 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1799 gSpectKeyPress
:= True;
1801 if gSpectMode
= SPECT_MAPVIEW
then
1803 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1804 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1805 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1806 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1807 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1808 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1809 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1810 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1811 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1814 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1815 gSpectKeyPress
:= True;
1817 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1820 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1821 gSpectKeyPress
:= True;
1824 if gSpectMode
= SPECT_PLAYERS
then
1826 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1829 gSpectViewTwo
:= True;
1830 gSpectKeyPress
:= True;
1832 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1834 // remove second view
1835 gSpectViewTwo
:= False;
1836 gSpectKeyPress
:= True;
1838 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1840 // prev player (view 1)
1841 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1842 gSpectKeyPress
:= True;
1844 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1846 // next player (view 1)
1847 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1848 gSpectKeyPress
:= True;
1850 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1852 // prev player (view 2)
1853 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1854 gSpectKeyPress
:= True;
1856 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1858 // next player (view 2)
1859 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1860 gSpectKeyPress
:= True;
1865 if (not isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)) and
1866 (not isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
)) and
1867 (not isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
)) and
1868 (not isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
)) and
1869 (not isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
)) and
1870 (not isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
)) and
1871 (not isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
)) then
1872 gSpectKeyPress
:= False;
1875 // Îáíîâëÿåì âñå îñòàëüíîå:
1878 g_Triggers_Update();
1880 g_Monsters_Update();
1882 g_Player_UpdateAll();
1883 g_Player_UpdatePhysicalObjects();
1885 // server: send newly spawned monsters unconditionally
1886 if (gGameSettings
.GameType
= GT_SERVER
) then
1888 if (Length(gMonstersSpawned
) > 0) then
1890 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1891 SetLength(gMonstersSpawned
, 0);
1895 if (gSoundTriggerTime
> 8) then
1897 g_Game_UpdateTriggerSounds();
1898 gSoundTriggerTime
:= 0;
1902 Inc(gSoundTriggerTime
);
1905 if (NetMode
= NET_SERVER
) then
1907 Inc(NetTimeToUpdate
);
1908 Inc(NetTimeToReliable
);
1910 // send monster updates
1911 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
1913 // send all monsters (periodic sync)
1914 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
1916 for I
:= 0 to High(gPlayers
) do
1918 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
1921 g_Mons_ForEach(sendMonsPos
);
1923 if reliableUpdate
then
1925 NetTimeToReliable
:= 0;
1926 NetTimeToUpdate
:= NetUpdateRate
;
1930 NetTimeToUpdate
:= 0;
1935 // send only mosters with some unexpected changes
1936 g_Mons_ForEach(sendMonsPosUnexpected
);
1939 // send unexpected platform changes
1940 g_Map_NetSendInterestingPanels();
1942 if NetUseMaster
then
1944 if gTime
>= NetTimeToMaster
then
1946 if (NetMHost
= nil) or (NetMPeer
= nil) then
1948 if not g_Net_Slist_Connect
then g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1952 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1956 else if (NetMode
= NET_CLIENT
) then
1958 MC_SEND_PlayerPos();
1960 end; // if gameOn ...
1962 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1963 if g_ActiveWindow
<> nil then
1965 w
:= e_GetFirstKeyPressed();
1967 if (w
<> IK_INVALID
) then
1969 Msg
.Msg
:= MESSAGE_DIKEY
;
1971 g_ActiveWindow
.OnMessage(Msg
);
1974 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1975 if g_ActiveWindow
<> nil then
1976 g_ActiveWindow
.Update();
1978 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1979 if gResolutionChange
then
1981 e_WriteLog('Changing resolution', TMsgType
.Notify
);
1982 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1983 gResolutionChange
:= False;
1986 // Íóæíî ñìåíèòü ÿçûê:
1987 if gLanguageChange
then
1989 //e_WriteLog('Read language file', MSG_NOTIFY);
1990 //g_Language_Load(DataDir + gLanguage + '.txt');
1991 g_Language_Set(gLanguage
);
1993 gLanguageChange
:= False;
1997 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1998 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
1999 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
2002 LastScreenShot
:= GetTimer();
2005 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2006 if e_KeyPressed(IK_F10
) and
2008 (not gConsoleShow
) and
2009 (g_ActiveWindow
= nil) then
2014 Time
:= GetTimer() {div 1000};
2016 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2017 if gDelayedEvents
<> nil then
2018 for a
:= 0 to High(gDelayedEvents
) do
2019 if gDelayedEvents
[a
].Pending
and
2021 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2022 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2025 case gDelayedEvents
[a
].DEType
of
2027 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2030 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2034 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2035 if g_Game_IsNet
and g_Game_IsServer
then
2036 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2039 gDelayedEvents
[a
].Pending
:= False;
2042 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2043 UPSCounter
:= UPSCounter
+ 1;
2044 if Time
- UPSTime
>= 1000 then
2053 g_Weapon_AddDynLights();
2054 g_Items_AddDynLights();
2058 procedure g_Game_LoadChatSounds(Resource
: string);
2061 FileName
, Snd
: string;
2063 len
, cnt
, tags
, i
, j
: Integer;
2066 FileName
:= g_ExtractWadName(Resource
);
2068 WAD
:= TWADFile
.Create();
2069 WAD
.ReadFile(FileName
);
2071 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2078 cfg
:= TConfig
.CreateMem(p
, len
);
2079 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2081 SetLength(gChatSounds
, cnt
);
2082 for i
:= 0 to Length(gChatSounds
) - 1 do
2084 gChatSounds
[i
].Sound
:= nil;
2085 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2086 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2087 if (Snd
= '') or (Tags
<= 0) then
2089 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2090 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2091 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2092 SetLength(gChatSounds
[i
].Tags
, tags
);
2093 for j
:= 0 to tags
- 1 do
2094 gChatSounds
[i
].Tags
[j
] := LowerCase(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2095 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2102 procedure g_Game_FreeChatSounds();
2106 for i
:= 0 to Length(gChatSounds
) - 1 do
2108 gChatSounds
[i
].Sound
.Free();
2109 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2111 SetLength(gChatSounds
, 0);
2115 procedure g_Game_LoadData();
2122 if DataLoaded
then Exit
;
2124 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2126 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2127 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2128 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2129 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2130 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2131 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2132 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2133 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2134 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2135 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2136 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2137 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2138 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2139 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2142 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2143 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2144 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2145 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2149 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2150 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2151 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2152 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2153 if (wl
> 0) and (hl
> 0) and (wr
> 0) and (hr
= hl
) and (wb
> 0) and (hb
= hl
) and (wm
> 0) and (hm
> 0) and (hm
<= hl
) then
2159 hasPBarGfx
:= false;
2163 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2164 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2165 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2166 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2167 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2168 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2169 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2170 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2171 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2172 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2173 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2174 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2175 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2176 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2177 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2178 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2179 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2180 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2181 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2182 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2184 goodsnd
[0] := TPlayableSound
.Create();
2185 goodsnd
[1] := TPlayableSound
.Create();
2186 goodsnd
[2] := TPlayableSound
.Create();
2187 goodsnd
[3] := TPlayableSound
.Create();
2189 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2190 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2191 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2192 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2194 killsnd
[0] := TPlayableSound
.Create();
2195 killsnd
[1] := TPlayableSound
.Create();
2196 killsnd
[2] := TPlayableSound
.Create();
2197 killsnd
[3] := TPlayableSound
.Create();
2199 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2200 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2201 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2202 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2204 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2206 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2209 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2210 g_Weapon_LoadData();
2212 g_Monsters_LoadData();
2217 procedure g_Game_FreeData();
2219 if not DataLoaded
then Exit
;
2222 g_Weapon_FreeData();
2223 g_Monsters_FreeData();
2225 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2227 g_Texture_Delete('NOTEXTURE');
2228 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2229 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2230 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2231 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2232 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2233 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2234 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2235 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2236 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2237 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2238 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2239 g_Frames_DeleteByName('FRAMES_TELEPORT');
2240 g_Sound_Delete('SOUND_GAME_TELEPORT');
2241 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2242 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2243 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2244 g_Sound_Delete('SOUND_GAME_BULK1');
2245 g_Sound_Delete('SOUND_GAME_BULK2');
2246 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2247 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2248 g_Sound_Delete('SOUND_GAME_SWITCH1');
2249 g_Sound_Delete('SOUND_GAME_SWITCH0');
2256 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2257 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2258 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2259 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2266 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2267 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2268 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2269 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2271 g_Game_FreeChatSounds();
2273 DataLoaded
:= False;
2276 procedure DrawCustomStat();
2282 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2283 s1
, s2
, topstr
: String;
2285 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2287 g_ProcessMessages();
2289 if e_KeyPressed(IK_TAB
) then
2291 if not gStatsPressed
then
2293 gStatsOff
:= not gStatsOff
;
2294 gStatsPressed
:= True;
2298 gStatsPressed
:= False;
2302 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2303 w
:= (Length(s1
) * ww2
) div 2;
2304 x
:= gScreenWidth
div 2 - w
;
2306 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2310 if (gGameSettings
.GameMode
= GM_COOP
) then
2312 if gMissionFailed
then
2313 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2315 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2318 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2320 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2321 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2323 if g_Game_IsNet
then
2325 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2326 if not gChatShow
then
2327 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2328 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2331 if g_Game_IsClient
then
2332 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2334 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2335 if not gChatShow
then
2336 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2337 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2342 w
:= gScreenWidth
-x
*2;
2348 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2349 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2351 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2353 case CustomStat
.GameMode
of
2356 if gGameSettings
.MaxLives
= 0 then
2357 s1
:= _lc
[I_GAME_DM
]
2359 s1
:= _lc
[I_GAME_LMS
];
2363 if gGameSettings
.MaxLives
= 0 then
2364 s1
:= _lc
[I_GAME_TDM
]
2366 s1
:= _lc
[I_GAME_TLMS
];
2368 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2371 if gGameSettings
.MaxLives
= 0 then
2372 s1
:= _lc
[I_GAME_COOP
]
2374 s1
:= _lc
[I_GAME_SURV
];
2380 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2384 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2385 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2388 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2389 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2390 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2391 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2393 pc
:= Length(CustomStat
.PlayerStat
);
2394 if pc
= 0 then Exit
;
2396 if CustomStat
.GameMode
= GM_COOP
then
2398 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2400 s2
:= _lc
[I_GAME_MONSTERS
];
2401 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2402 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2404 s2
:= _lc
[I_GAME_SECRETS
];
2405 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2406 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2409 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2411 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2412 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2413 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2415 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2416 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2417 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2421 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2426 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2427 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2428 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2430 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2433 for t
:= TEAM_RED
to TEAM_BLUE
do
2435 if t
= TEAM_RED
then
2437 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2438 gStdFont
, 255, 0, 0, 1);
2439 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2440 gStdFont
, 255, 0, 0, 1);
2447 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2448 gStdFont
, 0, 0, 255, 1);
2449 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2450 gStdFont
, 0, 0, 255, 1);
2456 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2459 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2460 if CustomStat
.PlayerStat
[p
].Team
= t
then
2461 with CustomStat
.PlayerStat
[p
] do
2475 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2476 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2477 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2484 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2487 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2488 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2489 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2492 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2493 with CustomStat
.PlayerStat
[p
] do
2495 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2502 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2503 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2504 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2510 procedure DrawSingleStat();
2512 tm
, key_x
, val_x
, y
: Integer;
2516 procedure player_stat(n
: Integer);
2522 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2523 s2
:= Format(' %d', [gTotalMonsters
]);
2525 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2526 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2527 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2528 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2530 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2531 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2533 // "Kills-per-minute: ##.#":
2534 s1
:= _lc
[I_MENU_INTER_KPM
];
2536 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2538 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2539 s2
:= Format(' %.1f', [kpm
]);
2541 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2542 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2544 // "Secrets found: # / #":
2545 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2546 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2548 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2549 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2550 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2551 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2553 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2554 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2558 // "Level Complete":
2559 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2560 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2562 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2563 s1
:= _lc
[I_MENU_INTER_KPM
];
2564 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2567 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2569 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2570 val_x
:= key_x
+ w1
;
2573 tm
:= SingleStat
.GameTime
div 1000;
2574 s1
:= _lc
[I_MENU_INTER_TIME
];
2575 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2577 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2578 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2580 if SingleStat
.TwoPlayers
then
2583 s1
:= _lc
[I_MENU_PLAYER_1
];
2584 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2585 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2587 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2592 s1
:= _lc
[I_MENU_PLAYER_2
];
2593 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2594 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2596 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2602 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2608 procedure DrawLoadingStat();
2609 procedure drawRect (x
, y
, w
, h
: Integer);
2611 if (w
< 1) or (h
< 1) then exit
;
2613 glVertex2f(x
+0.375, y
+0.375);
2614 glVertex2f(x
+w
+0.375, y
+0.375);
2615 glVertex2f(x
+w
+0.375, y
+h
+0.375);
2616 glVertex2f(x
+0.375, y
+h
+0.375);
2620 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
2622 rectW
, rectH
: Integer;
2629 idl
, idr
, idb
, idm
: LongWord;
2633 if (total
< 1) then exit
;
2634 if (cur
< 1) then exit
; // don't blink
2635 if (not washere
) and (cur
>= total
) then exit
; // don't blink
2636 //if (cur < 0) then cur := 0;
2637 //if (cur > total) then cur := total;
2640 if (hasPBarGfx
) then
2642 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
2643 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2644 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
2645 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2646 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
2647 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2648 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
2649 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2651 //rectW := gScreenWidth-360;
2652 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
2655 x0
:= (gScreenWidth
-rectW
) div 2;
2656 y0
:= gScreenHeight
-rectH
-64;
2657 if (y0
< 2) then y0
:= 2;
2659 glEnable(GL_SCISSOR_TEST
);
2662 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
2663 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
2664 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
2667 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
2669 while (f
< x0
+rectW
) do
2671 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
2676 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
2677 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
2680 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
2681 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
2685 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
2691 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
2695 rectW
:= gScreenWidth
-64;
2698 x0
:= (gScreenWidth
-rectW
) div 2;
2699 y0
:= gScreenHeight
-rectH
-64;
2700 if (y0
< 2) then y0
:= 2;
2702 glDisable(GL_BLEND
);
2703 glDisable(GL_TEXTURE_2D
);
2705 //glClearColor(0, 0, 0, 0);
2706 //glClear(GL_COLOR_BUFFER_BIT);
2708 glColor4ub(127, 127, 127, 255);
2709 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
2711 glColor4ub(0, 0, 0, 255);
2712 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
2714 glColor4ub(127, 127, 127, 255);
2715 wdt
:= rectW
*cur
div total
;
2716 if (wdt
> rectW
) then wdt
:= rectW
;
2717 drawRect(x0
, y0
, wdt
, rectH
);
2726 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
2728 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2729 yy
:= (gScreenHeight
div 3);
2730 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2731 xx
:= (gScreenWidth
div 3);
2735 for i
:= 0 to NextMsg
-1 do
2737 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2738 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2742 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2743 yy
:= yy
+ LOADING_INTERLINE
;
2744 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
2749 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2751 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2753 function monDraw (mon
: TMonster
): Boolean;
2755 result
:= false; // don't stop
2760 // Ëåâûé âåðõíèé óãîë
2761 aX
:= Obj
.X
div ScaleSz
+ 1;
2762 aY
:= Obj
.Y
div ScaleSz
+ 1;
2764 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2765 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2766 // Ïðàâûé íèæíèé óãîë
2767 aX2
:= aX
+ aX2
- 1;
2768 aY2
:= aY
+ aY2
- 1;
2769 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2775 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2776 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2779 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2780 ScaleSz
:= 16 div Scale
;
2781 // Ðàçìåðû ìèíè-êàðòû:
2782 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2783 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2785 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2787 if gWalls
<> nil then
2790 for a
:= 0 to High(gWalls
) do
2792 if PanelType
<> 0 then
2794 // Ëåâûé âåðõíèé óãîë:
2795 aX
:= X
div ScaleSz
;
2796 aY
:= Y
div ScaleSz
;
2798 aX2
:= max(Width
div ScaleSz
, 1);
2799 aY2
:= max(Height
div ScaleSz
, 1);
2800 // Ïðàâûé íèæíèé óãîë:
2801 aX2
:= aX
+ aX2
- 1;
2802 aY2
:= aY
+ aY2
- 1;
2805 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2806 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2807 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2811 if gSteps
<> nil then
2814 for a
:= 0 to High(gSteps
) do
2816 if PanelType
<> 0 then
2818 // Ëåâûé âåðõíèé óãîë:
2819 aX
:= X
div ScaleSz
;
2820 aY
:= Y
div ScaleSz
;
2822 aX2
:= max(Width
div ScaleSz
, 1);
2823 aY2
:= max(Height
div ScaleSz
, 1);
2824 // Ïðàâûé íèæíèé óãîë:
2825 aX2
:= aX
+ aX2
- 1;
2826 aY2
:= aY
+ aY2
- 1;
2828 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2831 if gLifts
<> nil then
2834 for a
:= 0 to High(gLifts
) do
2836 if PanelType
<> 0 then
2838 // Ëåâûé âåðõíèé óãîë:
2839 aX
:= X
div ScaleSz
;
2840 aY
:= Y
div ScaleSz
;
2842 aX2
:= max(Width
div ScaleSz
, 1);
2843 aY2
:= max(Height
div ScaleSz
, 1);
2844 // Ïðàâûé íèæíèé óãîë:
2845 aX2
:= aX
+ aX2
- 1;
2846 aY2
:= aY
+ aY2
- 1;
2849 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2850 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2851 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2852 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2856 if gWater
<> nil then
2859 for a
:= 0 to High(gWater
) do
2861 if PanelType
<> 0 then
2863 // Ëåâûé âåðõíèé óãîë:
2864 aX
:= X
div ScaleSz
;
2865 aY
:= Y
div ScaleSz
;
2867 aX2
:= max(Width
div ScaleSz
, 1);
2868 aY2
:= max(Height
div ScaleSz
, 1);
2869 // Ïðàâûé íèæíèé óãîë:
2870 aX2
:= aX
+ aX2
- 1;
2871 aY2
:= aY
+ aY2
- 1;
2873 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2876 if gAcid1
<> nil then
2878 // Ðèñóåì êèñëîòó 1:
2879 for a
:= 0 to High(gAcid1
) do
2881 if PanelType
<> 0 then
2883 // Ëåâûé âåðõíèé óãîë:
2884 aX
:= X
div ScaleSz
;
2885 aY
:= Y
div ScaleSz
;
2887 aX2
:= max(Width
div ScaleSz
, 1);
2888 aY2
:= max(Height
div ScaleSz
, 1);
2889 // Ïðàâûé íèæíèé óãîë:
2890 aX2
:= aX
+ aX2
- 1;
2891 aY2
:= aY
+ aY2
- 1;
2893 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2896 if gAcid2
<> nil then
2898 // Ðèñóåì êèñëîòó 2:
2899 for a
:= 0 to High(gAcid2
) do
2901 if PanelType
<> 0 then
2903 // Ëåâûé âåðõíèé óãîë:
2904 aX
:= X
div ScaleSz
;
2905 aY
:= Y
div ScaleSz
;
2907 aX2
:= max(Width
div ScaleSz
, 1);
2908 aY2
:= max(Height
div ScaleSz
, 1);
2909 // Ïðàâûé íèæíèé óãîë:
2910 aX2
:= aX
+ aX2
- 1;
2911 aY2
:= aY
+ aY2
- 1;
2913 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2916 if gPlayers
<> nil then
2919 for a
:= 0 to High(gPlayers
) do
2920 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2922 // Ëåâûé âåðõíèé óãîë:
2923 aX
:= Obj
.X
div ScaleSz
+ 1;
2924 aY
:= Obj
.Y
div ScaleSz
+ 1;
2926 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2927 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2928 // Ïðàâûé íèæíèé óãîë:
2929 aX2
:= aX
+ aX2
- 1;
2930 aY2
:= aY
+ aY2
- 1;
2932 if gPlayers
[a
] = p
then
2933 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2936 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2937 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2938 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2943 g_Mons_ForEach(monDraw
);
2948 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
2950 if not hasAmbient
then exit
;
2951 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
2955 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
2956 //FIXME: broken for splitscreen mode
2957 procedure renderDynLightsInternal ();
2959 //hasAmbient: Boolean;
2960 //ambColor: TDFColor;
2962 lx
, ly
, lrad
: Integer;
2963 scxywh
: array[0..3] of GLint
;
2966 if e_NoGraphics
then exit
;
2968 //TODO: lights should be in separate grid, i think
2969 // but on the other side: grid may be slower for dynlights, as their lifetime is short
2970 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
2973 //ambColor := gCurrentMap['light_ambient'].rgba;
2974 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
2976 { // this will multiply incoming color to alpha from framebuffer
2978 glBlendFunc(GL_DST_ALPHA, GL_ONE);
2982 * light rendering: (INVALID!)
2983 * glStencilFunc(GL_EQUAL, 0, $ff);
2985 * glClear(GL_STENCIL_BUFFER_BIT);
2986 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
2987 * draw shadow volume into stencil buffer
2988 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
2989 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
2991 * draw color-less quad with light alpha (WARNING! don't touch color!)
2992 * glEnable(GL_BLEND);
2993 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
2994 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
2997 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
2998 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3000 // setup OpenGL parameters
3001 glStencilMask($FFFFFFFF);
3002 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3003 glEnable(GL_STENCIL_TEST
);
3004 glEnable(GL_SCISSOR_TEST
);
3005 glClear(GL_STENCIL_BUFFER_BIT
);
3006 glStencilFunc(GL_EQUAL
, 0, $ff);
3008 for lln
:= 0 to g_dynLightCount
-1 do
3010 lx
:= g_dynLights
[lln
].x
;
3011 ly
:= g_dynLights
[lln
].y
;
3012 lrad
:= g_dynLights
[lln
].radius
;
3013 if (lrad
< 3) then continue
;
3015 if (lx
-sX
+lrad
< 0) then continue
;
3016 if (ly
-sY
+lrad
< 0) then continue
;
3017 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3018 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3020 // set scissor to optimize drawing
3021 if (g_dbg_scale
= 1.0) then
3023 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3027 glScissor(0, 0, gWinSizeX
, gWinSizeY
);
3029 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3030 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3031 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3032 // draw extruded panels
3033 glDisable(GL_TEXTURE_2D
);
3034 glDisable(GL_BLEND
);
3035 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3036 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3037 // render light texture
3038 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3039 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3042 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3043 glEnable(GL_TEXTURE_2D
);
3044 // color and opacity
3045 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3046 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3048 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3049 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3050 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3051 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3056 glDisable(GL_STENCIL_TEST
);
3057 glDisable(GL_BLEND
);
3058 glDisable(GL_SCISSOR_TEST
);
3059 //glScissor(0, 0, sWidth, sHeight);
3061 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3062 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3066 function fixViewportForScale (): Boolean;
3068 nx0
, ny0
, nw
, nh
: Integer;
3071 if (g_dbg_scale
<> 1.0) then
3074 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3075 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3076 nw
:= round(sWidth
/g_dbg_scale
);
3077 nh
:= round(sHeight
/g_dbg_scale
);
3086 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3087 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3088 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3090 TDrawCB
= procedure ();
3093 hasAmbient
: Boolean;
3095 doAmbient
: Boolean = false;
3097 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3102 profileFrameDraw
.sectionBegin(profname
);
3103 if gdbg_map_use_accel_render
then
3105 tagmask
:= panelTypeToTag(panType
);
3106 while (gDrawPanelList
.count
> 0) do
3108 pan
:= TPanel(gDrawPanelList
.front());
3109 if ((pan
.tag
and tagmask
) = 0) then break
;
3110 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3111 gDrawPanelList
.popFront();
3116 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3118 profileFrameDraw
.sectionEnd();
3121 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3123 profileFrameDraw
.sectionBegin(profname
);
3124 if assigned(cb
) then cb();
3125 profileFrameDraw
.sectionEnd();
3129 profileFrameDraw
.sectionBegin('total');
3131 // our accelerated renderer will collect all panels to gDrawPanelList
3132 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3133 profileFrameDraw
.sectionBegin('collect');
3134 if gdbg_map_use_accel_render
then
3136 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3138 profileFrameDraw
.sectionEnd();
3140 profileFrameDraw
.sectionBegin('skyback');
3141 g_Map_DrawBack(backXOfs
, backYOfs
);
3142 profileFrameDraw
.sectionEnd();
3144 if setTransMatrix
then
3146 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3147 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3148 glTranslatef(-sX
, -sY
, 0);
3152 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3153 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3158 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3159 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3160 glClear(GL_COLOR_BUFFER_BIT);
3163 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3166 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3167 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3168 drawOther('items', @g_Items_Draw
);
3169 drawOther('weapons', @g_Weapon_Draw
);
3170 drawOther('shells', @g_Player_DrawShells
);
3171 drawOther('drawall', @g_Player_DrawAll
);
3172 drawOther('corpses', @g_Player_DrawCorpses
);
3173 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3174 drawOther('monsters', @g_Monsters_Draw
);
3175 drawOther('itemdrop', @g_Items_DrawDrop
);
3176 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3177 drawOther('gfx', @g_GFX_Draw
);
3178 drawOther('flags', @g_Map_DrawFlags
);
3179 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3180 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3181 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3182 drawOther('dynlights', @renderDynLightsInternal
);
3184 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3186 renderAmbientQuad(hasAmbient
, ambColor
);
3190 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3193 if g_debug_HealthBar
then
3195 g_Monsters_DrawHealth();
3196 g_Player_DrawHealth();
3199 profileFrameDraw
.mainEnd(); // map rendering
3203 procedure DrawMapView(x
, y
, w
, h
: Integer);
3210 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3211 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3218 fixViewportForScale();
3219 renderMapInternal(-bx
, -by
, true);
3225 procedure DrawPlayer(p
: TPlayer
);
3227 px
, py
, a
, b
, c
, d
: Integer;
3230 if (p
= nil) or (p
.FDummy
) then
3233 g_Map_DrawBack(0, 0);
3238 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3239 profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3245 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3246 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3248 if (g_dbg_scale
= 1.0) then
3250 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3251 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3253 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3254 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3256 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3257 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3260 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3263 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3264 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3267 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3272 // scaled, ignore level bounds
3273 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3274 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3277 if p
.IncCam
<> 0 then
3279 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
3281 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
3283 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
3287 if py
< gPlayerScreenSize
.Y
div 2 then
3289 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
3291 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
3295 if p
.IncCam
< 0 then
3297 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
3300 if p
.IncCam
> 0 then
3302 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
3306 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
3307 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
3308 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
3310 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
3311 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
3312 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
3315 sY
:= -(b
+p
.IncCam
);
3316 sWidth
:= gPlayerScreenSize
.X
;
3317 sHeight
:= gPlayerScreenSize
.Y
;
3319 //glTranslatef(a, b+p.IncCam, 0);
3321 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3323 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3324 fixViewportForScale();
3325 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3328 p
.viewPortW
:= sWidth
;
3329 p
.viewPortH
:= sHeight
;
3331 if (p
= gPlayer1
) then
3333 g_Holmes_plrViewPos(sX
, sY
);
3334 g_Holmes_plrViewSize(sWidth
, sHeight
);
3337 renderMapInternal(-c
, -d
, true);
3339 if p
.FSpectator
then
3340 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3341 p
.GameY
+ PLAYER_RECT_CY
- 4,
3342 'X', gStdFont
, 255, 255, 255, 1, True);
3344 for a := 0 to High(gCollideMap) do
3345 for b := 0 to High(gCollideMap[a]) do
3348 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3350 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3354 1: e_DrawPoint(1, b, a, 200, 200, 200);
3355 2: e_DrawPoint(1, b, a, 64, 64, 255);
3356 3: e_DrawPoint(1, b, a, 255, 0, 255);
3366 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3367 if g_Debug_Player
then
3368 g_Player_DrawDebug(p
);
3372 procedure drawProfilers ();
3377 if g_profile_frame_draw
then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3378 if g_profile_collision
then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3379 if g_profile_los
then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3382 procedure g_Game_Draw();
3389 plView1
, plView2
: TPlayer
;
3392 if gExit
= EXIT_QUIT
then Exit
;
3394 Time
:= GetTimer() {div 1000};
3395 FPSCounter
:= FPSCounter
+1;
3396 if Time
- FPSTime
>= 1000 then
3403 if gGameOn
or (gState
= STATE_FOLD
) then
3405 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3407 gSpectMode
:= SPECT_NONE
;
3408 if not gRevertPlayers
then
3410 plView1
:= gPlayer1
;
3411 plView2
:= gPlayer2
;
3415 plView1
:= gPlayer2
;
3416 plView2
:= gPlayer1
;
3420 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3422 gSpectMode
:= SPECT_NONE
;
3423 if gPlayer2
= nil then
3426 plView1
:= gPlayer2
;
3435 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3436 gSpectMode
:= SPECT_STATS
;
3438 if gSpectMode
= SPECT_PLAYERS
then
3439 if gPlayers
<> nil then
3441 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3442 if plView1
= nil then
3444 gSpectPID1
:= GetActivePlayerID_Next();
3445 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3447 if gSpectViewTwo
then
3449 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3450 if plView2
= nil then
3452 gSpectPID2
:= GetActivePlayerID_Next();
3453 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3458 if gSpectMode
= SPECT_MAPVIEW
then
3460 // Ðåæèì ïðîñìîòðà êàðòû
3462 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3463 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3464 gHearPoint1
.Active
:= True;
3465 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3466 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3467 gHearPoint2
.Active
:= False;
3471 Split
:= (plView1
<> nil) and (plView2
<> nil);
3473 // Òî÷êè ñëóõà èãðîêîâ
3474 if plView1
<> nil then
3476 gHearPoint1
.Active
:= True;
3477 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
3478 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
3480 gHearPoint1
.Active
:= False;
3481 if plView2
<> nil then
3483 gHearPoint2
.Active
:= True;
3484 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
3485 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
3487 gHearPoint2
.Active
:= False;
3489 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3490 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3493 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3494 if gScreenHeight
mod 2 = 0 then
3495 Dec(gPlayerScreenSize
.Y
);
3498 gPlayerScreenSize
.Y
:= gScreenHeight
;
3501 if gScreenHeight
mod 2 = 0 then
3502 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3504 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3506 DrawPlayer(plView1
);
3507 gPlayer1ScreenCoord
.X
:= sX
;
3508 gPlayer1ScreenCoord
.Y
:= sY
;
3512 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3514 DrawPlayer(plView2
);
3515 gPlayer2ScreenCoord
.X
:= sX
;
3516 gPlayer2ScreenCoord
.Y
:= sY
;
3519 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3522 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3526 if (g_holmes_enabled
) then g_Holmes_Draw();
3528 if MessageText
<> '' then
3532 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3534 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3535 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3537 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3538 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3541 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3543 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
3545 // Draw spectator GUI
3548 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3551 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3553 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3555 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3557 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3558 if gSpectMode
= SPECT_MAPVIEW
then
3560 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
3561 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
3562 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
3563 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
3564 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
3566 if gSpectMode
= SPECT_PLAYERS
then
3568 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
3569 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
3570 if gSpectViewTwo
then
3572 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
3573 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
3574 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3575 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3579 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3580 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3586 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
3588 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3589 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3591 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
3592 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3593 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
3598 if (gState
= STATE_MENU
) then
3600 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then
3602 if g_Texture_Get('MENU_BACKGROUND', ID
) then e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3603 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3605 // F3 at menu will show game loading dialog
3606 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
3607 if (g_ActiveWindow
<> nil) then
3609 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3610 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3614 // F3 at titlepic will show game loading dialog
3615 if e_KeyPressed(IK_F3
) then
3617 g_Menu_Show_LoadMenu(true);
3618 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3623 if gState
= STATE_FOLD
then
3625 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3628 if gState
= STATE_INTERCUSTOM
then
3630 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
3632 back
:= 'TEXTURE_endpic';
3633 if not g_Texture_Get(back
, ID
) then
3634 back
:= _lc
[I_TEXTURE_ENDPIC
];
3639 if g_Texture_Get(back
, ID
) then
3640 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3642 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3646 if g_ActiveWindow
<> nil then
3648 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3649 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3653 if gState
= STATE_INTERSINGLE
then
3655 if EndingGameCounter
> 0 then
3657 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3663 if g_Texture_Get(back
, ID
) then
3664 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3666 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3670 if g_ActiveWindow
<> nil then
3672 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3673 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3678 if gState
= STATE_ENDPIC
then
3681 if not g_Texture_Get('TEXTURE_endpic', ID
) then
3682 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
3684 if ID
<> DWORD(-1) then
3685 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3687 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3689 if g_ActiveWindow
<> nil then
3691 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3692 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3696 if gState
= STATE_SLIST
then
3698 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3700 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
3701 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3702 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3704 g_Serverlist_Draw(slCurrent
);
3708 if g_ActiveWindow
<> nil then
3712 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3713 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3715 g_ActiveWindow
.Draw();
3720 if g_debug_Sounds
and gGameOn
then
3722 for w
:= 0 to High(e_SoundsArray
) do
3723 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
3724 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
3729 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3730 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3733 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3734 drawTime(gScreenWidth
-72, gScreenHeight
-16);
3736 if gGameOn
then drawProfilers();
3741 procedure g_Game_Quit();
3743 g_Game_StopAllSounds(True);
3745 g_Game_SaveOptions();
3747 g_PlayerModel_FreeData();
3748 g_Texture_DeleteAll();
3749 g_Frames_DeleteAll();
3752 if NetInitDone
then g_Net_Free
;
3754 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3755 if gMapToDelete
<> '' then
3756 g_Game_DeleteTestMap();
3762 procedure g_FatalError(Text: String);
3764 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3765 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
3767 gExit
:= EXIT_SIMPLE
;
3770 procedure g_SimpleError(Text: String);
3772 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3773 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
3776 procedure g_Game_SetupScreenSize();
3778 RES_FACTOR
= 4.0 / 3.0;
3784 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3785 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3786 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3787 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3789 gPlayerScreenSize
.Y
:= gScreenHeight
;
3791 // Ðàçìåð çàäíåãî ïëàíà:
3792 if BackID
<> DWORD(-1) then
3795 if (gScreenWidth
*s
> gMapInfo
.Width
) or
3796 (gScreenHeight
*s
> gMapInfo
.Height
) then
3798 gBackSize
.X
:= gScreenWidth
;
3799 gBackSize
.Y
:= gScreenHeight
;
3803 e_GetTextureSize(BackID
, @bw
, @bh
);
3804 rf
:= Single(bw
) / Single(bh
);
3805 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
3806 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
3807 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
3808 if (s
< 1.0) then s
:= 1.0;
3809 gBackSize
.X
:= Round(bw
*s
);
3810 gBackSize
.Y
:= Round(bh
*s
);
3815 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3817 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3820 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3822 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3823 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3825 if gPlayer1
= nil then
3827 if g_Game_IsClient
then
3829 if NetPlrUID1
> -1 then
3831 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3832 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3837 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3838 Team
:= gPlayer1Settings
.Team
;
3840 // Ñîçäàíèå ïåðâîãî èãðîêà:
3841 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3842 gPlayer1Settings
.Color
,
3844 if gPlayer1
= nil then
3845 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3848 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3849 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3850 if g_Game_IsServer
and g_Game_IsNet
then
3851 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3852 gPlayer1
.Respawn(False, True);
3854 if g_Game_IsNet
and NetUseMaster
then
3860 if gPlayer2
= nil then
3862 if g_Game_IsClient
then
3864 if NetPlrUID2
> -1 then
3865 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3869 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3870 Team
:= gPlayer2Settings
.Team
;
3872 // Ñîçäàíèå âòîðîãî èãðîêà:
3873 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3874 gPlayer2Settings
.Color
,
3876 if gPlayer2
= nil then
3877 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3880 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3881 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3882 if g_Game_IsServer
and g_Game_IsNet
then
3883 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3884 gPlayer2
.Respawn(False, True);
3886 if g_Game_IsNet
and NetUseMaster
then
3894 procedure g_Game_RemovePlayer();
3898 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3899 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3904 if g_Game_IsServer
then
3907 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3908 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3909 g_Player_Remove(Pl
.UID
);
3911 if g_Game_IsNet
and NetUseMaster
then
3920 if g_Game_IsServer
then
3923 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3924 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3925 g_Player_Remove(Pl
.UID
);
3927 if g_Game_IsNet
and NetUseMaster
then
3932 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3938 procedure g_Game_Spectate();
3940 g_Game_RemovePlayer();
3941 if gPlayer1
<> nil then
3942 g_Game_RemovePlayer();
3945 procedure g_Game_SpectateCenterView();
3947 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3948 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3951 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3958 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
3960 g_Game_ClearLoading();
3963 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3966 gGameSettings
.GameType
:= GT_SINGLE
;
3967 gGameSettings
.MaxLives
:= 0;
3968 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3969 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3970 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3971 gSwitchGameMode
:= GM_SINGLE
;
3973 g_Game_ExecuteEvent('ongamestart');
3975 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3976 g_Game_SetupScreenSize();
3978 // Ñîçäàíèå ïåðâîãî èãðîêà:
3979 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3980 gPlayer1Settings
.Color
,
3981 gPlayer1Settings
.Team
, False));
3982 if gPlayer1
= nil then
3984 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3988 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3991 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3994 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3995 gPlayer2Settings
.Color
,
3996 gPlayer2Settings
.Team
, False));
3997 if gPlayer2
= nil then
3999 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4003 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4007 // Çàãðóçêà è çàïóñê êàðòû:
4008 if not g_Game_StartMap(MAP
, True) then
4010 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4011 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4015 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4019 for i
:= nPl
+1 to nPlayers
do
4020 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4023 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4024 TimeLimit
, GoalLimit
: Word;
4026 Options
: LongWord; nPlayers
: Byte);
4032 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4034 g_Game_ClearLoading();
4037 gGameSettings
.GameType
:= GT_CUSTOM
;
4038 gGameSettings
.GameMode
:= GameMode
;
4039 gSwitchGameMode
:= GameMode
;
4040 gGameSettings
.TimeLimit
:= TimeLimit
;
4041 gGameSettings
.GoalLimit
:= GoalLimit
;
4042 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4043 gGameSettings
.Options
:= Options
;
4045 gCoopTotalMonstersKilled
:= 0;
4046 gCoopTotalSecretsFound
:= 0;
4047 gCoopTotalMonsters
:= 0;
4048 gCoopTotalSecrets
:= 0;
4052 g_Game_ExecuteEvent('ongamestart');
4054 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4055 g_Game_SetupScreenSize();
4057 // Ðåæèì íàáëþäàòåëÿ:
4058 if nPlayers
= 0 then
4065 if nPlayers
>= 1 then
4067 // Ñîçäàíèå ïåðâîãî èãðîêà:
4068 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4069 gPlayer1Settings
.Color
,
4070 gPlayer1Settings
.Team
, False));
4071 if gPlayer1
= nil then
4073 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4077 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4081 if nPlayers
>= 2 then
4083 // Ñîçäàíèå âòîðîãî èãðîêà:
4084 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4085 gPlayer2Settings
.Color
,
4086 gPlayer2Settings
.Team
, False));
4087 if gPlayer2
= nil then
4089 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4093 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4097 // Çàãðóçêà è çàïóñê êàðòû:
4098 if not g_Game_StartMap(Map
, True) then
4100 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4104 // Íåò òî÷åê ïîÿâëåíèÿ:
4105 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4106 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4107 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4108 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4109 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4111 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4115 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4119 for i
:= nPl
+1 to nPlayers
do
4120 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4123 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4124 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4125 Options
: LongWord; nPlayers
: Byte;
4126 IPAddr
: LongWord; Port
: Word);
4130 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4132 g_Game_ClearLoading();
4135 gGameSettings
.GameType
:= GT_SERVER
;
4136 gGameSettings
.GameMode
:= GameMode
;
4137 gSwitchGameMode
:= GameMode
;
4138 gGameSettings
.TimeLimit
:= TimeLimit
;
4139 gGameSettings
.GoalLimit
:= GoalLimit
;
4140 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4141 gGameSettings
.Options
:= Options
;
4143 gCoopTotalMonstersKilled
:= 0;
4144 gCoopTotalSecretsFound
:= 0;
4145 gCoopTotalMonsters
:= 0;
4146 gCoopTotalSecrets
:= 0;
4150 g_Game_ExecuteEvent('ongamestart');
4152 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4153 g_Game_SetupScreenSize();
4155 // Ðåæèì íàáëþäàòåëÿ:
4156 if nPlayers
= 0 then
4162 if nPlayers
>= 1 then
4164 // Ñîçäàíèå ïåðâîãî èãðîêà:
4165 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4166 gPlayer1Settings
.Color
,
4167 gPlayer1Settings
.Team
, False));
4168 if gPlayer1
= nil then
4170 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4174 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4177 if nPlayers
>= 2 then
4179 // Ñîçäàíèå âòîðîãî èãðîêà:
4180 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4181 gPlayer2Settings
.Color
,
4182 gPlayer2Settings
.Team
, False));
4183 if gPlayer2
= nil then
4185 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4189 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4193 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4195 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
4199 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
4201 // Çàãðóçêà è çàïóñê êàðòû:
4202 if not g_Game_StartMap(Map
, True) then
4204 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4208 // Íåò òî÷åê ïîÿâëåíèÿ:
4209 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4210 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4211 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4212 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4213 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4215 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4219 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4222 NetState
:= NET_STATE_GAME
;
4225 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4240 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4241 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4243 g_Game_ClearLoading();
4246 gGameSettings
.GameType
:= GT_CLIENT
;
4248 gCoopTotalMonstersKilled
:= 0;
4249 gCoopTotalSecretsFound
:= 0;
4250 gCoopTotalMonsters
:= 0;
4251 gCoopTotalSecrets
:= 0;
4255 g_Game_ExecuteEvent('ongamestart');
4257 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4258 g_Game_SetupScreenSize();
4260 NetState
:= NET_STATE_AUTH
;
4262 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4264 if not g_Net_Connect(Addr
, Port
) then
4266 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4267 NetState
:= NET_STATE_NONE
;
4271 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4273 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4278 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
4280 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4282 Ptr
:= NetEvent
.packet
^.data
;
4283 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4286 MID
:= InMsg
.ReadByte();
4288 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4290 NetMyID
:= InMsg
.ReadByte();
4291 NetPlrUID1
:= InMsg
.ReadWord();
4293 WadName
:= InMsg
.ReadString();
4294 Map
:= InMsg
.ReadString();
4296 gWADHash
:= InMsg
.ReadMD5();
4298 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4299 gSwitchGameMode
:= gGameSettings
.GameMode
;
4300 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4301 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4302 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4303 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4304 T
:= InMsg
.ReadLongWord();
4306 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
4307 if newResPath
= '' then
4309 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4310 newResPath
:= g_Res_DownloadWAD(WadName
);
4311 if newResPath
= '' then
4313 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4314 enet_packet_destroy(NetEvent
.packet
);
4315 NetState
:= NET_STATE_NONE
;
4319 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
4321 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4322 gPlayer1Settings
.Color
,
4323 gPlayer1Settings
.Team
, False));
4325 if gPlayer1
= nil then
4327 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4329 enet_packet_destroy(NetEvent
.packet
);
4330 NetState
:= NET_STATE_NONE
;
4334 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4335 gPlayer1
.UID
:= NetPlrUID1
;
4336 gPlayer1
.Reset(True);
4338 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
4340 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4342 enet_packet_destroy(NetEvent
.packet
);
4343 NetState
:= NET_STATE_NONE
;
4351 enet_packet_destroy(NetEvent
.packet
);
4355 enet_packet_destroy(NetEvent
.packet
);
4359 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4362 if (NetEvent
.data
<= NET_DISC_MAX
) then
4363 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4364 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4371 ProcessLoading(true);
4373 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
4382 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4383 NetState
:= NET_STATE_NONE
;
4387 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4388 gLMSRespawnTime
:= 0;
4391 NetState
:= NET_STATE_GAME
;
4392 MC_SEND_FullStateRequest
;
4393 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4396 procedure g_Game_SaveOptions();
4398 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
4401 procedure g_Game_ChangeMap(const MapPath
: String);
4405 g_Game_ClearLoading();
4407 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4408 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4409 if gExitByTrigger
then
4412 gExitByTrigger
:= False;
4414 if not g_Game_StartMap(MapPath
, Force
) then
4415 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4418 procedure g_Game_Restart();
4422 if g_Game_IsClient
then
4424 map
:= g_ExtractFileName(gMapInfo
.Map
);
4428 g_Game_ClearLoading();
4429 g_Game_StartMap(Map
, True, gCurrentMapFileName
);
4432 function g_Game_StartMap(Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4434 NewWAD
, ResName
: String;
4437 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4438 g_Player_RemoveAllCorpses();
4440 if (not g_Game_IsClient
) and
4441 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4442 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4444 if gSwitchGameMode
= GM_CTF
then
4445 gGameSettings
.MaxLives
:= 0;
4446 gGameSettings
.GameMode
:= gSwitchGameMode
;
4449 gSwitchGameMode
:= gGameSettings
.GameMode
;
4451 g_Player_ResetTeams();
4453 if isWadPath(Map
) then
4455 NewWAD
:= g_ExtractWadName(Map
);
4456 ResName
:= g_ExtractFileName(Map
);
4457 if g_Game_IsServer
then
4459 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
4460 g_Game_LoadWAD(NewWAD
);
4462 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
4463 g_Game_ClientWAD(NewWAD
, gWADHash
);
4467 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
4470 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4472 gState
:= STATE_NONE
;
4473 g_ActiveWindow
:= nil;
4479 if gGameSettings
.GameMode
= GM_CTF
then
4481 g_Map_ResetFlag(FLAG_RED
);
4482 g_Map_ResetFlag(FLAG_BLUE
);
4483 // CTF, à ôëàãîâ íåò:
4484 if not g_Map_HaveFlagPoints() then
4485 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4490 gState
:= STATE_MENU
;
4495 gPauseMain
:= false;
4496 gPauseHolmes
:= false;
4498 NetTimeToUpdate
:= 1;
4499 NetTimeToReliable
:= 0;
4500 NetTimeToMaster
:= NetMasterRate
;
4501 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4502 gLMSRespawnTime
:= 0;
4503 gMissionFailed
:= False;
4506 gCoopMonstersKilled
:= 0;
4507 gCoopSecretsFound
:= 0;
4509 gVoteInProgress
:= False;
4510 gVotePassed
:= False;
4516 if not gGameOn
then Exit
;
4518 g_Game_SpectateCenterView();
4520 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
4522 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4523 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
4524 gLMSSoftSpawn
:= True;
4525 if NetMode
= NET_SERVER
then
4526 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
4528 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
4531 if NetMode
= NET_SERVER
then
4533 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
4536 if NetUseMaster
then
4538 if (NetMHost
= nil) or (NetMPeer
= nil) then
4539 if not g_Net_Slist_Connect
then
4540 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4545 if NetClients
<> nil then
4546 for I
:= 0 to High(NetClients
) do
4547 if NetClients
[I
].Used
then
4549 NetClients
[I
].Voted
:= False;
4550 if NetClients
[I
].RequestedFullUpdate
then
4552 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
4553 NetClients
[I
].RequestedFullUpdate
:= False;
4557 g_Net_UnbanNonPermHosts();
4562 gCoopTotalMonstersKilled
:= 0;
4563 gCoopTotalSecretsFound
:= 0;
4564 gCoopTotalMonsters
:= 0;
4565 gCoopTotalSecrets
:= 0;
4569 g_Game_ExecuteEvent('onmapstart');
4572 procedure SetFirstLevel();
4576 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4577 if MapList
= nil then
4580 SortSArray(MapList
);
4581 gNextMap
:= MapList
[Low(MapList
)];
4586 procedure g_Game_ExitLevel(const Map
: AnsiString);
4590 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
4591 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
4592 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
4593 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
4595 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4596 if gGameSettings
.GameType
= GT_SINGLE
then
4597 gExit
:= EXIT_ENDLEVELSINGLE
4598 else // Âûøëè â âûõîä â Ñâîåé èãðå
4600 gExit
:= EXIT_ENDLEVELCUSTOM
;
4601 if gGameSettings
.GameMode
= GM_COOP
then
4602 g_Player_RememberAll
;
4604 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4607 if gGameSettings
.GameMode
= GM_COOP
then
4610 gStatsPressed
:= True;
4611 gNextMap
:= 'MAP01';
4613 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4616 if g_Game_IsNet
then
4618 MH_SEND_GameStats();
4619 MH_SEND_CoopStats();
4625 procedure g_Game_RestartLevel();
4629 if gGameSettings
.GameMode
= GM_SINGLE
then
4634 gExit
:= EXIT_ENDLEVELCUSTOM
;
4635 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4639 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
4643 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
4645 if not g_Game_IsClient
then
4647 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
4650 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4651 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
4655 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
4659 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
4660 g_Game_LoadWAD(NewWAD
);
4663 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
4665 i
, n
, nb
, nr
: Integer;
4667 function monRespawn (mon
: TMonster
): Boolean;
4669 result
:= false; // don't stop
4670 if not mon
.FNoRespawn
then mon
.Respawn();
4674 if not g_Game_IsServer
then Exit
;
4675 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
4676 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4677 gLMSRespawnTime
:= 0;
4680 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
4682 gMissionFailed
:= True;
4683 g_Game_RestartLevel
;
4687 n
:= 0; nb
:= 0; nr
:= 0;
4688 for i
:= Low(gPlayers
) to High(gPlayers
) do
4689 if (gPlayers
[i
] <> nil) and
4690 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
4691 (gPlayers
[i
] is TBot
)) then
4694 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
4695 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
4698 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
4700 // wait a second until the fuckers finally decide to join
4701 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4702 gLMSRespawnTime
:= gTime
+ 1000;
4703 gLMSSoftSpawn
:= NoMapRestart
;
4707 g_Player_RemoveAllCorpses
;
4708 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
4709 if g_Game_IsNet
then
4710 MH_SEND_GameEvent(NET_EV_LMS_START
);
4712 for i
:= Low(gPlayers
) to High(gPlayers
) do
4714 if gPlayers
[i
] = nil then continue
;
4715 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
4716 // don't touch normal spectators
4717 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
4719 gPlayers
[i
].FNoRespawn
:= True;
4720 gPlayers
[i
].Lives
:= 0;
4721 if g_Game_IsNet
then
4722 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
4725 gPlayers
[i
].FNoRespawn
:= False;
4726 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
4727 gPlayers
[i
].Respawn(False, True);
4728 if gGameSettings
.GameMode
= GM_COOP
then
4730 gPlayers
[i
].Frags
:= 0;
4731 gPlayers
[i
].RecallState
;
4733 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
4734 gPlayer1
:= g_Player_Get(gLMSPID1
);
4735 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
4736 gPlayer2
:= g_Player_Get(gLMSPID2
);
4739 g_Items_RestartRound();
4742 g_Mons_ForEach(monRespawn
);
4744 gLMSSoftSpawn
:= False;
4747 function g_Game_GetFirstMap(WAD
: String): String;
4751 MapList
:= g_Map_GetMapsList(WAD
);
4752 if MapList
= nil then
4755 SortSArray(MapList
);
4756 Result
:= MapList
[Low(MapList
)];
4758 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4764 function g_Game_GetNextMap(): String;
4771 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4772 if MapList
= nil then
4775 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4777 SortSArray(MapList
);
4779 for I
:= Low(MapList
) to High(MapList
) do
4780 if Map
= MapList
[I
] then
4786 if MapIndex
<> -255 then
4788 if MapIndex
= High(MapList
) then
4789 Result
:= MapList
[Low(MapList
)]
4791 Result
:= MapList
[MapIndex
+ 1];
4793 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4799 procedure g_Game_NextLevel();
4801 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4802 gExit
:= EXIT_ENDLEVELCUSTOM
4805 gExit
:= EXIT_ENDLEVELSINGLE
;
4809 if gNextMap
<> '' then Exit
;
4810 gNextMap
:= g_Game_GetNextMap();
4813 function g_Game_IsTestMap(): Boolean;
4815 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4818 procedure g_Game_DeleteTestMap();
4821 //MapName: AnsiString;
4829 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
4830 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
4831 if (a
= 0) then exit
;
4833 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
4834 WadName
:= Copy(gMapToDelete
, 1, a
+3);
4835 Delete(gMapToDelete
, 1, a
+5);
4836 gMapToDelete
:= UpperCase(gMapToDelete
);
4838 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
4841 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4842 if MapName <> TEST_MAP_NAME then
4845 if not gTempDelete then
4847 time := g_GetFileTime(WadName);
4848 WAD := TWADFile.Create();
4851 if not WAD.ReadFile(WadName) then
4852 begin // Íåò òàêîãî WAD-ôàéëà
4857 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4859 MapList := WAD.GetResourcesList('');
4861 if MapList <> nil then
4862 for a := 0 to High(MapList) do
4863 if MapList[a] = MapName then
4865 // Óäàëÿåì è ñîõðàíÿåì:
4866 WAD.RemoveResource('', MapName);
4867 WAD.SaveTo(WadName);
4872 g_SetFileTime(WadName, time);
4875 if gTempDelete
then DeleteFile(WadName
);
4878 procedure GameCVars(P
: SSArray
);
4881 stat
: TPlayerStatArray
;
4886 cmd
:= LowerCase(P
[0]);
4887 if cmd
= 'r_showfps' then
4889 if (Length(P
) > 1) and
4890 ((P
[1] = '1') or (P
[1] = '0')) then
4891 gShowFPS
:= (P
[1][1] = '1');
4894 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4896 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4898 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4900 with gGameSettings
do
4902 if (Length(P
) > 1) and
4903 ((P
[1] = '1') or (P
[1] = '0')) then
4905 if (P
[1][1] = '1') then
4906 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4908 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4911 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4912 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4914 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4916 if g_Game_IsNet
then MH_SEND_GameSettings
;
4919 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4921 with gGameSettings
do
4923 if (Length(P
) > 1) and
4924 ((P
[1] = '1') or (P
[1] = '0')) then
4926 if (P
[1][1] = '1') then
4927 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4929 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4932 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4933 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4935 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4937 if g_Game_IsNet
then MH_SEND_GameSettings
;
4940 else if cmd
= 'g_gamemode' then
4942 a
:= g_Game_TextToMode(P
[1]);
4943 if a
= GM_SINGLE
then a
:= GM_COOP
;
4944 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4946 gSwitchGameMode
:= a
;
4947 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4948 (gState
= STATE_INTERSINGLE
) then
4949 gSwitchGameMode
:= GM_SINGLE
;
4951 gGameSettings
.GameMode
:= gSwitchGameMode
;
4953 if gSwitchGameMode
= gGameSettings
.GameMode
then
4954 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4955 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4957 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4958 [g_Game_ModeToText(gGameSettings
.GameMode
),
4959 g_Game_ModeToText(gSwitchGameMode
)]));
4961 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4963 with gGameSettings
do
4965 if (Length(P
) > 1) and
4966 ((P
[1] = '1') or (P
[1] = '0')) then
4968 if (P
[1][1] = '1') then
4969 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4971 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4974 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4975 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4977 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4978 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4980 if g_Game_IsNet
then MH_SEND_GameSettings
;
4983 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4985 with gGameSettings
do
4987 if (Length(P
) > 1) and
4988 ((P
[1] = '1') or (P
[1] = '0')) then
4990 if (P
[1][1] = '1') then
4991 Options
:= Options
or GAME_OPTION_MONSTERS
4993 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4996 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4997 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4999 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
5000 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5002 if g_Game_IsNet
then MH_SEND_GameSettings
;
5005 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
5007 with gGameSettings
do
5009 if (Length(P
) > 1) and
5010 ((P
[1] = '1') or (P
[1] = '0')) then
5012 if (P
[1][1] = '1') then
5013 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
5015 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
5018 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
5019 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
5021 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
5023 if g_Game_IsNet
then MH_SEND_GameSettings
;
5026 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
5028 with gGameSettings
do
5030 if (Length(P
) > 1) and
5031 ((P
[1] = '1') or (P
[1] = '0')) then
5033 if (P
[1][1] = '1') then
5034 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
5036 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
5039 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
5040 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
5042 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
5044 if g_Game_IsNet
then MH_SEND_GameSettings
;
5047 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
5049 if Length(P
) > 1 then
5051 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
5052 gGameSettings
.WarmupTime
:= 30
5054 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
5057 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
5058 [gGameSettings
.WarmupTime
]));
5059 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5061 else if cmd
= 'net_interp' then
5063 if (Length(P
) > 1) then
5064 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
5066 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
5067 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5068 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
5069 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5072 else if cmd
= 'net_forceplayerupdate' then
5074 if (Length(P
) > 1) and
5075 ((P
[1] = '1') or (P
[1] = '0')) then
5076 NetForcePlayerUpdate
:= (P
[1][1] = '1');
5078 if NetForcePlayerUpdate
then
5079 g_Console_Add('net_forceplayerupdate = 1')
5081 g_Console_Add('net_forceplayerupdate = 0');
5082 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5083 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
5084 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5087 else if cmd
= 'net_predictself' then
5089 if (Length(P
) > 1) and
5090 ((P
[1] = '1') or (P
[1] = '0')) then
5091 NetPredictSelf
:= (P
[1][1] = '1');
5093 if NetPredictSelf
then
5094 g_Console_Add('net_predictself = 1')
5096 g_Console_Add('net_predictself = 0');
5097 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5098 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
5099 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5102 else if cmd
= 'sv_name' then
5104 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5106 NetServerName
:= P
[1];
5107 if Length(NetServerName
) > 64 then
5108 SetLength(NetServerName
, 64);
5109 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
5113 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
5115 else if cmd
= 'sv_passwd' then
5117 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5119 NetPassword
:= P
[1];
5120 if Length(NetPassword
) > 24 then
5121 SetLength(NetPassword
, 24);
5122 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
5126 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
5128 else if cmd
= 'sv_maxplrs' then
5130 if (Length(P
) > 1) then
5132 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
5133 if g_Game_IsServer
and g_Game_IsNet
then
5136 for a
:= 0 to High(NetClients
) do
5137 if NetClients
[a
].Used
then
5140 if b
> NetMaxClients
then
5142 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
5143 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
5144 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5145 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5148 if NetUseMaster
then
5153 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
5155 else if cmd
= 'sv_public' then
5157 if (Length(P
) > 1) then
5159 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
5160 if g_Game_IsServer
and g_Game_IsNet
then
5161 if NetUseMaster
then
5163 if NetMPeer
= nil then
5164 if not g_Net_Slist_Connect() then
5165 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
5166 g_Net_Slist_Update();
5169 if NetMPeer
<> nil then
5170 g_Net_Slist_Disconnect();
5173 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
5175 else if cmd
= 'sv_intertime' then
5177 if (Length(P
) > 1) then
5178 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5180 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5182 else if cmd
= 'p1_name' then
5184 if (Length(P
) > 1) and gGameOn
then
5186 if g_Game_IsClient
then
5188 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5189 MC_SEND_PlayerSettings
;
5192 if gPlayer1
<> nil then
5194 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5195 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5198 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5201 else if cmd
= 'p2_name' then
5203 if (Length(P
) > 1) and gGameOn
then
5205 if g_Game_IsClient
then
5207 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5208 MC_SEND_PlayerSettings
;
5211 if gPlayer2
<> nil then
5213 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5214 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5217 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5220 else if cmd
= 'p1_color' then
5222 if Length(P
) > 3 then
5223 if g_Game_IsClient
then
5225 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5226 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5227 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5228 MC_SEND_PlayerSettings
;
5231 if gPlayer1
<> nil then
5233 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5234 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5235 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5236 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5239 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5240 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5241 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5243 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5245 if Length(P
) > 3 then
5246 if g_Game_IsClient
then
5248 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5249 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5250 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5251 MC_SEND_PlayerSettings
;
5254 if gPlayer2
<> nil then
5256 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5257 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5258 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5259 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5262 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5263 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5264 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5266 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5268 if cmd
= 'r_showtime' then
5270 if (Length(P
) > 1) and
5271 ((P
[1] = '1') or (P
[1] = '0')) then
5272 gShowTime
:= (P
[1][1] = '1');
5275 g_Console_Add(_lc
[I_MSG_TIME_ON
])
5277 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
5279 else if cmd
= 'r_showscore' then
5281 if (Length(P
) > 1) and
5282 ((P
[1] = '1') or (P
[1] = '0')) then
5283 gShowGoals
:= (P
[1][1] = '1');
5286 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5288 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5290 else if cmd
= 'r_showstat' then
5292 if (Length(P
) > 1) and
5293 ((P
[1] = '1') or (P
[1] = '0')) then
5294 gShowStat
:= (P
[1][1] = '1');
5297 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5299 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5301 else if cmd
= 'r_showkillmsg' then
5303 if (Length(P
) > 1) and
5304 ((P
[1] = '1') or (P
[1] = '0')) then
5305 gShowKillMsg
:= (P
[1][1] = '1');
5307 if gShowKillMsg
then
5308 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5310 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5312 else if cmd
= 'r_showlives' then
5314 if (Length(P
) > 1) and
5315 ((P
[1] = '1') or (P
[1] = '0')) then
5316 gShowLives
:= (P
[1][1] = '1');
5319 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5321 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5323 else if cmd
= 'r_showspect' then
5325 if (Length(P
) > 1) and
5326 ((P
[1] = '1') or (P
[1] = '0')) then
5327 gSpectHUD
:= (P
[1][1] = '1');
5330 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5332 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5334 else if cmd
= 'r_showping' then
5336 if (Length(P
) > 1) and
5337 ((P
[1] = '1') or (P
[1] = '0')) then
5338 gShowPing
:= (P
[1][1] = '1');
5341 g_Console_Add(_lc
[I_MSG_PING_ON
])
5343 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5345 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5347 if Length(P
) > 1 then
5349 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5350 gGameSettings
.GoalLimit
:= 0
5355 if gGameSettings
.GameMode
= GM_DM
then
5357 stat
:= g_Player_GetStats();
5359 for a
:= 0 to High(stat
) do
5360 if stat
[a
].Frags
> b
then
5364 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5366 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5369 if g_Game_IsNet
then MH_SEND_GameSettings
;
5372 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5374 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5376 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5377 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5379 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5380 [gGameSettings
.TimeLimit
div 3600,
5381 (gGameSettings
.TimeLimit
div 60) mod 60,
5382 gGameSettings
.TimeLimit
mod 60]));
5383 if g_Game_IsNet
then MH_SEND_GameSettings
;
5385 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5387 if Length(P
) > 1 then
5389 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5390 gGameSettings
.MaxLives
:= 0
5394 stat
:= g_Player_GetStats();
5396 for a
:= 0 to High(stat
) do
5397 if stat
[a
].Lives
> b
then
5399 gGameSettings
.MaxLives
:=
5400 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5404 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5405 [gGameSettings
.MaxLives
]));
5406 if g_Game_IsNet
then MH_SEND_GameSettings
;
5411 procedure PrintHeapStats();
5415 hs
:= GetFPCHeapStatus();
5416 e_LogWriteLn ('v===== heap status =====v');
5417 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5418 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5419 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5420 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5421 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5422 e_LogWriteLn ('^=======================^');
5425 procedure DebugCommands(P
: SSArray
);
5432 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5433 if {gDebugMode}conIsCheatsEnabled
then
5435 cmd
:= LowerCase(P
[0]);
5436 if cmd
= 'd_window' then
5438 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
5439 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
5440 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5441 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5442 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
5444 else if cmd
= 'd_sounds' then
5446 if (Length(P
) > 1) and
5447 ((P
[1] = '1') or (P
[1] = '0')) then
5448 g_Debug_Sounds
:= (P
[1][1] = '1');
5450 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5452 else if cmd
= 'd_frames' then
5454 if (Length(P
) > 1) and
5455 ((P
[1] = '1') or (P
[1] = '0')) then
5456 g_Debug_Frames
:= (P
[1][1] = '1');
5458 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5460 else if cmd
= 'd_winmsg' then
5462 if (Length(P
) > 1) and
5463 ((P
[1] = '1') or (P
[1] = '0')) then
5464 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5466 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5468 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5470 if (Length(P
) > 1) and
5471 ((P
[1] = '1') or (P
[1] = '0')) then
5472 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5474 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5476 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5478 if Length(P
) > 1 then
5480 '0': g_debug_BotAIOff
:= 0;
5481 '1': g_debug_BotAIOff
:= 1;
5482 '2': g_debug_BotAIOff
:= 2;
5483 '3': g_debug_BotAIOff
:= 3;
5486 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5488 else if cmd
= 'd_monster' then
5490 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5491 if Length(P
) < 2 then
5493 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5494 g_Console_Add('ID | Name');
5495 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5496 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5497 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5500 a
:= StrToIntDef(P
[1], 0);
5501 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5502 a
:= g_Mons_TypeIdByName(P
[1]);
5504 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5505 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5508 with gPlayer1
.Obj
do
5510 mon
:= g_Monsters_Create(a
,
5511 X
+ Rect
.X
+ (Rect
.Width
div 2),
5512 Y
+ Rect
.Y
+ Rect
.Height
,
5513 gPlayer1
.Direction
, True);
5515 if (Length(P
) > 2) and (mon
<> nil) then
5517 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
5518 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
5519 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
5520 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
5521 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
5522 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5523 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5524 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5525 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5530 else if (cmd
= 'd_health') then
5532 if (Length(P
) > 1) and
5533 ((P
[1] = '1') or (P
[1] = '0')) then
5534 g_debug_HealthBar
:= (P
[1][1] = '1');
5536 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5538 else if (cmd
= 'd_player') then
5540 if (Length(P
) > 1) and
5541 ((P
[1] = '1') or (P
[1] = '0')) then
5542 g_debug_Player
:= (P
[1][1] = '1');
5544 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5546 else if (cmd
= 'd_joy') then
5549 g_Console_Add(e_JoystickStateToString(a
));
5551 else if (cmd
= 'd_mem') then
5557 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5561 procedure GameCheats(P
: SSArray
);
5567 if (not gGameOn
) or (not conIsCheatsEnabled
) then
5569 g_Console_Add('not available');
5575 g_Console_Add('where is the player?!');
5578 cmd
:= LowerCase(P
[0]);
5582 plr
.GodMode
:= not plr
.GodMode
;
5583 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5586 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5587 if cmd
= 'give' then
5589 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
5590 for f
:= 1 to High(P
) do
5592 cmd
:= LowerCase(P
[f
]);
5593 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
5594 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
5595 if cmd
= 'exit' then
5597 if gTriggers
<> nil then
5599 for a
:= 0 to High(gTriggers
) do
5601 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5603 g_Console_Add('player left the map');
5604 gExitByTrigger
:= True;
5605 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
5606 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
5614 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
5615 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
5616 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
5617 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
5618 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
5620 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
5621 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
5623 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
5624 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;
5626 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
5627 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
5629 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
5630 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
5632 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
5633 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
5635 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
5636 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
5637 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
5639 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
5640 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
5641 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
5642 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;
5643 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
5644 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
5646 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;
5647 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;
5648 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;
5649 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;
5650 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;
5651 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;
5653 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
5654 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;
5656 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;
5657 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;
5659 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
5661 if cmd
= 'ammo' then
5663 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
5664 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
5665 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
5666 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
5667 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
5668 g_Console_Add('player got some ammo');
5672 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
5673 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
5675 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
5676 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
5678 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
5679 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
5681 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
5682 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
5684 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
5686 if cmd
= 'weapons' then
5688 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
5689 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
5690 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
5691 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
5692 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
5693 plr
.GiveItem(ITEM_WEAPON_BFG
);
5694 g_Console_Add('player got weapons');
5698 if cmd
= 'keys' then
5700 plr
.GiveItem(ITEM_KEY_RED
);
5701 plr
.GiveItem(ITEM_KEY_GREEN
);
5702 plr
.GiveItem(ITEM_KEY_BLUE
);
5703 g_Console_Add('player got all keys');
5707 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
5712 if cmd
= 'open' then
5714 g_Console_Add('player activated sesame');
5715 g_Triggers_OpenAll();
5722 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
5726 if cmd
= 'noclip' then
5729 g_Console_Add('wall hardeness adjusted');
5733 if cmd
= 'notarget' then
5735 plr
.NoTarget
:= not plr
.NoTarget
;
5736 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
5740 if cmd
= 'noreload' then
5742 plr
.NoReload
:= not plr
.NoReload
;
5743 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
5747 if cmd
= 'speedy' then
5749 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
5750 g_Console_Add('speed adjusted');
5754 if cmd
= 'jumpy' then
5756 VEL_JUMP
:= 30-VEL_JUMP
;
5757 g_Console_Add('jump height adjusted');
5761 if cmd
= 'automap' then
5763 gShowMap
:= not gShowMap
;
5764 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
5768 if cmd
= 'aimline' then
5770 gAimLine
:= not gAimLine
;
5771 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
5776 procedure GameCommands(P
: SSArray
);
5782 pl
: pTNetClient
= nil;
5789 cmd
:= LowerCase(P
[0]);
5791 if (cmd
= 'quit') or
5798 else if cmd
= 'pause' then
5800 if (g_ActiveWindow
= nil) then
5801 g_Game_Pause(not gPauseMain
);
5803 else if cmd
= 'endgame' then
5804 gExit
:= EXIT_SIMPLE
5805 else if cmd
= 'restart' then
5807 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5809 if g_Game_IsClient
then
5811 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5816 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5818 else if cmd
= 'kick' then
5820 if g_Game_IsServer
then
5822 if Length(P
) < 2 then
5824 g_Console_Add('kick <name>');
5829 g_Console_Add('kick <name>');
5833 if g_Game_IsNet
then
5834 pl
:= g_Net_Client_ByName(P
[1]);
5837 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5838 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
5839 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5840 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5841 if NetUseMaster
then
5843 end else if gPlayers
<> nil then
5844 for a
:= Low(gPlayers
) to High(gPlayers
) do
5845 if gPlayers
[a
] <> nil then
5846 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5848 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
5849 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5851 gPlayers
[a
].Lives
:= 0;
5852 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5853 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5854 g_Player_Remove(gPlayers
[a
].UID
);
5855 if NetUseMaster
then
5857 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
5861 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5863 else if cmd
= 'kick_id' then
5865 if g_Game_IsServer
and g_Game_IsNet
then
5867 if Length(P
) < 2 then
5869 g_Console_Add('kick_id <client ID>');
5874 g_Console_Add('kick_id <client ID>');
5878 a
:= StrToIntDef(P
[1], 0);
5879 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5881 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5883 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5884 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5885 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5886 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5887 if NetUseMaster
then
5892 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5894 else if cmd
= 'ban' then
5896 if g_Game_IsServer
and g_Game_IsNet
then
5898 if Length(P
) < 2 then
5900 g_Console_Add('ban <name>');
5905 g_Console_Add('ban <name>');
5909 pl
:= g_Net_Client_ByName(P
[1]);
5912 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5913 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5914 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5915 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5916 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5917 if NetUseMaster
then
5920 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5922 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5924 else if cmd
= 'ban_id' then
5926 if g_Game_IsServer
and g_Game_IsNet
then
5928 if Length(P
) < 2 then
5930 g_Console_Add('ban_id <client ID>');
5935 g_Console_Add('ban_id <client ID>');
5939 a
:= StrToIntDef(P
[1], 0);
5940 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5941 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5943 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5944 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5945 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5946 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5947 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5948 if NetUseMaster
then
5952 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5954 else if cmd
= 'permban' then
5956 if g_Game_IsServer
and g_Game_IsNet
then
5958 if Length(P
) < 2 then
5960 g_Console_Add('permban <name>');
5965 g_Console_Add('permban <name>');
5969 pl
:= g_Net_Client_ByName(P
[1]);
5972 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5973 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5974 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5975 g_Net_SaveBanList();
5976 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5977 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5978 if NetUseMaster
then
5981 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5983 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5985 else if cmd
= 'permban_id' then
5987 if g_Game_IsServer
and g_Game_IsNet
then
5989 if Length(P
) < 2 then
5991 g_Console_Add('permban_id <client ID>');
5996 g_Console_Add('permban_id <client ID>');
6000 a
:= StrToIntDef(P
[1], 0);
6001 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6002 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6004 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6005 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6006 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6007 g_Net_SaveBanList();
6008 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6009 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6010 if NetUseMaster
then
6014 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6016 else if cmd
= 'unban' then
6018 if g_Game_IsServer
and g_Game_IsNet
then
6020 if Length(P
) < 2 then
6022 g_Console_Add('unban <IP Address>');
6027 g_Console_Add('unban <IP Address>');
6031 if g_Net_UnbanHost(P
[1]) then
6033 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6034 g_Net_SaveBanList();
6036 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6038 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6040 else if cmd
= 'clientlist' then
6042 if g_Game_IsServer
and g_Game_IsNet
then
6045 if NetClients
<> nil then
6046 for a
:= Low(NetClients
) to High(NetClients
) do
6047 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6049 plr
:= g_Player_Get(NetClients
[a
].Player
);
6050 if plr
= nil then continue
;
6052 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6053 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6056 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6058 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6060 else if cmd
= 'connect' then
6062 if (NetMode
= NET_NONE
) then
6064 if Length(P
) < 2 then
6066 g_Console_Add('connect <IP> [port] [password]');
6071 g_Console_Add('connect <IP> [port] [password]');
6075 if Length(P
) > 2 then
6076 prt
:= StrToIntDef(P
[2], 25666)
6080 if Length(P
) > 3 then
6085 g_Game_StartClient(P
[1], prt
, pw
);
6088 else if cmd
= 'disconnect' then
6090 if (NetMode
= NET_CLIENT
) then
6093 else if cmd
= 'reconnect' then
6095 if (NetMode
= NET_SERVER
) then
6098 if (NetMode
= NET_CLIENT
) then
6101 gExit
:= EXIT_SIMPLE
;
6105 //TODO: Use last successful password to reconnect, instead of ''
6106 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6108 else if (cmd
= 'addbot') or
6109 (cmd
= 'bot_add') then
6111 if Length(P
) > 1 then
6112 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6114 g_Bot_Add(TEAM_NONE
, 2);
6116 else if cmd
= 'bot_addlist' then
6118 if Length(P
) > 1 then
6119 if Length(P
) = 2 then
6120 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6122 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6124 else if cmd
= 'bot_removeall' then
6126 else if cmd
= 'chat' then
6128 if g_Game_IsNet
then
6130 if Length(P
) > 1 then
6132 for a
:= 1 to High(P
) do
6133 chstr
:= chstr
+ P
[a
] + ' ';
6135 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6137 if Length(chstr
) < 1 then
6139 g_Console_Add('chat <text>');
6143 chstr
:= b_Text_Format(chstr
);
6144 if g_Game_IsClient
then
6145 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6147 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6150 g_Console_Add('chat <text>');
6152 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6154 else if cmd
= 'teamchat' then
6156 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6158 if Length(P
) > 1 then
6160 for a
:= 1 to High(P
) do
6161 chstr
:= chstr
+ P
[a
] + ' ';
6163 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6165 if Length(chstr
) < 1 then
6167 g_Console_Add('teamchat <text>');
6171 chstr
:= b_Text_Format(chstr
);
6172 if g_Game_IsClient
then
6173 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6175 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6176 gPlayer1Settings
.Team
);
6179 g_Console_Add('teamchat <text>');
6181 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6183 else if cmd
= 'game' then
6185 if gGameSettings
.GameType
<> GT_NONE
then
6187 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6190 if Length(P
) = 1 then
6192 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6195 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
6196 P
[1] := addWadExtension(P
[1]);
6197 if FileExists(MapsDir
+ P
[1]) then
6199 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6200 if Length(P
) < 3 then
6203 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6206 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6208 if g_Map_Exist(MapsDir
+ s
) then
6210 // Çàïóñêàåì ñâîþ èãðó
6212 with gGameSettings
do
6214 GameMode
:= g_Game_TextToMode(gcGameMode
);
6215 if gSwitchGameMode
<> GM_NONE
then
6216 GameMode
:= gSwitchGameMode
;
6217 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6218 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6220 if Length(P
) >= 4 then
6221 b
:= StrToIntDef(P
[3], 1);
6222 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6223 GoalLimit
, MaxLives
, Options
, b
);
6228 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6230 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6232 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6234 else if cmd
= 'host' then
6236 if gGameSettings
.GameType
<> GT_NONE
then
6238 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6241 if Length(P
) < 4 then
6243 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6246 if not StrToIp(P
[1], listen
) then
6248 prt
:= StrToIntDef(P
[2], 25666);
6250 P
[3] := addWadExtension(P
[3]);
6251 if FileExists(MapsDir
+ P
[3]) then
6253 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6254 if Length(P
) < 5 then
6257 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6260 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6262 if g_Map_Exist(MapsDir
+ s
) then
6264 // Çàïóñêàåì ñâîþ èãðó
6266 with gGameSettings
do
6268 GameMode
:= g_Game_TextToMode(gcGameMode
);
6269 if gSwitchGameMode
<> GM_NONE
then
6270 GameMode
:= gSwitchGameMode
;
6271 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6272 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6274 if Length(P
) >= 6 then
6275 b
:= StrToIntDef(P
[5], 0);
6276 g_Game_StartServer(s
, GameMode
, TimeLimit
,
6277 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
6282 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6284 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]));
6286 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
6288 else if cmd
= 'map' then
6290 if Length(P
) = 1 then
6292 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6294 g_Console_Add(cmd
+ ' <MAP>');
6295 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6297 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6299 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6301 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
6302 if Length(P
) < 3 then
6304 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6305 s
:= UpperCase(P
[1]);
6306 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6307 begin // Êàðòà íàøëàñü
6308 gExitByTrigger
:= False;
6310 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6312 gExit
:= EXIT_ENDLEVELCUSTOM
;
6314 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6315 g_Game_ChangeMap(s
);
6318 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6319 P
[1] := addWadExtension(P
[1]);
6320 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6321 if FileExists(MapsDir
+ P
[1]) then
6323 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6325 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6327 s
:= P
[1] + ':\' + P
[2];
6329 if g_Map_Exist(MapsDir
+ s
) then
6331 gExitByTrigger
:= False;
6333 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6335 gExit
:= EXIT_ENDLEVELCUSTOM
;
6337 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6338 g_Game_ChangeMap(s
);
6341 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6343 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6345 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6349 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6350 P
[1] := addWadExtension(P
[1]);
6351 if FileExists(MapsDir
+ P
[1]) then
6354 P
[2] := UpperCase(P
[2]);
6355 s
:= P
[1] + ':\' + P
[2];
6357 if g_Map_Exist(MapsDir
+ s
) then
6358 begin // Íàøëè êàðòó
6359 gExitByTrigger
:= False;
6361 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6363 gExit
:= EXIT_ENDLEVELCUSTOM
;
6365 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6366 g_Game_ChangeMap(s
);
6368 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6370 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6373 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6375 else if cmd
= 'nextmap' then
6377 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6378 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6381 if Length(P
) = 1 then
6383 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6385 g_Console_Add(cmd
+ ' <MAP>');
6386 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6389 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6394 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6396 if Length(P
) < 3 then
6398 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6399 s
:= UpperCase(P
[1]);
6400 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6401 begin // Êàðòà íàøëàñü
6402 gExitByTrigger
:= False;
6407 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6408 P
[1] := addWadExtension(P
[1]);
6409 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6410 if FileExists(MapsDir
+ P
[1]) then
6412 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6414 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6416 s
:= P
[1] + ':\' + P
[2];
6418 if g_Map_Exist(MapsDir
+ s
) then
6419 begin // Óñòàíàâëèâàåì êàðòó
6420 gExitByTrigger
:= False;
6425 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6427 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6429 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6433 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6434 P
[1] := addWadExtension(P
[1]);
6435 if FileExists(MapsDir
+ P
[1]) then
6438 P
[2] := UpperCase(P
[2]);
6439 s
:= P
[1] + ':\' + P
[2];
6441 if g_Map_Exist(MapsDir
+ s
) then
6442 begin // Íàøëè êàðòó
6443 gExitByTrigger
:= False;
6447 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6449 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6452 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6455 if gNextMap
= '' then
6456 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
6458 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
6461 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
6464 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6466 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6468 gExitByTrigger
:= False;
6469 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6470 if (gNextMap
= '') and (gTriggers
<> nil) then
6471 for a
:= 0 to High(gTriggers
) do
6472 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6474 gExitByTrigger
:= True;
6475 //gNextMap := gTriggers[a].Data.MapName;
6476 gNextMap
:= gTriggers
[a
].tgcMap
;
6479 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6480 if gNextMap
= '' then
6481 gNextMap
:= g_Game_GetNextMap();
6482 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6483 if not isWadPath(gNextMap
) then
6484 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
6487 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6488 if g_Map_Exist(MapsDir
+ s
) then
6489 gExit
:= EXIT_ENDLEVELCUSTOM
6491 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
6493 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6495 else if (cmd
= 'event') then
6497 if (Length(P
) <= 1) then
6499 for a
:= 0 to High(gEvents
) do
6500 if gEvents
[a
].Command
= '' then
6501 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6503 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6506 if (Length(P
) = 2) then
6508 for a
:= 0 to High(gEvents
) do
6509 if gEvents
[a
].Name
= P
[1] then
6510 if gEvents
[a
].Command
= '' then
6511 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6513 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6516 for a
:= 0 to High(gEvents
) do
6517 if gEvents
[a
].Name
= P
[1] then
6519 gEvents
[a
].Command
:= '';
6520 for b
:= 2 to High(P
) do
6521 if Pos(' ', P
[b
]) = 0 then
6522 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6524 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6525 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6529 else if cmd
= 'suicide' then
6533 if g_Game_IsClient
then
6534 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6537 if gPlayer1
<> nil then
6538 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6539 if gPlayer2
<> nil then
6540 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6544 // Êîìàíäû Ñâîåé èãðû:
6545 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6547 if cmd
= 'bot_addred' then
6549 if Length(P
) > 1 then
6550 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6552 g_Bot_Add(TEAM_RED
, 2);
6554 else if cmd
= 'bot_addblue' then
6556 if Length(P
) > 1 then
6557 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6559 g_Bot_Add(TEAM_BLUE
, 2);
6561 else if cmd
= 'spectate' then
6567 else if cmd
= 'say' then
6569 if g_Game_IsServer
and g_Game_IsNet
then
6571 if Length(P
) > 1 then
6574 for a
:= 1 to High(P
) do
6575 chstr
:= chstr
+ P
[a
] + ' ';
6577 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6579 if Length(chstr
) < 1 then
6581 g_Console_Add('say <text>');
6585 chstr
:= b_Text_Format(chstr
);
6586 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6588 else g_Console_Add('say <text>');
6590 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6592 else if cmd
= 'tell' then
6594 if g_Game_IsServer
and g_Game_IsNet
then
6596 if (Length(P
) > 2) and (P
[1] <> '') then
6599 for a
:= 2 to High(P
) do
6600 chstr
:= chstr
+ P
[a
] + ' ';
6602 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6604 if Length(chstr
) < 1 then
6606 g_Console_Add('tell <playername> <text>');
6610 pl
:= g_Net_Client_ByName(P
[1]);
6612 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6614 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6616 else g_Console_Add('tell <playername> <text>');
6618 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6620 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6622 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6624 // Äîïîëíèòåëüíîå âðåìÿ:
6625 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6627 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6628 [gGameSettings
.TimeLimit
div 3600,
6629 (gGameSettings
.TimeLimit
div 60) mod 60,
6630 gGameSettings
.TimeLimit
mod 60]));
6631 if g_Game_IsNet
then MH_SEND_GameSettings
;
6633 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6635 if (Length(P
) <= 1) then
6636 g_Console_Add('rcon_password <password>')
6638 MC_SEND_RCONPassword(P
[1]);
6640 else if cmd
= 'rcon' then
6642 if g_Game_IsClient
then
6644 if Length(P
) > 1 then
6647 for a
:= 1 to High(P
) do
6648 chstr
:= chstr
+ P
[a
] + ' ';
6650 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6652 if Length(chstr
) < 1 then
6654 g_Console_Add('rcon <command>');
6658 MC_SEND_RCONCommand(chstr
);
6660 else g_Console_Add('rcon <command>');
6663 else if cmd
= 'ready' then
6665 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6666 gLMSRespawnTime
:= gTime
+ 100;
6668 else if (cmd
= 'callvote') and g_Game_IsNet
then
6670 if Length(P
) > 1 then
6673 for a
:= 1 to High(P
) do begin
6674 if a
> 1 then chstr
:= chstr
+ ' ';
6675 chstr
:= chstr
+ P
[a
];
6678 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6680 if Length(chstr
) < 1 then
6682 g_Console_Add('callvote <command>');
6686 if g_Game_IsClient
then
6687 MC_SEND_Vote(True, chstr
)
6689 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6690 g_Console_Process('vote', True);
6693 g_Console_Add('callvote <command>');
6695 else if (cmd
= 'vote') and g_Game_IsNet
then
6697 if g_Game_IsClient
then
6699 else if gVoteInProgress
then
6701 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6702 a
:= Floor((NetClientCount
+1)/2.0) + 1
6704 a
:= Floor(NetClientCount
/2.0) + 1;
6709 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6710 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6716 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6717 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6725 procedure g_TakeScreenShot();
6733 if e_NoGraphics
then Exit
;
6734 ssdir
:= GameDir
+'/screenshots';
6735 if not findFileCI(ssdir
, true) then
6737 // try to create dir
6742 if not findFileCI(ssdir
, true) then exit
; // alas
6745 for a
:= 1 to High(Word) do
6747 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
6749 if findFileCI(t
, true) then continue
;
6750 if not findFileCI(FileName
) then
6753 st
:= createDiskFile(FileName
);
6755 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
6760 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
6768 procedure g_Game_InGameMenu(Show
: Boolean);
6770 if (g_ActiveWindow
= nil) and Show
then
6772 if gGameSettings
.GameType
= GT_SINGLE
then
6773 g_GUI_ShowWindow('GameSingleMenu')
6776 if g_Game_IsClient
then
6777 g_GUI_ShowWindow('GameClientMenu')
6779 if g_Game_IsNet
then
6780 g_GUI_ShowWindow('GameServerMenu')
6782 g_GUI_ShowWindow('GameCustomMenu');
6784 g_Sound_PlayEx('MENU_OPEN');
6786 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6787 if (not g_Game_IsNet
) then
6791 if (g_ActiveWindow
<> nil) and (not Show
) then
6793 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6794 if (not g_Game_IsNet
) then
6795 g_Game_Pause(False);
6799 procedure g_Game_Pause (Enable
: Boolean);
6803 if not gGameOn
then exit
;
6805 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6808 gPauseMain
:= Enable
;
6810 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6813 procedure g_Game_HolmesPause (Enable
: Boolean);
6817 if not gGameOn
then exit
;
6818 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6821 gPauseHolmes
:= Enable
;
6823 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6826 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6831 if gTriggers
<> nil then
6832 for i
:= 0 to High(gTriggers
) do
6833 with gTriggers
[i
] do
6834 if (TriggerType
= TRIGGER_SOUND
) and
6836 Sound
.IsPlaying() then
6838 Sound
.Pause(Enable
);
6842 if gPlayers
<> nil then
6843 for i
:= 0 to High(gPlayers
) do
6844 if gPlayers
[i
] <> nil then
6845 gPlayers
[i
].PauseSounds(Enable
);
6848 if gMusic
<> nil then
6849 gMusic
.Pause(Enable
);
6852 procedure g_Game_StopAllSounds(all
: Boolean);
6856 if gTriggers
<> nil then
6857 for i
:= 0 to High(gTriggers
) do
6858 with gTriggers
[i
] do
6859 if (TriggerType
= TRIGGER_SOUND
) and
6863 if gMusic
<> nil then
6870 procedure g_Game_UpdateTriggerSounds();
6874 if gTriggers
<> nil then
6875 for i
:= 0 to High(gTriggers
) do
6876 with gTriggers
[i
] do
6877 if (TriggerType
= TRIGGER_SOUND
) and
6880 Sound
.IsPlaying() then
6882 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
6883 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
6885 Sound
.SetPan(0.5 - tgcPan
/255.0);
6886 Sound
.SetVolume(tgcVolume
/255.0);
6889 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0);
6893 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6896 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6901 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6906 if gSpectMode
<> SPECT_PLAYERS
then
6908 if gSpectPID1
= UID
then
6913 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6920 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6925 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6930 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6935 if gSpectMode
<> SPECT_PLAYERS
then
6937 Pl
:= g_Player_Get(gSpectPID1
);
6938 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6943 if gSpectViewTwo
then
6945 Pl
:= g_Player_Get(gSpectPID2
);
6946 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6954 procedure g_Game_Message(Msg
: string; Time
: Word);
6956 MessageText
:= b_Text_Format(Msg
);
6957 MessageTime
:= Time
;
6960 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6966 function FilterPunctuation(S
: String): String;
6968 S
:= StringReplace(S
, '.', ' ', [rfReplaceAll
]);
6969 S
:= StringReplace(S
, ',', ' ', [rfReplaceAll
]);
6970 S
:= StringReplace(S
, ':', ' ', [rfReplaceAll
]);
6971 S
:= StringReplace(S
, ';', ' ', [rfReplaceAll
]);
6972 S
:= StringReplace(S
, '!', ' ', [rfReplaceAll
]);
6973 S
:= StringReplace(S
, '?', ' ', [rfReplaceAll
]);
6977 g_Sound_PlayEx('SOUND_GAME_RADIO');
6979 if Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
6981 // remove player name
6982 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6983 // for FullWord check
6984 Text := LowerCase(' ' + Text + ' ');
6985 fpText
:= FilterPunctuation(Text);
6987 for i
:= 0 to Length(gChatSounds
) - 1 do
6990 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
6992 if gChatSounds
[i
].FullWord
and
6993 (gChatSounds
[i
].Tags
[j
] <> '.') and (gChatSounds
[i
].Tags
[j
] <> ',') and
6994 (gChatSounds
[i
].Tags
[j
] <> ':') and (gChatSounds
[i
].Tags
[j
] <> ';') and
6995 (gChatSounds
[i
].Tags
[j
] <> '!') and (gChatSounds
[i
].Tags
[j
] <> '?') then
6996 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
6998 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7004 gChatSounds
[i
].Sound
.Play();
7011 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7020 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7024 if goodsnd
[a
].IsPlaying() then
7027 goodsnd
[Random(4)].Play();
7030 procedure g_Game_Announce_KillCombo(Param
: Integer);
7037 UID
:= Param
and $FFFF;
7042 Pl
:= g_Player_Get(UID
);
7051 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7055 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7059 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7063 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7071 if not g_Game_IsWatchedPlayer(UID
) then
7074 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7078 if killsnd
[n
].IsPlaying() then
7083 procedure g_Game_StartVote(Command
, Initiator
: string);
7087 if not gVotesEnabled
then Exit
;
7088 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7089 if gVoteInProgress
or gVotePassed
then
7091 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7092 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7095 gVoteInProgress
:= True;
7096 gVotePassed
:= False;
7097 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7100 gVoteCommand
:= Command
;
7102 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7103 Need
:= Floor((NetClientCount
+1)/2.0)+1
7105 Need
:= Floor(NetClientCount
/2.0)+1;
7106 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7107 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7110 procedure g_Game_CheckVote
;
7114 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7115 if not gVoteInProgress
then Exit
;
7117 if (gTime
>= gVoteTimer
) then
7119 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7120 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7122 Need
:= Floor(NetClientCount
/2.0) + 1;
7123 if gVoteCount
>= Need
then
7125 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7126 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7127 gVotePassed
:= True;
7128 gVoteCmdTimer
:= gTime
+ 5000;
7132 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7133 MH_SEND_VoteEvent(NET_VE_FAILED
);
7135 if NetClients
<> nil then
7136 for I
:= Low(NetClients
) to High(NetClients
) do
7137 if NetClients
[i
].Used
then
7138 NetClients
[i
].Voted
:= False;
7139 gVoteInProgress
:= False;
7145 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7146 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7148 Need
:= Floor(NetClientCount
/2.0) + 1;
7149 if gVoteCount
>= Need
then
7151 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7152 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7153 gVoteInProgress
:= False;
7154 gVotePassed
:= True;
7155 gVoteCmdTimer
:= gTime
+ 5000;
7158 if NetClients
<> nil then
7159 for I
:= Low(NetClients
) to High(NetClients
) do
7160 if NetClients
[i
].Used
then
7161 NetClients
[i
].Voted
:= False;
7166 procedure g_Game_LoadMapList(FileName
: string);
7174 if not FileExists(FileName
) then Exit
;
7176 AssignFile(ListFile
, FileName
);
7178 while not EOF(ListFile
) do
7180 ReadLn(ListFile
, s
);
7183 if s
= '' then Continue
;
7185 SetLength(MapList
, Length(MapList
)+1);
7186 MapList
[High(MapList
)] := s
;
7188 CloseFile(ListFile
);
7191 procedure g_Game_SetDebugMode();
7194 // ×èòû (äàæå â ñâîåé èãðå):
7198 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7202 if Length(LoadingStat
.Msgs
) = 0 then
7208 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7209 if NextMsg
= Length(Msgs
) then
7211 for i
:= 0 to High(Msgs
)-1 do
7212 Msgs
[i
] := Msgs
[i
+1];
7220 Msgs
[NextMsg
-1] := Text;
7224 PBarWasHere
:= false;
7227 g_ActiveWindow
:= nil;
7229 ProcessLoading(true);
7232 procedure g_Game_StepLoading();
7238 if (ShowCount
> LOADING_SHOW_STEP
) then
7246 procedure g_Game_ClearLoading();
7255 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7256 if len
< 1 then len
:= 1;
7257 SetLength(Msgs
, len
);
7258 for len
:= Low(Msgs
) to High(Msgs
) do
7261 PBarWasHere
:= false;
7265 procedure Parse_Params(var pars
: TParamStrValues
);
7272 while i
<= ParamCount
do
7275 if (s
[1] = '-') and (Length(s
) > 1) then
7277 if (s
[2] = '-') and (Length(s
) > 2) then
7278 begin // Îäèíî÷íûé ïàðàìåòð
7279 SetLength(pars
, Length(pars
) + 1);
7280 with pars
[High(pars
)] do
7282 Name
:= LowerCase(s
);
7287 if (i
< ParamCount
) then
7288 begin // Ïàðàìåòð ñî çíà÷åíèåì
7290 SetLength(pars
, Length(pars
) + 1);
7291 with pars
[High(pars
)] do
7293 Name
:= LowerCase(s
);
7294 Value
:= LowerCase(ParamStr(i
));
7303 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
7308 for i
:= 0 to High(pars
) do
7309 if pars
[i
].Name
= aName
then
7311 Result
:= pars
[i
].Value
;
7316 procedure g_Game_Process_Params();
7318 pars
: TParamStrValues
;
7321 LimT
, LimS
: Integer;
7332 s
:= Find_Param_Value(pars
, '--debug');
7335 g_Game_SetDebugMode();
7336 s
:= Find_Param_Value(pars
, '--netdump');
7341 // Connect when game loads
7342 ip
:= Find_Param_Value(pars
, '-connect');
7346 s
:= Find_Param_Value(pars
, '-port');
7347 if (s
= '') or not TryStrToInt(s
, Port
) then
7350 s
:= Find_Param_Value(pars
, '-pw');
7352 g_Game_StartClient(ip
, Port
, s
);
7356 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
7359 gDefaultMegawadStart
:= s
;
7362 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
7363 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
7365 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
7368 // Start map when game loads:
7369 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
7370 if isWadPath(map
) then
7373 s
:= Find_Param_Value(pars
, '-gm');
7374 GMode
:= g_Game_TextToMode(s
);
7375 if GMode
= GM_NONE
then GMode
:= GM_DM
;
7376 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
7379 s
:= Find_Param_Value(pars
, '-limt');
7380 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
7386 s
:= Find_Param_Value(pars
, '-lims');
7387 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
7393 s
:= Find_Param_Value(pars
, '-lives');
7394 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
7400 s
:= Find_Param_Value(pars
, '-opt');
7402 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
7404 Opt
:= StrToIntDef(s
, 0);
7406 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
7409 s
:= Find_Param_Value(pars
, '--close');
7413 // Override map to test:
7414 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
7416 gTestMap
:= MapsDir
+ s
;
7418 // Delete test map after play:
7419 s
:= Find_Param_Value(pars
, '--testdelete');
7422 gMapToDelete
:= MapsDir
+ map
;
7423 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
7427 // Delete temporary WAD after play:
7428 s
:= Find_Param_Value(pars
, '--tempdelete');
7429 if (s
<> '') and (gTestMap
<> '') then
7431 gMapToDelete
:= gTestMap
;
7432 gTempDelete
:= True;
7435 // Number of players:
7436 s
:= Find_Param_Value(pars
, '-pl');
7440 n
:= StrToIntDef(s
, 1);
7443 s
:= Find_Param_Value(pars
, '-port');
7444 if (s
= '') or not TryStrToInt(s
, Port
) then
7445 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
7447 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
7450 // Execute script when game loads:
7451 s
:= Find_Param_Value(pars
, '-exec');
7454 if not isWadPath(s
) then
7455 s
:= GameDir
+ '/' + s
;
7460 if IOResult
<> 0 then
7462 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7463 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7467 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
7468 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7473 if IOResult
<> 0 then
7475 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7476 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7480 if Pos('#', s
) <> 1 then // script comment
7481 g_Console_Process(s
, True);
7492 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7493 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7494 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7495 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7497 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7498 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7499 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7500 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7502 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7503 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7505 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7506 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7508 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7510 conRegVar('dbg_scale', @g_dbg_scale
, 0.01, 100.0, 'experimental deBUG scale mode', '', false);
7512 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7513 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');