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
, mempool
, 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 gUseChatSounds
: Boolean = True;
314 gChatSounds
: Array of TChatSound
;
316 g_dbg_ignore_bounds
: Boolean = false;
318 // move button values:
319 // bits 0-1: l/r state:
320 // 0: neither left, nor right pressed
323 // bits 4-5: l/r state when strafe was pressed
324 P1MoveButton
: Byte = 0;
325 P2MoveButton
: Byte = 0;
327 g_profile_frame_update
: Boolean = false;
328 g_profile_frame_draw
: Boolean = false;
329 g_profile_collision
: Boolean = false;
330 g_profile_los
: Boolean = false;
331 g_profile_history_size
: Integer = 1000;
333 g_rlayer_back
: Boolean = true;
334 g_rlayer_step
: Boolean = true;
335 g_rlayer_wall
: Boolean = true;
336 g_rlayer_door
: Boolean = true;
337 g_rlayer_acid1
: Boolean = true;
338 g_rlayer_acid2
: Boolean = true;
339 g_rlayer_water
: Boolean = true;
340 g_rlayer_fore
: Boolean = true;
343 procedure g_ResetDynlights ();
344 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
345 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
347 function conIsCheatsEnabled (): Boolean; inline;
348 function gPause (): Boolean; inline;
359 e_texture
, g_textures
, g_main
, g_window
, g_menu
,
360 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
361 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
362 g_triggers
, g_monsters
, e_sound
, CONFIG
,
364 ENet
, e_msg
, g_netmsg
, g_netmaster
,
365 sfs
, wadreader
, g_holmes
;
369 hasPBarGfx
: Boolean = false;
372 // ////////////////////////////////////////////////////////////////////////// //
373 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
376 // ////////////////////////////////////////////////////////////////////////// //
377 function conIsCheatsEnabled (): Boolean; inline;
380 if g_Game_IsNet
then exit
;
381 if not gDebugMode
then
383 //if not gCheats then exit;
384 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
385 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
391 // ////////////////////////////////////////////////////////////////////////// //
393 profileFrameDraw
: TProfiler
= nil;
396 // ////////////////////////////////////////////////////////////////////////// //
399 x
, y
, radius
: Integer;
402 exploRadius
: Integer;
406 g_dynLights
: array of TDynLight
= nil;
407 g_dynLightCount
: Integer = 0;
408 g_playerLight
: Boolean = false;
410 procedure g_ResetDynlights ();
414 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
416 for idx
:= 0 to g_dynLightCount
-1 do
418 if g_dynLights
[idx
].exploCount
= -666 then
425 Inc(g_dynLights
[idx
].exploCount
);
426 if (g_dynLights
[idx
].exploCount
< 10) then
428 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
429 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
430 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
431 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
436 g_dynLightCount
:= lnum
;
439 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
441 if not gwin_has_stencil
then exit
;
442 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
443 g_dynLights
[g_dynLightCount
].x
:= x
;
444 g_dynLights
[g_dynLightCount
].y
:= y
;
445 g_dynLights
[g_dynLightCount
].radius
:= radius
;
446 g_dynLights
[g_dynLightCount
].r
:= r
;
447 g_dynLights
[g_dynLightCount
].g
:= g
;
448 g_dynLights
[g_dynLightCount
].b
:= b
;
449 g_dynLights
[g_dynLightCount
].a
:= a
;
450 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
451 Inc(g_dynLightCount
);
454 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
456 if not gwin_has_stencil
then exit
;
457 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
458 g_dynLights
[g_dynLightCount
].x
:= x
;
459 g_dynLights
[g_dynLightCount
].y
:= y
;
460 g_dynLights
[g_dynLightCount
].radius
:= 0;
461 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
462 g_dynLights
[g_dynLightCount
].r
:= r
;
463 g_dynLights
[g_dynLightCount
].g
:= g
;
464 g_dynLights
[g_dynLightCount
].b
:= b
;
465 g_dynLights
[g_dynLightCount
].a
:= 0;
466 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
467 Inc(g_dynLightCount
);
471 // ////////////////////////////////////////////////////////////////////////// //
472 function calcProfilesHeight (prof
: TProfiler
): Integer;
475 if (prof
= nil) then exit
;
476 if (length(prof
.bars
) = 0) then exit
;
477 result
:= length(prof
.bars
)*(16+2);
481 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
488 if (prof
= nil) then exit
;
490 if (length(prof
.bars
) = 0) then exit
;
492 hgt
:= calcProfilesHeight(prof
);
493 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
494 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
496 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
497 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
498 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
501 for ii
:= 0 to High(prof
.bars
) do
503 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);
510 // ////////////////////////////////////////////////////////////////////////// //
512 TEndCustomGameStat
= record
513 PlayerStat
: TPlayerStatArray
;
517 Map
, MapName
: String;
520 TEndSingleGameStat
= record
521 PlayerStat
: Array [0..1] of record
527 TotalSecrets
: Integer;
530 TLoadingStat
= record
534 Msgs
: Array of String;
536 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
539 TParamStrValue
= record
544 TParamStrValues
= Array of TParamStrValue
;
547 INTER_ACTION_TEXT
= 1;
548 INTER_ACTION_PIC
= 2;
549 INTER_ACTION_MUSIC
= 3;
553 FPSCounter
, UPSCounter
: Word;
554 FPSTime
, UPSTime
: LongWord;
555 DataLoaded
: Boolean = False;
556 LastScreenShot
: Int64;
557 IsDrawStat
: Boolean = False;
558 CustomStat
: TEndCustomGameStat
;
559 SingleStat
: TEndSingleGameStat
;
560 LoadingStat
: TLoadingStat
;
561 EndingGameCounter
: Byte = 0;
564 MessageLineLength
: Integer = 80;
565 MapList
: SSArray
= nil;
566 MapIndex
: Integer = -1;
572 text: Array of ShortString;
573 anim
: Array of ShortString;
574 pic
: Array of ShortString;
575 mus
: Array of ShortString;
577 triggers
: Array of record
579 actions
: Array of record
580 action
, p1
, p2
: Integer;
583 cur_trigger
: Integer;
596 function Compare(a
, b
: TPlayerStat
): Integer;
598 if a
.Spectator
then Result
:= 1
599 else if b
.Spectator
then Result
:= -1
600 else if a
.Frags
< b
.Frags
then Result
:= 1
601 else if a
.Frags
> b
.Frags
then Result
:= -1
602 else if a
.Deaths
< b
.Deaths
then Result
:= -1
603 else if a
.Deaths
> b
.Deaths
then Result
:= 1
604 else if a
.Kills
< b
.Kills
then Result
:= -1
608 procedure SortGameStat(var stat
: TPlayerStatArray
);
613 if stat
= nil then Exit
;
615 for I
:= High(stat
) downto Low(stat
) do
616 for J
:= Low(stat
) to High(stat
) - 1 do
617 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
620 stat
[J
] := stat
[J
+ 1];
625 function g_Game_ModeToText(Mode
: Byte): string;
629 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
630 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
631 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
632 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
633 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
637 function g_Game_TextToMode(Mode
: string): Byte;
640 Mode
:= UpperCase(Mode
);
641 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
646 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
651 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
656 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
661 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
668 function g_Game_IsNet(): Boolean;
670 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
673 function g_Game_IsServer(): Boolean;
675 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
678 function g_Game_IsClient(): Boolean;
680 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
683 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
690 Result
.name
:= ExtractFileName(WAD
);
691 Result
.description
:= '';
694 w
:= TWADFile
.Create();
697 if not w
.GetResource('INTERSCRIPT', p
, len
) then
703 cfg
:= TConfig
.CreateMem(p
, len
);
704 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
705 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
706 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
707 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
713 procedure g_Game_FreeWAD();
717 for a
:= 0 to High(MegaWAD
.res
.pic
) do
718 if MegaWAD
.res
.pic
[a
] <> '' then
719 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
721 for a
:= 0 to High(MegaWAD
.res
.mus
) do
722 if MegaWAD
.res
.mus
[a
] <> '' then
723 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
725 MegaWAD
.res
.pic
:= nil;
726 MegaWAD
.res
.text := nil;
727 MegaWAD
.res
.anim
:= nil;
728 MegaWAD
.res
.mus
:= nil;
729 MegaWAD
.triggers
:= nil;
731 g_Texture_Delete('TEXTURE_endpic');
732 g_Sound_Delete('MUSIC_endmus');
734 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
735 gGameSettings
.WAD
:= '';
738 procedure g_Game_LoadWAD(WAD
: string);
747 gGameSettings
.WAD
:= WAD
;
748 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
751 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
753 w
:= TWADFile
.Create();
754 w
.ReadFile(MapsDir
+ WAD
);
756 if not w
.GetResource('INTERSCRIPT', p
, len
) then
762 cfg
:= TConfig
.CreateMem(p
, len
);
767 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
768 if s = '' then Break;
771 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
772 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
774 g_Texture_CreateWADEx(s, s);
780 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
781 if s = '' then Break;
784 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
785 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
787 g_Music_CreateWADEx(s, s);
790 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
791 if MegaWAD
.endpic
<> '' then
793 s
:= g_ExtractWadName(MegaWAD
.endpic
);
794 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
795 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
797 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
798 if MegaWAD
.endmus
<> '' then
800 s
:= g_ExtractWadName(MegaWAD
.endmus
);
801 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
802 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
810 {procedure start_trigger(t: string);
814 function next_trigger(): Boolean;
818 procedure DisableCheats();
824 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
825 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
826 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
827 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
829 {$IF DEFINED(D2F_DEBUG)}
830 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
831 gAimLine
:= g_dbg_aimline_on
;
835 procedure g_Game_ExecuteEvent(Name
: String);
841 if gEvents
= nil then
843 for a
:= 0 to High(gEvents
) do
844 if gEvents
[a
].Name
= Name
then
846 if gEvents
[a
].Command
<> '' then
847 g_Console_Process(gEvents
[a
].Command
, True);
852 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
857 if gDelayedEvents
<> nil then
858 for a
:= 0 to High(gDelayedEvents
) do
859 if not gDelayedEvents
[a
].Pending
then
866 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
867 n
:= High(gDelayedEvents
);
869 gDelayedEvents
[n
].Pending
:= True;
870 gDelayedEvents
[n
].DEType
:= DEType
;
871 gDelayedEvents
[n
].DENum
:= Num
;
872 gDelayedEvents
[n
].DEStr
:= Str
;
873 if DEType
= DE_GLOBEVENT
then
874 gDelayedEvents
[n
].Time
:= (GetTimer() {div 1000}) + Time
876 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
885 if g_Game_IsNet
and g_Game_IsServer
then
886 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
890 gPauseHolmes
:= false;
893 g_Game_StopAllSounds(False);
898 EndingGameCounter
:= 0;
899 g_ActiveWindow
:= nil;
901 gLMSRespawn
:= LMS_RESPAWN_NONE
;
902 gLMSRespawnTime
:= 0;
905 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
910 begin // Ýòî áûë òåñò
914 begin // Âûõîä â ãëàâíîå ìåíþ
915 gMusic
.SetByName('MUSIC_MENU');
917 if gState
<> STATE_SLIST
then
919 g_GUI_ShowWindow('MainMenu');
920 gState
:= STATE_MENU
;
923 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
924 slReturnPressed
:= True;
925 if g_Net_Slist_Fetch(slCurrent
) then
927 if slCurrent
= nil then
928 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
931 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
934 g_Game_ExecuteEvent('ongameend');
938 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
940 if not g_Game_IsClient
then g_Game_Restart();
943 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
945 // Ñòàòèñòèêà Ñâîåé èãðû:
946 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
948 CustomStat
.GameTime
:= gTime
;
949 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
950 CustomStat
.MapName
:= gMapInfo
.Name
;
951 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
952 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
953 CustomStat
.TeamStat
:= gTeamStat
;
955 CustomStat
.PlayerStat
:= nil;
957 // Ñòàòèñòèêà èãðîêîâ:
958 if gPlayers
<> nil then
960 for a
:= 0 to High(gPlayers
) do
961 if gPlayers
[a
] <> nil then
963 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
964 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
966 Name
:= gPlayers
[a
].Name
;
967 Frags
:= gPlayers
[a
].Frags
;
968 Deaths
:= gPlayers
[a
].Death
;
969 Kills
:= gPlayers
[a
].Kills
;
970 Team
:= gPlayers
[a
].Team
;
971 Color
:= gPlayers
[a
].Model
.Color
;
972 Spectator
:= gPlayers
[a
].FSpectator
;
976 SortGameStat(CustomStat
.PlayerStat
);
979 g_Game_ExecuteEvent('onmapend');
982 EndingGameCounter
:= 255;
983 gState
:= STATE_FOLD
;
985 if gDefInterTime
< 0 then
986 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
988 gInterEndTime
:= gDefInterTime
* 1000;
991 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
993 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
994 SingleStat
.GameTime
:= gTime
;
995 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
996 SingleStat
.TotalSecrets
:= gSecretsCount
;
997 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
998 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
999 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1000 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1001 if SingleStat
.TwoPlayers
then
1003 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1004 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1007 g_Game_ExecuteEvent('onmapend');
1010 if gNextMap
<> '' then
1012 gMusic
.SetByName('MUSIC_INTERMUS');
1014 gState
:= STATE_INTERSINGLE
;
1016 g_Game_ExecuteEvent('oninter');
1018 else // Áîëüøå íåò êàðò
1020 // Çàòóõàþùèé ýêðàí:
1021 EndingGameCounter
:= 255;
1022 gState
:= STATE_FOLD
;
1027 // Îêîí÷àíèå îáðàáîòàíî:
1028 if gExit
<> EXIT_QUIT
then
1032 procedure drawTime(X
, Y
: Integer); inline;
1034 e_TextureFontPrint(x
, y
,
1035 Format('%d:%.2d:%.2d', [
1036 gTime
div 1000 div 3600,
1037 (gTime
div 1000 div 60) mod 60,
1038 gTime
div 1000 mod 60
1043 procedure DrawStat();
1045 pc
, x
, y
, w
, h
: Integer;
1046 w1
, w2
, w3
, w4
: Integer;
1048 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1051 stat
: TPlayerStatArray
;
1058 pc
:= g_Player_GetCount
;
1059 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1061 w
:= gScreenWidth
-(gScreenWidth
div 5);
1062 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1065 h
:= 40+ch
*5+(ch
+8)*pc
;
1066 x
:= (gScreenWidth
div 2)-(w
div 2);
1067 y
:= (gScreenHeight
div 2)-(h
div 2);
1069 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1070 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1072 drawTime(x
+w
-78, y
+8);
1074 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1075 map
:= g_ExtractFileName(gMapInfo
.Map
);
1076 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1078 case gGameSettings
.GameMode
of
1081 if gGameSettings
.MaxLives
= 0 then
1082 s1
:= _lc
[I_GAME_DM
]
1084 s1
:= _lc
[I_GAME_LMS
];
1085 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1086 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1091 if gGameSettings
.MaxLives
= 0 then
1092 s1
:= _lc
[I_GAME_TDM
]
1094 s1
:= _lc
[I_GAME_TLMS
];
1095 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1096 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1101 s1
:= _lc
[I_GAME_CTF
];
1102 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1103 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1108 if gGameSettings
.MaxLives
= 0 then
1109 s1
:= _lc
[I_GAME_COOP
]
1111 s1
:= _lc
[I_GAME_SURV
];
1112 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1113 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1124 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1126 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1128 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1130 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1131 gStdFont
, 200, 200, 200, 1);
1133 if NetMode
= NET_SERVER
then
1134 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1136 if NetMode
= NET_CLIENT
then
1137 e_TextureFontPrintEx(x
+8, y
+ 8,
1138 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1142 stat
:= g_Player_GetStats();
1145 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1146 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1148 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1150 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1154 for a
:= TEAM_RED
to TEAM_BLUE
do
1156 if a
= TEAM_RED
then
1158 s1
:= _lc
[I_GAME_TEAM_RED
];
1165 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1171 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1172 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1173 gStdFont
, r
, g
, b
, 1);
1175 _y
:= _y
+ch
+(ch
div 4);
1176 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1177 _y
:= _y
+(ch
div 4);
1179 for aa
:= 0 to High(stat
) do
1180 if stat
[aa
].Team
= a
then
1196 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1198 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1200 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1202 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1209 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1212 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1213 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1214 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1215 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1218 for aa
:= 0 to High(stat
) do
1232 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1233 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1235 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1237 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1239 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1241 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1247 procedure g_Game_Init();
1253 gTempDelete
:= False;
1255 sfsGCDisable(); // temporary disable removing of temporary volumes
1258 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1259 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1260 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1261 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1263 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1264 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1265 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1267 g_Game_ClearLoading();
1268 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1269 g_Game_SetLoadingText('', 0, False);
1271 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1274 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1275 g_PlayerModel_LoadData();
1277 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1279 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1280 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1281 until FindNext(SR
) <> 0;
1284 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1286 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1287 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1288 until FindNext(SR
) <> 0;
1291 if FindFirst(ModelsDir
+'*.zip', faAnyFile
, SR
) = 0 then
1293 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1294 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1295 until FindNext(SR
) <> 0;
1299 gPauseMain
:= false;
1300 gPauseHolmes
:= false;
1302 LastScreenShot
:= 0;
1304 {e_MouseInfo.Accel := 1.0;}
1306 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1309 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1310 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1311 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1312 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1313 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1315 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1318 gMusic
:= TMusic
.Create();
1319 gMusic
.SetByName('MUSIC_MENU');
1322 gGameSettings
.WarmupTime
:= 30;
1324 gState
:= STATE_MENU
;
1326 SetLength(gEvents
, 6);
1327 gEvents
[0].Name
:= 'ongamestart';
1328 gEvents
[1].Name
:= 'ongameend';
1329 gEvents
[2].Name
:= 'onmapstart';
1330 gEvents
[3].Name
:= 'onmapend';
1331 gEvents
[4].Name
:= 'oninter';
1332 gEvents
[5].Name
:= 'onwadend';
1334 sfsGCEnable(); // enable releasing unused volumes
1338 procedure g_Game_Free(freeTextures
: Boolean=true);
1340 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1341 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1343 g_Map_Free(freeTextures
);
1345 g_Player_RemoveAllCorpses();
1347 gGameSettings
.GameType
:= GT_NONE
;
1348 if gGameSettings
.GameMode
= GM_SINGLE
then
1349 gGameSettings
.GameMode
:= GM_DM
;
1350 gSwitchGameMode
:= gGameSettings
.GameMode
;
1353 gExitByTrigger
:= False;
1356 function IsActivePlayer(p
: TPlayer
): Boolean;
1361 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1364 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1371 if gPlayers
= nil then
1373 for a
:= Low(gPlayers
) to High(gPlayers
) do
1374 if IsActivePlayer(gPlayers
[a
]) then
1376 if gPlayers
[a
].UID
<> ID
then
1378 Result
:= gPlayers
[a
];
1383 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1389 if gPlayers
= nil then
1393 for a
:= Low(gPlayers
) to High(gPlayers
) do
1394 if IsActivePlayer(gPlayers
[a
]) then
1396 SetLength(ids
, Length(ids
) + 1);
1397 ids
[High(ids
)] := gPlayers
[a
].UID
;
1398 if gPlayers
[a
].UID
= Skip
then
1401 if Length(ids
) = 0 then
1406 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1409 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1415 if gPlayers
= nil then
1419 for a
:= Low(gPlayers
) to High(gPlayers
) do
1420 if IsActivePlayer(gPlayers
[a
]) then
1422 SetLength(ids
, Length(ids
) + 1);
1423 ids
[High(ids
)] := gPlayers
[a
].UID
;
1424 if gPlayers
[a
].UID
= Skip
then
1427 if Length(ids
) = 0 then
1430 Result
:= ids
[Length(ids
) - 1]
1432 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1435 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
1437 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
1438 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
1442 procedure processPlayerControls (plr
: TPlayer
; var ctrl
: TPlayerControl
; var MoveButton
: Byte; p2hack
: Boolean=false);
1448 if (plr
= nil) then exit
;
1449 if (p2hack
) then time
:= 1000 else time
:= 1;
1450 strafeDir
:= MoveButton
shr 4;
1451 MoveButton
:= MoveButton
and $0F;
1454 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1455 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1456 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1458 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1459 if MoveButton
= 1 then plr
.PressKey(KEY_LEFT
, time
)
1460 else if MoveButton
= 2 then plr
.PressKey(KEY_RIGHT
, time
);
1462 // if we have "strafe" key, turn off old strafe mechanics
1463 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
1465 // new strafe mechanics
1466 if (strafeDir
= 0) then strafeDir
:= MoveButton
; // start strafing
1467 // now set direction according to strafe (reversed)
1468 if (strafeDir
= 2) then plr
.SetDirection(TDirection
.D_LEFT
)
1469 else if (strafeDir
= 1) then plr
.SetDirection(TDirection
.D_RIGHT
);
1473 strafeDir
:= 0; // not strafing anymore
1474 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1475 if (MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then plr
.SetDirection(TDirection
.D_LEFT
)
1476 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1477 else if (MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then plr
.SetDirection(TDirection
.D_RIGHT
)
1478 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1479 else if MoveButton
<> 0 then plr
.SetDirection(TDirection(MoveButton
-1));
1482 // fix movebutton state
1483 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1485 // Îñòàëüíûå êëàâèøè:
1486 if isKeyPressed(KeyJump
, KeyJump2
) then plr
.PressKey(KEY_JUMP
, time
);
1487 if isKeyPressed(KeyUp
, KeyUp2
) then plr
.PressKey(KEY_UP
, time
);
1488 if isKeyPressed(KeyDown
, KeyDown2
) then plr
.PressKey(KEY_DOWN
, time
);
1489 if isKeyPressed(KeyFire
, KeyFire2
) then plr
.PressKey(KEY_FIRE
);
1490 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then plr
.PressKey(KEY_NEXTWEAPON
);
1491 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then plr
.PressKey(KEY_PREVWEAPON
);
1492 if isKeyPressed(KeyOpen
, KeyOpen2
) then plr
.PressKey(KEY_OPEN
);
1494 for i
:= 0 to High(KeyWeapon
) do
1495 if isKeyPressed(KeyWeapon
[i
], KeyWeapon2
[i
]) then
1496 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1499 // HACK: add dynlight here
1500 if gwin_k8_enable_light_experiments
then
1502 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1504 g_playerLight
:= true;
1506 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1508 g_playerLight
:= false;
1512 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1515 procedure g_Game_Update();
1517 Msg
: g_gui
.TMessage
;
1523 function sendMonsPos (mon
: TMonster
): Boolean;
1525 result
:= false; // don't stop
1526 // this will also reset "need-send" flag
1527 if mon
.gncNeedSend
then
1529 MH_SEND_MonsterPos(mon
.UID
);
1531 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1533 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1535 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1537 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1541 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1543 result
:= false; // don't stop
1544 // this will also reset "need-send" flag
1545 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1549 reliableUpdate
: Boolean;
1554 // Ïîðà âûêëþ÷àòü èãðó:
1555 if gExit
= EXIT_QUIT
then
1557 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1561 if gExit
= EXIT_QUIT
then
1565 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1566 // no need to, as we'll do it in event handler
1568 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1571 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1573 gExit
:= EXIT_SIMPLE
;
1579 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1580 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1581 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1582 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1584 if g_Game_IsNet
and g_Game_IsServer
then
1586 gInterTime
:= gInterTime
+ GAME_TICK
;
1587 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1588 if a
<> gServInterTime
then
1590 gServInterTime
:= a
;
1591 MH_SEND_TimeSync(gServInterTime
);
1595 if (not g_Game_IsClient
) and
1598 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1599 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1600 and (g_ActiveWindow
= nil)
1602 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1605 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1606 g_Game_StopAllSounds(True);
1608 if gMapOnce
then // Ýòî áûë òåñò
1609 gExit
:= EXIT_SIMPLE
1611 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1612 g_Game_ChangeMap(gNextMap
)
1613 else // Ñëåäóþùåé êàðòû íåò
1615 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1617 // Âûõîä â ãëàâíîå ìåíþ:
1619 g_GUI_ShowWindow('MainMenu');
1620 gMusic
.SetByName('MUSIC_MENU');
1622 gState
:= STATE_MENU
;
1625 // Ôèíàëüíàÿ êàðòèíêà:
1626 g_Game_ExecuteEvent('onwadend');
1628 if not gMusic
.SetByName('MUSIC_endmus') then
1629 gMusic
.SetByName('MUSIC_STDENDMUS');
1631 gState
:= STATE_ENDPIC
;
1633 g_Game_ExecuteEvent('ongameend');
1639 if gState
= STATE_INTERTEXT
then
1640 if InterText
.counter
> 0 then
1641 InterText
.counter
:= InterText
.counter
- 1;
1644 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1646 if EndingGameCounter
= 0 then
1648 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1649 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1651 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1653 g_Game_ExecuteEvent('onwadend');
1654 if not gMusic
.SetByName('MUSIC_endmus') then
1655 gMusic
.SetByName('MUSIC_STDENDMUS');
1658 gMusic
.SetByName('MUSIC_ROUNDMUS');
1661 gState
:= STATE_INTERCUSTOM
;
1663 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1665 gMusic
.SetByName('MUSIC_INTERMUS');
1667 gState
:= STATE_INTERSINGLE
;
1669 g_Game_ExecuteEvent('oninter');
1672 DecMin(EndingGameCounter
, 6, 0);
1675 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1677 if gMapOnce
then // Ýòî áûë òåñò
1679 gExit
:= EXIT_SIMPLE
;
1685 g_Serverlist_Control(slCurrent
);
1688 if g_Game_IsNet
then
1689 if not gConsoleShow
then
1690 if not gChatShow
then
1692 if g_ActiveWindow
= nil then
1694 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1695 g_Console_Chat_Switch(False)
1696 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1697 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1698 g_Console_Chat_Switch(True);
1701 if not gChatEnter
then
1702 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1703 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1706 // Ñòàòèñòèêà ïî Tab:
1708 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1709 (gGameSettings
.GameType
<> GT_SINGLE
) and
1710 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1713 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1715 // Âðåìÿ += 28 ìèëëèñåêóíä:
1716 gTime
:= gTime
+ GAME_TICK
;
1718 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1719 if MessageTime
= 0 then
1721 if MessageTime
> 0 then
1722 MessageTime
:= MessageTime
- 1;
1724 if (g_Game_IsServer
) then
1726 // Áûë çàäàí ëèìèò âðåìåíè:
1727 if (gGameSettings
.TimeLimit
> 0) then
1728 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1729 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1734 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1735 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1736 g_Game_RestartRound(gLMSSoftSpawn
);
1738 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1739 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1741 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1743 g_Console_Process(gVoteCommand
);
1745 gVotePassed
:= False;
1748 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1749 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1750 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1751 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1752 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1754 // Áûë çàäàí ëèìèò ïîáåä:
1755 if (gGameSettings
.GoalLimit
> 0) then
1759 if gGameSettings
.GameMode
= GM_DM
then
1760 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1761 for i
:= 0 to High(gPlayers
) do
1762 if gPlayers
[i
] <> nil then
1763 if gPlayers
[i
].Frags
> b
then
1764 b
:= gPlayers
[i
].Frags
;
1767 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1768 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1769 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1772 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1773 if b
>= gGameSettings
.GoalLimit
then
1780 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1781 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1782 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1783 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1785 processPlayerControls(gPlayer1
, gGameControls
.P1Control
, P1MoveButton
);
1786 processPlayerControls(gPlayer2
, gGameControls
.P2Control
, P2MoveButton
, true);
1787 end // if not console
1790 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1792 // process weapon switch queue
1796 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1797 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1799 if not gSpectKeyPress
then
1801 if isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
) then
1803 // switch spect mode
1805 SPECT_NONE
: ; // not spectator
1807 SPECT_MAPVIEW
: Inc(gSpectMode
);
1808 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1810 gSpectKeyPress
:= True;
1812 if gSpectMode
= SPECT_MAPVIEW
then
1814 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1815 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1816 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1817 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1818 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1819 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1820 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1821 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1822 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1825 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1826 gSpectKeyPress
:= True;
1828 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1831 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1832 gSpectKeyPress
:= True;
1835 if gSpectMode
= SPECT_PLAYERS
then
1837 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1840 gSpectViewTwo
:= True;
1841 gSpectKeyPress
:= True;
1843 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1845 // remove second view
1846 gSpectViewTwo
:= False;
1847 gSpectKeyPress
:= True;
1849 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1851 // prev player (view 1)
1852 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1853 gSpectKeyPress
:= True;
1855 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1857 // next player (view 1)
1858 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1859 gSpectKeyPress
:= True;
1861 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1863 // prev player (view 2)
1864 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1865 gSpectKeyPress
:= True;
1867 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1869 // next player (view 2)
1870 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1871 gSpectKeyPress
:= True;
1876 if (not isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)) and
1877 (not isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
)) and
1878 (not isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
)) and
1879 (not isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
)) and
1880 (not isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
)) and
1881 (not isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
)) and
1882 (not isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
)) then
1883 gSpectKeyPress
:= False;
1886 // Îáíîâëÿåì âñå îñòàëüíîå:
1889 g_Triggers_Update();
1891 g_Monsters_Update();
1893 g_Player_UpdateAll();
1894 g_Player_UpdatePhysicalObjects();
1896 // server: send newly spawned monsters unconditionally
1897 if (gGameSettings
.GameType
= GT_SERVER
) then
1899 if (Length(gMonstersSpawned
) > 0) then
1901 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1902 SetLength(gMonstersSpawned
, 0);
1906 if (gSoundTriggerTime
> 8) then
1908 g_Game_UpdateTriggerSounds();
1909 gSoundTriggerTime
:= 0;
1913 Inc(gSoundTriggerTime
);
1916 if (NetMode
= NET_SERVER
) then
1918 Inc(NetTimeToUpdate
);
1919 Inc(NetTimeToReliable
);
1921 // send monster updates
1922 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
1924 // send all monsters (periodic sync)
1925 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
1927 for I
:= 0 to High(gPlayers
) do
1929 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
1932 g_Mons_ForEach(sendMonsPos
);
1934 if reliableUpdate
then
1936 NetTimeToReliable
:= 0;
1937 NetTimeToUpdate
:= NetUpdateRate
;
1941 NetTimeToUpdate
:= 0;
1946 // send only mosters with some unexpected changes
1947 g_Mons_ForEach(sendMonsPosUnexpected
);
1950 // send unexpected platform changes
1951 g_Map_NetSendInterestingPanels();
1953 if NetUseMaster
then
1955 if gTime
>= NetTimeToMaster
then
1957 if (NetMHost
= nil) or (NetMPeer
= nil) then
1959 if not g_Net_Slist_Connect
then g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1963 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1967 else if (NetMode
= NET_CLIENT
) then
1969 MC_SEND_PlayerPos();
1971 end; // if gameOn ...
1973 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1974 if g_ActiveWindow
<> nil then
1976 w
:= e_GetFirstKeyPressed();
1978 if (w
<> IK_INVALID
) then
1980 Msg
.Msg
:= MESSAGE_DIKEY
;
1982 g_ActiveWindow
.OnMessage(Msg
);
1985 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1986 if g_ActiveWindow
<> nil then
1987 g_ActiveWindow
.Update();
1989 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1990 if gResolutionChange
then
1992 e_WriteLog('Changing resolution', TMsgType
.Notify
);
1993 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1994 gResolutionChange
:= False;
1995 g_ActiveWindow
:= nil;
1998 // Íóæíî ñìåíèòü ÿçûê:
1999 if gLanguageChange
then
2001 //e_WriteLog('Read language file', MSG_NOTIFY);
2002 //g_Language_Load(DataDir + gLanguage + '.txt');
2003 g_Language_Set(gLanguage
);
2005 gLanguageChange
:= False;
2009 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
2010 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
2011 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
2014 LastScreenShot
:= GetTimer();
2017 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2018 if e_KeyPressed(IK_F10
) and
2020 (not gConsoleShow
) and
2021 (g_ActiveWindow
= nil) then
2026 Time
:= GetTimer() {div 1000};
2028 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2029 if gDelayedEvents
<> nil then
2030 for a
:= 0 to High(gDelayedEvents
) do
2031 if gDelayedEvents
[a
].Pending
and
2033 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2034 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2037 case gDelayedEvents
[a
].DEType
of
2039 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2042 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2046 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2047 if g_Game_IsNet
and g_Game_IsServer
then
2048 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2051 gDelayedEvents
[a
].Pending
:= False;
2054 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2055 UPSCounter
:= UPSCounter
+ 1;
2056 if Time
- UPSTime
>= 1000 then
2065 g_Weapon_AddDynLights();
2066 g_Items_AddDynLights();
2070 procedure g_Game_LoadChatSounds(Resource
: string);
2073 FileName
, Snd
: string;
2075 len
, cnt
, tags
, i
, j
: Integer;
2078 FileName
:= g_ExtractWadName(Resource
);
2080 WAD
:= TWADFile
.Create();
2081 WAD
.ReadFile(FileName
);
2083 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2090 cfg
:= TConfig
.CreateMem(p
, len
);
2091 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2093 SetLength(gChatSounds
, cnt
);
2094 for i
:= 0 to Length(gChatSounds
) - 1 do
2096 gChatSounds
[i
].Sound
:= nil;
2097 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2098 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2099 if (Snd
= '') or (Tags
<= 0) then
2101 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2102 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2103 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2104 SetLength(gChatSounds
[i
].Tags
, tags
);
2105 for j
:= 0 to tags
- 1 do
2106 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2107 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2114 procedure g_Game_FreeChatSounds();
2118 for i
:= 0 to Length(gChatSounds
) - 1 do
2120 gChatSounds
[i
].Sound
.Free();
2121 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2123 SetLength(gChatSounds
, 0);
2127 procedure g_Game_LoadData();
2134 if DataLoaded
then Exit
;
2136 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2138 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2139 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2140 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2141 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2142 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2143 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2144 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2145 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2146 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2147 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2148 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2149 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2150 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2151 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2154 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2155 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2156 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2157 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2161 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2162 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2163 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2164 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2165 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
2171 hasPBarGfx
:= false;
2175 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2176 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':TEXTURES\PUNCH', 64, 64, 4, False);
2177 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2178 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2179 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2180 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2181 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2182 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2183 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2184 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2185 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2186 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2187 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2188 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2189 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2190 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2191 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2192 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2193 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2194 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2195 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2197 goodsnd
[0] := TPlayableSound
.Create();
2198 goodsnd
[1] := TPlayableSound
.Create();
2199 goodsnd
[2] := TPlayableSound
.Create();
2200 goodsnd
[3] := TPlayableSound
.Create();
2202 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2203 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2204 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2205 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2207 killsnd
[0] := TPlayableSound
.Create();
2208 killsnd
[1] := TPlayableSound
.Create();
2209 killsnd
[2] := TPlayableSound
.Create();
2210 killsnd
[3] := TPlayableSound
.Create();
2212 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2213 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2214 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2215 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2217 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2219 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2222 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2223 g_Weapon_LoadData();
2225 g_Monsters_LoadData();
2230 procedure g_Game_FreeData();
2232 if not DataLoaded
then Exit
;
2235 g_Weapon_FreeData();
2236 g_Monsters_FreeData();
2238 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2240 g_Texture_Delete('NOTEXTURE');
2241 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2242 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2243 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2244 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2245 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2246 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2247 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2248 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2249 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2250 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2251 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2252 g_Frames_DeleteByName('FRAMES_TELEPORT');
2253 g_Frames_DeleteByName('FRAMES_PUNCH');
2254 g_Sound_Delete('SOUND_GAME_TELEPORT');
2255 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2256 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2257 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2258 g_Sound_Delete('SOUND_GAME_BULK1');
2259 g_Sound_Delete('SOUND_GAME_BULK2');
2260 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2261 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2262 g_Sound_Delete('SOUND_GAME_SWITCH1');
2263 g_Sound_Delete('SOUND_GAME_SWITCH0');
2270 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2271 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2272 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2273 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2280 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2281 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2282 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2283 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2285 g_Game_FreeChatSounds();
2287 DataLoaded
:= False;
2290 procedure DrawCustomStat();
2296 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2297 s1
, s2
, topstr
: String;
2299 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2301 g_ProcessMessages();
2303 if e_KeyPressed(IK_TAB
) then
2305 if not gStatsPressed
then
2307 gStatsOff
:= not gStatsOff
;
2308 gStatsPressed
:= True;
2312 gStatsPressed
:= False;
2316 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2317 w
:= (Length(s1
) * ww2
) div 2;
2318 x
:= gScreenWidth
div 2 - w
;
2320 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2324 if (gGameSettings
.GameMode
= GM_COOP
) then
2326 if gMissionFailed
then
2327 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2329 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2332 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2334 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2335 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2337 if g_Game_IsNet
then
2339 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2340 if not gChatShow
then
2341 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2342 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2345 if g_Game_IsClient
then
2346 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2348 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2349 if not gChatShow
then
2350 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2351 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2356 w
:= gScreenWidth
-x
*2;
2362 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2363 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2365 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2367 case CustomStat
.GameMode
of
2370 if gGameSettings
.MaxLives
= 0 then
2371 s1
:= _lc
[I_GAME_DM
]
2373 s1
:= _lc
[I_GAME_LMS
];
2377 if gGameSettings
.MaxLives
= 0 then
2378 s1
:= _lc
[I_GAME_TDM
]
2380 s1
:= _lc
[I_GAME_TLMS
];
2382 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2385 if gGameSettings
.MaxLives
= 0 then
2386 s1
:= _lc
[I_GAME_COOP
]
2388 s1
:= _lc
[I_GAME_SURV
];
2394 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2398 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2399 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2402 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2403 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2404 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2405 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2407 pc
:= Length(CustomStat
.PlayerStat
);
2408 if pc
= 0 then Exit
;
2410 if CustomStat
.GameMode
= GM_COOP
then
2412 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2414 s2
:= _lc
[I_GAME_MONSTERS
];
2415 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2416 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2418 s2
:= _lc
[I_GAME_SECRETS
];
2419 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2420 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2423 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2425 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2426 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2427 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2429 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2430 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2431 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2435 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2440 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2441 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2442 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2444 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2447 for t
:= TEAM_RED
to TEAM_BLUE
do
2449 if t
= TEAM_RED
then
2451 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2452 gStdFont
, 255, 0, 0, 1);
2453 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2454 gStdFont
, 255, 0, 0, 1);
2461 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2462 gStdFont
, 0, 0, 255, 1);
2463 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2464 gStdFont
, 0, 0, 255, 1);
2470 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2473 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2474 if CustomStat
.PlayerStat
[p
].Team
= t
then
2475 with CustomStat
.PlayerStat
[p
] do
2489 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2490 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2491 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2498 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2501 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2502 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2503 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2506 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2507 with CustomStat
.PlayerStat
[p
] do
2509 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2516 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2517 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2518 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2524 procedure DrawSingleStat();
2526 tm
, key_x
, val_x
, y
: Integer;
2530 procedure player_stat(n
: Integer);
2536 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2537 s2
:= Format(' %d', [gTotalMonsters
]);
2539 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2540 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2541 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2542 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2544 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2545 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2547 // "Kills-per-minute: ##.#":
2548 s1
:= _lc
[I_MENU_INTER_KPM
];
2550 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2552 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2553 s2
:= Format(' %.1f', [kpm
]);
2555 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2556 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2558 // "Secrets found: # / #":
2559 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2560 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2562 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2563 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2564 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2565 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2567 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2568 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2572 // "Level Complete":
2573 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2574 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2576 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2577 s1
:= _lc
[I_MENU_INTER_KPM
];
2578 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2581 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2583 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2584 val_x
:= key_x
+ w1
;
2587 tm
:= SingleStat
.GameTime
div 1000;
2588 s1
:= _lc
[I_MENU_INTER_TIME
];
2589 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2591 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2592 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2594 if SingleStat
.TwoPlayers
then
2597 s1
:= _lc
[I_MENU_PLAYER_1
];
2598 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2599 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2601 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2606 s1
:= _lc
[I_MENU_PLAYER_2
];
2607 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2608 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2610 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2616 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2622 procedure DrawLoadingStat();
2623 procedure drawRect (x
, y
, w
, h
: Integer);
2625 if (w
< 1) or (h
< 1) then exit
;
2627 glVertex2f(x
+0.375, y
+0.375);
2628 glVertex2f(x
+w
+0.375, y
+0.375);
2629 glVertex2f(x
+w
+0.375, y
+h
+0.375);
2630 glVertex2f(x
+0.375, y
+h
+0.375);
2634 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
2636 rectW
, rectH
: Integer;
2643 idl
, idr
, idb
, idm
: LongWord;
2647 if (total
< 1) then exit
;
2648 if (cur
< 1) then exit
; // don't blink
2649 if (not washere
) and (cur
>= total
) then exit
; // don't blink
2650 //if (cur < 0) then cur := 0;
2651 //if (cur > total) then cur := total;
2654 if (hasPBarGfx
) then
2656 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
2657 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2658 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
2659 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2660 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
2661 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2662 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
2663 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2665 //rectW := gScreenWidth-360;
2666 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
2669 x0
:= (gScreenWidth
-rectW
) div 2;
2670 y0
:= gScreenHeight
-rectH
-64;
2671 if (y0
< 2) then y0
:= 2;
2673 glEnable(GL_SCISSOR_TEST
);
2676 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
2677 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
2678 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
2681 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
2683 while (f
< x0
+rectW
) do
2685 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
2690 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
2691 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
2694 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
2695 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
2699 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
2705 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
2709 rectW
:= gScreenWidth
-64;
2712 x0
:= (gScreenWidth
-rectW
) div 2;
2713 y0
:= gScreenHeight
-rectH
-64;
2714 if (y0
< 2) then y0
:= 2;
2716 glDisable(GL_BLEND
);
2717 glDisable(GL_TEXTURE_2D
);
2719 //glClearColor(0, 0, 0, 0);
2720 //glClear(GL_COLOR_BUFFER_BIT);
2722 glColor4ub(127, 127, 127, 255);
2723 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
2725 glColor4ub(0, 0, 0, 255);
2726 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
2728 glColor4ub(127, 127, 127, 255);
2729 wdt
:= rectW
*cur
div total
;
2730 if (wdt
> rectW
) then wdt
:= rectW
;
2731 drawRect(x0
, y0
, wdt
, rectH
);
2740 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
2742 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2743 yy
:= (gScreenHeight
div 3);
2744 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2745 xx
:= (gScreenWidth
div 3);
2749 for i
:= 0 to NextMsg
-1 do
2751 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2752 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2756 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2757 yy
:= yy
+ LOADING_INTERLINE
;
2758 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
2763 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2765 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2767 function monDraw (mon
: TMonster
): Boolean;
2769 result
:= false; // don't stop
2774 // Ëåâûé âåðõíèé óãîë
2775 aX
:= Obj
.X
div ScaleSz
+ 1;
2776 aY
:= Obj
.Y
div ScaleSz
+ 1;
2778 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2779 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2780 // Ïðàâûé íèæíèé óãîë
2781 aX2
:= aX
+ aX2
- 1;
2782 aY2
:= aY
+ aY2
- 1;
2783 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2789 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2790 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2793 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2794 ScaleSz
:= 16 div Scale
;
2795 // Ðàçìåðû ìèíè-êàðòû:
2796 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2797 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2799 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2801 if gWalls
<> nil then
2804 for a
:= 0 to High(gWalls
) do
2806 if PanelType
<> 0 then
2808 // Ëåâûé âåðõíèé óãîë:
2809 aX
:= X
div ScaleSz
;
2810 aY
:= Y
div ScaleSz
;
2812 aX2
:= max(Width
div ScaleSz
, 1);
2813 aY2
:= max(Height
div ScaleSz
, 1);
2814 // Ïðàâûé íèæíèé óãîë:
2815 aX2
:= aX
+ aX2
- 1;
2816 aY2
:= aY
+ aY2
- 1;
2819 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2820 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2821 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2825 if gSteps
<> nil then
2828 for a
:= 0 to High(gSteps
) do
2830 if PanelType
<> 0 then
2832 // Ëåâûé âåðõíèé óãîë:
2833 aX
:= X
div ScaleSz
;
2834 aY
:= Y
div ScaleSz
;
2836 aX2
:= max(Width
div ScaleSz
, 1);
2837 aY2
:= max(Height
div ScaleSz
, 1);
2838 // Ïðàâûé íèæíèé óãîë:
2839 aX2
:= aX
+ aX2
- 1;
2840 aY2
:= aY
+ aY2
- 1;
2842 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2845 if gLifts
<> nil then
2848 for a
:= 0 to High(gLifts
) do
2850 if PanelType
<> 0 then
2852 // Ëåâûé âåðõíèé óãîë:
2853 aX
:= X
div ScaleSz
;
2854 aY
:= Y
div ScaleSz
;
2856 aX2
:= max(Width
div ScaleSz
, 1);
2857 aY2
:= max(Height
div ScaleSz
, 1);
2858 // Ïðàâûé íèæíèé óãîë:
2859 aX2
:= aX
+ aX2
- 1;
2860 aY2
:= aY
+ aY2
- 1;
2863 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2864 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2865 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2866 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2870 if gWater
<> nil then
2873 for a
:= 0 to High(gWater
) do
2875 if PanelType
<> 0 then
2877 // Ëåâûé âåðõíèé óãîë:
2878 aX
:= X
div ScaleSz
;
2879 aY
:= Y
div ScaleSz
;
2881 aX2
:= max(Width
div ScaleSz
, 1);
2882 aY2
:= max(Height
div ScaleSz
, 1);
2883 // Ïðàâûé íèæíèé óãîë:
2884 aX2
:= aX
+ aX2
- 1;
2885 aY2
:= aY
+ aY2
- 1;
2887 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2890 if gAcid1
<> nil then
2892 // Ðèñóåì êèñëîòó 1:
2893 for a
:= 0 to High(gAcid1
) do
2895 if PanelType
<> 0 then
2897 // Ëåâûé âåðõíèé óãîë:
2898 aX
:= X
div ScaleSz
;
2899 aY
:= Y
div ScaleSz
;
2901 aX2
:= max(Width
div ScaleSz
, 1);
2902 aY2
:= max(Height
div ScaleSz
, 1);
2903 // Ïðàâûé íèæíèé óãîë:
2904 aX2
:= aX
+ aX2
- 1;
2905 aY2
:= aY
+ aY2
- 1;
2907 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2910 if gAcid2
<> nil then
2912 // Ðèñóåì êèñëîòó 2:
2913 for a
:= 0 to High(gAcid2
) do
2915 if PanelType
<> 0 then
2917 // Ëåâûé âåðõíèé óãîë:
2918 aX
:= X
div ScaleSz
;
2919 aY
:= Y
div ScaleSz
;
2921 aX2
:= max(Width
div ScaleSz
, 1);
2922 aY2
:= max(Height
div ScaleSz
, 1);
2923 // Ïðàâûé íèæíèé óãîë:
2924 aX2
:= aX
+ aX2
- 1;
2925 aY2
:= aY
+ aY2
- 1;
2927 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2930 if gPlayers
<> nil then
2933 for a
:= 0 to High(gPlayers
) do
2934 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2936 // Ëåâûé âåðõíèé óãîë:
2937 aX
:= Obj
.X
div ScaleSz
+ 1;
2938 aY
:= Obj
.Y
div ScaleSz
+ 1;
2940 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2941 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2942 // Ïðàâûé íèæíèé óãîë:
2943 aX2
:= aX
+ aX2
- 1;
2944 aY2
:= aY
+ aY2
- 1;
2946 if gPlayers
[a
] = p
then
2947 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2950 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2951 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2952 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2957 g_Mons_ForEach(monDraw
);
2962 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
2964 if not hasAmbient
then exit
;
2965 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
2969 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
2970 //FIXME: broken for splitscreen mode
2971 procedure renderDynLightsInternal ();
2973 //hasAmbient: Boolean;
2974 //ambColor: TDFColor;
2976 lx
, ly
, lrad
: Integer;
2977 scxywh
: array[0..3] of GLint
;
2980 if e_NoGraphics
then exit
;
2982 //TODO: lights should be in separate grid, i think
2983 // but on the other side: grid may be slower for dynlights, as their lifetime is short
2984 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
2987 //ambColor := gCurrentMap['light_ambient'].rgba;
2988 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
2990 { // this will multiply incoming color to alpha from framebuffer
2992 glBlendFunc(GL_DST_ALPHA, GL_ONE);
2996 * light rendering: (INVALID!)
2997 * glStencilFunc(GL_EQUAL, 0, $ff);
2999 * glClear(GL_STENCIL_BUFFER_BIT);
3000 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3001 * draw shadow volume into stencil buffer
3002 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3003 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3005 * draw color-less quad with light alpha (WARNING! don't touch color!)
3006 * glEnable(GL_BLEND);
3007 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3008 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3010 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3011 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3013 // setup OpenGL parameters
3014 glStencilMask($FFFFFFFF);
3015 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3016 glEnable(GL_STENCIL_TEST
);
3017 glEnable(GL_SCISSOR_TEST
);
3018 glClear(GL_STENCIL_BUFFER_BIT
);
3019 glStencilFunc(GL_EQUAL
, 0, $ff);
3021 for lln
:= 0 to g_dynLightCount
-1 do
3023 lx
:= g_dynLights
[lln
].x
;
3024 ly
:= g_dynLights
[lln
].y
;
3025 lrad
:= g_dynLights
[lln
].radius
;
3026 if (lrad
< 3) then continue
;
3028 if (lx
-sX
+lrad
< 0) then continue
;
3029 if (ly
-sY
+lrad
< 0) then continue
;
3030 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3031 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3033 // set scissor to optimize drawing
3034 if (g_dbg_scale
= 1.0) then
3036 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3040 glScissor(0, 0, gWinSizeX
, gWinSizeY
);
3042 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3043 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3044 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3045 // draw extruded panels
3046 glDisable(GL_TEXTURE_2D
);
3047 glDisable(GL_BLEND
);
3048 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3049 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3050 // render light texture
3051 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3052 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3055 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3056 glEnable(GL_TEXTURE_2D
);
3057 // color and opacity
3058 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3059 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3061 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3062 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3063 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3064 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3069 glDisable(GL_STENCIL_TEST
);
3070 glDisable(GL_BLEND
);
3071 glDisable(GL_SCISSOR_TEST
);
3072 //glScissor(0, 0, sWidth, sHeight);
3074 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3075 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3079 function fixViewportForScale (): Boolean;
3081 nx0
, ny0
, nw
, nh
: Integer;
3084 if (g_dbg_scale
<> 1.0) then
3087 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3088 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3089 nw
:= round(sWidth
/g_dbg_scale
);
3090 nh
:= round(sHeight
/g_dbg_scale
);
3099 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3100 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3101 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3103 TDrawCB
= procedure ();
3106 hasAmbient
: Boolean;
3108 doAmbient
: Boolean = false;
3110 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3115 profileFrameDraw
.sectionBegin(profname
);
3116 if gdbg_map_use_accel_render
then
3118 tagmask
:= panelTypeToTag(panType
);
3119 while (gDrawPanelList
.count
> 0) do
3121 pan
:= TPanel(gDrawPanelList
.front());
3122 if ((pan
.tag
and tagmask
) = 0) then break
;
3123 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3124 gDrawPanelList
.popFront();
3129 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3131 profileFrameDraw
.sectionEnd();
3134 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3136 profileFrameDraw
.sectionBegin(profname
);
3137 if assigned(cb
) then cb();
3138 profileFrameDraw
.sectionEnd();
3142 profileFrameDraw
.sectionBegin('total');
3144 // our accelerated renderer will collect all panels to gDrawPanelList
3145 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3146 profileFrameDraw
.sectionBegin('collect');
3147 if gdbg_map_use_accel_render
then
3149 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3151 profileFrameDraw
.sectionEnd();
3153 profileFrameDraw
.sectionBegin('skyback');
3154 g_Map_DrawBack(backXOfs
, backYOfs
);
3155 profileFrameDraw
.sectionEnd();
3157 if setTransMatrix
then
3159 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3160 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3161 glTranslatef(-sX
, -sY
, 0);
3165 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3166 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3171 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3172 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3173 glClear(GL_COLOR_BUFFER_BIT);
3176 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3179 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3180 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3181 drawOther('items', @g_Items_Draw
);
3182 drawOther('weapons', @g_Weapon_Draw
);
3183 drawOther('shells', @g_Player_DrawShells
);
3184 drawOther('drawall', @g_Player_DrawAll
);
3185 drawOther('corpses', @g_Player_DrawCorpses
);
3186 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3187 drawOther('monsters', @g_Monsters_Draw
);
3188 drawOther('itemdrop', @g_Items_DrawDrop
);
3189 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3190 drawOther('gfx', @g_GFX_Draw
);
3191 drawOther('flags', @g_Map_DrawFlags
);
3192 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3193 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3194 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3195 drawOther('dynlights', @renderDynLightsInternal
);
3197 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3199 renderAmbientQuad(hasAmbient
, ambColor
);
3203 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3206 if g_debug_HealthBar
then
3208 g_Monsters_DrawHealth();
3209 g_Player_DrawHealth();
3212 profileFrameDraw
.mainEnd(); // map rendering
3216 procedure DrawMapView(x
, y
, w
, h
: Integer);
3223 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3224 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3231 fixViewportForScale();
3232 renderMapInternal(-bx
, -by
, true);
3238 procedure DrawPlayer(p
: TPlayer
);
3240 px
, py
, a
, b
, c
, d
: Integer;
3243 if (p
= nil) or (p
.FDummy
) then
3246 g_Map_DrawBack(0, 0);
3251 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3252 profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3258 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3259 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3261 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3263 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3264 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3266 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3267 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3269 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3270 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3273 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3276 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3277 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3280 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3285 // scaled, ignore level bounds
3286 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3287 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3290 if p
.IncCam
<> 0 then
3292 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
3294 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
3296 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
3300 if py
< gPlayerScreenSize
.Y
div 2 then
3302 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
3304 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
3308 if p
.IncCam
< 0 then
3310 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
3313 if p
.IncCam
> 0 then
3315 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
3319 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
3320 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
3321 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
3323 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
3324 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
3325 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
3328 sY
:= -(b
+p
.IncCam
);
3329 sWidth
:= gPlayerScreenSize
.X
;
3330 sHeight
:= gPlayerScreenSize
.Y
;
3332 //glTranslatef(a, b+p.IncCam, 0);
3334 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3336 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3337 fixViewportForScale();
3338 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3339 if (g_dbg_scale
<> 1.0) and (not g_dbg_ignore_bounds
) then
3341 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3342 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3343 if (sX
< 0) then sX
:= 0;
3344 if (sY
< 0) then sY
:= 0;
3346 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3347 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3351 p
.viewPortW
:= sWidth
;
3352 p
.viewPortH
:= sHeight
;
3354 if (p
= gPlayer1
) then
3356 g_Holmes_plrViewPos(sX
, sY
);
3357 g_Holmes_plrViewSize(sWidth
, sHeight
);
3360 renderMapInternal(-c
, -d
, true);
3362 if p
.FSpectator
then
3363 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3364 p
.GameY
+ PLAYER_RECT_CY
- 4,
3365 'X', gStdFont
, 255, 255, 255, 1, True);
3367 for a := 0 to High(gCollideMap) do
3368 for b := 0 to High(gCollideMap[a]) do
3371 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3373 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3377 1: e_DrawPoint(1, b, a, 200, 200, 200);
3378 2: e_DrawPoint(1, b, a, 64, 64, 255);
3379 3: e_DrawPoint(1, b, a, 255, 0, 255);
3389 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3390 if g_Debug_Player
then
3391 g_Player_DrawDebug(p
);
3395 procedure drawProfilers ();
3400 if g_profile_frame_draw
then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3401 if g_profile_collision
then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3402 if g_profile_los
then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3405 procedure g_Game_Draw();
3412 plView1
, plView2
: TPlayer
;
3415 if gExit
= EXIT_QUIT
then Exit
;
3417 Time
:= GetTimer() {div 1000};
3418 FPSCounter
:= FPSCounter
+1;
3419 if Time
- FPSTime
>= 1000 then
3426 if gGameOn
or (gState
= STATE_FOLD
) then
3428 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3430 gSpectMode
:= SPECT_NONE
;
3431 if not gRevertPlayers
then
3433 plView1
:= gPlayer1
;
3434 plView2
:= gPlayer2
;
3438 plView1
:= gPlayer2
;
3439 plView2
:= gPlayer1
;
3443 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3445 gSpectMode
:= SPECT_NONE
;
3446 if gPlayer2
= nil then
3449 plView1
:= gPlayer2
;
3458 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3459 gSpectMode
:= SPECT_STATS
;
3461 if gSpectMode
= SPECT_PLAYERS
then
3462 if gPlayers
<> nil then
3464 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3465 if plView1
= nil then
3467 gSpectPID1
:= GetActivePlayerID_Next();
3468 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3470 if gSpectViewTwo
then
3472 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3473 if plView2
= nil then
3475 gSpectPID2
:= GetActivePlayerID_Next();
3476 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3481 if gSpectMode
= SPECT_MAPVIEW
then
3483 // Ðåæèì ïðîñìîòðà êàðòû
3485 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3486 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3487 gHearPoint1
.Active
:= True;
3488 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3489 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3490 gHearPoint2
.Active
:= False;
3494 Split
:= (plView1
<> nil) and (plView2
<> nil);
3496 // Òî÷êè ñëóõà èãðîêîâ
3497 if plView1
<> nil then
3499 gHearPoint1
.Active
:= True;
3500 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
3501 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
3503 gHearPoint1
.Active
:= False;
3504 if plView2
<> nil then
3506 gHearPoint2
.Active
:= True;
3507 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
3508 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
3510 gHearPoint2
.Active
:= False;
3512 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3513 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3516 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3517 if gScreenHeight
mod 2 = 0 then
3518 Dec(gPlayerScreenSize
.Y
);
3521 gPlayerScreenSize
.Y
:= gScreenHeight
;
3524 if gScreenHeight
mod 2 = 0 then
3525 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3527 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3529 DrawPlayer(plView1
);
3530 gPlayer1ScreenCoord
.X
:= sX
;
3531 gPlayer1ScreenCoord
.Y
:= sY
;
3535 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3537 DrawPlayer(plView2
);
3538 gPlayer2ScreenCoord
.X
:= sX
;
3539 gPlayer2ScreenCoord
.Y
:= sY
;
3542 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3545 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3549 if (g_holmes_enabled
) then g_Holmes_Draw();
3551 if MessageText
<> '' then
3555 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3557 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3558 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3560 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3561 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3564 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3566 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
3568 // Draw spectator GUI
3571 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3574 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3576 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3578 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3580 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3581 if gSpectMode
= SPECT_MAPVIEW
then
3583 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
3584 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
3585 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
3586 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
3587 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
3589 if gSpectMode
= SPECT_PLAYERS
then
3591 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
3592 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
3593 if gSpectViewTwo
then
3595 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
3596 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
3597 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3598 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3602 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3603 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3609 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
3611 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3612 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3614 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
3615 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3616 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
3621 if (gState
= STATE_MENU
) then
3623 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then
3625 if g_Texture_Get('MENU_BACKGROUND', ID
) then e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3626 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3628 // F3 at menu will show game loading dialog
3629 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
3630 if (g_ActiveWindow
<> nil) then
3632 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3633 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3637 // F3 at titlepic will show game loading dialog
3638 if e_KeyPressed(IK_F3
) then
3640 g_Menu_Show_LoadMenu(true);
3641 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3646 if gState
= STATE_FOLD
then
3648 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3651 if gState
= STATE_INTERCUSTOM
then
3653 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
3655 back
:= 'TEXTURE_endpic';
3656 if not g_Texture_Get(back
, ID
) then
3657 back
:= _lc
[I_TEXTURE_ENDPIC
];
3662 if g_Texture_Get(back
, ID
) then
3663 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3665 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3669 if g_ActiveWindow
<> nil then
3671 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3672 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3676 if gState
= STATE_INTERSINGLE
then
3678 if EndingGameCounter
> 0 then
3680 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3686 if g_Texture_Get(back
, ID
) then
3687 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3689 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3693 if g_ActiveWindow
<> nil then
3695 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3696 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3701 if gState
= STATE_ENDPIC
then
3704 if not g_Texture_Get('TEXTURE_endpic', ID
) then
3705 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
3707 if ID
<> DWORD(-1) then
3708 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3710 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3712 if g_ActiveWindow
<> nil then
3714 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3715 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3719 if gState
= STATE_SLIST
then
3721 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3723 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
3724 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3725 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3727 g_Serverlist_Draw(slCurrent
);
3731 if g_ActiveWindow
<> nil then
3735 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3736 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3738 g_ActiveWindow
.Draw();
3743 if g_debug_Sounds
and gGameOn
then
3745 for w
:= 0 to High(e_SoundsArray
) do
3746 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
3747 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
3752 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3753 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3756 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3757 drawTime(gScreenWidth
-72, gScreenHeight
-16);
3759 if gGameOn
then drawProfilers();
3764 procedure g_Game_Quit();
3766 g_Game_StopAllSounds(True);
3768 g_Game_SaveOptions();
3770 g_PlayerModel_FreeData();
3771 g_Texture_DeleteAll();
3772 g_Frames_DeleteAll();
3773 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
3775 if NetInitDone
then g_Net_Free
;
3777 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3778 if gMapToDelete
<> '' then
3779 g_Game_DeleteTestMap();
3785 procedure g_FatalError(Text: String);
3787 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3788 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
3790 gExit
:= EXIT_SIMPLE
;
3793 procedure g_SimpleError(Text: String);
3795 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3796 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
3799 procedure g_Game_SetupScreenSize();
3801 RES_FACTOR
= 4.0 / 3.0;
3807 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3808 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3809 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3810 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3812 gPlayerScreenSize
.Y
:= gScreenHeight
;
3814 // Ðàçìåð çàäíåãî ïëàíà:
3815 if BackID
<> DWORD(-1) then
3818 if (gScreenWidth
*s
> gMapInfo
.Width
) or
3819 (gScreenHeight
*s
> gMapInfo
.Height
) then
3821 gBackSize
.X
:= gScreenWidth
;
3822 gBackSize
.Y
:= gScreenHeight
;
3826 e_GetTextureSize(BackID
, @bw
, @bh
);
3827 rf
:= Single(bw
) / Single(bh
);
3828 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
3829 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
3830 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
3831 if (s
< 1.0) then s
:= 1.0;
3832 gBackSize
.X
:= Round(bw
*s
);
3833 gBackSize
.Y
:= Round(bh
*s
);
3838 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3840 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3843 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3845 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3846 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3848 if gPlayer1
= nil then
3850 if g_Game_IsClient
then
3852 if NetPlrUID1
> -1 then
3854 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3855 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3860 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3861 Team
:= gPlayer1Settings
.Team
;
3863 // Ñîçäàíèå ïåðâîãî èãðîêà:
3864 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3865 gPlayer1Settings
.Color
,
3867 if gPlayer1
= nil then
3868 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3871 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3872 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3873 if g_Game_IsServer
and g_Game_IsNet
then
3874 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3875 gPlayer1
.Respawn(False, True);
3877 if g_Game_IsNet
and NetUseMaster
then
3883 if gPlayer2
= nil then
3885 if g_Game_IsClient
then
3887 if NetPlrUID2
> -1 then
3888 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3892 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3893 Team
:= gPlayer2Settings
.Team
;
3895 // Ñîçäàíèå âòîðîãî èãðîêà:
3896 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3897 gPlayer2Settings
.Color
,
3899 if gPlayer2
= nil then
3900 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3903 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3904 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3905 if g_Game_IsServer
and g_Game_IsNet
then
3906 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3907 gPlayer2
.Respawn(False, True);
3909 if g_Game_IsNet
and NetUseMaster
then
3917 procedure g_Game_RemovePlayer();
3921 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3922 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3927 if g_Game_IsServer
then
3930 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3931 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3932 g_Player_Remove(Pl
.UID
);
3934 if g_Game_IsNet
and NetUseMaster
then
3943 if g_Game_IsServer
then
3946 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3947 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3948 g_Player_Remove(Pl
.UID
);
3950 if g_Game_IsNet
and NetUseMaster
then
3955 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3961 procedure g_Game_Spectate();
3963 g_Game_RemovePlayer();
3964 if gPlayer1
<> nil then
3965 g_Game_RemovePlayer();
3968 procedure g_Game_SpectateCenterView();
3970 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3971 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3974 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3981 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
3983 g_Game_ClearLoading();
3986 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3989 gGameSettings
.GameType
:= GT_SINGLE
;
3990 gGameSettings
.MaxLives
:= 0;
3991 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3992 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3993 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3994 gSwitchGameMode
:= GM_SINGLE
;
3996 g_Game_ExecuteEvent('ongamestart');
3998 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3999 g_Game_SetupScreenSize();
4001 // Ñîçäàíèå ïåðâîãî èãðîêà:
4002 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4003 gPlayer1Settings
.Color
,
4004 gPlayer1Settings
.Team
, False));
4005 if gPlayer1
= nil then
4007 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4011 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4014 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4017 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4018 gPlayer2Settings
.Color
,
4019 gPlayer2Settings
.Team
, False));
4020 if gPlayer2
= nil then
4022 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4026 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4030 // Çàãðóçêà è çàïóñê êàðòû:
4031 if not g_Game_StartMap(MAP
, True) then
4033 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4034 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4038 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4042 for i
:= nPl
+1 to nPlayers
do
4043 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4046 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4047 TimeLimit
, GoalLimit
: Word;
4049 Options
: LongWord; nPlayers
: Byte);
4055 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4057 g_Game_ClearLoading();
4060 gGameSettings
.GameType
:= GT_CUSTOM
;
4061 gGameSettings
.GameMode
:= GameMode
;
4062 gSwitchGameMode
:= GameMode
;
4063 gGameSettings
.TimeLimit
:= TimeLimit
;
4064 gGameSettings
.GoalLimit
:= GoalLimit
;
4065 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4066 gGameSettings
.Options
:= Options
;
4068 gCoopTotalMonstersKilled
:= 0;
4069 gCoopTotalSecretsFound
:= 0;
4070 gCoopTotalMonsters
:= 0;
4071 gCoopTotalSecrets
:= 0;
4075 g_Game_ExecuteEvent('ongamestart');
4077 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4078 g_Game_SetupScreenSize();
4080 // Ðåæèì íàáëþäàòåëÿ:
4081 if nPlayers
= 0 then
4088 if nPlayers
>= 1 then
4090 // Ñîçäàíèå ïåðâîãî èãðîêà:
4091 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4092 gPlayer1Settings
.Color
,
4093 gPlayer1Settings
.Team
, False));
4094 if gPlayer1
= nil then
4096 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4100 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4104 if nPlayers
>= 2 then
4106 // Ñîçäàíèå âòîðîãî èãðîêà:
4107 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4108 gPlayer2Settings
.Color
,
4109 gPlayer2Settings
.Team
, False));
4110 if gPlayer2
= nil then
4112 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4116 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4120 // Çàãðóçêà è çàïóñê êàðòû:
4121 if not g_Game_StartMap(Map
, True) then
4123 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4127 // Íåò òî÷åê ïîÿâëåíèÿ:
4128 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4129 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4130 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4131 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4132 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4134 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4138 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4142 for i
:= nPl
+1 to nPlayers
do
4143 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4146 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4147 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4148 Options
: LongWord; nPlayers
: Byte;
4149 IPAddr
: LongWord; Port
: Word);
4153 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4155 g_Game_ClearLoading();
4158 gGameSettings
.GameType
:= GT_SERVER
;
4159 gGameSettings
.GameMode
:= GameMode
;
4160 gSwitchGameMode
:= GameMode
;
4161 gGameSettings
.TimeLimit
:= TimeLimit
;
4162 gGameSettings
.GoalLimit
:= GoalLimit
;
4163 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4164 gGameSettings
.Options
:= Options
;
4166 gCoopTotalMonstersKilled
:= 0;
4167 gCoopTotalSecretsFound
:= 0;
4168 gCoopTotalMonsters
:= 0;
4169 gCoopTotalSecrets
:= 0;
4173 g_Game_ExecuteEvent('ongamestart');
4175 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4176 g_Game_SetupScreenSize();
4178 // Ðåæèì íàáëþäàòåëÿ:
4179 if nPlayers
= 0 then
4185 if nPlayers
>= 1 then
4187 // Ñîçäàíèå ïåðâîãî èãðîêà:
4188 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4189 gPlayer1Settings
.Color
,
4190 gPlayer1Settings
.Team
, False));
4191 if gPlayer1
= nil then
4193 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4197 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4200 if nPlayers
>= 2 then
4202 // Ñîçäàíèå âòîðîãî èãðîêà:
4203 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4204 gPlayer2Settings
.Color
,
4205 gPlayer2Settings
.Team
, False));
4206 if gPlayer2
= nil then
4208 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4212 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4215 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4216 if NetForwardPorts
then
4217 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4220 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4222 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
4226 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
4228 // Çàãðóçêà è çàïóñê êàðòû:
4229 if not g_Game_StartMap(Map
, True) then
4231 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4235 // Íåò òî÷åê ïîÿâëåíèÿ:
4236 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4237 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4238 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4239 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4240 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4242 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4246 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4249 NetState
:= NET_STATE_GAME
;
4252 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4267 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4268 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4270 g_Game_ClearLoading();
4273 gGameSettings
.GameType
:= GT_CLIENT
;
4275 gCoopTotalMonstersKilled
:= 0;
4276 gCoopTotalSecretsFound
:= 0;
4277 gCoopTotalMonsters
:= 0;
4278 gCoopTotalSecrets
:= 0;
4282 g_Game_ExecuteEvent('ongamestart');
4284 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4285 g_Game_SetupScreenSize();
4287 NetState
:= NET_STATE_AUTH
;
4289 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4291 if not g_Net_Connect(Addr
, Port
) then
4293 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4294 NetState
:= NET_STATE_NONE
;
4298 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4300 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4305 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
4307 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4309 Ptr
:= NetEvent
.packet
^.data
;
4310 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4313 MID
:= InMsg
.ReadByte();
4315 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4317 NetMyID
:= InMsg
.ReadByte();
4318 NetPlrUID1
:= InMsg
.ReadWord();
4320 WadName
:= InMsg
.ReadString();
4321 Map
:= InMsg
.ReadString();
4323 gWADHash
:= InMsg
.ReadMD5();
4325 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4326 gSwitchGameMode
:= gGameSettings
.GameMode
;
4327 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4328 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4329 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4330 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4331 T
:= InMsg
.ReadLongWord();
4333 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
4334 if newResPath
= '' then
4336 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4337 newResPath
:= g_Res_DownloadWAD(WadName
);
4338 if newResPath
= '' then
4340 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4341 enet_packet_destroy(NetEvent
.packet
);
4342 NetState
:= NET_STATE_NONE
;
4346 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
4348 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4349 gPlayer1Settings
.Color
,
4350 gPlayer1Settings
.Team
, False));
4352 if gPlayer1
= nil then
4354 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4356 enet_packet_destroy(NetEvent
.packet
);
4357 NetState
:= NET_STATE_NONE
;
4361 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4362 gPlayer1
.UID
:= NetPlrUID1
;
4363 gPlayer1
.Reset(True);
4365 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
4367 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4369 enet_packet_destroy(NetEvent
.packet
);
4370 NetState
:= NET_STATE_NONE
;
4378 enet_packet_destroy(NetEvent
.packet
);
4382 enet_packet_destroy(NetEvent
.packet
);
4386 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4389 if (NetEvent
.data
<= NET_DISC_MAX
) then
4390 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4391 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4398 ProcessLoading(true);
4400 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
4409 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4410 NetState
:= NET_STATE_NONE
;
4414 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4415 gLMSRespawnTime
:= 0;
4418 NetState
:= NET_STATE_GAME
;
4419 MC_SEND_FullStateRequest
;
4420 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4423 procedure g_Game_SaveOptions();
4425 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
4428 procedure g_Game_ChangeMap(const MapPath
: String);
4432 g_Game_ClearLoading();
4434 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4435 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4436 if gExitByTrigger
then
4439 gExitByTrigger
:= False;
4441 if not g_Game_StartMap(MapPath
, Force
) then
4442 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4445 procedure g_Game_Restart();
4449 if g_Game_IsClient
then
4451 map
:= g_ExtractFileName(gMapInfo
.Map
);
4455 g_Game_ClearLoading();
4456 g_Game_StartMap(Map
, True, gCurrentMapFileName
);
4459 function g_Game_StartMap(Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4461 NewWAD
, ResName
: String;
4464 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4465 g_Player_RemoveAllCorpses();
4467 if (not g_Game_IsClient
) and
4468 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4469 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4471 if gSwitchGameMode
= GM_CTF
then
4472 gGameSettings
.MaxLives
:= 0;
4473 gGameSettings
.GameMode
:= gSwitchGameMode
;
4476 gSwitchGameMode
:= gGameSettings
.GameMode
;
4478 g_Player_ResetTeams();
4480 if isWadPath(Map
) then
4482 NewWAD
:= g_ExtractWadName(Map
);
4483 ResName
:= g_ExtractFileName(Map
);
4484 if g_Game_IsServer
then
4486 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
4487 g_Game_LoadWAD(NewWAD
);
4489 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
4490 g_Game_ClientWAD(NewWAD
, gWADHash
);
4494 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
4497 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4499 gState
:= STATE_NONE
;
4500 g_ActiveWindow
:= nil;
4506 if gGameSettings
.GameMode
= GM_CTF
then
4508 g_Map_ResetFlag(FLAG_RED
);
4509 g_Map_ResetFlag(FLAG_BLUE
);
4510 // CTF, à ôëàãîâ íåò:
4511 if not g_Map_HaveFlagPoints() then
4512 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4517 gState
:= STATE_MENU
;
4522 gPauseMain
:= false;
4523 gPauseHolmes
:= false;
4525 NetTimeToUpdate
:= 1;
4526 NetTimeToReliable
:= 0;
4527 NetTimeToMaster
:= NetMasterRate
;
4528 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4529 gLMSRespawnTime
:= 0;
4530 gMissionFailed
:= False;
4533 gCoopMonstersKilled
:= 0;
4534 gCoopSecretsFound
:= 0;
4536 gVoteInProgress
:= False;
4537 gVotePassed
:= False;
4543 if not gGameOn
then Exit
;
4545 g_Game_SpectateCenterView();
4547 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
4549 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4550 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
4551 gLMSSoftSpawn
:= True;
4552 if NetMode
= NET_SERVER
then
4553 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
4555 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
4558 if NetMode
= NET_SERVER
then
4560 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
4563 if NetUseMaster
then
4565 if (NetMHost
= nil) or (NetMPeer
= nil) then
4566 if not g_Net_Slist_Connect
then
4567 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4572 if NetClients
<> nil then
4573 for I
:= 0 to High(NetClients
) do
4574 if NetClients
[I
].Used
then
4576 NetClients
[I
].Voted
:= False;
4577 if NetClients
[I
].RequestedFullUpdate
then
4579 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
4580 NetClients
[I
].RequestedFullUpdate
:= False;
4584 g_Net_UnbanNonPermHosts();
4589 gCoopTotalMonstersKilled
:= 0;
4590 gCoopTotalSecretsFound
:= 0;
4591 gCoopTotalMonsters
:= 0;
4592 gCoopTotalSecrets
:= 0;
4596 g_Game_ExecuteEvent('onmapstart');
4599 procedure SetFirstLevel();
4603 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4604 if MapList
= nil then
4607 SortSArray(MapList
);
4608 gNextMap
:= MapList
[Low(MapList
)];
4613 procedure g_Game_ExitLevel(const Map
: AnsiString);
4617 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
4618 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
4619 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
4620 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
4622 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4623 if gGameSettings
.GameType
= GT_SINGLE
then
4624 gExit
:= EXIT_ENDLEVELSINGLE
4625 else // Âûøëè â âûõîä â Ñâîåé èãðå
4627 gExit
:= EXIT_ENDLEVELCUSTOM
;
4628 if gGameSettings
.GameMode
= GM_COOP
then
4629 g_Player_RememberAll
;
4631 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4634 if gGameSettings
.GameMode
= GM_COOP
then
4637 gStatsPressed
:= True;
4638 gNextMap
:= 'MAP01';
4640 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4643 if g_Game_IsNet
then
4645 MH_SEND_GameStats();
4646 MH_SEND_CoopStats();
4652 procedure g_Game_RestartLevel();
4656 if gGameSettings
.GameMode
= GM_SINGLE
then
4661 gExit
:= EXIT_ENDLEVELCUSTOM
;
4662 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4666 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
4670 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
4672 if not g_Game_IsClient
then
4674 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
4677 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4678 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
4682 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
4686 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
4687 g_Game_LoadWAD(NewWAD
);
4690 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
4692 i
, n
, nb
, nr
: Integer;
4694 function monRespawn (mon
: TMonster
): Boolean;
4696 result
:= false; // don't stop
4697 if not mon
.FNoRespawn
then mon
.Respawn();
4701 if not g_Game_IsServer
then Exit
;
4702 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
4703 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4704 gLMSRespawnTime
:= 0;
4707 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
4709 gMissionFailed
:= True;
4710 g_Game_RestartLevel
;
4714 n
:= 0; nb
:= 0; nr
:= 0;
4715 for i
:= Low(gPlayers
) to High(gPlayers
) do
4716 if (gPlayers
[i
] <> nil) and
4717 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
4718 (gPlayers
[i
] is TBot
)) then
4721 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
4722 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
4725 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
4727 // wait a second until the fuckers finally decide to join
4728 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4729 gLMSRespawnTime
:= gTime
+ 1000;
4730 gLMSSoftSpawn
:= NoMapRestart
;
4734 g_Player_RemoveAllCorpses
;
4735 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
4736 if g_Game_IsNet
then
4737 MH_SEND_GameEvent(NET_EV_LMS_START
);
4739 for i
:= Low(gPlayers
) to High(gPlayers
) do
4741 if gPlayers
[i
] = nil then continue
;
4742 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
4743 // don't touch normal spectators
4744 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
4746 gPlayers
[i
].FNoRespawn
:= True;
4747 gPlayers
[i
].Lives
:= 0;
4748 if g_Game_IsNet
then
4749 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
4752 gPlayers
[i
].FNoRespawn
:= False;
4753 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
4754 gPlayers
[i
].Respawn(False, True);
4755 if gGameSettings
.GameMode
= GM_COOP
then
4757 gPlayers
[i
].Frags
:= 0;
4758 gPlayers
[i
].RecallState
;
4760 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
4761 gPlayer1
:= g_Player_Get(gLMSPID1
);
4762 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
4763 gPlayer2
:= g_Player_Get(gLMSPID2
);
4766 g_Items_RestartRound();
4769 g_Mons_ForEach(monRespawn
);
4771 gLMSSoftSpawn
:= False;
4774 function g_Game_GetFirstMap(WAD
: String): String;
4778 MapList
:= g_Map_GetMapsList(WAD
);
4779 if MapList
= nil then
4782 SortSArray(MapList
);
4783 Result
:= MapList
[Low(MapList
)];
4785 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4791 function g_Game_GetNextMap(): String;
4798 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4799 if MapList
= nil then
4802 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4804 SortSArray(MapList
);
4806 for I
:= Low(MapList
) to High(MapList
) do
4807 if Map
= MapList
[I
] then
4813 if MapIndex
<> -255 then
4815 if MapIndex
= High(MapList
) then
4816 Result
:= MapList
[Low(MapList
)]
4818 Result
:= MapList
[MapIndex
+ 1];
4820 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4826 procedure g_Game_NextLevel();
4828 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4829 gExit
:= EXIT_ENDLEVELCUSTOM
4832 gExit
:= EXIT_ENDLEVELSINGLE
;
4836 if gNextMap
<> '' then Exit
;
4837 gNextMap
:= g_Game_GetNextMap();
4840 function g_Game_IsTestMap(): Boolean;
4842 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4845 procedure g_Game_DeleteTestMap();
4848 //MapName: AnsiString;
4856 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
4857 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
4858 if (a
= 0) then exit
;
4860 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
4861 WadName
:= Copy(gMapToDelete
, 1, a
+3);
4862 Delete(gMapToDelete
, 1, a
+5);
4863 gMapToDelete
:= UpperCase(gMapToDelete
);
4865 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
4868 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4869 if MapName <> TEST_MAP_NAME then
4872 if not gTempDelete then
4874 time := g_GetFileTime(WadName);
4875 WAD := TWADFile.Create();
4878 if not WAD.ReadFile(WadName) then
4879 begin // Íåò òàêîãî WAD-ôàéëà
4884 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4886 MapList := WAD.GetResourcesList('');
4888 if MapList <> nil then
4889 for a := 0 to High(MapList) do
4890 if MapList[a] = MapName then
4892 // Óäàëÿåì è ñîõðàíÿåì:
4893 WAD.RemoveResource('', MapName);
4894 WAD.SaveTo(WadName);
4899 g_SetFileTime(WadName, time);
4902 if gTempDelete
then DeleteFile(WadName
);
4905 procedure GameCVars(P
: SSArray
);
4908 stat
: TPlayerStatArray
;
4913 cmd
:= LowerCase(P
[0]);
4914 if cmd
= 'r_showfps' then
4916 if (Length(P
) > 1) and
4917 ((P
[1] = '1') or (P
[1] = '0')) then
4918 gShowFPS
:= (P
[1][1] = '1');
4921 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4923 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4925 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4927 with gGameSettings
do
4929 if (Length(P
) > 1) and
4930 ((P
[1] = '1') or (P
[1] = '0')) then
4932 if (P
[1][1] = '1') then
4933 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4935 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4938 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4939 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4941 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4943 if g_Game_IsNet
then MH_SEND_GameSettings
;
4946 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4948 with gGameSettings
do
4950 if (Length(P
) > 1) and
4951 ((P
[1] = '1') or (P
[1] = '0')) then
4953 if (P
[1][1] = '1') then
4954 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4956 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4959 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4960 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4962 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4964 if g_Game_IsNet
then MH_SEND_GameSettings
;
4967 else if cmd
= 'g_gamemode' then
4969 a
:= g_Game_TextToMode(P
[1]);
4970 if a
= GM_SINGLE
then a
:= GM_COOP
;
4971 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4973 gSwitchGameMode
:= a
;
4974 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4975 (gState
= STATE_INTERSINGLE
) then
4976 gSwitchGameMode
:= GM_SINGLE
;
4978 gGameSettings
.GameMode
:= gSwitchGameMode
;
4980 if gSwitchGameMode
= gGameSettings
.GameMode
then
4981 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4982 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4984 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4985 [g_Game_ModeToText(gGameSettings
.GameMode
),
4986 g_Game_ModeToText(gSwitchGameMode
)]));
4988 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4990 with gGameSettings
do
4992 if (Length(P
) > 1) and
4993 ((P
[1] = '1') or (P
[1] = '0')) then
4995 if (P
[1][1] = '1') then
4996 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4998 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
5001 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
5002 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
5004 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
5005 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5007 if g_Game_IsNet
then MH_SEND_GameSettings
;
5010 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
5012 with gGameSettings
do
5014 if (Length(P
) > 1) and
5015 ((P
[1] = '1') or (P
[1] = '0')) then
5017 if (P
[1][1] = '1') then
5018 Options
:= Options
or GAME_OPTION_MONSTERS
5020 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
5023 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
5024 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
5026 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
5027 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5029 if g_Game_IsNet
then MH_SEND_GameSettings
;
5032 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
5034 with gGameSettings
do
5036 if (Length(P
) > 1) and
5037 ((P
[1] = '1') or (P
[1] = '0')) then
5039 if (P
[1][1] = '1') then
5040 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
5042 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
5045 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
5046 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
5048 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
5050 if g_Game_IsNet
then MH_SEND_GameSettings
;
5053 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
5055 with gGameSettings
do
5057 if (Length(P
) > 1) and
5058 ((P
[1] = '1') or (P
[1] = '0')) then
5060 if (P
[1][1] = '1') then
5061 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
5063 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
5066 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
5067 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
5069 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
5071 if g_Game_IsNet
then MH_SEND_GameSettings
;
5074 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
5076 if Length(P
) > 1 then
5078 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
5079 gGameSettings
.WarmupTime
:= 30
5081 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
5084 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
5085 [gGameSettings
.WarmupTime
]));
5086 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5088 else if cmd
= 'net_interp' then
5090 if (Length(P
) > 1) then
5091 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
5093 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
5094 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5095 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
5096 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5099 else if cmd
= 'net_forceplayerupdate' then
5101 if (Length(P
) > 1) and
5102 ((P
[1] = '1') or (P
[1] = '0')) then
5103 NetForcePlayerUpdate
:= (P
[1][1] = '1');
5105 if NetForcePlayerUpdate
then
5106 g_Console_Add('net_forceplayerupdate = 1')
5108 g_Console_Add('net_forceplayerupdate = 0');
5109 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5110 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
5111 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5114 else if cmd
= 'net_predictself' then
5116 if (Length(P
) > 1) and
5117 ((P
[1] = '1') or (P
[1] = '0')) then
5118 NetPredictSelf
:= (P
[1][1] = '1');
5120 if NetPredictSelf
then
5121 g_Console_Add('net_predictself = 1')
5123 g_Console_Add('net_predictself = 0');
5124 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5125 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
5126 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5129 else if cmd
= 'sv_name' then
5131 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5133 NetServerName
:= P
[1];
5134 if Length(NetServerName
) > 64 then
5135 SetLength(NetServerName
, 64);
5136 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
5140 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
5142 else if cmd
= 'sv_passwd' then
5144 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5146 NetPassword
:= P
[1];
5147 if Length(NetPassword
) > 24 then
5148 SetLength(NetPassword
, 24);
5149 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
5153 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
5155 else if cmd
= 'sv_maxplrs' then
5157 if (Length(P
) > 1) then
5159 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
5160 if g_Game_IsServer
and g_Game_IsNet
then
5163 for a
:= 0 to High(NetClients
) do
5164 if NetClients
[a
].Used
then
5167 if b
> NetMaxClients
then
5169 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
5170 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
5171 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5172 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5175 if NetUseMaster
then
5180 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
5182 else if cmd
= 'sv_public' then
5184 if (Length(P
) > 1) then
5186 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
5187 if g_Game_IsServer
and g_Game_IsNet
then
5188 if NetUseMaster
then
5190 if NetMPeer
= nil then
5191 if not g_Net_Slist_Connect() then
5192 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
5193 g_Net_Slist_Update();
5196 if NetMPeer
<> nil then
5197 g_Net_Slist_Disconnect();
5200 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
5202 else if cmd
= 'sv_intertime' then
5204 if (Length(P
) > 1) then
5205 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5207 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5209 else if cmd
= 'p1_name' then
5211 if (Length(P
) > 1) and gGameOn
then
5213 if g_Game_IsClient
then
5215 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5216 MC_SEND_PlayerSettings
;
5219 if gPlayer1
<> nil then
5221 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5222 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5225 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5228 else if cmd
= 'p2_name' then
5230 if (Length(P
) > 1) and gGameOn
then
5232 if g_Game_IsClient
then
5234 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5235 MC_SEND_PlayerSettings
;
5238 if gPlayer2
<> nil then
5240 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5241 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5244 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5247 else if cmd
= 'p1_color' then
5249 if Length(P
) > 3 then
5250 if g_Game_IsClient
then
5252 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5253 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5254 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5255 MC_SEND_PlayerSettings
;
5258 if gPlayer1
<> nil then
5260 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5261 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5262 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5263 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5266 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5267 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5268 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5270 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5272 if Length(P
) > 3 then
5273 if g_Game_IsClient
then
5275 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5276 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5277 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5278 MC_SEND_PlayerSettings
;
5281 if gPlayer2
<> nil then
5283 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5284 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5285 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5286 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5289 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5290 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5291 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5293 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5295 if cmd
= 'r_showtime' then
5297 if (Length(P
) > 1) and
5298 ((P
[1] = '1') or (P
[1] = '0')) then
5299 gShowTime
:= (P
[1][1] = '1');
5302 g_Console_Add(_lc
[I_MSG_TIME_ON
])
5304 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
5306 else if cmd
= 'r_showscore' then
5308 if (Length(P
) > 1) and
5309 ((P
[1] = '1') or (P
[1] = '0')) then
5310 gShowGoals
:= (P
[1][1] = '1');
5313 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5315 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5317 else if cmd
= 'r_showstat' then
5319 if (Length(P
) > 1) and
5320 ((P
[1] = '1') or (P
[1] = '0')) then
5321 gShowStat
:= (P
[1][1] = '1');
5324 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5326 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5328 else if cmd
= 'r_showkillmsg' then
5330 if (Length(P
) > 1) and
5331 ((P
[1] = '1') or (P
[1] = '0')) then
5332 gShowKillMsg
:= (P
[1][1] = '1');
5334 if gShowKillMsg
then
5335 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5337 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5339 else if cmd
= 'r_showlives' then
5341 if (Length(P
) > 1) and
5342 ((P
[1] = '1') or (P
[1] = '0')) then
5343 gShowLives
:= (P
[1][1] = '1');
5346 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5348 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5350 else if cmd
= 'r_showspect' then
5352 if (Length(P
) > 1) and
5353 ((P
[1] = '1') or (P
[1] = '0')) then
5354 gSpectHUD
:= (P
[1][1] = '1');
5357 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5359 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5361 else if cmd
= 'r_showping' then
5363 if (Length(P
) > 1) and
5364 ((P
[1] = '1') or (P
[1] = '0')) then
5365 gShowPing
:= (P
[1][1] = '1');
5368 g_Console_Add(_lc
[I_MSG_PING_ON
])
5370 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5372 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5374 if Length(P
) > 1 then
5376 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5377 gGameSettings
.GoalLimit
:= 0
5382 if gGameSettings
.GameMode
= GM_DM
then
5384 stat
:= g_Player_GetStats();
5386 for a
:= 0 to High(stat
) do
5387 if stat
[a
].Frags
> b
then
5391 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5393 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5396 if g_Game_IsNet
then MH_SEND_GameSettings
;
5399 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5401 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5403 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5404 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5406 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5407 [gGameSettings
.TimeLimit
div 3600,
5408 (gGameSettings
.TimeLimit
div 60) mod 60,
5409 gGameSettings
.TimeLimit
mod 60]));
5410 if g_Game_IsNet
then MH_SEND_GameSettings
;
5412 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5414 if Length(P
) > 1 then
5416 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5417 gGameSettings
.MaxLives
:= 0
5421 stat
:= g_Player_GetStats();
5423 for a
:= 0 to High(stat
) do
5424 if stat
[a
].Lives
> b
then
5426 gGameSettings
.MaxLives
:=
5427 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5431 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5432 [gGameSettings
.MaxLives
]));
5433 if g_Game_IsNet
then MH_SEND_GameSettings
;
5438 procedure PrintHeapStats();
5442 hs
:= GetFPCHeapStatus();
5443 e_LogWriteLn ('v===== heap status =====v');
5444 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5445 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5446 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5447 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5448 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5449 e_LogWriteLn ('^=======================^');
5452 procedure DebugCommands(P
: SSArray
);
5459 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5460 if {gDebugMode}conIsCheatsEnabled
then
5462 cmd
:= LowerCase(P
[0]);
5463 if cmd
= 'd_window' then
5465 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
5466 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
5467 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5468 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5469 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
5471 else if cmd
= 'd_sounds' then
5473 if (Length(P
) > 1) and
5474 ((P
[1] = '1') or (P
[1] = '0')) then
5475 g_Debug_Sounds
:= (P
[1][1] = '1');
5477 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5479 else if cmd
= 'd_frames' then
5481 if (Length(P
) > 1) and
5482 ((P
[1] = '1') or (P
[1] = '0')) then
5483 g_Debug_Frames
:= (P
[1][1] = '1');
5485 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5487 else if cmd
= 'd_winmsg' then
5489 if (Length(P
) > 1) and
5490 ((P
[1] = '1') or (P
[1] = '0')) then
5491 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5493 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5495 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5497 if (Length(P
) > 1) and
5498 ((P
[1] = '1') or (P
[1] = '0')) then
5499 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5501 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5503 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5505 if Length(P
) > 1 then
5507 '0': g_debug_BotAIOff
:= 0;
5508 '1': g_debug_BotAIOff
:= 1;
5509 '2': g_debug_BotAIOff
:= 2;
5510 '3': g_debug_BotAIOff
:= 3;
5513 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5515 else if cmd
= 'd_monster' then
5517 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5518 if Length(P
) < 2 then
5520 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5521 g_Console_Add('ID | Name');
5522 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5523 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5524 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5527 a
:= StrToIntDef(P
[1], 0);
5528 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5529 a
:= g_Mons_TypeIdByName(P
[1]);
5531 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5532 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5535 with gPlayer1
.Obj
do
5537 mon
:= g_Monsters_Create(a
,
5538 X
+ Rect
.X
+ (Rect
.Width
div 2),
5539 Y
+ Rect
.Y
+ Rect
.Height
,
5540 gPlayer1
.Direction
, True);
5542 if (Length(P
) > 2) and (mon
<> nil) then
5544 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
5545 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
5546 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
5547 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
5548 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
5549 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5550 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5551 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5552 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5557 else if (cmd
= 'd_health') then
5559 if (Length(P
) > 1) and
5560 ((P
[1] = '1') or (P
[1] = '0')) then
5561 g_debug_HealthBar
:= (P
[1][1] = '1');
5563 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5565 else if (cmd
= 'd_player') then
5567 if (Length(P
) > 1) and
5568 ((P
[1] = '1') or (P
[1] = '0')) then
5569 g_debug_Player
:= (P
[1][1] = '1');
5571 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5573 else if (cmd
= 'd_joy') then
5576 g_Console_Add(e_JoystickStateToString(a
));
5578 else if (cmd
= 'd_mem') then
5584 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5588 procedure GameCheats(P
: SSArray
);
5594 if (not gGameOn
) or (not conIsCheatsEnabled
) then
5596 g_Console_Add('not available');
5602 g_Console_Add('where is the player?!');
5605 cmd
:= LowerCase(P
[0]);
5609 plr
.GodMode
:= not plr
.GodMode
;
5610 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5613 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5614 if cmd
= 'give' then
5616 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
5617 for f
:= 1 to High(P
) do
5619 cmd
:= LowerCase(P
[f
]);
5620 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
5621 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
5622 if cmd
= 'exit' then
5624 if gTriggers
<> nil then
5626 for a
:= 0 to High(gTriggers
) do
5628 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5630 g_Console_Add('player left the map');
5631 gExitByTrigger
:= True;
5632 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
5633 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
5641 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
5642 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
5643 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
5644 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
5645 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
5647 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
5648 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
5650 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
5651 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;
5653 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
5654 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
5656 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
5657 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
5659 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
5660 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
5662 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
5663 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
5664 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
5666 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
5667 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
5668 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
5669 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;
5670 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
5671 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
5673 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;
5674 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;
5675 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;
5676 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;
5677 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;
5678 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;
5680 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
5681 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;
5683 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;
5684 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;
5686 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
5688 if cmd
= 'ammo' then
5690 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
5691 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
5692 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
5693 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
5694 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
5695 g_Console_Add('player got some ammo');
5699 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
5700 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
5702 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
5703 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
5705 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
5706 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
5708 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
5709 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
5711 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
5713 if cmd
= 'weapons' then
5715 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
5716 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
5717 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
5718 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
5719 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
5720 plr
.GiveItem(ITEM_WEAPON_BFG
);
5721 g_Console_Add('player got weapons');
5725 if cmd
= 'keys' then
5727 plr
.GiveItem(ITEM_KEY_RED
);
5728 plr
.GiveItem(ITEM_KEY_GREEN
);
5729 plr
.GiveItem(ITEM_KEY_BLUE
);
5730 g_Console_Add('player got all keys');
5734 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
5739 if cmd
= 'open' then
5741 g_Console_Add('player activated sesame');
5742 g_Triggers_OpenAll();
5749 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
5753 if cmd
= 'noclip' then
5756 g_Console_Add('wall hardeness adjusted');
5760 if cmd
= 'notarget' then
5762 plr
.NoTarget
:= not plr
.NoTarget
;
5763 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
5767 if cmd
= 'noreload' then
5769 plr
.NoReload
:= not plr
.NoReload
;
5770 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
5774 if cmd
= 'speedy' then
5776 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
5777 g_Console_Add('speed adjusted');
5781 if cmd
= 'jumpy' then
5783 VEL_JUMP
:= 30-VEL_JUMP
;
5784 g_Console_Add('jump height adjusted');
5788 if cmd
= 'automap' then
5790 gShowMap
:= not gShowMap
;
5791 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
5795 if cmd
= 'aimline' then
5797 gAimLine
:= not gAimLine
;
5798 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
5803 procedure GameCommands(P
: SSArray
);
5809 pl
: pTNetClient
= nil;
5816 cmd
:= LowerCase(P
[0]);
5818 if (cmd
= 'quit') or
5825 else if cmd
= 'pause' then
5827 if (g_ActiveWindow
= nil) then
5828 g_Game_Pause(not gPauseMain
);
5830 else if cmd
= 'endgame' then
5831 gExit
:= EXIT_SIMPLE
5832 else if cmd
= 'restart' then
5834 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5836 if g_Game_IsClient
then
5838 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5843 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5845 else if cmd
= 'kick' then
5847 if g_Game_IsServer
then
5849 if Length(P
) < 2 then
5851 g_Console_Add('kick <name>');
5856 g_Console_Add('kick <name>');
5860 if g_Game_IsNet
then
5861 pl
:= g_Net_Client_ByName(P
[1]);
5864 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5865 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
5866 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5867 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5868 if NetUseMaster
then
5870 end else if gPlayers
<> nil then
5871 for a
:= Low(gPlayers
) to High(gPlayers
) do
5872 if gPlayers
[a
] <> nil then
5873 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5875 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
5876 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5878 gPlayers
[a
].Lives
:= 0;
5879 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5880 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5881 g_Player_Remove(gPlayers
[a
].UID
);
5882 if NetUseMaster
then
5884 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
5888 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5890 else if cmd
= 'kick_id' then
5892 if g_Game_IsServer
and g_Game_IsNet
then
5894 if Length(P
) < 2 then
5896 g_Console_Add('kick_id <client ID>');
5901 g_Console_Add('kick_id <client ID>');
5905 a
:= StrToIntDef(P
[1], 0);
5906 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5908 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5910 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5911 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5912 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5913 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5914 if NetUseMaster
then
5919 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5921 else if cmd
= 'ban' then
5923 if g_Game_IsServer
and g_Game_IsNet
then
5925 if Length(P
) < 2 then
5927 g_Console_Add('ban <name>');
5932 g_Console_Add('ban <name>');
5936 pl
:= g_Net_Client_ByName(P
[1]);
5939 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5940 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5941 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5942 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5943 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5944 if NetUseMaster
then
5947 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5949 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5951 else if cmd
= 'ban_id' then
5953 if g_Game_IsServer
and g_Game_IsNet
then
5955 if Length(P
) < 2 then
5957 g_Console_Add('ban_id <client ID>');
5962 g_Console_Add('ban_id <client ID>');
5966 a
:= StrToIntDef(P
[1], 0);
5967 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5968 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5970 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5971 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5972 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5973 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5974 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5975 if NetUseMaster
then
5979 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5981 else if cmd
= 'permban' then
5983 if g_Game_IsServer
and g_Game_IsNet
then
5985 if Length(P
) < 2 then
5987 g_Console_Add('permban <name>');
5992 g_Console_Add('permban <name>');
5996 pl
:= g_Net_Client_ByName(P
[1]);
5999 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6000 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6001 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6002 g_Net_SaveBanList();
6003 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6004 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6005 if NetUseMaster
then
6008 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6010 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6012 else if cmd
= 'permban_id' then
6014 if g_Game_IsServer
and g_Game_IsNet
then
6016 if Length(P
) < 2 then
6018 g_Console_Add('permban_id <client ID>');
6023 g_Console_Add('permban_id <client ID>');
6027 a
:= StrToIntDef(P
[1], 0);
6028 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6029 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6031 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6032 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6033 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6034 g_Net_SaveBanList();
6035 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6036 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6037 if NetUseMaster
then
6041 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6043 else if cmd
= 'unban' then
6045 if g_Game_IsServer
and g_Game_IsNet
then
6047 if Length(P
) < 2 then
6049 g_Console_Add('unban <IP Address>');
6054 g_Console_Add('unban <IP Address>');
6058 if g_Net_UnbanHost(P
[1]) then
6060 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6061 g_Net_SaveBanList();
6063 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6065 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6067 else if cmd
= 'clientlist' then
6069 if g_Game_IsServer
and g_Game_IsNet
then
6072 if NetClients
<> nil then
6073 for a
:= Low(NetClients
) to High(NetClients
) do
6074 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6076 plr
:= g_Player_Get(NetClients
[a
].Player
);
6077 if plr
= nil then continue
;
6079 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6080 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6083 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6085 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6087 else if cmd
= 'connect' then
6089 if (NetMode
= NET_NONE
) then
6091 if Length(P
) < 2 then
6093 g_Console_Add('connect <IP> [port] [password]');
6098 g_Console_Add('connect <IP> [port] [password]');
6102 if Length(P
) > 2 then
6103 prt
:= StrToIntDef(P
[2], 25666)
6107 if Length(P
) > 3 then
6112 g_Game_StartClient(P
[1], prt
, pw
);
6115 else if cmd
= 'disconnect' then
6117 if (NetMode
= NET_CLIENT
) then
6120 else if cmd
= 'reconnect' then
6122 if (NetMode
= NET_SERVER
) then
6125 if (NetMode
= NET_CLIENT
) then
6128 gExit
:= EXIT_SIMPLE
;
6132 //TODO: Use last successful password to reconnect, instead of ''
6133 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6135 else if (cmd
= 'addbot') or
6136 (cmd
= 'bot_add') then
6138 if Length(P
) > 1 then
6139 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6141 g_Bot_Add(TEAM_NONE
, 2);
6143 else if cmd
= 'bot_addlist' then
6145 if Length(P
) > 1 then
6146 if Length(P
) = 2 then
6147 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6149 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6151 else if cmd
= 'bot_removeall' then
6153 else if cmd
= 'chat' then
6155 if g_Game_IsNet
then
6157 if Length(P
) > 1 then
6159 for a
:= 1 to High(P
) do
6160 chstr
:= chstr
+ P
[a
] + ' ';
6162 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6164 if Length(chstr
) < 1 then
6166 g_Console_Add('chat <text>');
6170 chstr
:= b_Text_Format(chstr
);
6171 if g_Game_IsClient
then
6172 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6174 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6177 g_Console_Add('chat <text>');
6179 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6181 else if cmd
= 'teamchat' then
6183 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6185 if Length(P
) > 1 then
6187 for a
:= 1 to High(P
) do
6188 chstr
:= chstr
+ P
[a
] + ' ';
6190 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6192 if Length(chstr
) < 1 then
6194 g_Console_Add('teamchat <text>');
6198 chstr
:= b_Text_Format(chstr
);
6199 if g_Game_IsClient
then
6200 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6202 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6203 gPlayer1Settings
.Team
);
6206 g_Console_Add('teamchat <text>');
6208 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6210 else if cmd
= 'game' then
6212 if gGameSettings
.GameType
<> GT_NONE
then
6214 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6217 if Length(P
) = 1 then
6219 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6222 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
6223 P
[1] := addWadExtension(P
[1]);
6224 if FileExists(MapsDir
+ P
[1]) then
6226 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6227 if Length(P
) < 3 then
6230 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6233 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6235 if g_Map_Exist(MapsDir
+ s
) then
6237 // Çàïóñêàåì ñâîþ èãðó
6239 with gGameSettings
do
6241 GameMode
:= g_Game_TextToMode(gcGameMode
);
6242 if gSwitchGameMode
<> GM_NONE
then
6243 GameMode
:= gSwitchGameMode
;
6244 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6245 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6247 if Length(P
) >= 4 then
6248 b
:= StrToIntDef(P
[3], 1);
6249 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6250 GoalLimit
, MaxLives
, Options
, b
);
6255 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6257 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6259 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6261 else if cmd
= 'host' then
6263 if gGameSettings
.GameType
<> GT_NONE
then
6265 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6268 if Length(P
) < 4 then
6270 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6273 if not StrToIp(P
[1], listen
) then
6275 prt
:= StrToIntDef(P
[2], 25666);
6277 P
[3] := addWadExtension(P
[3]);
6278 if FileExists(MapsDir
+ P
[3]) then
6280 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6281 if Length(P
) < 5 then
6284 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6287 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6289 if g_Map_Exist(MapsDir
+ s
) then
6291 // Çàïóñêàåì ñâîþ èãðó
6293 with gGameSettings
do
6295 GameMode
:= g_Game_TextToMode(gcGameMode
);
6296 if gSwitchGameMode
<> GM_NONE
then
6297 GameMode
:= gSwitchGameMode
;
6298 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6299 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6301 if Length(P
) >= 6 then
6302 b
:= StrToIntDef(P
[5], 0);
6303 g_Game_StartServer(s
, GameMode
, TimeLimit
,
6304 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
6309 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6311 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]));
6313 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
6315 else if cmd
= 'map' then
6317 if Length(P
) = 1 then
6319 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6321 g_Console_Add(cmd
+ ' <MAP>');
6322 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6324 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6326 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6328 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
6329 if Length(P
) < 3 then
6331 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6332 s
:= UpperCase(P
[1]);
6333 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6334 begin // Êàðòà íàøëàñü
6335 gExitByTrigger
:= False;
6337 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6339 gExit
:= EXIT_ENDLEVELCUSTOM
;
6341 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6342 g_Game_ChangeMap(s
);
6345 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6346 P
[1] := addWadExtension(P
[1]);
6347 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6348 if FileExists(MapsDir
+ P
[1]) then
6350 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6352 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6354 s
:= P
[1] + ':\' + P
[2];
6356 if g_Map_Exist(MapsDir
+ s
) then
6358 gExitByTrigger
:= False;
6360 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6362 gExit
:= EXIT_ENDLEVELCUSTOM
;
6364 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6365 g_Game_ChangeMap(s
);
6368 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6370 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6372 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6376 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6377 P
[1] := addWadExtension(P
[1]);
6378 if FileExists(MapsDir
+ P
[1]) then
6381 P
[2] := UpperCase(P
[2]);
6382 s
:= P
[1] + ':\' + P
[2];
6384 if g_Map_Exist(MapsDir
+ s
) then
6385 begin // Íàøëè êàðòó
6386 gExitByTrigger
:= False;
6388 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6390 gExit
:= EXIT_ENDLEVELCUSTOM
;
6392 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6393 g_Game_ChangeMap(s
);
6395 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6397 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6400 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6402 else if cmd
= 'nextmap' then
6404 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6405 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6408 if Length(P
) = 1 then
6410 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6412 g_Console_Add(cmd
+ ' <MAP>');
6413 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6416 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6421 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6423 if Length(P
) < 3 then
6425 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6426 s
:= UpperCase(P
[1]);
6427 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6428 begin // Êàðòà íàøëàñü
6429 gExitByTrigger
:= False;
6434 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6435 P
[1] := addWadExtension(P
[1]);
6436 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6437 if FileExists(MapsDir
+ P
[1]) then
6439 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6441 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6443 s
:= P
[1] + ':\' + P
[2];
6445 if g_Map_Exist(MapsDir
+ s
) then
6446 begin // Óñòàíàâëèâàåì êàðòó
6447 gExitByTrigger
:= False;
6452 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6454 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6456 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6460 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6461 P
[1] := addWadExtension(P
[1]);
6462 if FileExists(MapsDir
+ P
[1]) then
6465 P
[2] := UpperCase(P
[2]);
6466 s
:= P
[1] + ':\' + P
[2];
6468 if g_Map_Exist(MapsDir
+ s
) then
6469 begin // Íàøëè êàðòó
6470 gExitByTrigger
:= False;
6474 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6476 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6479 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6482 if gNextMap
= '' then
6483 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
6485 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
6488 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
6491 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6493 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6495 gExitByTrigger
:= False;
6496 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6497 if (gNextMap
= '') and (gTriggers
<> nil) then
6498 for a
:= 0 to High(gTriggers
) do
6499 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6501 gExitByTrigger
:= True;
6502 //gNextMap := gTriggers[a].Data.MapName;
6503 gNextMap
:= gTriggers
[a
].tgcMap
;
6506 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6507 if gNextMap
= '' then
6508 gNextMap
:= g_Game_GetNextMap();
6509 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6510 if not isWadPath(gNextMap
) then
6511 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
6514 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6515 if g_Map_Exist(MapsDir
+ s
) then
6516 gExit
:= EXIT_ENDLEVELCUSTOM
6518 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
6520 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6522 else if (cmd
= 'event') then
6524 if (Length(P
) <= 1) then
6526 for a
:= 0 to High(gEvents
) do
6527 if gEvents
[a
].Command
= '' then
6528 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6530 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6533 if (Length(P
) = 2) then
6535 for a
:= 0 to High(gEvents
) do
6536 if gEvents
[a
].Name
= P
[1] then
6537 if gEvents
[a
].Command
= '' then
6538 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6540 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6543 for a
:= 0 to High(gEvents
) do
6544 if gEvents
[a
].Name
= P
[1] then
6546 gEvents
[a
].Command
:= '';
6547 for b
:= 2 to High(P
) do
6548 if Pos(' ', P
[b
]) = 0 then
6549 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6551 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6552 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6556 else if cmd
= 'suicide' then
6560 if g_Game_IsClient
then
6561 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6564 if gPlayer1
<> nil then
6565 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6566 if gPlayer2
<> nil then
6567 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6571 // Êîìàíäû Ñâîåé èãðû:
6572 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6574 if cmd
= 'bot_addred' then
6576 if Length(P
) > 1 then
6577 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6579 g_Bot_Add(TEAM_RED
, 2);
6581 else if cmd
= 'bot_addblue' then
6583 if Length(P
) > 1 then
6584 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6586 g_Bot_Add(TEAM_BLUE
, 2);
6588 else if cmd
= 'spectate' then
6594 else if cmd
= 'say' then
6596 if g_Game_IsServer
and g_Game_IsNet
then
6598 if Length(P
) > 1 then
6601 for a
:= 1 to High(P
) do
6602 chstr
:= chstr
+ P
[a
] + ' ';
6604 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6606 if Length(chstr
) < 1 then
6608 g_Console_Add('say <text>');
6612 chstr
:= b_Text_Format(chstr
);
6613 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6615 else g_Console_Add('say <text>');
6617 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6619 else if cmd
= 'tell' then
6621 if g_Game_IsServer
and g_Game_IsNet
then
6623 if (Length(P
) > 2) and (P
[1] <> '') then
6626 for a
:= 2 to High(P
) do
6627 chstr
:= chstr
+ P
[a
] + ' ';
6629 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6631 if Length(chstr
) < 1 then
6633 g_Console_Add('tell <playername> <text>');
6637 pl
:= g_Net_Client_ByName(P
[1]);
6639 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6641 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6643 else g_Console_Add('tell <playername> <text>');
6645 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6647 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6649 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6651 // Äîïîëíèòåëüíîå âðåìÿ:
6652 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6654 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6655 [gGameSettings
.TimeLimit
div 3600,
6656 (gGameSettings
.TimeLimit
div 60) mod 60,
6657 gGameSettings
.TimeLimit
mod 60]));
6658 if g_Game_IsNet
then MH_SEND_GameSettings
;
6660 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6662 if (Length(P
) <= 1) then
6663 g_Console_Add('rcon_password <password>')
6665 MC_SEND_RCONPassword(P
[1]);
6667 else if cmd
= 'rcon' then
6669 if g_Game_IsClient
then
6671 if Length(P
) > 1 then
6674 for a
:= 1 to High(P
) do
6675 chstr
:= chstr
+ P
[a
] + ' ';
6677 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6679 if Length(chstr
) < 1 then
6681 g_Console_Add('rcon <command>');
6685 MC_SEND_RCONCommand(chstr
);
6687 else g_Console_Add('rcon <command>');
6690 else if cmd
= 'ready' then
6692 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6693 gLMSRespawnTime
:= gTime
+ 100;
6695 else if (cmd
= 'callvote') and g_Game_IsNet
then
6697 if Length(P
) > 1 then
6700 for a
:= 1 to High(P
) do begin
6701 if a
> 1 then chstr
:= chstr
+ ' ';
6702 chstr
:= chstr
+ P
[a
];
6705 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6707 if Length(chstr
) < 1 then
6709 g_Console_Add('callvote <command>');
6713 if g_Game_IsClient
then
6714 MC_SEND_Vote(True, chstr
)
6716 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6717 g_Console_Process('vote', True);
6720 g_Console_Add('callvote <command>');
6722 else if (cmd
= 'vote') and g_Game_IsNet
then
6724 if g_Game_IsClient
then
6726 else if gVoteInProgress
then
6728 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6729 a
:= Floor((NetClientCount
+1)/2.0) + 1
6731 a
:= Floor(NetClientCount
/2.0) + 1;
6736 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6737 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6743 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6744 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6752 procedure g_TakeScreenShot();
6760 if e_NoGraphics
then Exit
;
6761 ssdir
:= GameDir
+'/screenshots';
6762 if not findFileCI(ssdir
, true) then
6764 // try to create dir
6769 if not findFileCI(ssdir
, true) then exit
; // alas
6772 for a
:= 1 to High(Word) do
6774 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
6776 if findFileCI(t
, true) then continue
;
6777 if not findFileCI(FileName
) then
6780 st
:= createDiskFile(FileName
);
6782 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
6787 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
6795 procedure g_Game_InGameMenu(Show
: Boolean);
6797 if (g_ActiveWindow
= nil) and Show
then
6799 if gGameSettings
.GameType
= GT_SINGLE
then
6800 g_GUI_ShowWindow('GameSingleMenu')
6803 if g_Game_IsClient
then
6804 g_GUI_ShowWindow('GameClientMenu')
6806 if g_Game_IsNet
then
6807 g_GUI_ShowWindow('GameServerMenu')
6809 g_GUI_ShowWindow('GameCustomMenu');
6811 g_Sound_PlayEx('MENU_OPEN');
6813 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6814 if (not g_Game_IsNet
) then
6818 if (g_ActiveWindow
<> nil) and (not Show
) then
6820 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6821 if (not g_Game_IsNet
) then
6822 g_Game_Pause(False);
6826 procedure g_Game_Pause (Enable
: Boolean);
6830 if not gGameOn
then exit
;
6832 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6835 gPauseMain
:= Enable
;
6837 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6840 procedure g_Game_HolmesPause (Enable
: Boolean);
6844 if not gGameOn
then exit
;
6845 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6848 gPauseHolmes
:= Enable
;
6850 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6853 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6858 if gTriggers
<> nil then
6859 for i
:= 0 to High(gTriggers
) do
6860 with gTriggers
[i
] do
6861 if (TriggerType
= TRIGGER_SOUND
) and
6863 Sound
.IsPlaying() then
6865 Sound
.Pause(Enable
);
6869 if gPlayers
<> nil then
6870 for i
:= 0 to High(gPlayers
) do
6871 if gPlayers
[i
] <> nil then
6872 gPlayers
[i
].PauseSounds(Enable
);
6875 if gMusic
<> nil then
6876 gMusic
.Pause(Enable
);
6879 procedure g_Game_StopAllSounds(all
: Boolean);
6883 if gTriggers
<> nil then
6884 for i
:= 0 to High(gTriggers
) do
6885 with gTriggers
[i
] do
6886 if (TriggerType
= TRIGGER_SOUND
) and
6890 if gMusic
<> nil then
6897 procedure g_Game_UpdateTriggerSounds();
6901 if gTriggers
<> nil then
6902 for i
:= 0 to High(gTriggers
) do
6903 with gTriggers
[i
] do
6904 if (TriggerType
= TRIGGER_SOUND
) and
6907 Sound
.IsPlaying() then
6909 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
6910 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
6912 Sound
.SetPan(0.5 - tgcPan
/255.0);
6913 Sound
.SetVolume(tgcVolume
/255.0);
6916 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0);
6920 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6923 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6928 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6933 if gSpectMode
<> SPECT_PLAYERS
then
6935 if gSpectPID1
= UID
then
6940 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6947 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6952 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6957 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6962 if gSpectMode
<> SPECT_PLAYERS
then
6964 Pl
:= g_Player_Get(gSpectPID1
);
6965 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6970 if gSpectViewTwo
then
6972 Pl
:= g_Player_Get(gSpectPID2
);
6973 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6981 procedure g_Game_Message(Msg
: string; Time
: Word);
6983 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
6984 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
6985 MessageTime
:= Time
;
6988 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
6990 punct
: Array[0..13] of String =
6991 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6997 function IsPunctuation(S
: String): Boolean;
7002 if Length(S
) <> 1 then
7004 for i
:= Low(punct
) to High(punct
) do
7005 if S
= punct
[i
] then
7011 function FilterPunctuation(S
: String): String;
7015 for i
:= Low(punct
) to High(punct
) do
7016 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7022 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7024 // remove player name
7025 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7026 // for FullWord check
7027 Text := toLowerCase1251(' ' + Text + ' ');
7028 fpText
:= FilterPunctuation(Text);
7030 for i
:= 0 to Length(gChatSounds
) - 1 do
7033 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7035 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7036 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7038 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7044 gChatSounds
[i
].Sound
.Play();
7050 g_Sound_PlayEx('SOUND_GAME_RADIO');
7053 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7062 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7066 if goodsnd
[a
].IsPlaying() then
7069 goodsnd
[Random(4)].Play();
7072 procedure g_Game_Announce_KillCombo(Param
: Integer);
7079 UID
:= Param
and $FFFF;
7084 Pl
:= g_Player_Get(UID
);
7093 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7097 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7101 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7105 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7113 if not g_Game_IsWatchedPlayer(UID
) then
7116 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7120 if killsnd
[n
].IsPlaying() then
7125 procedure g_Game_StartVote(Command
, Initiator
: string);
7129 if not gVotesEnabled
then Exit
;
7130 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7131 if gVoteInProgress
or gVotePassed
then
7133 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7134 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7137 gVoteInProgress
:= True;
7138 gVotePassed
:= False;
7139 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7142 gVoteCommand
:= Command
;
7144 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7145 Need
:= Floor((NetClientCount
+1)/2.0)+1
7147 Need
:= Floor(NetClientCount
/2.0)+1;
7148 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7149 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7152 procedure g_Game_CheckVote
;
7156 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7157 if not gVoteInProgress
then Exit
;
7159 if (gTime
>= gVoteTimer
) then
7161 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7162 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7164 Need
:= Floor(NetClientCount
/2.0) + 1;
7165 if gVoteCount
>= Need
then
7167 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7168 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7169 gVotePassed
:= True;
7170 gVoteCmdTimer
:= gTime
+ 5000;
7174 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7175 MH_SEND_VoteEvent(NET_VE_FAILED
);
7177 if NetClients
<> nil then
7178 for I
:= Low(NetClients
) to High(NetClients
) do
7179 if NetClients
[i
].Used
then
7180 NetClients
[i
].Voted
:= False;
7181 gVoteInProgress
:= False;
7187 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7188 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7190 Need
:= Floor(NetClientCount
/2.0) + 1;
7191 if gVoteCount
>= Need
then
7193 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7194 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7195 gVoteInProgress
:= False;
7196 gVotePassed
:= True;
7197 gVoteCmdTimer
:= gTime
+ 5000;
7200 if NetClients
<> nil then
7201 for I
:= Low(NetClients
) to High(NetClients
) do
7202 if NetClients
[i
].Used
then
7203 NetClients
[i
].Voted
:= False;
7208 procedure g_Game_LoadMapList(FileName
: string);
7216 if not FileExists(FileName
) then Exit
;
7218 AssignFile(ListFile
, FileName
);
7220 while not EOF(ListFile
) do
7222 ReadLn(ListFile
, s
);
7225 if s
= '' then Continue
;
7227 SetLength(MapList
, Length(MapList
)+1);
7228 MapList
[High(MapList
)] := s
;
7230 CloseFile(ListFile
);
7233 procedure g_Game_SetDebugMode();
7236 // ×èòû (äàæå â ñâîåé èãðå):
7240 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7244 if Length(LoadingStat
.Msgs
) = 0 then
7250 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7251 if NextMsg
= Length(Msgs
) then
7253 for i
:= 0 to High(Msgs
)-1 do
7254 Msgs
[i
] := Msgs
[i
+1];
7262 Msgs
[NextMsg
-1] := Text;
7266 PBarWasHere
:= false;
7269 g_ActiveWindow
:= nil;
7271 ProcessLoading(true);
7274 procedure g_Game_StepLoading();
7280 if (ShowCount
> LOADING_SHOW_STEP
) then
7288 procedure g_Game_ClearLoading();
7297 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7298 if len
< 1 then len
:= 1;
7299 SetLength(Msgs
, len
);
7300 for len
:= Low(Msgs
) to High(Msgs
) do
7303 PBarWasHere
:= false;
7307 procedure Parse_Params(var pars
: TParamStrValues
);
7314 while i
<= ParamCount
do
7317 if (s
[1] = '-') and (Length(s
) > 1) then
7319 if (s
[2] = '-') and (Length(s
) > 2) then
7320 begin // Îäèíî÷íûé ïàðàìåòð
7321 SetLength(pars
, Length(pars
) + 1);
7322 with pars
[High(pars
)] do
7324 Name
:= LowerCase(s
);
7329 if (i
< ParamCount
) then
7330 begin // Ïàðàìåòð ñî çíà÷åíèåì
7332 SetLength(pars
, Length(pars
) + 1);
7333 with pars
[High(pars
)] do
7335 Name
:= LowerCase(s
);
7336 Value
:= LowerCase(ParamStr(i
));
7345 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
7350 for i
:= 0 to High(pars
) do
7351 if pars
[i
].Name
= aName
then
7353 Result
:= pars
[i
].Value
;
7358 procedure g_Game_Process_Params();
7360 pars
: TParamStrValues
;
7363 LimT
, LimS
: Integer;
7374 s
:= Find_Param_Value(pars
, '--debug');
7377 g_Game_SetDebugMode();
7378 s
:= Find_Param_Value(pars
, '--netdump');
7383 // Connect when game loads
7384 ip
:= Find_Param_Value(pars
, '-connect');
7388 s
:= Find_Param_Value(pars
, '-port');
7389 if (s
= '') or not TryStrToInt(s
, Port
) then
7392 s
:= Find_Param_Value(pars
, '-pw');
7394 g_Game_StartClient(ip
, Port
, s
);
7398 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
7401 gDefaultMegawadStart
:= s
;
7404 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
7405 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
7407 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
7410 // Start map when game loads:
7411 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
7412 if isWadPath(map
) then
7415 s
:= Find_Param_Value(pars
, '-gm');
7416 GMode
:= g_Game_TextToMode(s
);
7417 if GMode
= GM_NONE
then GMode
:= GM_DM
;
7418 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
7421 s
:= Find_Param_Value(pars
, '-limt');
7422 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
7428 s
:= Find_Param_Value(pars
, '-lims');
7429 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
7435 s
:= Find_Param_Value(pars
, '-lives');
7436 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
7442 s
:= Find_Param_Value(pars
, '-opt');
7444 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
7446 Opt
:= StrToIntDef(s
, 0);
7448 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
7451 s
:= Find_Param_Value(pars
, '--close');
7455 // Override map to test:
7456 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
7458 gTestMap
:= MapsDir
+ s
;
7460 // Delete test map after play:
7461 s
:= Find_Param_Value(pars
, '--testdelete');
7464 gMapToDelete
:= MapsDir
+ map
;
7465 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
7469 // Delete temporary WAD after play:
7470 s
:= Find_Param_Value(pars
, '--tempdelete');
7471 if (s
<> '') and (gTestMap
<> '') then
7473 gMapToDelete
:= gTestMap
;
7474 gTempDelete
:= True;
7477 // Number of players:
7478 s
:= Find_Param_Value(pars
, '-pl');
7482 n
:= StrToIntDef(s
, 1);
7485 s
:= Find_Param_Value(pars
, '-port');
7486 if (s
= '') or not TryStrToInt(s
, Port
) then
7487 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
7489 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
7492 // Execute script when game loads:
7493 s
:= Find_Param_Value(pars
, '-exec');
7496 if not isWadPath(s
) then
7497 s
:= GameDir
+ '/' + s
;
7502 if IOResult
<> 0 then
7504 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7505 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7509 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
7510 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7515 if IOResult
<> 0 then
7517 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7518 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7522 if Pos('#', s
) <> 1 then // script comment
7523 g_Console_Process(s
, True);
7534 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7535 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7536 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7537 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7539 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7540 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7541 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7542 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7544 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7545 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7547 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7548 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7550 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7552 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7554 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
7556 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7557 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');