1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 g_basic
, g_player
, e_graphics
, g_res_downloader
,
24 g_sound
, g_gui
, utils
, md5
, mempool
, xprofiler
,
28 TGameSettings
= record
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; const 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_Announce_BodyKill(SpawnerUID
: Word);
127 procedure g_Game_StartVote(Command
, Initiator
: string);
128 procedure g_Game_CheckVote
;
129 procedure g_TakeScreenShot();
130 procedure g_FatalError(Text: String);
131 procedure g_SimpleError(Text: String);
132 function g_Game_IsTestMap(): Boolean;
133 procedure g_Game_DeleteTestMap();
134 procedure GameCVars(P
: SSArray
);
135 procedure GameCommands(P
: SSArray
);
136 procedure GameCheats(P
: SSArray
);
137 procedure DebugCommands(P
: SSArray
);
138 procedure g_Game_Process_Params
;
139 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
140 procedure g_Game_StepLoading(Value
: Integer = -1);
141 procedure g_Game_ClearLoading();
142 procedure g_Game_SetDebugMode();
143 procedure DrawLoadingStat();
144 procedure DrawMenuBackground(tex
: AnsiString);
146 { procedure SetWinPause(Enable: Boolean); }
151 LOADING_SHOW_STEP
= 100;
152 LOADING_INTERLINE
= 20;
167 MESSAGE_DIKEY
= WM_USER
+ 1;
172 EXIT_ENDLEVELSINGLE
= 4;
173 EXIT_ENDLEVELCUSTOM
= 5;
175 GAME_OPTION_RESERVED
= 1;
176 GAME_OPTION_TEAMDAMAGE
= 2;
177 GAME_OPTION_ALLOWEXIT
= 4;
178 GAME_OPTION_WEAPONSTAY
= 8;
179 GAME_OPTION_MONSTERS
= 16;
180 GAME_OPTION_BOTVSPLAYER
= 32;
181 GAME_OPTION_BOTVSMONSTER
= 64;
186 STATE_INTERCUSTOM
= 3;
187 STATE_INTERSINGLE
= 4;
193 LMS_RESPAWN_NONE
= 0;
194 LMS_RESPAWN_WARMUP
= 1;
195 LMS_RESPAWN_FINAL
= 2;
212 CONFIG_FILENAME
= 'Doom2DF.cfg';
214 TEST_MAP_NAME
= '$$$_TEST_$$$';
216 STD_PLAYER_MODEL
= 'Doomer';
226 gGameSettings
: TGameSettings
;
227 gPlayer1Settings
: TPlayerSettings
;
228 gPlayer2Settings
: TPlayerSettings
;
230 gPlayerScreenSize
: TDFPoint
;
231 gPlayer1ScreenCoord
: TDFPoint
;
232 gPlayer2ScreenCoord
: TDFPoint
;
233 gPlayer1
: TPlayer
= nil;
234 gPlayer2
: TPlayer
= nil;
235 gPlayerDrawn
: TPlayer
= nil;
237 gSwitchGameMode
: Byte = GM_DM
;
238 gHearPoint1
, gHearPoint2
: THearPoint
;
239 gSoundEffectsDF
: Boolean = False;
240 gSoundTriggerTime
: Word = 0;
241 gAnnouncer
: Byte = ANNOUNCE_NONE
;
242 goodsnd
: array[0..3] of TPlayableSound
;
243 killsnd
: array[0..3] of TPlayableSound
;
244 hahasnd
: array[0..2] of TPlayableSound
;
245 sound_get_flag
: array[0..1] of TPlayableSound
;
246 sound_lost_flag
: array[0..1] of TPlayableSound
;
247 sound_ret_flag
: array[0..1] of TPlayableSound
;
248 sound_cap_flag
: array[0..1] of TPlayableSound
;
249 gBodyKillEvent
: Integer = -1;
250 gDefInterTime
: ShortInt = -1;
251 gInterEndTime
: LongWord = 0;
252 gInterTime
: LongWord = 0;
253 gServInterTime
: Byte = 0;
254 gGameStartTime
: LongWord = 0;
255 gTotalMonsters
: Integer = 0;
256 gPauseMain
: Boolean = false;
257 gPauseHolmes
: Boolean = false;
258 gShowTime
: Boolean = False;
259 gShowFPS
: Boolean = False;
260 gShowGoals
: Boolean = True;
261 gShowStat
: Boolean = True;
262 gShowKillMsg
: Boolean = True;
263 gShowLives
: Boolean = True;
264 gShowPing
: Boolean = False;
265 gShowMap
: Boolean = False;
267 gState
: Byte = STATE_NONE
;
269 sWidth
, sHeight
: Word;
270 gSpectMode
: Byte = SPECT_NONE
;
271 gSpectHUD
: Boolean = True;
272 gSpectKeyPress
: Boolean = False;
273 gSpectX
: Integer = 0;
274 gSpectY
: Integer = 0;
275 gSpectStep
: Byte = 8;
276 gSpectViewTwo
: Boolean = False;
277 gSpectPID1
: Integer = -1;
278 gSpectPID2
: Integer = -1;
279 gSpectAuto
: Boolean = False;
280 gSpectAutoNext
: LongWord;
281 gSpectAutoStepX
: Integer;
282 gSpectAutoStepY
: Integer;
283 gMusic
: TMusic
= nil;
284 gLoadGameMode
: Boolean;
285 gCheats
: Boolean = False;
286 gMapOnce
: Boolean = False;
287 gMapToDelete
: String;
288 gTempDelete
: Boolean = False;
289 gLastMap
: Boolean = False;
290 gWinPosX
, gWinPosY
: Integer;
291 gWinSizeX
, gWinSizeY
: Integer;
292 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
293 gWinActive
: Boolean = True; // by default window is active, lol
294 gResolutionChange
: Boolean = False;
295 gRC_Width
, gRC_Height
: Word;
296 gRC_FullScreen
, gRC_Maximized
: Boolean;
297 gLanguageChange
: Boolean = False;
298 gDebugMode
: Boolean = False;
299 g_debug_Sounds
: Boolean = False;
300 g_debug_Frames
: Boolean = False;
301 g_debug_WinMsgs
: Boolean = False;
302 g_debug_MonsterOff
: Boolean = False;
303 g_debug_BotAIOff
: Byte = 0;
304 g_debug_HealthBar
: Boolean = False;
305 g_Debug_Player
: Boolean = False;
306 gCoopMonstersKilled
: Word = 0;
307 gCoopSecretsFound
: Word = 0;
308 gCoopTotalMonstersKilled
: Word = 0;
309 gCoopTotalSecretsFound
: Word = 0;
310 gCoopTotalMonsters
: Word = 0;
311 gCoopTotalSecrets
: Word = 0;
312 gStatsOff
: Boolean = False;
313 gStatsPressed
: Boolean = False;
314 gExitByTrigger
: Boolean = False;
315 gNextMap
: String = '';
316 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
317 gLMSRespawnTime
: Cardinal = 0;
318 gLMSSoftSpawn
: Boolean = False;
319 gMissionFailed
: Boolean = False;
320 gVoteInProgress
: Boolean = False;
321 gVotePassed
: Boolean = False;
322 gVoteCommand
: string = '';
323 gVoteTimer
: Cardinal = 0;
324 gVoteCmdTimer
: Cardinal = 0;
325 gVoteCount
: Integer = 0;
326 gVoteTimeout
: Cardinal = 30;
327 gVoted
: Boolean = False;
328 gVotesEnabled
: Boolean = True;
329 gEvents
: Array of TGameEvent
;
330 gDelayedEvents
: Array of TDelayedEvent
;
331 gUseChatSounds
: Boolean = True;
332 gChatSounds
: Array of TChatSound
;
333 gSelectWeapon
: Array [0..1, WP_FIRST
..WP_LAST
] of Boolean; // [player, weapon]
334 gInterReadyCount
: Integer = 0;
336 g_dbg_ignore_bounds
: Boolean = false;
337 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
338 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
340 // move button values:
341 // bits 0-1: l/r state:
342 // 0: neither left, nor right pressed
345 // bits 4-5: l/r state when strafe was pressed
346 P1MoveButton
: Byte = 0;
347 P2MoveButton
: Byte = 0;
349 g_profile_frame_update
: Boolean = false;
350 g_profile_frame_draw
: Boolean = false;
351 g_profile_collision
: Boolean = false;
352 g_profile_los
: Boolean = false;
353 g_profile_history_size
: Integer = 1000;
355 g_rlayer_back
: Boolean = true;
356 g_rlayer_step
: Boolean = true;
357 g_rlayer_wall
: Boolean = true;
358 g_rlayer_door
: Boolean = true;
359 g_rlayer_acid1
: Boolean = true;
360 g_rlayer_acid2
: Boolean = true;
361 g_rlayer_water
: Boolean = true;
362 g_rlayer_fore
: Boolean = true;
365 procedure g_ResetDynlights ();
366 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
367 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
369 function conIsCheatsEnabled (): Boolean; inline;
370 function gPause (): Boolean; inline;
376 {$INCLUDE ../nogl/noGLuses.inc}
377 {$IFDEF ENABLE_HOLMES}
380 e_texture
, e_res
, g_textures
, g_main
, g_window
, g_menu
,
381 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
382 g_playermodel
, g_gfx
, g_options
, Math
,
383 g_triggers
, g_monsters
, e_sound
, CONFIG
,
385 ENet
, e_msg
, g_netmsg
, g_netmaster
,
386 sfs
, wadreader
, g_system
;
390 hasPBarGfx
: Boolean = false;
393 // ////////////////////////////////////////////////////////////////////////// //
394 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
397 // ////////////////////////////////////////////////////////////////////////// //
398 function conIsCheatsEnabled (): Boolean; inline;
401 if g_Game_IsNet
then exit
;
402 if not gDebugMode
then
404 //if not gCheats then exit;
405 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
406 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
412 // ////////////////////////////////////////////////////////////////////////// //
414 profileFrameDraw
: TProfiler
= nil;
417 // ////////////////////////////////////////////////////////////////////////// //
420 x
, y
, radius
: Integer;
423 exploRadius
: Integer;
427 g_dynLights
: array of TDynLight
= nil;
428 g_dynLightCount
: Integer = 0;
429 g_playerLight
: Boolean = false;
431 procedure g_ResetDynlights ();
435 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
437 for idx
:= 0 to g_dynLightCount
-1 do
439 if g_dynLights
[idx
].exploCount
= -666 then
446 Inc(g_dynLights
[idx
].exploCount
);
447 if (g_dynLights
[idx
].exploCount
< 10) then
449 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
450 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
451 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
452 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
457 g_dynLightCount
:= lnum
;
460 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
462 if not gwin_has_stencil
then exit
;
463 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
464 g_dynLights
[g_dynLightCount
].x
:= x
;
465 g_dynLights
[g_dynLightCount
].y
:= y
;
466 g_dynLights
[g_dynLightCount
].radius
:= radius
;
467 g_dynLights
[g_dynLightCount
].r
:= r
;
468 g_dynLights
[g_dynLightCount
].g
:= g
;
469 g_dynLights
[g_dynLightCount
].b
:= b
;
470 g_dynLights
[g_dynLightCount
].a
:= a
;
471 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
472 Inc(g_dynLightCount
);
475 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
477 if not gwin_has_stencil
then exit
;
478 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
479 g_dynLights
[g_dynLightCount
].x
:= x
;
480 g_dynLights
[g_dynLightCount
].y
:= y
;
481 g_dynLights
[g_dynLightCount
].radius
:= 0;
482 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
483 g_dynLights
[g_dynLightCount
].r
:= r
;
484 g_dynLights
[g_dynLightCount
].g
:= g
;
485 g_dynLights
[g_dynLightCount
].b
:= b
;
486 g_dynLights
[g_dynLightCount
].a
:= 0;
487 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
488 Inc(g_dynLightCount
);
492 // ////////////////////////////////////////////////////////////////////////// //
493 function calcProfilesHeight (prof
: TProfiler
): Integer;
496 if (prof
= nil) then exit
;
497 if (length(prof
.bars
) = 0) then exit
;
498 result
:= length(prof
.bars
)*(16+2);
502 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
509 if (prof
= nil) then exit
;
511 if (length(prof
.bars
) = 0) then exit
;
513 hgt
:= calcProfilesHeight(prof
);
514 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
515 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
517 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
518 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
519 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
522 for ii
:= 0 to High(prof
.bars
) do
524 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);
531 // ////////////////////////////////////////////////////////////////////////// //
533 TEndCustomGameStat
= record
534 PlayerStat
: TPlayerStatArray
;
538 Map
, MapName
: String;
541 TEndSingleGameStat
= record
542 PlayerStat
: Array [0..1] of record
548 TotalSecrets
: Integer;
551 TLoadingStat
= record
555 Msgs
: Array of String;
557 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
560 TParamStrValue
= record
565 TParamStrValues
= Array of TParamStrValue
;
568 INTER_ACTION_TEXT
= 1;
569 INTER_ACTION_PIC
= 2;
570 INTER_ACTION_MUSIC
= 3;
574 FPSCounter
, UPSCounter
: Word;
575 FPSTime
, UPSTime
: LongWord;
576 DataLoaded
: Boolean = False;
577 IsDrawStat
: Boolean = False;
578 CustomStat
: TEndCustomGameStat
;
579 SingleStat
: TEndSingleGameStat
;
580 LoadingStat
: TLoadingStat
;
581 EndingGameCounter
: Byte = 0;
584 MessageLineLength
: Integer = 80;
585 MapList
: SSArray
= nil;
586 MapIndex
: Integer = -1;
587 InterReadyTime
: Integer = -1;
593 text: Array of ShortString;
594 anim
: Array of ShortString;
595 pic
: Array of ShortString;
596 mus
: Array of ShortString;
598 triggers
: Array of record
600 actions
: Array of record
601 action
, p1
, p2
: Integer;
604 cur_trigger
: Integer;
617 function Compare(a
, b
: TPlayerStat
): Integer;
619 if a
.Spectator
then Result
:= 1
620 else if b
.Spectator
then Result
:= -1
621 else if a
.Frags
< b
.Frags
then Result
:= 1
622 else if a
.Frags
> b
.Frags
then Result
:= -1
623 else if a
.Deaths
< b
.Deaths
then Result
:= -1
624 else if a
.Deaths
> b
.Deaths
then Result
:= 1
625 else if a
.Kills
< b
.Kills
then Result
:= -1
629 procedure SortGameStat(var stat
: TPlayerStatArray
);
634 if stat
= nil then Exit
;
636 for I
:= High(stat
) downto Low(stat
) do
637 for J
:= Low(stat
) to High(stat
) - 1 do
638 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
641 stat
[J
] := stat
[J
+ 1];
646 function g_Game_ModeToText(Mode
: Byte): string;
650 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
651 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
652 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
653 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
654 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
658 function g_Game_TextToMode(Mode
: string): Byte;
661 Mode
:= UpperCase(Mode
);
662 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
667 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
672 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
677 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
682 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
689 function g_Game_IsNet(): Boolean;
691 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
694 function g_Game_IsServer(): Boolean;
696 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
699 function g_Game_IsClient(): Boolean;
701 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
704 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
711 Result
.name
:= ExtractFileName(WAD
);
712 Result
.description
:= '';
715 w
:= TWADFile
.Create();
718 if not w
.GetResource('INTERSCRIPT', p
, len
) then
724 cfg
:= TConfig
.CreateMem(p
, len
);
725 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
726 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
727 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
728 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
734 procedure g_Game_FreeWAD();
738 for a
:= 0 to High(MegaWAD
.res
.pic
) do
739 if MegaWAD
.res
.pic
[a
] <> '' then
740 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
742 for a
:= 0 to High(MegaWAD
.res
.mus
) do
743 if MegaWAD
.res
.mus
[a
] <> '' then
744 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
746 MegaWAD
.res
.pic
:= nil;
747 MegaWAD
.res
.text := nil;
748 MegaWAD
.res
.anim
:= nil;
749 MegaWAD
.res
.mus
:= nil;
750 MegaWAD
.triggers
:= nil;
752 g_Texture_Delete('TEXTURE_endpic');
753 g_Sound_Delete('MUSIC_endmus');
755 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
756 gGameSettings
.WAD
:= '';
759 procedure g_Game_LoadWAD(WAD
: string);
768 gGameSettings
.WAD
:= WAD
;
769 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
772 MegaWAD
.info
:= g_Game_GetMegaWADInfo(WAD
);
774 w
:= TWADFile
.Create();
777 if not w
.GetResource('INTERSCRIPT', p
, len
) then
783 cfg
:= TConfig
.CreateMem(p
, len
);
788 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
789 if s = '' then Break;
792 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
793 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
795 g_Texture_CreateWADEx(s, s);
801 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
802 if s = '' then Break;
805 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
806 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
808 g_Music_CreateWADEx(s, s);
811 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
812 if MegaWAD
.endpic
<> '' then
814 TEXTUREFILTER
:= GL_LINEAR
;
815 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endpic
, WAD
);
816 g_Texture_CreateWADEx('TEXTURE_endpic', s
);
817 TEXTUREFILTER
:= GL_NEAREST
;
819 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
820 if MegaWAD
.endmus
<> '' then
822 s
:= e_GetResourcePath(WadDirs
, MegaWAD
.endmus
, WAD
);
823 g_Sound_CreateWADEx('MUSIC_endmus', s
, True);
831 {procedure start_trigger(t: string);
835 function next_trigger(): Boolean;
839 procedure DisableCheats();
845 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
846 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
847 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
848 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
850 {$IF DEFINED(D2F_DEBUG)}
851 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
852 gAimLine
:= g_dbg_aimline_on
;
856 procedure g_Game_ExecuteEvent(Name
: String);
862 if gEvents
= nil then
864 for a
:= 0 to High(gEvents
) do
865 if gEvents
[a
].Name
= Name
then
867 if gEvents
[a
].Command
<> '' then
868 g_Console_Process(gEvents
[a
].Command
, True);
873 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
878 if gDelayedEvents
<> nil then
879 for a
:= 0 to High(gDelayedEvents
) do
880 if not gDelayedEvents
[a
].Pending
then
887 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
888 n
:= High(gDelayedEvents
);
890 gDelayedEvents
[n
].Pending
:= True;
891 gDelayedEvents
[n
].DEType
:= DEType
;
892 gDelayedEvents
[n
].DENum
:= Num
;
893 gDelayedEvents
[n
].DEStr
:= Str
;
894 if DEType
= DE_GLOBEVENT
then
895 gDelayedEvents
[n
].Time
:= (sys_GetTicks() {div 1000}) + Time
897 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
906 if g_Game_IsNet
and g_Game_IsServer
then
907 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
911 gPauseHolmes
:= false;
914 g_Game_StopAllSounds(False);
919 EndingGameCounter
:= 0;
920 g_ActiveWindow
:= nil;
922 gLMSRespawn
:= LMS_RESPAWN_NONE
;
923 gLMSRespawnTime
:= 0;
926 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
931 begin // Ýòî áûë òåñò
935 begin // Âûõîä â ãëàâíîå ìåíþ
936 gMusic
.SetByName('MUSIC_MENU');
938 if gState
<> STATE_SLIST
then
940 g_GUI_ShowWindow('MainMenu');
941 gState
:= STATE_MENU
;
944 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
945 slReturnPressed
:= True;
946 if g_Net_Slist_Fetch(slCurrent
) then
948 if slCurrent
= nil then
949 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
952 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
953 g_Serverlist_GenerateTable(slCurrent
, slTable
);
956 g_Game_ExecuteEvent('ongameend');
960 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
962 if not g_Game_IsClient
then g_Game_Restart();
965 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
967 // Ñòàòèñòèêà Ñâîåé èãðû:
968 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
970 CustomStat
.GameTime
:= gTime
;
971 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
972 CustomStat
.MapName
:= gMapInfo
.Name
;
973 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
974 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
975 CustomStat
.TeamStat
:= gTeamStat
;
977 CustomStat
.PlayerStat
:= nil;
979 // Ñòàòèñòèêà èãðîêîâ:
980 if gPlayers
<> nil then
982 for a
:= 0 to High(gPlayers
) do
983 if gPlayers
[a
] <> nil then
985 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
986 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
989 Name
:= gPlayers
[a
].Name
;
990 Frags
:= gPlayers
[a
].Frags
;
991 Deaths
:= gPlayers
[a
].Death
;
992 Kills
:= gPlayers
[a
].Kills
;
993 Team
:= gPlayers
[a
].Team
;
994 Color
:= gPlayers
[a
].Model
.Color
;
995 Spectator
:= gPlayers
[a
].FSpectator
;
999 SortGameStat(CustomStat
.PlayerStat
);
1002 g_Game_ExecuteEvent('onmapend');
1003 if not g_Game_IsClient
then g_Player_ResetReady
;
1004 gInterReadyCount
:= 0;
1006 // Çàòóõàþùèé ýêðàí:
1007 EndingGameCounter
:= 255;
1008 gState
:= STATE_FOLD
;
1010 if gDefInterTime
< 0 then
1011 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
1013 gInterEndTime
:= gDefInterTime
* 1000;
1016 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1018 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1019 SingleStat
.GameTime
:= gTime
;
1020 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1021 SingleStat
.TotalSecrets
:= gSecretsCount
;
1022 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1023 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1024 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1025 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1026 if SingleStat
.TwoPlayers
then
1028 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1029 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1032 g_Game_ExecuteEvent('onmapend');
1035 if gNextMap
<> '' then
1037 gMusic
.SetByName('MUSIC_INTERMUS');
1039 gState
:= STATE_INTERSINGLE
;
1042 g_Game_ExecuteEvent('oninter');
1044 else // Áîëüøå íåò êàðò
1046 // Çàòóõàþùèé ýêðàí:
1047 EndingGameCounter
:= 255;
1048 gState
:= STATE_FOLD
;
1053 // Îêîí÷àíèå îáðàáîòàíî:
1054 if gExit
<> EXIT_QUIT
then
1058 procedure drawTime(X
, Y
: Integer); inline;
1060 e_TextureFontPrint(x
, y
,
1061 Format('%d:%.2d:%.2d', [
1062 gTime
div 1000 div 3600,
1063 (gTime
div 1000 div 60) mod 60,
1064 gTime
div 1000 mod 60
1069 procedure DrawStat();
1071 pc
, x
, y
, w
, h
: Integer;
1072 w1
, w2
, w3
, w4
: Integer;
1074 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1077 stat
: TPlayerStatArray
;
1084 pc
:= g_Player_GetCount
;
1085 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1087 w
:= gScreenWidth
-(gScreenWidth
div 5);
1088 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1091 h
:= 40+ch
*5+(ch
+8)*pc
;
1092 x
:= (gScreenWidth
div 2)-(w
div 2);
1093 y
:= (gScreenHeight
div 2)-(h
div 2);
1095 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1096 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1098 drawTime(x
+w
-78, y
+8);
1100 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1101 map
:= g_ExtractFileName(gMapInfo
.Map
);
1102 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1104 case gGameSettings
.GameMode
of
1107 if gGameSettings
.MaxLives
= 0 then
1108 s1
:= _lc
[I_GAME_DM
]
1110 s1
:= _lc
[I_GAME_LMS
];
1111 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1112 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1117 if gGameSettings
.MaxLives
= 0 then
1118 s1
:= _lc
[I_GAME_TDM
]
1120 s1
:= _lc
[I_GAME_TLMS
];
1121 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1122 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1127 s1
:= _lc
[I_GAME_CTF
];
1128 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1129 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1134 if gGameSettings
.MaxLives
= 0 then
1135 s1
:= _lc
[I_GAME_COOP
]
1137 s1
:= _lc
[I_GAME_SURV
];
1138 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1139 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1150 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1152 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1154 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1156 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1157 gStdFont
, 200, 200, 200, 1);
1159 if NetMode
= NET_SERVER
then
1160 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1162 if NetMode
= NET_CLIENT
then
1163 e_TextureFontPrintEx(x
+8, y
+ 8,
1164 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1168 stat
:= g_Player_GetStats();
1171 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1172 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1174 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1176 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1180 for a
:= TEAM_RED
to TEAM_BLUE
do
1182 if a
= TEAM_RED
then
1184 s1
:= _lc
[I_GAME_TEAM_RED
];
1191 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1197 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1198 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1199 gStdFont
, r
, g
, b
, 1);
1201 _y
:= _y
+ch
+(ch
div 4);
1202 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1203 _y
:= _y
+(ch
div 4);
1205 for aa
:= 0 to High(stat
) do
1206 if stat
[aa
].Team
= a
then
1222 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1224 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1226 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1228 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1235 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1238 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1239 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1240 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1241 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1244 for aa
:= 0 to High(stat
) do
1258 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1259 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1261 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1263 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1265 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1267 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1273 procedure g_Game_Init();
1279 gTempDelete
:= False;
1281 sfsGCDisable(); // temporary disable removing of temporary volumes
1284 TEXTUREFILTER
:= GL_LINEAR
;
1285 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1286 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1287 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1288 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1289 TEXTUREFILTER
:= GL_NEAREST
;
1291 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1292 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1293 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1295 g_Game_ClearLoading();
1296 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1297 g_Game_SetLoadingText('', 0, False);
1299 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1302 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1303 g_PlayerModel_LoadData();
1305 if e_FindFirst(ModelDirs
, '*.wad', faAnyFile
, SR
) = 0 then
1307 if not g_PlayerModel_Load(e_FindWad(ModelDirs
, SR
.Name
)) then
1308 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1309 until FindNext(SR
) <> 0;
1312 if e_FindFirst(ModelDirs
, '*.pk3', faAnyFile
, SR
) = 0 then
1314 if not g_PlayerModel_Load(e_FindWad(ModelDirs
, SR
.Name
)) then
1315 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1316 until FindNext(SR
) <> 0;
1319 if e_FindFirst(ModelDirs
, '*.zip', faAnyFile
, SR
) = 0 then
1321 if not g_PlayerModel_Load(e_FindWad(ModelDirs
, SR
.Name
)) then
1322 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1323 until FindNext(SR
) <> 0;
1327 gPauseMain
:= false;
1328 gPauseHolmes
:= false;
1331 {e_MouseInfo.Accel := 1.0;}
1333 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1336 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1337 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1338 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1339 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True, True);
1340 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1343 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1347 gMusic
:= TMusic
.Create();
1348 gMusic
.SetByName('MUSIC_MENU');
1351 gGameSettings
.WarmupTime
:= 30;
1353 gState
:= STATE_MENU
;
1355 SetLength(gEvents
, 6);
1356 gEvents
[0].Name
:= 'ongamestart';
1357 gEvents
[1].Name
:= 'ongameend';
1358 gEvents
[2].Name
:= 'onmapstart';
1359 gEvents
[3].Name
:= 'onmapend';
1360 gEvents
[4].Name
:= 'oninter';
1361 gEvents
[5].Name
:= 'onwadend';
1363 sfsGCEnable(); // enable releasing unused volumes
1367 procedure g_Game_Free(freeTextures
: Boolean=true);
1369 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1370 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1372 g_Map_Free(freeTextures
);
1374 g_Player_RemoveAllCorpses();
1376 gGameSettings
.GameType
:= GT_NONE
;
1377 if gGameSettings
.GameMode
= GM_SINGLE
then
1378 gGameSettings
.GameMode
:= GM_DM
;
1379 gSwitchGameMode
:= gGameSettings
.GameMode
;
1382 gExitByTrigger
:= False;
1385 function IsActivePlayer(p
: TPlayer
): Boolean;
1390 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1393 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1400 if gPlayers
= nil then
1402 for a
:= Low(gPlayers
) to High(gPlayers
) do
1403 if IsActivePlayer(gPlayers
[a
]) then
1405 if gPlayers
[a
].UID
<> ID
then
1407 Result
:= gPlayers
[a
];
1412 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1418 if gPlayers
= nil then
1422 for a
:= Low(gPlayers
) to High(gPlayers
) do
1423 if IsActivePlayer(gPlayers
[a
]) then
1425 SetLength(ids
, Length(ids
) + 1);
1426 ids
[High(ids
)] := gPlayers
[a
].UID
;
1427 if gPlayers
[a
].UID
= Skip
then
1430 if Length(ids
) = 0 then
1435 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1438 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1444 if gPlayers
= nil then
1448 for a
:= Low(gPlayers
) to High(gPlayers
) do
1449 if IsActivePlayer(gPlayers
[a
]) then
1451 SetLength(ids
, Length(ids
) + 1);
1452 ids
[High(ids
)] := gPlayers
[a
].UID
;
1453 if gPlayers
[a
].UID
= Skip
then
1456 if Length(ids
) = 0 then
1459 Result
:= ids
[Length(ids
) - 1]
1461 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1464 function GetActivePlayerID_Random(Skip
: Integer = -1): Integer;
1470 if gPlayers
= nil then
1474 for a
:= Low(gPlayers
) to High(gPlayers
) do
1475 if IsActivePlayer(gPlayers
[a
]) then
1477 SetLength(ids
, Length(ids
) + 1);
1478 ids
[High(ids
)] := gPlayers
[a
].UID
;
1479 if gPlayers
[a
].UID
= Skip
then
1482 if Length(ids
) = 0 then
1484 if Length(ids
) = 1 then
1489 Result
:= ids
[Random(Length(ids
))];
1491 while (idx
<> -1) and (Result
= Skip
) and (a
> 0) do
1493 Result
:= ids
[Random(Length(ids
))];
1498 function GetRandomSpectMode(Current
: Byte): Byte;
1505 0: Result
:= SPECT_STATS
;
1506 1: Result
:= SPECT_MAPVIEW
;
1507 2: Result
:= SPECT_MAPVIEW
;
1508 3: Result
:= SPECT_PLAYERS
;
1509 4: Result
:= SPECT_PLAYERS
;
1510 5: Result
:= SPECT_PLAYERS
;
1511 6: Result
:= SPECT_PLAYERS
;
1513 if (Current
in [SPECT_STATS
, SPECT_MAPVIEW
]) and (Current
= Result
) then
1517 procedure ProcessPlayerControls (plr
: TPlayer
; p
: Integer; var MoveButton
: Byte);
1523 if (plr
= nil) then exit
;
1524 if (p
= 2) then time
:= 1000 else time
:= 1;
1525 strafeDir
:= MoveButton
shr 4;
1526 MoveButton
:= MoveButton
and $0F;
1528 if gPlayerAction
[p
, ACTION_MOVELEFT
] and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1529 MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1530 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1531 MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1532 else if (not gPlayerAction
[p
, ACTION_MOVELEFT
]) and (not gPlayerAction
[p
, ACTION_MOVERIGHT
]) then
1533 MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1535 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1536 if MoveButton
= 1 then
1537 plr
.PressKey(KEY_LEFT
, time
)
1538 else if MoveButton
= 2 then
1539 plr
.PressKey(KEY_RIGHT
, time
);
1541 // if we have "strafe" key, turn off old strafe mechanics
1542 if gPlayerAction
[p
, ACTION_STRAFE
] then
1544 // new strafe mechanics
1545 if (strafeDir
= 0) then
1546 strafeDir
:= MoveButton
; // start strafing
1547 // now set direction according to strafe (reversed)
1548 if (strafeDir
= 2) then
1549 plr
.SetDirection(TDirection
.D_LEFT
)
1550 else if (strafeDir
= 1) then
1551 plr
.SetDirection(TDirection
.D_RIGHT
)
1555 strafeDir
:= 0; // not strafing anymore
1556 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1557 if (MoveButton
= 2) and gPlayerAction
[p
, ACTION_MOVELEFT
] then
1558 plr
.SetDirection(TDirection
.D_LEFT
)
1559 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1560 else if (MoveButton
= 1) and gPlayerAction
[p
, ACTION_MOVERIGHT
] then
1561 plr
.SetDirection(TDirection
.D_RIGHT
)
1562 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1563 else if MoveButton
<> 0 then
1564 plr
.SetDirection(TDirection(MoveButton
-1))
1567 // fix movebutton state
1568 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1570 // Îñòàëüíûå êëàâèøè:
1571 if gPlayerAction
[p
, ACTION_JUMP
] then plr
.PressKey(KEY_JUMP
, time
);
1572 if gPlayerAction
[p
, ACTION_LOOKUP
] then plr
.PressKey(KEY_UP
, time
);
1573 if gPlayerAction
[p
, ACTION_LOOKDOWN
] then plr
.PressKey(KEY_DOWN
, time
);
1574 if gPlayerAction
[p
, ACTION_ATTACK
] then plr
.PressKey(KEY_FIRE
);
1575 if gPlayerAction
[p
, ACTION_WEAPNEXT
] then plr
.PressKey(KEY_NEXTWEAPON
);
1576 if gPlayerAction
[p
, ACTION_WEAPPREV
] then plr
.PressKey(KEY_PREVWEAPON
);
1577 if gPlayerAction
[p
, ACTION_ACTIVATE
] then plr
.PressKey(KEY_OPEN
);
1579 gPlayerAction
[p
, ACTION_WEAPNEXT
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1580 gPlayerAction
[p
, ACTION_WEAPPREV
] := False; // HACK, remove after readyweaon&pendinweapon implementation
1582 for i
:= WP_FIRST
to WP_LAST
do
1584 if gSelectWeapon
[p
, i
] then
1586 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1587 gSelectWeapon
[p
, i
] := False
1591 // HACK: add dynlight here
1592 if gwin_k8_enable_light_experiments
then
1594 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1596 g_playerLight
:= true;
1598 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1600 g_playerLight
:= false;
1604 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1607 // HACK: don't have a "key was pressed" function
1608 procedure InterReady();
1610 if InterReadyTime
> gTime
then Exit
;
1611 InterReadyTime
:= gTime
+ 3000;
1612 MC_SEND_CheatRequest(NET_CHEAT_READY
);
1615 procedure g_Game_Update();
1617 Msg
: g_gui
.TMessage
;
1623 function sendMonsPos (mon
: TMonster
): Boolean;
1625 result
:= false; // don't stop
1626 // this will also reset "need-send" flag
1627 if mon
.gncNeedSend
then
1629 MH_SEND_MonsterPos(mon
.UID
);
1631 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1633 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1635 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1637 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1641 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1643 result
:= false; // don't stop
1644 // this will also reset "need-send" flag
1645 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1649 reliableUpdate
: Boolean;
1654 // Ïîðà âûêëþ÷àòü èãðó:
1655 if gExit
= EXIT_QUIT
then
1657 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1661 if gExit
= EXIT_QUIT
then
1665 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1666 // no need to, as we'll do it in event handler
1668 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1671 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1673 gExit
:= EXIT_SIMPLE
;
1678 // process master server communications
1679 g_Net_Slist_Pulse();
1682 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1683 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1684 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1685 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1687 if g_Game_IsNet
and g_Game_IsServer
then
1689 gInterTime
:= gInterTime
+ GAME_TICK
;
1690 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1691 if a
<> gServInterTime
then
1693 gServInterTime
:= a
;
1694 MH_SEND_TimeSync(gServInterTime
);
1698 if (not g_Game_IsClient
) and
1702 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1703 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1704 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1705 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1707 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1708 and (g_ActiveWindow
= nil)
1710 or (g_Game_IsNet
and ((gInterTime
> gInterEndTime
) or (gInterReadyCount
>= NetClientCount
)))
1713 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1714 g_Game_StopAllSounds(True);
1716 if gMapOnce
then // Ýòî áûë òåñò
1717 gExit
:= EXIT_SIMPLE
1719 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1720 g_Game_ChangeMap(gNextMap
)
1721 else // Ñëåäóþùåé êàðòû íåò
1723 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1725 // Âûõîä â ãëàâíîå ìåíþ:
1727 g_GUI_ShowWindow('MainMenu');
1728 gMusic
.SetByName('MUSIC_MENU');
1730 gState
:= STATE_MENU
;
1733 // Ôèíàëüíàÿ êàðòèíêà:
1734 g_Game_ExecuteEvent('onwadend');
1736 if not gMusic
.SetByName('MUSIC_endmus') then
1737 gMusic
.SetByName('MUSIC_STDENDMUS');
1739 gState
:= STATE_ENDPIC
;
1741 g_Game_ExecuteEvent('ongameend');
1746 else if g_Game_IsClient
and
1749 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1750 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
1751 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or
1752 e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
)
1754 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1755 and (g_ActiveWindow
= nil)
1763 if gState
= STATE_INTERTEXT
then
1764 if InterText
.counter
> 0 then
1765 InterText
.counter
:= InterText
.counter
- 1;
1768 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1770 if EndingGameCounter
= 0 then
1772 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1773 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1775 InterReadyTime
:= -1;
1776 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1778 g_Game_ExecuteEvent('onwadend');
1779 if not gMusic
.SetByName('MUSIC_endmus') then
1780 gMusic
.SetByName('MUSIC_STDENDMUS');
1783 gMusic
.SetByName('MUSIC_ROUNDMUS');
1786 gState
:= STATE_INTERCUSTOM
;
1789 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1791 gMusic
.SetByName('MUSIC_INTERMUS');
1793 gState
:= STATE_INTERSINGLE
;
1796 g_Game_ExecuteEvent('oninter');
1799 DecMin(EndingGameCounter
, 6, 0);
1802 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1804 if gMapOnce
then // Ýòî áûë òåñò
1806 gExit
:= EXIT_SIMPLE
;
1812 g_Serverlist_Control(slCurrent
, slTable
);
1815 // Ñòàòèñòèêà ïî Tab:
1817 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and (gGameSettings
.GameType
<> GT_SINGLE
) and g_Console_Action(ACTION_SCORES
);
1820 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1822 // Âðåìÿ += 28 ìèëëèñåêóíä:
1823 gTime
:= gTime
+ GAME_TICK
;
1825 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1826 if MessageTime
= 0 then
1828 if MessageTime
> 0 then
1829 MessageTime
:= MessageTime
- 1;
1831 if (g_Game_IsServer
) then
1833 // Áûë çàäàí ëèìèò âðåìåíè:
1834 if (gGameSettings
.TimeLimit
> 0) then
1835 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1836 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1841 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1842 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1843 g_Game_RestartRound(gLMSSoftSpawn
);
1845 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1846 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1848 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1850 g_Console_Process(gVoteCommand
);
1852 gVotePassed
:= False;
1855 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1856 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1857 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1858 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1859 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1861 // Áûë çàäàí ëèìèò ïîáåä:
1862 if (gGameSettings
.GoalLimit
> 0) then
1866 if gGameSettings
.GameMode
= GM_DM
then
1867 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1868 for i
:= 0 to High(gPlayers
) do
1869 if gPlayers
[i
] <> nil then
1870 if gPlayers
[i
].Frags
> b
then
1871 b
:= gPlayers
[i
].Frags
;
1874 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1875 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1876 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1879 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1880 if b
>= gGameSettings
.GoalLimit
then
1887 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1888 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1889 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1890 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1892 ProcessPlayerControls(gPlayer1
, 0, P1MoveButton
);
1893 ProcessPlayerControls(gPlayer2
, 1, P2MoveButton
);
1894 end // if not console
1897 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1899 // process weapon switch queue
1903 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1904 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1906 if not gSpectKeyPress
then
1908 if gPlayerAction
[0, ACTION_JUMP
] and (not gSpectAuto
) then
1910 // switch spect mode
1912 SPECT_NONE
: ; // not spectator
1914 SPECT_MAPVIEW
: Inc(gSpectMode
);
1915 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1917 gSpectKeyPress
:= True;
1919 if (gSpectMode
= SPECT_MAPVIEW
)
1920 and (not gSpectAuto
) then
1922 if gPlayerAction
[0, ACTION_MOVELEFT
] then
1923 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1924 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
1925 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1926 if gPlayerAction
[0, ACTION_LOOKUP
] then
1927 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1928 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
1929 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1930 if gPlayerAction
[0, ACTION_WEAPPREV
] then
1933 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1934 gSpectKeyPress
:= True;
1936 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
1939 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1940 gSpectKeyPress
:= True;
1943 if (gSpectMode
= SPECT_PLAYERS
)
1944 and (not gSpectAuto
) then
1946 if gPlayerAction
[0, ACTION_LOOKUP
] then
1949 gSpectViewTwo
:= True;
1950 gSpectKeyPress
:= True;
1952 if gPlayerAction
[0, ACTION_LOOKDOWN
] then
1954 // remove second view
1955 gSpectViewTwo
:= False;
1956 gSpectKeyPress
:= True;
1958 if gPlayerAction
[0, ACTION_MOVELEFT
] then
1960 // prev player (view 1)
1961 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1962 gSpectKeyPress
:= True;
1964 if gPlayerAction
[0, ACTION_MOVERIGHT
] then
1966 // next player (view 1)
1967 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1968 gSpectKeyPress
:= True;
1970 if gPlayerAction
[0, ACTION_WEAPPREV
] then
1972 // prev player (view 2)
1973 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1974 gSpectKeyPress
:= True;
1976 if gPlayerAction
[0, ACTION_WEAPNEXT
] then
1978 // next player (view 2)
1979 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1980 gSpectKeyPress
:= True;
1983 if gPlayerAction
[0, ACTION_ATTACK
] then
1985 if (gSpectMode
= SPECT_STATS
) and (not gSpectAuto
) then
1988 gSpectAutoNext
:= 0;
1989 gSpectViewTwo
:= False;
1990 gSpectKeyPress
:= True;
1995 gSpectMode
:= SPECT_STATS
;
1996 gSpectAuto
:= False;
1997 gSpectKeyPress
:= True;
2002 if (not gPlayerAction
[0, ACTION_JUMP
]) and
2003 (not gPlayerAction
[0, ACTION_ATTACK
]) and
2004 (not gPlayerAction
[0, ACTION_MOVELEFT
]) and
2005 (not gPlayerAction
[0, ACTION_MOVERIGHT
]) and
2006 (not gPlayerAction
[0, ACTION_LOOKUP
]) and
2007 (not gPlayerAction
[0, ACTION_LOOKDOWN
]) and
2008 (not gPlayerAction
[0, ACTION_WEAPPREV
]) and
2009 (not gPlayerAction
[0, ACTION_WEAPNEXT
]) then
2010 gSpectKeyPress
:= False;
2014 if gSpectMode
= SPECT_MAPVIEW
then
2016 i
:= Min(Max(gSpectX
+ gSpectAutoStepX
, 0), gMapInfo
.Width
- gScreenWidth
);
2018 gSpectAutoNext
:= gTime
2021 i
:= Min(Max(gSpectY
+ gSpectAutoStepY
, 0), gMapInfo
.Height
- gScreenHeight
);
2023 gSpectAutoNext
:= gTime
2027 if gSpectAutoNext
<= gTime
then
2029 if gSpectAutoNext
> 0 then
2031 gSpectMode
:= GetRandomSpectMode(gSpectMode
);
2035 gSpectX
:= Random(gMapInfo
.Width
- gScreenWidth
);
2036 gSpectY
:= Random(gMapInfo
.Height
- gScreenHeight
);
2037 gSpectAutoStepX
:= Random(9) - 4;
2038 gSpectAutoStepY
:= Random(9) - 4;
2039 if ((gSpectX
< 800) and (gSpectAutoStepX
< 0)) or
2040 ((gSpectX
> gMapInfo
.Width
- gScreenWidth
- 800) and (gSpectAutoStepX
> 0)) then
2041 gSpectAutoStepX
:= gSpectAutoStepX
* -1;
2042 if ((gSpectY
< 800) and (gSpectAutoStepY
< 0)) or
2043 ((gSpectY
> gMapInfo
.Height
- gScreenHeight
- 800) and (gSpectAutoStepY
> 0)) then
2044 gSpectAutoStepY
:= gSpectAutoStepY
* -1;
2048 gSpectPID1
:= GetActivePlayerID_Random(gSpectPID1
);
2053 SPECT_STATS
: gSpectAutoNext
:= gTime
+ (Random(3) + 5) * 1000;
2054 SPECT_MAPVIEW
: gSpectAutoNext
:= gTime
+ (Random(4) + 7) * 1000;
2055 SPECT_PLAYERS
: gSpectAutoNext
:= gTime
+ (Random(7) + 8) * 1000;
2061 // Îáíîâëÿåì âñå îñòàëüíîå:
2064 g_Triggers_Update();
2066 g_Monsters_Update();
2068 g_Player_UpdateAll();
2069 g_Player_UpdatePhysicalObjects();
2071 // server: send newly spawned monsters unconditionally
2072 if (gGameSettings
.GameType
= GT_SERVER
) then
2074 if (Length(gMonstersSpawned
) > 0) then
2076 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
2077 SetLength(gMonstersSpawned
, 0);
2081 if (gSoundTriggerTime
> 8) then
2083 g_Game_UpdateTriggerSounds();
2084 gSoundTriggerTime
:= 0;
2088 Inc(gSoundTriggerTime
);
2091 if (NetMode
= NET_SERVER
) then
2093 Inc(NetTimeToUpdate
);
2094 Inc(NetTimeToReliable
);
2096 // send monster updates
2097 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
2099 // send all monsters (periodic sync)
2100 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
2102 for I
:= 0 to High(gPlayers
) do
2104 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
2107 g_Mons_ForEach(sendMonsPos
);
2109 if reliableUpdate
then
2111 NetTimeToReliable
:= 0;
2112 NetTimeToUpdate
:= NetUpdateRate
;
2116 NetTimeToUpdate
:= 0;
2121 // send only mosters with some unexpected changes
2122 g_Mons_ForEach(sendMonsPosUnexpected
);
2125 // send unexpected platform changes
2126 g_Map_NetSendInterestingPanels();
2128 g_Net_Slist_ServerUpdate();
2130 if NetUseMaster then
2132 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2134 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2136 NetTimeToMaster := gTime + NetMasterRate;
2141 else if (NetMode
= NET_CLIENT
) then
2143 MC_SEND_PlayerPos();
2145 end; // if gameOn ...
2147 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2148 if g_ActiveWindow
<> nil then
2150 w
:= e_GetFirstKeyPressed();
2152 if (w
<> IK_INVALID
) then
2154 Msg
.Msg
:= MESSAGE_DIKEY
;
2156 g_ActiveWindow
.OnMessage(Msg
);
2159 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2160 if g_ActiveWindow
<> nil then
2161 g_ActiveWindow
.Update();
2163 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2164 if gResolutionChange
then
2166 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2167 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2168 gResolutionChange
:= False;
2169 g_ActiveWindow
:= nil;
2172 // Íóæíî ñìåíèòü ÿçûê:
2173 if gLanguageChange
then
2175 //e_WriteLog('Read language file', MSG_NOTIFY);
2176 //g_Language_Load(DataDir + gLanguage + '.txt');
2177 g_Language_Set(gLanguage
);
2181 gLanguageChange
:= False;
2185 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2186 if e_KeyPressed(IK_F10
) and
2188 (not gConsoleShow
) and
2189 (g_ActiveWindow
= nil) then
2194 Time
:= sys_GetTicks() {div 1000};
2196 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2197 if gDelayedEvents
<> nil then
2198 for a
:= 0 to High(gDelayedEvents
) do
2199 if gDelayedEvents
[a
].Pending
and
2201 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2202 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2205 case gDelayedEvents
[a
].DEType
of
2207 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2210 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2214 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2215 if g_Game_IsNet
and g_Game_IsServer
then
2216 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2220 g_Game_Announce_BodyKill(gDelayedEvents
[a
].DENum
);
2222 gDelayedEvents
[a
].Pending
:= False;
2225 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2226 UPSCounter
:= UPSCounter
+ 1;
2227 if Time
- UPSTime
>= 1000 then
2236 g_Weapon_AddDynLights();
2237 g_Items_AddDynLights();
2241 procedure g_Game_LoadChatSounds(Resource
: string);
2244 FileName
, Snd
: string;
2246 len
, cnt
, tags
, i
, j
: Integer;
2249 FileName
:= g_ExtractWadName(Resource
);
2251 WAD
:= TWADFile
.Create();
2252 WAD
.ReadFile(FileName
);
2254 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2261 cfg
:= TConfig
.CreateMem(p
, len
);
2262 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2264 SetLength(gChatSounds
, cnt
);
2265 for i
:= 0 to Length(gChatSounds
) - 1 do
2267 gChatSounds
[i
].Sound
:= nil;
2268 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2269 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2270 if (Snd
= '') or (Tags
<= 0) then
2272 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2273 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2274 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2275 SetLength(gChatSounds
[i
].Tags
, tags
);
2276 for j
:= 0 to tags
- 1 do
2277 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2278 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2285 procedure g_Game_FreeChatSounds();
2289 for i
:= 0 to Length(gChatSounds
) - 1 do
2291 gChatSounds
[i
].Sound
.Free();
2292 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2294 SetLength(gChatSounds
, 0);
2298 procedure g_Game_LoadData();
2305 if DataLoaded
then Exit
;
2307 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2309 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2310 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2311 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2312 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2313 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2314 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2315 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2316 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2317 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2318 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2319 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2320 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2321 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2322 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2323 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD
+':TEXTURES\PLRIND');
2326 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2327 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2328 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2329 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2333 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2334 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2335 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2336 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2337 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
2343 hasPBarGfx
:= false;
2347 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2348 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':WEAPONS\PUNCH', 64, 64, 4, False);
2349 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD
+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2350 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD
+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2351 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD
+':WEAPONS\PUNCHB', 64, 64, 4, False);
2352 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD
+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2353 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD
+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2354 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2355 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2356 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD
+':SOUNDS\SECRET');
2357 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2358 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2359 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2360 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2361 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2362 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2363 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD
+':SOUNDS\BURNING');
2364 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2365 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2366 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2367 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2368 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2369 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2370 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2371 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2372 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2373 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2374 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2375 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD
+':SOUNDS\MUHAHA1');
2376 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD
+':SOUNDS\MUHAHA2');
2377 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD
+':SOUNDS\MUHAHA3');
2378 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD
+':SOUNDS\GETFLAG1');
2379 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD
+':SOUNDS\GETFLAG2');
2380 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD
+':SOUNDS\LOSTFLG1');
2381 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD
+':SOUNDS\LOSTFLG2');
2382 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD
+':SOUNDS\RETFLAG1');
2383 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD
+':SOUNDS\RETFLAG2');
2384 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD
+':SOUNDS\CAPFLAG1');
2385 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD
+':SOUNDS\CAPFLAG2');
2387 goodsnd
[0] := TPlayableSound
.Create();
2388 goodsnd
[1] := TPlayableSound
.Create();
2389 goodsnd
[2] := TPlayableSound
.Create();
2390 goodsnd
[3] := TPlayableSound
.Create();
2392 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2393 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2394 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2395 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2397 killsnd
[0] := TPlayableSound
.Create();
2398 killsnd
[1] := TPlayableSound
.Create();
2399 killsnd
[2] := TPlayableSound
.Create();
2400 killsnd
[3] := TPlayableSound
.Create();
2402 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2403 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2404 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2405 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2407 hahasnd
[0] := TPlayableSound
.Create();
2408 hahasnd
[1] := TPlayableSound
.Create();
2409 hahasnd
[2] := TPlayableSound
.Create();
2411 hahasnd
[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2412 hahasnd
[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2413 hahasnd
[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2415 sound_get_flag
[0] := TPlayableSound
.Create();
2416 sound_get_flag
[1] := TPlayableSound
.Create();
2417 sound_lost_flag
[0] := TPlayableSound
.Create();
2418 sound_lost_flag
[1] := TPlayableSound
.Create();
2419 sound_ret_flag
[0] := TPlayableSound
.Create();
2420 sound_ret_flag
[1] := TPlayableSound
.Create();
2421 sound_cap_flag
[0] := TPlayableSound
.Create();
2422 sound_cap_flag
[1] := TPlayableSound
.Create();
2424 sound_get_flag
[0].SetByName('SOUND_CTF_GET1');
2425 sound_get_flag
[1].SetByName('SOUND_CTF_GET2');
2426 sound_lost_flag
[0].SetByName('SOUND_CTF_LOST1');
2427 sound_lost_flag
[1].SetByName('SOUND_CTF_LOST2');
2428 sound_ret_flag
[0].SetByName('SOUND_CTF_RETURN1');
2429 sound_ret_flag
[1].SetByName('SOUND_CTF_RETURN2');
2430 sound_cap_flag
[0].SetByName('SOUND_CTF_CAPTURE1');
2431 sound_cap_flag
[1].SetByName('SOUND_CTF_CAPTURE2');
2433 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2435 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2438 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2439 g_Weapon_LoadData();
2441 g_Monsters_LoadData();
2446 procedure g_Game_FreeData();
2448 if not DataLoaded
then Exit
;
2451 g_Weapon_FreeData();
2452 g_Monsters_FreeData();
2454 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2456 g_Texture_Delete('NOTEXTURE');
2457 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2458 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2459 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2460 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2461 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2462 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2463 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2464 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2465 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2466 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2467 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2468 g_Frames_DeleteByName('FRAMES_TELEPORT');
2469 g_Frames_DeleteByName('FRAMES_PUNCH');
2470 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2471 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2472 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2473 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2474 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2475 g_Sound_Delete('SOUND_GAME_TELEPORT');
2476 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2477 g_Sound_Delete('SOUND_GAME_SECRET');
2478 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2479 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2480 g_Sound_Delete('SOUND_GAME_BULK1');
2481 g_Sound_Delete('SOUND_GAME_BULK2');
2482 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2483 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2484 g_Sound_Delete('SOUND_GAME_BURNING');
2485 g_Sound_Delete('SOUND_GAME_SWITCH1');
2486 g_Sound_Delete('SOUND_GAME_SWITCH0');
2493 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2494 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2495 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2496 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2503 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2504 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2505 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2506 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2512 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2513 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2514 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2516 sound_get_flag
[0].Free();
2517 sound_get_flag
[1].Free();
2518 sound_lost_flag
[0].Free();
2519 sound_lost_flag
[1].Free();
2520 sound_ret_flag
[0].Free();
2521 sound_ret_flag
[1].Free();
2522 sound_cap_flag
[0].Free();
2523 sound_cap_flag
[1].Free();
2525 g_Sound_Delete('SOUND_CTF_GET1');
2526 g_Sound_Delete('SOUND_CTF_GET2');
2527 g_Sound_Delete('SOUND_CTF_LOST1');
2528 g_Sound_Delete('SOUND_CTF_LOST2');
2529 g_Sound_Delete('SOUND_CTF_RETURN1');
2530 g_Sound_Delete('SOUND_CTF_RETURN2');
2531 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2532 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2534 g_Game_FreeChatSounds();
2536 DataLoaded
:= False;
2539 procedure DrawCustomStat();
2545 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2546 s1
, s2
, topstr
: String;
2548 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2552 if g_Console_Action(ACTION_SCORES
) then
2554 if not gStatsPressed
then
2556 gStatsOff
:= not gStatsOff
;
2557 gStatsPressed
:= True;
2561 gStatsPressed
:= False;
2565 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2566 w
:= (Length(s1
) * ww2
) div 2;
2567 x
:= gScreenWidth
div 2 - w
;
2569 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2573 if (gGameSettings
.GameMode
= GM_COOP
) then
2575 if gMissionFailed
then
2576 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2578 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2581 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2583 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2584 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2586 if g_Game_IsNet
then
2588 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2589 if not gChatShow
then
2590 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2591 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2594 if g_Game_IsClient
then
2595 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2597 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2598 if not gChatShow
then
2599 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2600 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2605 w
:= gScreenWidth
-x
*2;
2611 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2612 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2614 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2616 case CustomStat
.GameMode
of
2619 if gGameSettings
.MaxLives
= 0 then
2620 s1
:= _lc
[I_GAME_DM
]
2622 s1
:= _lc
[I_GAME_LMS
];
2626 if gGameSettings
.MaxLives
= 0 then
2627 s1
:= _lc
[I_GAME_TDM
]
2629 s1
:= _lc
[I_GAME_TLMS
];
2631 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2634 if gGameSettings
.MaxLives
= 0 then
2635 s1
:= _lc
[I_GAME_COOP
]
2637 s1
:= _lc
[I_GAME_SURV
];
2643 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2647 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2648 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2651 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2652 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2653 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2654 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2656 pc
:= Length(CustomStat
.PlayerStat
);
2657 if pc
= 0 then Exit
;
2659 if CustomStat
.GameMode
= GM_COOP
then
2661 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2663 s2
:= _lc
[I_GAME_MONSTERS
];
2664 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2665 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2667 s2
:= _lc
[I_GAME_SECRETS
];
2668 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2669 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2672 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2674 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2675 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2676 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2678 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2679 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2680 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2684 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2689 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2690 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2691 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2693 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2696 for t
:= TEAM_RED
to TEAM_BLUE
do
2698 if t
= TEAM_RED
then
2700 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2701 gStdFont
, 255, 0, 0, 1);
2702 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2703 gStdFont
, 255, 0, 0, 1);
2710 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2711 gStdFont
, 0, 0, 255, 1);
2712 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2713 gStdFont
, 0, 0, 255, 1);
2719 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2722 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2723 if CustomStat
.PlayerStat
[p
].Team
= t
then
2724 with CustomStat
.PlayerStat
[p
] do
2738 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2739 e_TextureFontPrintEx(x
+16, _y
, Name
+ ' *', gStdFont
, rr
, gg
, bb
, 1)
2741 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2742 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2743 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2750 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2753 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2754 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2755 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2758 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2759 with CustomStat
.PlayerStat
[p
] do
2761 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2768 if (gPlayers
[Num
] <> nil) and (gPlayers
[Num
].FReady
) then
2769 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
+ ' *', gStdFont
, r
, r
, r
, 1, True)
2771 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2772 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2773 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2779 procedure DrawSingleStat();
2781 tm
, key_x
, val_x
, y
: Integer;
2785 procedure player_stat(n
: Integer);
2791 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2792 s2
:= Format(' %d', [gTotalMonsters
]);
2794 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2795 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2796 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2797 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2799 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2800 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2802 // "Kills-per-minute: ##.#":
2803 s1
:= _lc
[I_MENU_INTER_KPM
];
2805 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2807 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2808 s2
:= Format(' %.1f', [kpm
]);
2810 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2811 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2813 // "Secrets found: # / #":
2814 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2815 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2817 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2818 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2819 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2820 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2822 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2823 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2827 // "Level Complete":
2828 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2829 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2831 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2832 s1
:= _lc
[I_MENU_INTER_KPM
];
2833 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2836 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2838 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2839 val_x
:= key_x
+ w1
;
2842 tm
:= SingleStat
.GameTime
div 1000;
2843 s1
:= _lc
[I_MENU_INTER_TIME
];
2844 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2846 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2847 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2849 if SingleStat
.TwoPlayers
then
2852 s1
:= _lc
[I_MENU_PLAYER_1
];
2853 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2854 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2856 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2861 s1
:= _lc
[I_MENU_PLAYER_2
];
2862 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2863 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2865 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2871 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2877 procedure DrawLoadingStat();
2878 procedure drawRect (x
, y
, w
, h
: Integer);
2880 if (w
< 1) or (h
< 1) then exit
;
2882 glVertex2f(x
+0.375, y
+0.375);
2883 glVertex2f(x
+w
+0.375, y
+0.375);
2884 glVertex2f(x
+w
+0.375, y
+h
+0.375);
2885 glVertex2f(x
+0.375, y
+h
+0.375);
2889 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
2891 rectW
, rectH
: Integer;
2898 idl
, idr
, idb
, idm
: LongWord;
2902 if (total
< 1) then exit
;
2903 if (cur
< 1) then exit
; // don't blink
2904 if (not washere
) and (cur
>= total
) then exit
; // don't blink
2905 //if (cur < 0) then cur := 0;
2906 //if (cur > total) then cur := total;
2909 if (hasPBarGfx
) then
2911 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
2912 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2913 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
2914 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2915 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
2916 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2917 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
2918 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2920 //rectW := gScreenWidth-360;
2921 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
2924 x0
:= (gScreenWidth
-rectW
) div 2;
2925 y0
:= gScreenHeight
-rectH
-64;
2926 if (y0
< 2) then y0
:= 2;
2928 glEnable(GL_SCISSOR_TEST
);
2931 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
2932 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
2933 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
2936 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
2938 while (f
< x0
+rectW
) do
2940 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
2945 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
2946 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
2949 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
2950 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
2954 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
2960 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
2964 rectW
:= gScreenWidth
-64;
2967 x0
:= (gScreenWidth
-rectW
) div 2;
2968 y0
:= gScreenHeight
-rectH
-64;
2969 if (y0
< 2) then y0
:= 2;
2971 glDisable(GL_BLEND
);
2972 glDisable(GL_TEXTURE_2D
);
2974 //glClearColor(0, 0, 0, 0);
2975 //glClear(GL_COLOR_BUFFER_BIT);
2977 glColor4ub(127, 127, 127, 255);
2978 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
2980 glColor4ub(0, 0, 0, 255);
2981 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
2983 glColor4ub(127, 127, 127, 255);
2984 wdt
:= rectW
*cur
div total
;
2985 if (wdt
> rectW
) then wdt
:= rectW
;
2986 drawRect(x0
, y0
, wdt
, rectH
);
2995 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
2997 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2998 yy
:= (gScreenHeight
div 3);
2999 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
3000 xx
:= (gScreenWidth
div 3);
3004 for i
:= 0 to NextMsg
-1 do
3006 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
3007 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
3011 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
3012 yy
:= yy
+ LOADING_INTERLINE
;
3013 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
3018 procedure DrawMenuBackground(tex
: AnsiString);
3024 if g_Texture_Get(tex
, ID
) then
3026 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3027 e_GetTextureSize(ID
, @w
, @h
);
3029 w
:= round(w
* 1.333 * (gScreenHeight
/ h
))
3031 w
:= trunc(w
* (gScreenHeight
/ h
));
3032 e_DrawSize(ID
, (gScreenWidth
- w
) div 2, 0, 0, False, False, w
, gScreenHeight
);
3034 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3037 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
3039 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
3041 function monDraw (mon
: TMonster
): Boolean;
3043 result
:= false; // don't stop
3048 // Ëåâûé âåðõíèé óãîë
3049 aX
:= Obj
.X
div ScaleSz
+ 1;
3050 aY
:= Obj
.Y
div ScaleSz
+ 1;
3052 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3053 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3054 // Ïðàâûé íèæíèé óãîë
3055 aX2
:= aX
+ aX2
- 1;
3056 aY2
:= aY
+ aY2
- 1;
3057 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
3063 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
3064 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
3067 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3068 ScaleSz
:= 16 div Scale
;
3069 // Ðàçìåðû ìèíè-êàðòû:
3070 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
3071 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
3073 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
3075 if gWalls
<> nil then
3078 for a
:= 0 to High(gWalls
) do
3080 if PanelType
<> 0 then
3082 // Ëåâûé âåðõíèé óãîë:
3083 aX
:= X
div ScaleSz
;
3084 aY
:= Y
div ScaleSz
;
3086 aX2
:= max(Width
div ScaleSz
, 1);
3087 aY2
:= max(Height
div ScaleSz
, 1);
3088 // Ïðàâûé íèæíèé óãîë:
3089 aX2
:= aX
+ aX2
- 1;
3090 aY2
:= aY
+ aY2
- 1;
3093 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
3094 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
3095 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
3099 if gSteps
<> nil then
3102 for a
:= 0 to High(gSteps
) do
3104 if PanelType
<> 0 then
3106 // Ëåâûé âåðõíèé óãîë:
3107 aX
:= X
div ScaleSz
;
3108 aY
:= Y
div ScaleSz
;
3110 aX2
:= max(Width
div ScaleSz
, 1);
3111 aY2
:= max(Height
div ScaleSz
, 1);
3112 // Ïðàâûé íèæíèé óãîë:
3113 aX2
:= aX
+ aX2
- 1;
3114 aY2
:= aY
+ aY2
- 1;
3116 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
3119 if gLifts
<> nil then
3122 for a
:= 0 to High(gLifts
) do
3124 if PanelType
<> 0 then
3126 // Ëåâûé âåðõíèé óãîë:
3127 aX
:= X
div ScaleSz
;
3128 aY
:= Y
div ScaleSz
;
3130 aX2
:= max(Width
div ScaleSz
, 1);
3131 aY2
:= max(Height
div ScaleSz
, 1);
3132 // Ïðàâûé íèæíèé óãîë:
3133 aX2
:= aX
+ aX2
- 1;
3134 aY2
:= aY
+ aY2
- 1;
3137 LIFTTYPE_UP
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
3138 LIFTTYPE_DOWN
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
3139 LIFTTYPE_LEFT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
3140 LIFTTYPE_RIGHT
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
3144 if gWater
<> nil then
3147 for a
:= 0 to High(gWater
) do
3149 if PanelType
<> 0 then
3151 // Ëåâûé âåðõíèé óãîë:
3152 aX
:= X
div ScaleSz
;
3153 aY
:= Y
div ScaleSz
;
3155 aX2
:= max(Width
div ScaleSz
, 1);
3156 aY2
:= max(Height
div ScaleSz
, 1);
3157 // Ïðàâûé íèæíèé óãîë:
3158 aX2
:= aX
+ aX2
- 1;
3159 aY2
:= aY
+ aY2
- 1;
3161 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
3164 if gAcid1
<> nil then
3166 // Ðèñóåì êèñëîòó 1:
3167 for a
:= 0 to High(gAcid1
) do
3169 if PanelType
<> 0 then
3171 // Ëåâûé âåðõíèé óãîë:
3172 aX
:= X
div ScaleSz
;
3173 aY
:= Y
div ScaleSz
;
3175 aX2
:= max(Width
div ScaleSz
, 1);
3176 aY2
:= max(Height
div ScaleSz
, 1);
3177 // Ïðàâûé íèæíèé óãîë:
3178 aX2
:= aX
+ aX2
- 1;
3179 aY2
:= aY
+ aY2
- 1;
3181 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
3184 if gAcid2
<> nil then
3186 // Ðèñóåì êèñëîòó 2:
3187 for a
:= 0 to High(gAcid2
) do
3189 if PanelType
<> 0 then
3191 // Ëåâûé âåðõíèé óãîë:
3192 aX
:= X
div ScaleSz
;
3193 aY
:= Y
div ScaleSz
;
3195 aX2
:= max(Width
div ScaleSz
, 1);
3196 aY2
:= max(Height
div ScaleSz
, 1);
3197 // Ïðàâûé íèæíèé óãîë:
3198 aX2
:= aX
+ aX2
- 1;
3199 aY2
:= aY
+ aY2
- 1;
3201 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
3204 if gPlayers
<> nil then
3207 for a
:= 0 to High(gPlayers
) do
3208 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
3210 // Ëåâûé âåðõíèé óãîë:
3211 aX
:= Obj
.X
div ScaleSz
+ 1;
3212 aY
:= Obj
.Y
div ScaleSz
+ 1;
3214 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
3215 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
3216 // Ïðàâûé íèæíèé óãîë:
3217 aX2
:= aX
+ aX2
- 1;
3218 aY2
:= aY
+ aY2
- 1;
3220 if gPlayers
[a
] = p
then
3221 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
3224 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
3225 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
3226 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
3231 g_Mons_ForEach(monDraw
);
3236 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
3238 if not hasAmbient
then exit
;
3239 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
3243 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3244 //FIXME: broken for splitscreen mode
3245 procedure renderDynLightsInternal ();
3247 //hasAmbient: Boolean;
3248 //ambColor: TDFColor;
3250 lx
, ly
, lrad
: Integer;
3251 scxywh
: array[0..3] of GLint
;
3254 if e_NoGraphics
then exit
;
3256 //TODO: lights should be in separate grid, i think
3257 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3258 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3261 //ambColor := gCurrentMap['light_ambient'].rgba;
3262 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3264 { // this will multiply incoming color to alpha from framebuffer
3266 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3270 * light rendering: (INVALID!)
3271 * glStencilFunc(GL_EQUAL, 0, $ff);
3273 * glClear(GL_STENCIL_BUFFER_BIT);
3274 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3275 * draw shadow volume into stencil buffer
3276 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3277 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3279 * draw color-less quad with light alpha (WARNING! don't touch color!)
3280 * glEnable(GL_BLEND);
3281 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3282 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3284 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3285 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3287 // setup OpenGL parameters
3288 glStencilMask($FFFFFFFF);
3289 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3290 glEnable(GL_STENCIL_TEST
);
3291 glEnable(GL_SCISSOR_TEST
);
3292 glClear(GL_STENCIL_BUFFER_BIT
);
3293 glStencilFunc(GL_EQUAL
, 0, $ff);
3295 for lln
:= 0 to g_dynLightCount
-1 do
3297 lx
:= g_dynLights
[lln
].x
;
3298 ly
:= g_dynLights
[lln
].y
;
3299 lrad
:= g_dynLights
[lln
].radius
;
3300 if (lrad
< 3) then continue
;
3302 if (lx
-sX
+lrad
< 0) then continue
;
3303 if (ly
-sY
+lrad
< 0) then continue
;
3304 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3305 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3307 // set scissor to optimize drawing
3308 if (g_dbg_scale
= 1.0) then
3310 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3314 glScissor(0, 0, gWinSizeX
, gWinSizeY
);
3316 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3317 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3318 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3319 // draw extruded panels
3320 glDisable(GL_TEXTURE_2D
);
3321 glDisable(GL_BLEND
);
3322 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3323 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3324 // render light texture
3325 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3326 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3329 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3330 glEnable(GL_TEXTURE_2D
);
3331 // color and opacity
3332 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3333 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3335 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3336 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3337 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3338 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3343 glDisable(GL_STENCIL_TEST
);
3344 glDisable(GL_BLEND
);
3345 glDisable(GL_SCISSOR_TEST
);
3346 //glScissor(0, 0, sWidth, sHeight);
3348 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3349 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3353 function fixViewportForScale (): Boolean;
3355 nx0
, ny0
, nw
, nh
: Integer;
3358 if (g_dbg_scale
<> 1.0) then
3361 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3362 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3363 nw
:= round(sWidth
/g_dbg_scale
);
3364 nh
:= round(sHeight
/g_dbg_scale
);
3373 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3374 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3375 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3377 TDrawCB
= procedure ();
3380 hasAmbient
: Boolean;
3382 doAmbient
: Boolean = false;
3384 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3389 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3390 if gdbg_map_use_accel_render
then
3392 tagmask
:= panelTypeToTag(panType
);
3393 while (gDrawPanelList
.count
> 0) do
3395 pan
:= TPanel(gDrawPanelList
.front());
3396 if ((pan
.tag
and tagmask
) = 0) then break
;
3397 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3398 gDrawPanelList
.popFront();
3403 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3405 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3408 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3410 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3411 if assigned(cb
) then cb();
3412 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3416 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3418 // our accelerated renderer will collect all panels to gDrawPanelList
3419 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3420 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3421 if gdbg_map_use_accel_render
then
3423 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3425 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3427 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3428 g_Map_DrawBack(backXOfs
, backYOfs
);
3429 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3431 if setTransMatrix
then
3433 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3434 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3435 glTranslatef(-sX
, -sY
, 0);
3439 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3440 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3445 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3446 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3447 glClear(GL_COLOR_BUFFER_BIT);
3450 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3453 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3454 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3455 drawOther('items', @g_Items_Draw
);
3456 drawOther('weapons', @g_Weapon_Draw
);
3457 drawOther('shells', @g_Player_DrawShells
);
3458 drawOther('drawall', @g_Player_DrawAll
);
3459 drawOther('corpses', @g_Player_DrawCorpses
);
3460 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3461 drawOther('monsters', @g_Monsters_Draw
);
3462 drawOther('itemdrop', @g_Items_DrawDrop
);
3463 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3464 drawOther('gfx', @g_GFX_Draw
);
3465 drawOther('flags', @g_Map_DrawFlags
);
3466 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3467 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3468 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3469 drawOther('dynlights', @renderDynLightsInternal
);
3471 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3473 renderAmbientQuad(hasAmbient
, ambColor
);
3477 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3480 if g_debug_HealthBar
then
3482 g_Monsters_DrawHealth();
3483 g_Player_DrawHealth();
3486 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3490 procedure DrawMapView(x
, y
, w
, h
: Integer);
3497 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3498 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3505 fixViewportForScale();
3506 renderMapInternal(-bx
, -by
, true);
3512 procedure DrawPlayer(p
: TPlayer
);
3514 px
, py
, a
, b
, c
, d
, i
: Integer;
3517 if (p
= nil) or (p
.FDummy
) then
3520 g_Map_DrawBack(0, 0);
3525 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3526 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3532 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3533 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3535 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3537 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3538 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3540 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3541 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3543 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3544 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3547 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3550 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3551 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3554 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3559 // scaled, ignore level bounds
3560 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3561 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3564 if p
.IncCam
<> 0 then
3566 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
3568 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
3570 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
3574 if py
< gPlayerScreenSize
.Y
div 2 then
3576 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
3578 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
3582 if p
.IncCam
< 0 then
3584 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
3587 if p
.IncCam
> 0 then
3589 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
3593 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
3594 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
3595 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
3597 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
3598 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
3599 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
3602 sY
:= -(b
+p
.IncCam
);
3603 sWidth
:= gPlayerScreenSize
.X
;
3604 sHeight
:= gPlayerScreenSize
.Y
;
3606 //glTranslatef(a, b+p.IncCam, 0);
3608 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3610 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3611 fixViewportForScale();
3612 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3614 if (g_dbg_scale
<> 1.0) and (not g_dbg_ignore_bounds
) then
3616 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3617 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3618 if (sX
< 0) then sX
:= 0;
3619 if (sY
< 0) then sY
:= 0;
3621 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3622 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3625 //r_smallmap_h: 0: left; 1: center; 2: right
3626 //r_smallmap_v: 0: top; 1: center; 2: bottom
3628 if (gMapInfo
.Width
= sWidth
) then
3632 else if (gMapInfo
.Width
< sWidth
) then
3634 case r_smallmap_h
of
3635 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3636 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3637 else sX
:= 0; // left
3641 if (gMapInfo
.Height
= sHeight
) then
3645 else if (gMapInfo
.Height
< sHeight
) then
3647 case r_smallmap_v
of
3648 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3649 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3650 else sY
:= 0; // top
3656 p
.viewPortW
:= sWidth
;
3657 p
.viewPortH
:= sHeight
;
3659 {$IFDEF ENABLE_HOLMES}
3660 if (p
= gPlayer1
) then
3662 g_Holmes_plrViewPos(sX
, sY
);
3663 g_Holmes_plrViewSize(sWidth
, sHeight
);
3667 renderMapInternal(-c
, -d
, true);
3669 if (gGameSettings
.GameMode
<> GM_SINGLE
) and (gPlayerIndicator
> 0) then
3670 case gPlayerIndicator
of
3672 p
.DrawIndicator(_RGB(255, 255, 255));
3675 for i
:= 0 to High(gPlayers
) do
3676 if gPlayers
[i
] <> nil then
3677 if gPlayers
[i
] = p
then p
.DrawIndicator(_RGB(255, 255, 255))
3678 else if (gPlayers
[i
].Team
= p
.Team
) and (gPlayers
[i
].Team
<> TEAM_NONE
) then
3679 if gPlayerIndicatorStyle
= 1 then
3680 gPlayers
[i
].DrawIndicator(_RGB(192, 192, 192))
3681 else gPlayers
[i
].DrawIndicator(gPlayers
[i
].GetColor
);
3684 if p
.FSpectator
then
3685 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3686 p
.GameY
+ PLAYER_RECT_CY
- 4,
3687 'X', gStdFont
, 255, 255, 255, 1, True);
3689 for a := 0 to High(gCollideMap) do
3690 for b := 0 to High(gCollideMap[a]) do
3693 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3695 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3699 1: e_DrawPoint(1, b, a, 200, 200, 200);
3700 2: e_DrawPoint(1, b, a, 64, 64, 255);
3701 3: e_DrawPoint(1, b, a, 255, 0, 255);
3711 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3712 if g_Debug_Player
then
3713 g_Player_DrawDebug(p
);
3717 procedure drawProfilers ();
3722 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3723 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3724 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3727 procedure g_Game_Draw();
3734 plView1
, plView2
: TPlayer
;
3737 if gExit
= EXIT_QUIT
then Exit
;
3739 Time
:= sys_GetTicks() {div 1000};
3740 FPSCounter
:= FPSCounter
+1;
3741 if Time
- FPSTime
>= 1000 then
3748 if gGameOn
or (gState
= STATE_FOLD
) then
3750 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3752 gSpectMode
:= SPECT_NONE
;
3753 if not gRevertPlayers
then
3755 plView1
:= gPlayer1
;
3756 plView2
:= gPlayer2
;
3760 plView1
:= gPlayer2
;
3761 plView2
:= gPlayer1
;
3765 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3767 gSpectMode
:= SPECT_NONE
;
3768 if gPlayer2
= nil then
3771 plView1
:= gPlayer2
;
3780 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3781 gSpectMode
:= SPECT_STATS
;
3783 if gSpectMode
= SPECT_PLAYERS
then
3784 if gPlayers
<> nil then
3786 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3787 if plView1
= nil then
3789 gSpectPID1
:= GetActivePlayerID_Next();
3790 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3792 if gSpectViewTwo
then
3794 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3795 if plView2
= nil then
3797 gSpectPID2
:= GetActivePlayerID_Next();
3798 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3803 if gSpectMode
= SPECT_MAPVIEW
then
3805 // Ðåæèì ïðîñìîòðà êàðòû
3807 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3808 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3809 gHearPoint1
.Active
:= True;
3810 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3811 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3812 gHearPoint2
.Active
:= False;
3816 Split
:= (plView1
<> nil) and (plView2
<> nil);
3818 // Òî÷êè ñëóõà èãðîêîâ
3819 if plView1
<> nil then
3821 gHearPoint1
.Active
:= True;
3822 gHearPoint1
.Coords
.X
:= plView1
.GameX
+ PLAYER_RECT
.Width
;
3823 gHearPoint1
.Coords
.Y
:= plView1
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3825 gHearPoint1
.Active
:= False;
3826 if plView2
<> nil then
3828 gHearPoint2
.Active
:= True;
3829 gHearPoint2
.Coords
.X
:= plView2
.GameX
+ PLAYER_RECT
.Width
;
3830 gHearPoint2
.Coords
.Y
:= plView2
.GameY
+ PLAYER_RECT
.Height
DIV 2;
3832 gHearPoint2
.Active
:= False;
3834 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3835 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3838 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3839 if gScreenHeight
mod 2 = 0 then
3840 Dec(gPlayerScreenSize
.Y
);
3843 gPlayerScreenSize
.Y
:= gScreenHeight
;
3846 if gScreenHeight
mod 2 = 0 then
3847 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3849 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3851 DrawPlayer(plView1
);
3852 gPlayer1ScreenCoord
.X
:= sX
;
3853 gPlayer1ScreenCoord
.Y
:= sY
;
3857 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3859 DrawPlayer(plView2
);
3860 gPlayer2ScreenCoord
.X
:= sX
;
3861 gPlayer2ScreenCoord
.Y
:= sY
;
3864 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3867 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3870 {$IFDEF ENABLE_HOLMES}
3872 if (g_holmes_enabled
) then g_Holmes_Draw();
3875 if MessageText
<> '' then
3879 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3881 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3882 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3884 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3885 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3888 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3890 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) and (not gSpectAuto
) then
3892 // Draw spectator GUI
3895 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3898 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3900 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3902 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3904 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3905 if gSpectMode
= SPECT_STATS
then
3907 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2)*2, 'Autoview', gStdFont
, 255, 255, 255, 1);
3908 e_TextureFontPrintEx(16*ww
, gScreenHeight
- (hh
+2), '< fire >', gStdFont
, 255, 255, 255, 1);
3910 if gSpectMode
= SPECT_MAPVIEW
then
3912 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
3913 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
3914 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
3915 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
3916 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
3918 if gSpectMode
= SPECT_PLAYERS
then
3920 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
3921 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
3922 if gSpectViewTwo
then
3924 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
3925 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
3926 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3927 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3931 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3932 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3938 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
3940 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3941 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3943 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
3944 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3945 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
3950 if (gState
= STATE_MENU
) then
3952 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then DrawMenuBackground('MENU_BACKGROUND');
3953 // F3 at menu will show game loading dialog
3954 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
3955 if (g_ActiveWindow
<> nil) then
3957 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3958 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3962 // F3 at titlepic will show game loading dialog
3963 if e_KeyPressed(IK_F3
) then
3965 g_Menu_Show_LoadMenu(true);
3966 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3971 if gState
= STATE_FOLD
then
3973 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3976 if gState
= STATE_INTERCUSTOM
then
3978 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
3980 back
:= 'TEXTURE_endpic';
3981 if not g_Texture_Get(back
, ID
) then
3982 back
:= _lc
[I_TEXTURE_ENDPIC
];
3987 DrawMenuBackground(back
);
3991 if g_ActiveWindow
<> nil then
3993 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3994 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3998 if gState
= STATE_INTERSINGLE
then
4000 if EndingGameCounter
> 0 then
4002 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
4008 DrawMenuBackground(back
);
4012 if g_ActiveWindow
<> nil then
4014 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4015 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4020 if gState
= STATE_ENDPIC
then
4023 if g_Texture_Get('TEXTURE_endpic', ID
) then DrawMenuBackground('TEXTURE_endpic')
4024 else DrawMenuBackground(_lc
[I_TEXTURE_ENDPIC
]);
4026 if g_ActiveWindow
<> nil then
4028 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4029 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4033 if gState
= STATE_SLIST
then
4035 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4037 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4038 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4040 DrawMenuBackground('MENU_BACKGROUND');
4041 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4042 g_Serverlist_Draw(slCurrent
, slTable
);
4046 if g_ActiveWindow
<> nil then
4050 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4051 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
4053 g_ActiveWindow
.Draw();
4060 if g_debug_Sounds
and gGameOn
then
4062 for w
:= 0 to High(e_SoundsArray
) do
4063 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
4064 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
4069 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
4070 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
4073 if gGameOn
and gShowTime
then
4074 drawTime(gScreenWidth
-72, gScreenHeight
-16);
4076 if gGameOn
then drawProfilers();
4078 {$IFDEF ENABLE_HOLMES}
4085 procedure g_Game_Quit();
4087 g_Game_StopAllSounds(True);
4089 g_Game_SaveOptions();
4091 g_PlayerModel_FreeData();
4092 g_Texture_DeleteAll();
4093 g_Frames_DeleteAll();
4095 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4098 if NetInitDone
then g_Net_Free
;
4100 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4101 if gMapToDelete
<> '' then
4102 g_Game_DeleteTestMap();
4108 procedure g_FatalError(Text: String);
4110 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
4111 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
4113 gExit
:= EXIT_SIMPLE
;
4116 procedure g_SimpleError(Text: String);
4118 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
4119 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
4122 procedure g_Game_SetupScreenSize();
4124 RES_FACTOR
= 4.0 / 3.0;
4130 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4131 gPlayerScreenSize
.X
:= gScreenWidth
-196;
4132 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
4133 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
4135 gPlayerScreenSize
.Y
:= gScreenHeight
;
4137 // Ðàçìåð çàäíåãî ïëàíà:
4138 if BackID
<> DWORD(-1) then
4141 if (gScreenWidth
*s
> gMapInfo
.Width
) or
4142 (gScreenHeight
*s
> gMapInfo
.Height
) then
4144 gBackSize
.X
:= gScreenWidth
;
4145 gBackSize
.Y
:= gScreenHeight
;
4149 e_GetTextureSize(BackID
, @bw
, @bh
);
4150 rf
:= Single(bw
) / Single(bh
);
4151 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
4152 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
4153 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
4154 if (s
< 1.0) then s
:= 1.0;
4155 gBackSize
.X
:= Round(bw
*s
);
4156 gBackSize
.Y
:= Round(bh
*s
);
4161 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
4163 sys_SetDisplayMode(newWidth
, newHeight
, gBPP
, nowFull
);
4166 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
4168 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4169 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4171 if gPlayer1
= nil then
4173 if g_Game_IsClient
then
4175 if NetPlrUID1
> -1 then
4177 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4178 gPlayer1
:= g_Player_Get(NetPlrUID1
);
4183 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4184 Team
:= gPlayer1Settings
.Team
;
4186 // Ñîçäàíèå ïåðâîãî èãðîêà:
4187 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4188 gPlayer1Settings
.Color
,
4190 if gPlayer1
= nil then
4191 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
4194 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4195 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
4196 if g_Game_IsServer
and g_Game_IsNet
then
4197 MH_SEND_PlayerCreate(gPlayer1
.UID
);
4198 gPlayer1
.Respawn(False, True);
4199 g_Net_Slist_ServerPlayerComes();
4204 if gPlayer2
= nil then
4206 if g_Game_IsClient
then
4208 if NetPlrUID2
> -1 then
4209 gPlayer2
:= g_Player_Get(NetPlrUID2
);
4213 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
4214 Team
:= gPlayer2Settings
.Team
;
4216 // Ñîçäàíèå âòîðîãî èãðîêà:
4217 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4218 gPlayer2Settings
.Color
,
4220 if gPlayer2
= nil then
4221 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
4224 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4225 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
4226 if g_Game_IsServer
and g_Game_IsNet
then
4227 MH_SEND_PlayerCreate(gPlayer2
.UID
);
4228 gPlayer2
.Respawn(False, True);
4229 g_Net_Slist_ServerPlayerComes();
4236 procedure g_Game_RemovePlayer();
4240 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
4241 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
4246 if g_Game_IsServer
then
4249 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4250 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4251 g_Player_Remove(Pl
.UID
);
4252 g_Net_Slist_ServerPlayerLeaves();
4260 if g_Game_IsServer
then
4263 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4264 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4265 g_Player_Remove(Pl
.UID
);
4266 g_Net_Slist_ServerPlayerLeaves();
4270 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4274 g_Net_Slist_ServerPlayerLeaves();
4277 procedure g_Game_Spectate();
4279 g_Game_RemovePlayer();
4280 if gPlayer1
<> nil then
4281 g_Game_RemovePlayer();
4284 procedure g_Game_SpectateCenterView();
4286 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4287 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4290 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4297 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4299 g_Game_ClearLoading();
4302 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4305 gGameSettings
.GameType
:= GT_SINGLE
;
4306 gGameSettings
.MaxLives
:= 0;
4307 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4308 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4309 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4310 gSwitchGameMode
:= GM_SINGLE
;
4312 g_Game_ExecuteEvent('ongamestart');
4314 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4315 g_Game_SetupScreenSize();
4317 // Ñîçäàíèå ïåðâîãî èãðîêà:
4318 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4319 gPlayer1Settings
.Color
,
4320 gPlayer1Settings
.Team
, False));
4321 if gPlayer1
= nil then
4323 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4327 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4330 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4333 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4334 gPlayer2Settings
.Color
,
4335 gPlayer2Settings
.Team
, False));
4336 if gPlayer2
= nil then
4338 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4342 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4346 // Çàãðóçêà è çàïóñê êàðòû:
4347 if not g_Game_StartMap(MAP
, True) then
4349 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4350 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4354 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4358 for i
:= nPl
+1 to nPlayers
do
4359 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4362 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4363 TimeLimit
, GoalLimit
: Word;
4365 Options
: LongWord; nPlayers
: Byte);
4371 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4373 g_Game_ClearLoading();
4376 gGameSettings
.GameType
:= GT_CUSTOM
;
4377 gGameSettings
.GameMode
:= GameMode
;
4378 gSwitchGameMode
:= GameMode
;
4379 gGameSettings
.TimeLimit
:= TimeLimit
;
4380 gGameSettings
.GoalLimit
:= GoalLimit
;
4381 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4382 gGameSettings
.Options
:= Options
;
4384 gCoopTotalMonstersKilled
:= 0;
4385 gCoopTotalSecretsFound
:= 0;
4386 gCoopTotalMonsters
:= 0;
4387 gCoopTotalSecrets
:= 0;
4391 g_Game_ExecuteEvent('ongamestart');
4393 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4394 g_Game_SetupScreenSize();
4396 // Ðåæèì íàáëþäàòåëÿ:
4397 if nPlayers
= 0 then
4404 if nPlayers
>= 1 then
4406 // Ñîçäàíèå ïåðâîãî èãðîêà:
4407 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4408 gPlayer1Settings
.Color
,
4409 gPlayer1Settings
.Team
, False));
4410 if gPlayer1
= nil then
4412 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4416 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4420 if nPlayers
>= 2 then
4422 // Ñîçäàíèå âòîðîãî èãðîêà:
4423 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4424 gPlayer2Settings
.Color
,
4425 gPlayer2Settings
.Team
, False));
4426 if gPlayer2
= nil then
4428 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4432 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4436 // Çàãðóçêà è çàïóñê êàðòû:
4437 if not g_Game_StartMap(Map
, True) then
4439 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4443 // Íåò òî÷åê ïîÿâëåíèÿ:
4444 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4445 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4446 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4447 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4448 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4450 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4454 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4458 for i
:= nPl
+1 to nPlayers
do
4459 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4462 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4463 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4464 Options
: LongWord; nPlayers
: Byte;
4465 IPAddr
: LongWord; Port
: Word);
4468 g_Net_Slist_ServerClosed();
4470 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4472 g_Game_ClearLoading();
4475 gGameSettings
.GameType
:= GT_SERVER
;
4476 gGameSettings
.GameMode
:= GameMode
;
4477 gSwitchGameMode
:= GameMode
;
4478 gGameSettings
.TimeLimit
:= TimeLimit
;
4479 gGameSettings
.GoalLimit
:= GoalLimit
;
4480 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4481 gGameSettings
.Options
:= Options
;
4483 gCoopTotalMonstersKilled
:= 0;
4484 gCoopTotalSecretsFound
:= 0;
4485 gCoopTotalMonsters
:= 0;
4486 gCoopTotalSecrets
:= 0;
4490 g_Game_ExecuteEvent('ongamestart');
4492 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4493 g_Game_SetupScreenSize();
4495 // Ðåæèì íàáëþäàòåëÿ:
4496 if nPlayers
= 0 then
4502 if nPlayers
>= 1 then
4504 // Ñîçäàíèå ïåðâîãî èãðîêà:
4505 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4506 gPlayer1Settings
.Color
,
4507 gPlayer1Settings
.Team
, False));
4508 if gPlayer1
= nil then
4510 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4514 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4517 if nPlayers
>= 2 then
4519 // Ñîçäàíèå âòîðîãî èãðîêà:
4520 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4521 gPlayer2Settings
.Color
,
4522 gPlayer2Settings
.Team
, False));
4523 if gPlayer2
= nil then
4525 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4529 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4532 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4533 if NetForwardPorts
then
4534 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4537 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4539 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
4543 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
, NetSlistList
);
4545 g_Net_Slist_ServerStarted();
4547 // Çàãðóçêà è çàïóñê êàðòû:
4548 if not g_Game_StartMap(Map
, True) then
4550 g_Net_Slist_ServerClosed();
4551 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4555 // Íåò òî÷åê ïîÿâëåíèÿ:
4556 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4557 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4558 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4559 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4560 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4562 g_Net_Slist_ServerClosed();
4563 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4567 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4570 g_Net_Slist_ServerMapStarted();
4571 NetState
:= NET_STATE_GAME
;
4574 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4589 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4590 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4592 g_Game_ClearLoading();
4595 gGameSettings
.GameType
:= GT_CLIENT
;
4597 gCoopTotalMonstersKilled
:= 0;
4598 gCoopTotalSecretsFound
:= 0;
4599 gCoopTotalMonsters
:= 0;
4600 gCoopTotalSecrets
:= 0;
4604 g_Game_ExecuteEvent('ongamestart');
4606 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4607 g_Game_SetupScreenSize();
4609 NetState
:= NET_STATE_AUTH
;
4611 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4613 // create (or update) map/resource databases
4614 g_Res_CreateDatabases(true);
4617 if not g_Net_Connect(Addr
, Port
) then
4619 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4620 NetState
:= NET_STATE_NONE
;
4624 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4626 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4631 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4632 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4633 // thank you, enet. let's ignore failures altogether then.
4634 while (enet_host_service(NetHost
, @NetEvent
, 50) > 0) do
4636 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4638 if (NetEvent
.channelID
= NET_CHAN_DOWNLOAD_EX
) then
4640 // ignore all download packets, they're processed by separate code
4641 enet_packet_destroy(NetEvent
.packet
);
4644 Ptr
:= NetEvent
.packet
^.data
;
4645 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4647 enet_packet_destroy(NetEvent
.packet
);
4651 InMsg
.ReadLongWord(); // skip size
4652 MID
:= InMsg
.ReadByte();
4654 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4656 NetMyID
:= InMsg
.ReadByte();
4657 NetPlrUID1
:= InMsg
.ReadWord();
4659 WadName
:= InMsg
.ReadString();
4660 Map
:= InMsg
.ReadString();
4662 gWADHash
:= InMsg
.ReadMD5();
4664 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4665 gSwitchGameMode
:= gGameSettings
.GameMode
;
4666 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4667 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4668 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4669 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4670 T
:= InMsg
.ReadLongWord();
4672 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4673 //if newResPath = '' then
4675 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4676 newResPath
:= g_Res_DownloadMapWAD(WadName
, gWADHash
);
4677 if newResPath
= '' then
4679 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4680 enet_packet_destroy(NetEvent
.packet
);
4681 NetState
:= NET_STATE_NONE
;
4684 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath
, WadName
], TMsgType
.Notify
);
4686 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4689 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4690 gPlayer1Settings
.Color
,
4691 gPlayer1Settings
.Team
, False));
4693 if gPlayer1
= nil then
4695 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4697 enet_packet_destroy(NetEvent
.packet
);
4698 NetState
:= NET_STATE_NONE
;
4702 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4703 gPlayer1
.UID
:= NetPlrUID1
;
4704 gPlayer1
.Reset(True);
4706 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
4708 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4710 enet_packet_destroy(NetEvent
.packet
);
4711 NetState
:= NET_STATE_NONE
;
4719 enet_packet_destroy(NetEvent
.packet
);
4723 enet_packet_destroy(NetEvent
.packet
);
4727 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4730 if (NetEvent
.data
<= NET_DISC_MAX
) then
4731 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4732 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4739 ProcessLoading(true);
4741 if g_Net_UserRequestExit() then
4750 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4751 NetState
:= NET_STATE_NONE
;
4755 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4756 gLMSRespawnTime
:= 0;
4759 NetState
:= NET_STATE_GAME
;
4760 MC_SEND_FullStateRequest
;
4761 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4764 procedure g_Game_SaveOptions
;
4767 s
:= e_GetDir(ConfigDirs
);
4769 g_Options_Write_Video(s
+ '/' + CONFIG_FILENAME
)
4771 e_LogWritefln('unable to find or create directory for configs', []);
4774 procedure g_Game_ChangeMap(const MapPath
: String);
4778 g_Game_ClearLoading();
4780 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4781 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4782 if gExitByTrigger
then
4785 gExitByTrigger
:= False;
4787 if not g_Game_StartMap(MapPath
, Force
) then
4788 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4791 procedure g_Game_Restart();
4795 if g_Game_IsClient
then
4797 map
:= g_ExtractFileName(gMapInfo
.Map
);
4798 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map
, gCurrentMapFileName
]);
4802 g_Game_ClearLoading();
4803 g_Game_StartMap(Map
, True, gCurrentMapFileName
);
4806 function g_Game_StartMap(Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4808 NewWAD
, ResName
: String;
4812 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4813 g_Player_RemoveAllCorpses();
4815 if (not g_Game_IsClient
) and
4816 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4817 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4819 if gSwitchGameMode
= GM_CTF
then
4820 gGameSettings
.MaxLives
:= 0;
4821 gGameSettings
.GameMode
:= gSwitchGameMode
;
4824 gSwitchGameMode
:= gGameSettings
.GameMode
;
4826 g_Player_ResetTeams();
4828 if isWadPath(Map
) then
4830 NewWAD
:= g_ExtractWadName(Map
);
4831 ResName
:= g_ExtractFileName(Map
);
4832 if g_Game_IsServer
then
4834 // nws := e_FindWad(MapDirs, NewWAD);
4836 if (length(nws
) = 0) then
4842 if (g_Game_IsNet
) then gWADHash
:= MD5File(nws
);
4843 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
4844 g_Game_LoadWAD(NewWAD
);
4847 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4848 g_Game_ClientWAD(NewWAD
, gWADHash
);
4852 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
4854 if ResName
<> '' then
4855 result
:= g_Map_Load(gGameSettings
.WAD
+ ':\' + ResName
);
4858 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4860 gState
:= STATE_NONE
;
4861 g_ActiveWindow
:= nil;
4867 if gGameSettings
.GameMode
= GM_CTF
then
4869 g_Map_ResetFlag(FLAG_RED
);
4870 g_Map_ResetFlag(FLAG_BLUE
);
4871 // CTF, à ôëàãîâ íåò:
4872 if not g_Map_HaveFlagPoints() then
4873 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4878 gState
:= STATE_MENU
;
4883 gPauseMain
:= false;
4884 gPauseHolmes
:= false;
4886 NetTimeToUpdate
:= 1;
4887 NetTimeToReliable
:= 0;
4888 NetTimeToMaster
:= NetMasterRate
;
4889 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4890 gLMSRespawnTime
:= 0;
4891 gMissionFailed
:= False;
4894 gCoopMonstersKilled
:= 0;
4895 gCoopSecretsFound
:= 0;
4897 gVoteInProgress
:= False;
4898 gVotePassed
:= False;
4904 if not gGameOn
then Exit
;
4906 g_Game_SpectateCenterView();
4908 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
4910 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4911 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
4912 gLMSSoftSpawn
:= True;
4913 if NetMode
= NET_SERVER
then
4914 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
4916 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
4919 if NetMode
= NET_SERVER
then
4921 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
4924 g_Net_Slist_ServerMapStarted();
4926 if NetClients
<> nil then
4927 for I
:= 0 to High(NetClients
) do
4928 if NetClients
[I
].Used
then
4930 NetClients
[I
].Voted
:= False;
4931 if NetClients
[I
].RequestedFullUpdate
then
4933 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
4934 NetClients
[I
].RequestedFullUpdate
:= False;
4938 g_Net_UnbanNonPermHosts();
4943 gCoopTotalMonstersKilled
:= 0;
4944 gCoopTotalSecretsFound
:= 0;
4945 gCoopTotalMonsters
:= 0;
4946 gCoopTotalSecrets
:= 0;
4950 g_Game_ExecuteEvent('onmapstart');
4953 procedure SetFirstLevel
;
4957 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
4958 if MapList
= nil then
4961 SortSArray(MapList
);
4962 gNextMap
:= MapList
[Low(MapList
)];
4967 procedure g_Game_ExitLevel(const Map
: AnsiString);
4971 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
4972 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
4973 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
4974 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
4976 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4977 if gGameSettings
.GameType
= GT_SINGLE
then
4978 gExit
:= EXIT_ENDLEVELSINGLE
4979 else // Âûøëè â âûõîä â Ñâîåé èãðå
4981 gExit
:= EXIT_ENDLEVELCUSTOM
;
4982 if gGameSettings
.GameMode
= GM_COOP
then
4983 g_Player_RememberAll
;
4985 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
4988 if gGameSettings
.GameMode
= GM_COOP
then
4991 gStatsPressed
:= True;
4992 gNextMap
:= 'MAP01';
4994 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + gNextMap
) then
4997 if g_Game_IsNet
then
4999 MH_SEND_GameStats();
5000 MH_SEND_CoopStats();
5006 procedure g_Game_RestartLevel();
5010 if gGameSettings
.GameMode
= GM_SINGLE
then
5015 gExit
:= EXIT_ENDLEVELCUSTOM
;
5016 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5020 procedure g_Game_ClientWAD(NewWAD
: String; const WHash
: TMD5Digest
);
5022 gWAD
{, xwad}: String;
5024 if not g_Game_IsClient
then Exit
;
5025 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5027 gWAD
:= g_Res_DownloadMapWAD(ExtractFileName(NewWAD
), WHash
);
5031 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
5036 xwad := ExtractRelativePath(MapsDir, gWAD);
5037 e_LogWritefln('using downloaded client map wad [%s] for [%s]`', [xwad, NewWAD], TMsgType.Notify);
5039 g_Game_LoadWAD(NewWAD);
5042 e_LogWritefln('using downloaded client map wad [%s]`', [NewWAD
], TMsgType
.Notify
);
5043 g_Game_LoadWAD(NewWAD
);
5046 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5047 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5050 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5051 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5055 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5059 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5060 g_Game_LoadWAD(NewWAD);
5064 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
5066 i
, n
, nb
, nr
: Integer;
5068 function monRespawn (mon
: TMonster
): Boolean;
5070 result
:= false; // don't stop
5071 if not mon
.FNoRespawn
then mon
.Respawn();
5075 if not g_Game_IsServer
then Exit
;
5076 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
5077 gLMSRespawn
:= LMS_RESPAWN_NONE
;
5078 gLMSRespawnTime
:= 0;
5081 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
5083 gMissionFailed
:= True;
5084 g_Game_RestartLevel
;
5088 n
:= 0; nb
:= 0; nr
:= 0;
5089 for i
:= Low(gPlayers
) to High(gPlayers
) do
5090 if (gPlayers
[i
] <> nil) and
5091 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
5092 (gPlayers
[i
] is TBot
)) then
5095 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
5096 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
5099 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
5101 // wait a second until the fuckers finally decide to join
5102 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
5103 gLMSRespawnTime
:= gTime
+ 1000;
5104 gLMSSoftSpawn
:= NoMapRestart
;
5108 g_Player_RemoveAllCorpses
;
5109 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
5110 if g_Game_IsNet
then
5111 MH_SEND_GameEvent(NET_EV_LMS_START
);
5113 for i
:= Low(gPlayers
) to High(gPlayers
) do
5115 if gPlayers
[i
] = nil then continue
;
5116 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
5117 // don't touch normal spectators
5118 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
5120 gPlayers
[i
].FNoRespawn
:= True;
5121 gPlayers
[i
].Lives
:= 0;
5122 if g_Game_IsNet
then
5123 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
5126 gPlayers
[i
].FNoRespawn
:= False;
5127 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
5128 gPlayers
[i
].Respawn(False, True);
5129 if gGameSettings
.GameMode
= GM_COOP
then
5131 gPlayers
[i
].Frags
:= 0;
5132 gPlayers
[i
].RecallState
;
5134 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
5135 gPlayer1
:= g_Player_Get(gLMSPID1
);
5136 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
5137 gPlayer2
:= g_Player_Get(gLMSPID2
);
5140 g_Items_RestartRound();
5143 g_Mons_ForEach(monRespawn
);
5145 gLMSSoftSpawn
:= False;
5148 function g_Game_GetFirstMap(WAD
: String): String;
5152 MapList
:= g_Map_GetMapsList(WAD
);
5153 if MapList
= nil then
5156 SortSArray(MapList
);
5157 Result
:= MapList
[Low(MapList
)];
5159 if not g_Map_Exist(WAD
+ ':\' + Result
) then
5165 function g_Game_GetNextMap(): String;
5172 MapList
:= g_Map_GetMapsList(gGameSettings
.WAD
);
5173 if MapList
= nil then
5176 Map
:= g_ExtractFileName(gMapInfo
.Map
);
5178 SortSArray(MapList
);
5180 for I
:= Low(MapList
) to High(MapList
) do
5181 if Map
= MapList
[I
] then
5187 if MapIndex
<> -255 then
5189 if MapIndex
= High(MapList
) then
5190 Result
:= MapList
[Low(MapList
)]
5192 Result
:= MapList
[MapIndex
+ 1];
5194 if not g_Map_Exist(gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
5200 procedure g_Game_NextLevel();
5202 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
5203 gExit
:= EXIT_ENDLEVELCUSTOM
5206 gExit
:= EXIT_ENDLEVELSINGLE
;
5210 if gNextMap
<> '' then Exit
;
5211 gNextMap
:= g_Game_GetNextMap();
5214 function g_Game_IsTestMap(): Boolean;
5216 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
5219 procedure g_Game_DeleteTestMap();
5222 //MapName: AnsiString;
5230 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
5231 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
5232 if (a
= 0) then exit
;
5234 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5235 WadName
:= Copy(gMapToDelete
, 1, a
+3);
5236 Delete(gMapToDelete
, 1, a
+5);
5237 gMapToDelete
:= UpperCase(gMapToDelete
);
5239 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5242 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5243 if MapName <> TEST_MAP_NAME then
5246 if not gTempDelete then
5248 time := g_GetFileTime(WadName);
5249 WAD := TWADFile.Create();
5252 if not WAD.ReadFile(WadName) then
5253 begin // Íåò òàêîãî WAD-ôàéëà
5258 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5260 MapList := WAD.GetResourcesList('');
5262 if MapList <> nil then
5263 for a := 0 to High(MapList) do
5264 if MapList[a] = MapName then
5266 // Óäàëÿåì è ñîõðàíÿåì:
5267 WAD.RemoveResource('', MapName);
5268 WAD.SaveTo(WadName);
5273 g_SetFileTime(WadName, time);
5276 if gTempDelete
then DeleteFile(WadName
);
5279 procedure GameCVars(P
: SSArray
);
5282 stat
: TPlayerStatArray
;
5287 cmd
:= LowerCase(P
[0]);
5288 if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
5290 with gGameSettings
do
5292 if (Length(P
) > 1) and
5293 ((P
[1] = '1') or (P
[1] = '0')) then
5295 if (P
[1][1] = '1') then
5296 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
5298 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
5301 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
5302 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
5304 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
5306 if g_Game_IsNet
then MH_SEND_GameSettings
;
5309 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
5311 with gGameSettings
do
5313 if (Length(P
) > 1) and
5314 ((P
[1] = '1') or (P
[1] = '0')) then
5316 if (P
[1][1] = '1') then
5317 Options
:= Options
or GAME_OPTION_WEAPONSTAY
5319 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
5322 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
5323 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
5325 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
5327 if g_Game_IsNet
then MH_SEND_GameSettings
;
5330 else if cmd
= 'g_gamemode' then
5332 a
:= g_Game_TextToMode(P
[1]);
5333 if a
= GM_SINGLE
then a
:= GM_COOP
;
5334 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
5336 gSwitchGameMode
:= a
;
5337 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5338 (gState
= STATE_INTERSINGLE
) then
5339 gSwitchGameMode
:= GM_SINGLE
;
5341 gGameSettings
.GameMode
:= gSwitchGameMode
;
5343 if gSwitchGameMode
= gGameSettings
.GameMode
then
5344 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5345 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5347 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5348 [g_Game_ModeToText(gGameSettings
.GameMode
),
5349 g_Game_ModeToText(gSwitchGameMode
)]));
5351 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
5353 with gGameSettings
do
5355 if (Length(P
) > 1) and
5356 ((P
[1] = '1') or (P
[1] = '0')) then
5358 if (P
[1][1] = '1') then
5359 Options
:= Options
or GAME_OPTION_ALLOWEXIT
5361 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
5364 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
5365 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
5367 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
5368 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5370 if g_Game_IsNet
then MH_SEND_GameSettings
;
5373 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
5375 with gGameSettings
do
5377 if (Length(P
) > 1) and
5378 ((P
[1] = '1') or (P
[1] = '0')) then
5380 if (P
[1][1] = '1') then
5381 Options
:= Options
or GAME_OPTION_MONSTERS
5383 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
5386 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
5387 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
5389 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
5390 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5392 if g_Game_IsNet
then MH_SEND_GameSettings
;
5395 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
5397 with gGameSettings
do
5399 if (Length(P
) > 1) and
5400 ((P
[1] = '1') or (P
[1] = '0')) then
5402 if (P
[1][1] = '1') then
5403 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
5405 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
5408 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
5409 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
5411 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
5413 if g_Game_IsNet
then MH_SEND_GameSettings
;
5416 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
5418 with gGameSettings
do
5420 if (Length(P
) > 1) and
5421 ((P
[1] = '1') or (P
[1] = '0')) then
5423 if (P
[1][1] = '1') then
5424 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
5426 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
5429 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
5430 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
5432 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
5434 if g_Game_IsNet
then MH_SEND_GameSettings
;
5437 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
5439 if Length(P
) > 1 then
5441 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
5442 gGameSettings
.WarmupTime
:= 30
5444 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
5447 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
5448 [gGameSettings
.WarmupTime
]));
5449 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5451 else if cmd
= 'net_interp' then
5453 if (Length(P
) > 1) then
5454 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
5455 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
5456 s
:= e_GetDir(ConfigDirs
);
5459 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5460 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
5461 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5465 else if cmd
= 'net_forceplayerupdate' then
5467 if (Length(P
) > 1) and ((P
[1] = '1') or (P
[1] = '0')) then
5468 NetForcePlayerUpdate
:= (P
[1][1] = '1');
5470 if NetForcePlayerUpdate
then
5471 g_Console_Add('net_forceplayerupdate = 1')
5473 g_Console_Add('net_forceplayerupdate = 0');
5475 s
:= e_GetDir(ConfigDirs
);
5478 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5479 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
5480 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5484 else if cmd
= 'net_predictself' then
5486 if (Length(P
) > 1) and
5487 ((P
[1] = '1') or (P
[1] = '0')) then
5488 NetPredictSelf
:= (P
[1][1] = '1');
5490 if NetPredictSelf
then
5491 g_Console_Add('net_predictself = 1')
5493 g_Console_Add('net_predictself = 0');
5495 s
:= e_GetDir(ConfigDirs
);
5498 config
:= TConfig
.CreateFile(s
+ '/' + CONFIG_FILENAME
);
5499 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
5500 config
.SaveFile(s
+ '/' + CONFIG_FILENAME
);
5504 else if cmd
= 'sv_name' then
5506 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5508 NetServerName
:= P
[1];
5509 if Length(NetServerName
) > 64 then
5510 SetLength(NetServerName
, 64);
5511 g_Net_Slist_ServerRenamed();
5514 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
5516 else if cmd
= 'sv_passwd' then
5518 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5520 NetPassword
:= P
[1];
5521 if Length(NetPassword
) > 24 then
5522 SetLength(NetPassword
, 24);
5523 g_Net_Slist_ServerRenamed();
5526 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
5528 else if cmd
= 'sv_maxplrs' then
5530 if (Length(P
) > 1) then
5532 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
5533 if g_Game_IsServer
and g_Game_IsNet
then
5536 for a
:= 0 to High(NetClients
) do
5538 if NetClients
[a
].Used
then
5541 if b
> NetMaxClients
then
5543 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
5544 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
5545 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5546 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5550 g_Net_Slist_ServerRenamed();
5554 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
5556 else if cmd
= 'sv_public' then
5558 if (Length(P
) > 1) then
5560 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
5561 if NetUseMaster
then g_Net_Slist_Public() else g_Net_Slist_Private();
5564 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
5566 else if cmd
= 'sv_intertime' then
5568 if (Length(P
) > 1) then
5569 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5571 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5573 else if cmd
= 'p1_name' then
5575 if (Length(P
) > 1) and gGameOn
then
5577 if g_Game_IsClient
then
5579 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5580 MC_SEND_PlayerSettings
;
5583 if gPlayer1
<> nil then
5585 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5586 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5589 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5592 else if cmd
= 'p2_name' then
5594 if (Length(P
) > 1) and gGameOn
then
5596 if g_Game_IsClient
then
5598 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5599 MC_SEND_PlayerSettings
;
5602 if gPlayer2
<> nil then
5604 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5605 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5608 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5611 else if cmd
= 'p1_color' then
5613 if Length(P
) > 3 then
5614 if g_Game_IsClient
then
5616 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5617 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5618 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5619 MC_SEND_PlayerSettings
;
5622 if gPlayer1
<> nil then
5624 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5625 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5626 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5627 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5630 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5631 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5632 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5634 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5636 if Length(P
) > 3 then
5637 if g_Game_IsClient
then
5639 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5640 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5641 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5642 MC_SEND_PlayerSettings
;
5645 if gPlayer2
<> nil then
5647 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5648 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5649 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5650 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5653 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5654 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5655 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5657 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5659 if cmd
= 'r_showscore' then
5661 if (Length(P
) > 1) and
5662 ((P
[1] = '1') or (P
[1] = '0')) then
5663 gShowGoals
:= (P
[1][1] = '1');
5666 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5668 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5670 else if cmd
= 'r_showstat' then
5672 if (Length(P
) > 1) and
5673 ((P
[1] = '1') or (P
[1] = '0')) then
5674 gShowStat
:= (P
[1][1] = '1');
5677 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5679 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5681 else if cmd
= 'r_showkillmsg' then
5683 if (Length(P
) > 1) and
5684 ((P
[1] = '1') or (P
[1] = '0')) then
5685 gShowKillMsg
:= (P
[1][1] = '1');
5687 if gShowKillMsg
then
5688 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5690 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5692 else if cmd
= 'r_showlives' then
5694 if (Length(P
) > 1) and
5695 ((P
[1] = '1') or (P
[1] = '0')) then
5696 gShowLives
:= (P
[1][1] = '1');
5699 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5701 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5703 else if cmd
= 'r_showspect' then
5705 if (Length(P
) > 1) and
5706 ((P
[1] = '1') or (P
[1] = '0')) then
5707 gSpectHUD
:= (P
[1][1] = '1');
5710 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5712 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5714 else if cmd
= 'r_showping' then
5716 if (Length(P
) > 1) and
5717 ((P
[1] = '1') or (P
[1] = '0')) then
5718 gShowPing
:= (P
[1][1] = '1');
5721 g_Console_Add(_lc
[I_MSG_PING_ON
])
5723 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5725 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5727 if Length(P
) > 1 then
5729 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5730 gGameSettings
.GoalLimit
:= 0
5735 if gGameSettings
.GameMode
= GM_DM
then
5737 stat
:= g_Player_GetStats();
5739 for a
:= 0 to High(stat
) do
5740 if stat
[a
].Frags
> b
then
5744 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5746 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5749 if g_Game_IsNet
then MH_SEND_GameSettings
;
5752 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5754 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5756 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5757 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5759 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5760 [gGameSettings
.TimeLimit
div 3600,
5761 (gGameSettings
.TimeLimit
div 60) mod 60,
5762 gGameSettings
.TimeLimit
mod 60]));
5763 if g_Game_IsNet
then MH_SEND_GameSettings
;
5765 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5767 if Length(P
) > 1 then
5769 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5770 gGameSettings
.MaxLives
:= 0
5774 stat
:= g_Player_GetStats();
5776 for a
:= 0 to High(stat
) do
5777 if stat
[a
].Lives
> b
then
5779 gGameSettings
.MaxLives
:=
5780 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5784 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5785 [gGameSettings
.MaxLives
]));
5786 if g_Game_IsNet
then MH_SEND_GameSettings
;
5791 procedure PrintHeapStats();
5795 hs
:= GetFPCHeapStatus();
5796 e_LogWriteLn ('v===== heap status =====v');
5797 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5798 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5799 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5800 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5801 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5802 e_LogWriteLn ('^=======================^');
5805 procedure DebugCommands(P
: SSArray
);
5812 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5813 if {gDebugMode}conIsCheatsEnabled
then
5815 cmd
:= LowerCase(P
[0]);
5816 if cmd
= 'd_window' then
5818 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
5819 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
5820 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5821 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5822 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
5824 else if cmd
= 'd_sounds' then
5826 if (Length(P
) > 1) and
5827 ((P
[1] = '1') or (P
[1] = '0')) then
5828 g_Debug_Sounds
:= (P
[1][1] = '1');
5830 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5832 else if cmd
= 'd_frames' then
5834 if (Length(P
) > 1) and
5835 ((P
[1] = '1') or (P
[1] = '0')) then
5836 g_Debug_Frames
:= (P
[1][1] = '1');
5838 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5840 else if cmd
= 'd_winmsg' then
5842 if (Length(P
) > 1) and
5843 ((P
[1] = '1') or (P
[1] = '0')) then
5844 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5846 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5848 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5850 if (Length(P
) > 1) and
5851 ((P
[1] = '1') or (P
[1] = '0')) then
5852 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5854 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5856 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5858 if Length(P
) > 1 then
5860 '0': g_debug_BotAIOff
:= 0;
5861 '1': g_debug_BotAIOff
:= 1;
5862 '2': g_debug_BotAIOff
:= 2;
5863 '3': g_debug_BotAIOff
:= 3;
5866 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5868 else if cmd
= 'd_monster' then
5870 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5871 if Length(P
) < 2 then
5873 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5874 g_Console_Add('ID | Name');
5875 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5876 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5877 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5880 a
:= StrToIntDef(P
[1], 0);
5881 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5882 a
:= g_Mons_TypeIdByName(P
[1]);
5884 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5885 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5888 with gPlayer1
.Obj
do
5890 mon
:= g_Monsters_Create(a
,
5891 X
+ Rect
.X
+ (Rect
.Width
div 2),
5892 Y
+ Rect
.Y
+ Rect
.Height
,
5893 gPlayer1
.Direction
, True);
5895 if (Length(P
) > 2) and (mon
<> nil) then
5897 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
5898 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
5899 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
5900 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
5901 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
5902 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5903 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5904 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5905 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5910 else if (cmd
= 'd_health') then
5912 if (Length(P
) > 1) and
5913 ((P
[1] = '1') or (P
[1] = '0')) then
5914 g_debug_HealthBar
:= (P
[1][1] = '1');
5916 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5918 else if (cmd
= 'd_player') then
5920 if (Length(P
) > 1) and
5921 ((P
[1] = '1') or (P
[1] = '0')) then
5922 g_debug_Player
:= (P
[1][1] = '1');
5924 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5926 else if (cmd
= 'd_mem') then
5932 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5936 procedure GameCheats(P
: SSArray
);
5942 if (not gGameOn
) or (not conIsCheatsEnabled
) then
5944 g_Console_Add('not available');
5950 g_Console_Add('where is the player?!');
5953 cmd
:= LowerCase(P
[0]);
5957 plr
.GodMode
:= not plr
.GodMode
;
5958 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5961 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5962 if cmd
= 'give' then
5964 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
5965 for f
:= 1 to High(P
) do
5967 cmd
:= LowerCase(P
[f
]);
5968 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
5969 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
5970 if cmd
= 'exit' then
5972 if gTriggers
<> nil then
5974 for a
:= 0 to High(gTriggers
) do
5976 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5978 g_Console_Add('player left the map');
5979 gExitByTrigger
:= True;
5980 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
5981 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
5989 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
5990 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
5991 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
5992 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
5993 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
5995 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
5996 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
5998 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
5999 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;
6001 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
6002 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
6004 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
6005 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
6007 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
6008 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
6010 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
6011 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
6012 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
6014 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
6015 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
6016 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
6017 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;
6018 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
6019 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
6021 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;
6022 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;
6023 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;
6024 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;
6025 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;
6026 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;
6028 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
6029 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;
6031 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;
6032 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;
6034 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
6036 if cmd
= 'ammo' then
6038 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
6039 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
6040 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
6041 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
6042 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
6043 g_Console_Add('player got some ammo');
6047 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
6048 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
6050 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
6051 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
6053 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
6054 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
6056 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
6057 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
6059 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
6061 if cmd
= 'weapons' then
6063 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
6064 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
6065 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
6066 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
6067 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
6068 plr
.GiveItem(ITEM_WEAPON_BFG
);
6069 g_Console_Add('player got weapons');
6073 if cmd
= 'keys' then
6075 plr
.GiveItem(ITEM_KEY_RED
);
6076 plr
.GiveItem(ITEM_KEY_GREEN
);
6077 plr
.GiveItem(ITEM_KEY_BLUE
);
6078 g_Console_Add('player got all keys');
6082 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
6087 if cmd
= 'open' then
6089 g_Console_Add('player activated sesame');
6090 g_Triggers_OpenAll();
6097 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6101 if cmd
= 'noclip' then
6104 g_Console_Add('wall hardeness adjusted');
6108 if cmd
= 'notarget' then
6110 plr
.NoTarget
:= not plr
.NoTarget
;
6111 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6115 if cmd
= 'noreload' then
6117 plr
.NoReload
:= not plr
.NoReload
;
6118 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6122 if cmd
= 'speedy' then
6124 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
6125 g_Console_Add('speed adjusted');
6129 if cmd
= 'jumpy' then
6131 VEL_JUMP
:= 30-VEL_JUMP
;
6132 g_Console_Add('jump height adjusted');
6136 if cmd
= 'automap' then
6138 gShowMap
:= not gShowMap
;
6139 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6143 if cmd
= 'aimline' then
6145 gAimLine
:= not gAimLine
;
6146 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6151 procedure GameCommands(P
: SSArray
);
6157 pl
: pTNetClient
= nil;
6165 cmd
:= LowerCase(P
[0]);
6167 if (cmd
= 'quit') or
6174 else if cmd
= 'pause' then
6176 if (g_ActiveWindow
= nil) then
6177 g_Game_Pause(not gPauseMain
);
6179 else if cmd
= 'endgame' then
6180 gExit
:= EXIT_SIMPLE
6181 else if cmd
= 'restart' then
6183 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
6185 if g_Game_IsClient
then
6187 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6192 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
6194 else if cmd
= 'kick' then
6196 if g_Game_IsServer
then
6198 if Length(P
) < 2 then
6200 g_Console_Add('kick <name>');
6205 g_Console_Add('kick <name>');
6209 if g_Game_IsNet
then
6210 pl
:= g_Net_Client_ByName(P
[1]);
6213 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6214 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
6215 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6216 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6217 g_Net_Slist_ServerPlayerLeaves();
6218 end else if gPlayers
<> nil then
6219 for a
:= Low(gPlayers
) to High(gPlayers
) do
6220 if gPlayers
[a
] <> nil then
6221 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
6223 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6224 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
6226 gPlayers
[a
].Lives
:= 0;
6227 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
6228 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
6229 g_Player_Remove(gPlayers
[a
].UID
);
6230 g_Net_Slist_ServerPlayerLeaves();
6231 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6235 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6237 else if cmd
= 'kick_id' then
6239 if g_Game_IsServer
and g_Game_IsNet
then
6241 if Length(P
) < 2 then
6243 g_Console_Add('kick_id <client ID>');
6248 g_Console_Add('kick_id <client ID>');
6252 a
:= StrToIntDef(P
[1], 0);
6253 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6255 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6257 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6258 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
6259 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
6260 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
6261 g_Net_Slist_ServerPlayerLeaves();
6265 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6267 else if cmd
= 'ban' then
6269 if g_Game_IsServer
and g_Game_IsNet
then
6271 if Length(P
) < 2 then
6273 g_Console_Add('ban <name>');
6278 g_Console_Add('ban <name>');
6282 pl
:= g_Net_Client_ByName(P
[1]);
6285 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6286 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
6287 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
6288 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6289 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6290 g_Net_Slist_ServerPlayerLeaves();
6292 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6294 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6296 else if cmd
= 'ban_id' then
6298 if g_Game_IsServer
and g_Game_IsNet
then
6300 if Length(P
) < 2 then
6302 g_Console_Add('ban_id <client ID>');
6307 g_Console_Add('ban_id <client ID>');
6311 a
:= StrToIntDef(P
[1], 0);
6312 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6313 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6315 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6316 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6317 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6318 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6319 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6320 g_Net_Slist_ServerPlayerLeaves();
6323 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6325 else if cmd
= 'permban' then
6327 if g_Game_IsServer
and g_Game_IsNet
then
6329 if Length(P
) < 2 then
6331 g_Console_Add('permban <name>');
6336 g_Console_Add('permban <name>');
6340 pl
:= g_Net_Client_ByName(P
[1]);
6343 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6344 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6345 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6346 g_Net_SaveBanList();
6347 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6348 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6349 g_Net_Slist_ServerPlayerLeaves();
6351 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6353 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6355 else if cmd
= 'permban_id' then
6357 if g_Game_IsServer
and g_Game_IsNet
then
6359 if Length(P
) < 2 then
6361 g_Console_Add('permban_id <client ID>');
6366 g_Console_Add('permban_id <client ID>');
6370 a
:= StrToIntDef(P
[1], 0);
6371 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6372 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6374 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6375 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6376 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6377 g_Net_SaveBanList();
6378 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6379 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6380 g_Net_Slist_ServerPlayerLeaves();
6383 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6385 else if cmd
= 'unban' then
6387 if g_Game_IsServer
and g_Game_IsNet
then
6389 if Length(P
) < 2 then
6391 g_Console_Add('unban <IP Address>');
6396 g_Console_Add('unban <IP Address>');
6400 if g_Net_UnbanHost(P
[1]) then
6402 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6403 g_Net_SaveBanList();
6405 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6407 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6409 else if cmd
= 'clientlist' then
6411 if g_Game_IsServer
and g_Game_IsNet
then
6414 if NetClients
<> nil then
6415 for a
:= Low(NetClients
) to High(NetClients
) do
6416 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6418 plr
:= g_Player_Get(NetClients
[a
].Player
);
6419 if plr
= nil then continue
;
6421 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6422 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6425 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6427 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6429 else if cmd
= 'connect' then
6431 if (NetMode
= NET_NONE
) then
6433 if Length(P
) < 2 then
6435 g_Console_Add('connect <IP> [port] [password]');
6440 g_Console_Add('connect <IP> [port] [password]');
6444 if Length(P
) > 2 then
6445 prt
:= StrToIntDef(P
[2], 25666)
6449 if Length(P
) > 3 then
6454 g_Game_StartClient(P
[1], prt
, pw
);
6457 else if cmd
= 'disconnect' then
6459 if (NetMode
= NET_CLIENT
) then
6462 else if cmd
= 'reconnect' then
6464 if (NetMode
= NET_SERVER
) then
6467 if (NetMode
= NET_CLIENT
) then
6470 gExit
:= EXIT_SIMPLE
;
6474 //TODO: Use last successful password to reconnect, instead of ''
6475 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6477 else if (cmd
= 'addbot') or
6478 (cmd
= 'bot_add') then
6480 if Length(P
) > 2 then
6481 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2), StrToIntDef(P
[2], 100))
6482 else if Length(P
) > 1 then
6483 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6485 g_Bot_Add(TEAM_NONE
, 2);
6487 else if cmd
= 'bot_addlist' then
6489 if Length(P
) > 1 then
6491 if Length(P
) = 2 then
6492 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6493 else if Length(P
) = 3 then
6494 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1), StrToIntDef(P
[2], 100))
6496 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6499 else if cmd
= 'bot_removeall' then
6501 else if cmd
= 'chat' then
6503 if g_Game_IsNet
then
6505 if Length(P
) > 1 then
6507 for a
:= 1 to High(P
) do
6508 chstr
:= chstr
+ P
[a
] + ' ';
6510 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6512 if Length(chstr
) < 1 then
6514 g_Console_Add('chat <text>');
6518 chstr
:= b_Text_Format(chstr
);
6519 if g_Game_IsClient
then
6520 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6522 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6525 g_Console_Add('chat <text>');
6527 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6529 else if cmd
= 'teamchat' then
6531 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6533 if Length(P
) > 1 then
6535 for a
:= 1 to High(P
) do
6536 chstr
:= chstr
+ P
[a
] + ' ';
6538 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6540 if Length(chstr
) < 1 then
6542 g_Console_Add('teamchat <text>');
6546 chstr
:= b_Text_Format(chstr
);
6547 if g_Game_IsClient
then
6548 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6550 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6551 gPlayer1Settings
.Team
);
6554 g_Console_Add('teamchat <text>');
6556 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6558 else if cmd
= 'game' then
6560 if gGameSettings
.GameType
<> GT_NONE
then
6562 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6565 if Length(P
) = 1 then
6567 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6570 // game not started yet, load fist map from some wad
6572 s
:= addWadExtension(P
[1]);
6573 found
:= e_FindResource(AllMapDirs
, s
);
6577 P
[1] := ExpandFileName(P
[1]);
6578 // if map not choosed then set first map
6579 if Length(P
) < 3 then
6582 P
[2] := g_Game_GetFirstMap(P
[1]);
6585 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6587 if g_Map_Exist(s
) then
6591 with gGameSettings
do
6593 GameMode
:= g_Game_TextToMode(gcGameMode
);
6594 if gSwitchGameMode
<> GM_NONE
then
6595 GameMode
:= gSwitchGameMode
;
6596 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6597 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6599 if Length(P
) >= 4 then
6600 b
:= StrToIntDef(P
[3], 1);
6601 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6602 GoalLimit
, MaxLives
, Options
, b
);
6607 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6609 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6611 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6613 else if cmd
= 'host' then
6615 if gGameSettings
.GameType
<> GT_NONE
then
6617 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6620 if Length(P
) < 4 then
6622 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6625 if not StrToIp(P
[1], listen
) then
6627 prt
:= StrToIntDef(P
[2], 25666);
6629 s
:= addWadExtension(P
[3]);
6630 found
:= e_FindResource(AllMapDirs
, s
);
6634 // get first map in wad, if not specified
6635 if Length(P
) < 5 then
6638 P
[4] := g_Game_GetFirstMap(P
[1]);
6640 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6641 if g_Map_Exist(s
) then
6645 with gGameSettings
do
6647 GameMode
:= g_Game_TextToMode(gcGameMode
);
6648 if gSwitchGameMode
<> GM_NONE
then GameMode
:= gSwitchGameMode
;
6649 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6650 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6652 if Length(P
) >= 6 then
6653 b
:= StrToIntDef(P
[5], 0);
6654 g_Game_StartServer(s
, GameMode
, TimeLimit
, GoalLimit
, MaxLives
, Options
, b
, listen
, prt
)
6660 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6662 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]))
6667 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]))
6670 else if cmd
= 'map' then
6672 if Length(P
) = 1 then
6674 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6676 g_Console_Add(cmd
+ ' <MAP>');
6677 g_Console_Add(cmd
+ ' <WAD> [MAP]')
6681 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6686 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6688 if Length(P
) < 3 then
6690 // first param is map or wad
6691 s
:= UpperCase(P
[1]);
6692 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6694 gExitByTrigger
:= False;
6697 // already in game, finish current map
6699 gExit
:= EXIT_ENDLEVELCUSTOM
;
6703 // intermission, so change map immediately
6710 found
:= e_FindResource(AllMapDirs
, s
);
6712 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, 'WAD ' + P
[1]]));
6715 // no such map, found wad
6717 P
[1] := ExpandFileName(pw
);
6718 P
[2] := g_Game_GetFirstMap(P
[1]);
6719 s
:= P
[1] + ':\' + P
[2];
6720 if g_Map_Exist(s
) then
6722 gExitByTrigger
:= False;
6725 // already in game, finish current map
6727 gExit
:= EXIT_ENDLEVELCUSTOM
6731 // intermission, so change map immediately
6738 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6740 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6745 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6751 s
:= addWadExtension(P
[1]);
6752 found
:= e_FindResource(AllMapDirs
, s
);
6756 P
[2] := UpperCase(P
[2]);
6757 s
:= P
[1] + ':\' + P
[2];
6758 if g_Map_Exist(s
) then
6760 gExitByTrigger
:= False;
6764 gExit
:= EXIT_ENDLEVELCUSTOM
6773 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6778 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6784 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6788 else if cmd
= 'nextmap' then
6790 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6792 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6797 if Length(P
) = 1 then
6799 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6801 g_Console_Add(cmd
+ ' <MAP>');
6802 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6807 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6813 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6815 if Length(P
) < 3 then
6817 // first param is map or wad
6818 s
:= UpperCase(P
[1]);
6819 if g_Map_Exist(gGameSettings
.WAD
+ ':\' + s
) then
6822 gExitByTrigger
:= False;
6828 // no such map, found wad
6829 pw
:= addWadExtension(P
[1]);
6830 found
:= e_FindResource(MapDirs
, pw
);
6832 found
:= e_FindResource(WadDirs
, pw
);
6834 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6837 // map not specified, select first map
6839 P
[2] := g_Game_GetFirstMap(P
[1]);
6840 s
:= P
[1] + ':\' + P
[2];
6841 if g_Map_Exist(s
) then
6843 gExitByTrigger
:= False;
6850 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6852 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6857 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6863 // specified two params wad + map
6864 pw
:= addWadExtension(P
[1]);
6865 found
:= e_FindResource(MapDirs
, pw
);
6867 found
:= e_FindResource(MapDirs
, pw
);
6871 P
[2] := UpperCase(P
[2]);
6872 s
:= P
[1] + ':\' + P
[2];
6873 if g_Map_Exist(s
) then
6875 gExitByTrigger
:= False;
6881 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]))
6886 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]))
6892 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6897 if gNextMap
= '' then
6898 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
6900 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]))
6904 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
6908 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6912 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6914 gExitByTrigger
:= False;
6915 // next map not specified, try to find trigger EXIT
6916 if (gNextMap
= '') and (gTriggers
<> nil) then
6918 for a
:= 0 to High(gTriggers
) do
6920 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6922 gExitByTrigger
:= True;
6923 //gNextMap := gTriggers[a].Data.MapName;
6924 gNextMap
:= gTriggers
[a
].tgcMap
;
6929 if gNextMap
= '' then
6930 gNextMap
:= g_Game_GetNextMap();
6931 if not isWadPath(gNextMap
) then
6932 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
6935 if g_Map_Exist(s
) then
6936 gExit
:= EXIT_ENDLEVELCUSTOM
6938 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]))
6942 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
])
6946 else if (cmd
= 'event') then
6948 if (Length(P
) <= 1) then
6950 for a
:= 0 to High(gEvents
) do
6951 if gEvents
[a
].Command
= '' then
6952 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6954 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6957 if (Length(P
) = 2) then
6959 for a
:= 0 to High(gEvents
) do
6960 if gEvents
[a
].Name
= P
[1] then
6961 if gEvents
[a
].Command
= '' then
6962 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6964 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6967 for a
:= 0 to High(gEvents
) do
6968 if gEvents
[a
].Name
= P
[1] then
6970 gEvents
[a
].Command
:= '';
6971 for b
:= 2 to High(P
) do
6972 if Pos(' ', P
[b
]) = 0 then
6973 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6975 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6976 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6980 else if cmd
= 'suicide' then
6984 if g_Game_IsClient
then
6985 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6988 if gPlayer1
<> nil then
6989 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6990 if gPlayer2
<> nil then
6991 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6995 else if cmd
= 'screenshot' then
6999 else if cmd
= 'weapon' then
7001 if Length(p
) = 2 then
7003 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7004 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7005 gSelectWeapon
[0, a
] := True
7008 else if (cmd
= 'p1_weapon') or (cmd
= 'p2_weapon') then
7010 if Length(p
) = 2 then
7012 a
:= WP_FIRST
+ StrToInt(p
[1]) - 1;
7013 b
:= ord(cmd
[2]) - ord('1');
7014 if (a
>= WP_FIRST
) and (a
<= WP_LAST
) then
7015 gSelectWeapon
[b
, a
] := True
7018 // Êîìàíäû Ñâîåé èãðû:
7019 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
7021 if cmd
= 'bot_addred' then
7023 if Length(P
) > 1 then
7024 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
7026 g_Bot_Add(TEAM_RED
, 2);
7028 else if cmd
= 'bot_addblue' then
7030 if Length(P
) > 1 then
7031 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
7033 g_Bot_Add(TEAM_BLUE
, 2);
7035 else if cmd
= 'spectate' then
7041 else if cmd
= 'say' then
7043 if g_Game_IsServer
and g_Game_IsNet
then
7045 if Length(P
) > 1 then
7048 for a
:= 1 to High(P
) do
7049 chstr
:= chstr
+ P
[a
] + ' ';
7051 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7053 if Length(chstr
) < 1 then
7055 g_Console_Add('say <text>');
7059 chstr
:= b_Text_Format(chstr
);
7060 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
7062 else g_Console_Add('say <text>');
7064 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7066 else if cmd
= 'tell' then
7068 if g_Game_IsServer
and g_Game_IsNet
then
7070 if (Length(P
) > 2) and (P
[1] <> '') then
7073 for a
:= 2 to High(P
) do
7074 chstr
:= chstr
+ P
[a
] + ' ';
7076 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7078 if Length(chstr
) < 1 then
7080 g_Console_Add('tell <playername> <text>');
7084 pl
:= g_Net_Client_ByName(P
[1]);
7086 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
7088 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
7090 else g_Console_Add('tell <playername> <text>');
7092 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
7094 else if (cmd
= 'overtime') and not g_Game_IsClient
then
7096 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
7098 // Äîïîëíèòåëüíîå âðåìÿ:
7099 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
7101 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
7102 [gGameSettings
.TimeLimit
div 3600,
7103 (gGameSettings
.TimeLimit
div 60) mod 60,
7104 gGameSettings
.TimeLimit
mod 60]));
7105 if g_Game_IsNet
then MH_SEND_GameSettings
;
7107 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
7109 if (Length(P
) <= 1) then
7110 g_Console_Add('rcon_password <password>')
7112 MC_SEND_RCONPassword(P
[1]);
7114 else if cmd
= 'rcon' then
7116 if g_Game_IsClient
then
7118 if Length(P
) > 1 then
7121 for a
:= 1 to High(P
) do
7122 chstr
:= chstr
+ P
[a
] + ' ';
7124 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7126 if Length(chstr
) < 1 then
7128 g_Console_Add('rcon <command>');
7132 MC_SEND_RCONCommand(chstr
);
7134 else g_Console_Add('rcon <command>');
7137 else if cmd
= 'ready' then
7139 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
7140 gLMSRespawnTime
:= gTime
+ 100;
7142 else if (cmd
= 'callvote') and g_Game_IsNet
then
7144 if Length(P
) > 1 then
7147 for a
:= 1 to High(P
) do begin
7148 if a
> 1 then chstr
:= chstr
+ ' ';
7149 chstr
:= chstr
+ P
[a
];
7152 if Length(chstr
) > 200 then SetLength(chstr
, 200);
7154 if Length(chstr
) < 1 then
7156 g_Console_Add('callvote <command>');
7160 if g_Game_IsClient
then
7161 MC_SEND_Vote(True, chstr
)
7163 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
7164 g_Console_Process('vote', True);
7167 g_Console_Add('callvote <command>');
7169 else if (cmd
= 'vote') and g_Game_IsNet
then
7171 if g_Game_IsClient
then
7173 else if gVoteInProgress
then
7175 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7176 a
:= Floor((NetClientCount
+1)/2.0) + 1
7178 a
:= Floor(NetClientCount
/2.0) + 1;
7183 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7184 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7190 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
7191 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
7199 procedure g_TakeScreenShot
;
7200 var s
: TStream
; t
: TDateTime
; date
, name
: String;
7202 if e_NoGraphics
then Exit
;
7204 DateTimeToString(date
, 'yyyy-mm-dd-hh-nn-ss', t
);
7205 name
:= 'screenshot-' + date
+ '.png';
7207 s
:= e_CreateResource(ScreenshotDirs
, name
);
7208 e_MakeScreenshot(s
, gScreenWidth
, gScreenHeight
);
7209 g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [name
]))
7211 g_Console_Add('oh shit, i can''t create screenshot!')
7215 procedure g_Game_InGameMenu(Show
: Boolean);
7217 if (g_ActiveWindow
= nil) and Show
then
7219 if gGameSettings
.GameType
= GT_SINGLE
then
7220 g_GUI_ShowWindow('GameSingleMenu')
7223 if g_Game_IsClient
then
7224 g_GUI_ShowWindow('GameClientMenu')
7226 if g_Game_IsNet
then
7227 g_GUI_ShowWindow('GameServerMenu')
7229 g_GUI_ShowWindow('GameCustomMenu');
7231 g_Sound_PlayEx('MENU_OPEN');
7233 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7234 if (not g_Game_IsNet
) then
7238 if (g_ActiveWindow
<> nil) and (not Show
) then
7240 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7241 if (not g_Game_IsNet
) then
7242 g_Game_Pause(False);
7246 procedure g_Game_Pause (Enable
: Boolean);
7250 if not gGameOn
then exit
;
7252 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7255 gPauseMain
:= Enable
;
7257 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7260 procedure g_Game_HolmesPause (Enable
: Boolean);
7264 if not gGameOn
then exit
;
7265 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
7268 gPauseHolmes
:= Enable
;
7270 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
7273 procedure g_Game_PauseAllSounds(Enable
: Boolean);
7278 if gTriggers
<> nil then
7279 for i
:= 0 to High(gTriggers
) do
7280 with gTriggers
[i
] do
7281 if (TriggerType
= TRIGGER_SOUND
) and
7283 Sound
.IsPlaying() then
7285 Sound
.Pause(Enable
);
7289 if gPlayers
<> nil then
7290 for i
:= 0 to High(gPlayers
) do
7291 if gPlayers
[i
] <> nil then
7292 gPlayers
[i
].PauseSounds(Enable
);
7295 if gMusic
<> nil then
7296 gMusic
.Pause(Enable
);
7299 procedure g_Game_StopAllSounds(all
: Boolean);
7303 if gTriggers
<> nil then
7304 for i
:= 0 to High(gTriggers
) do
7305 with gTriggers
[i
] do
7306 if (TriggerType
= TRIGGER_SOUND
) and
7310 if gMusic
<> nil then
7317 procedure g_Game_UpdateTriggerSounds
;
7320 if gTriggers
<> nil then
7321 for i
:= 0 to High(gTriggers
) do
7322 with gTriggers
[i
] do
7323 if (TriggerType
= TRIGGER_SOUND
) and (Sound
<> nil) and tgcLocal
and Sound
.IsPlaying() then
7324 Sound
.SetCoordsRect(X
, Y
, Width
, Height
, tgcVolume
/ 255.0)
7327 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
7330 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
7335 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
7340 if gSpectMode
<> SPECT_PLAYERS
then
7342 if gSpectPID1
= UID
then
7347 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7354 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7359 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7364 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7369 if gSpectMode
<> SPECT_PLAYERS
then
7371 Pl
:= g_Player_Get(gSpectPID1
);
7372 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7377 if gSpectViewTwo
then
7379 Pl
:= g_Player_Get(gSpectPID2
);
7380 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7388 procedure g_Game_Message(Msg
: string; Time
: Word);
7390 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7391 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7392 MessageTime
:= Time
;
7395 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7397 punct
: Array[0..13] of String =
7398 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7404 function IsPunctuation(S
: String): Boolean;
7409 if Length(S
) <> 1 then
7411 for i
:= Low(punct
) to High(punct
) do
7412 if S
= punct
[i
] then
7418 function FilterPunctuation(S
: String): String;
7422 for i
:= Low(punct
) to High(punct
) do
7423 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7429 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7431 // remove player name
7432 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7433 // for FullWord check
7434 Text := toLowerCase1251(' ' + Text + ' ');
7435 fpText
:= FilterPunctuation(Text);
7437 for i
:= 0 to Length(gChatSounds
) - 1 do
7440 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7442 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7443 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7445 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7451 gChatSounds
[i
].Sound
.Play();
7457 g_Sound_PlayEx('SOUND_GAME_RADIO');
7460 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7469 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7473 if goodsnd
[a
].IsPlaying() then
7476 goodsnd
[Random(4)].Play();
7479 procedure g_Game_Announce_KillCombo(Param
: Integer);
7486 UID
:= Param
and $FFFF;
7491 Pl
:= g_Player_Get(UID
);
7500 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7504 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7508 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7512 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7520 if not g_Game_IsWatchedPlayer(UID
) then
7523 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7527 if killsnd
[n
].IsPlaying() then
7532 procedure g_Game_Announce_BodyKill(SpawnerUID
: Word);
7541 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7545 if hahasnd
[a
].IsPlaying() then
7548 hahasnd
[Random(3)].Play();
7551 procedure g_Game_StartVote(Command
, Initiator
: string);
7555 if not gVotesEnabled
then Exit
;
7556 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7557 if gVoteInProgress
or gVotePassed
then
7559 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7560 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7563 gVoteInProgress
:= True;
7564 gVotePassed
:= False;
7565 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7568 gVoteCommand
:= Command
;
7570 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7571 Need
:= Floor((NetClientCount
+1)/2.0)+1
7573 Need
:= Floor(NetClientCount
/2.0)+1;
7574 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7575 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7578 procedure g_Game_CheckVote
;
7582 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7583 if not gVoteInProgress
then Exit
;
7585 if (gTime
>= gVoteTimer
) then
7587 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7588 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7590 Need
:= Floor(NetClientCount
/2.0) + 1;
7591 if gVoteCount
>= Need
then
7593 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7594 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7595 gVotePassed
:= True;
7596 gVoteCmdTimer
:= gTime
+ 5000;
7600 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7601 MH_SEND_VoteEvent(NET_VE_FAILED
);
7603 if NetClients
<> nil then
7604 for I
:= Low(NetClients
) to High(NetClients
) do
7605 if NetClients
[i
].Used
then
7606 NetClients
[i
].Voted
:= False;
7607 gVoteInProgress
:= False;
7613 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7614 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7616 Need
:= Floor(NetClientCount
/2.0) + 1;
7617 if gVoteCount
>= Need
then
7619 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7620 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7621 gVoteInProgress
:= False;
7622 gVotePassed
:= True;
7623 gVoteCmdTimer
:= gTime
+ 5000;
7626 if NetClients
<> nil then
7627 for I
:= Low(NetClients
) to High(NetClients
) do
7628 if NetClients
[i
].Used
then
7629 NetClients
[i
].Voted
:= False;
7634 procedure g_Game_LoadMapList(FileName
: string);
7642 if not FileExists(FileName
) then Exit
;
7644 AssignFile(ListFile
, FileName
);
7646 while not EOF(ListFile
) do
7648 ReadLn(ListFile
, s
);
7651 if s
= '' then Continue
;
7653 SetLength(MapList
, Length(MapList
)+1);
7654 MapList
[High(MapList
)] := s
;
7656 CloseFile(ListFile
);
7659 procedure g_Game_SetDebugMode();
7662 // ×èòû (äàæå â ñâîåé èãðå):
7666 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7670 if Length(LoadingStat
.Msgs
) = 0 then
7676 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7677 if NextMsg
= Length(Msgs
) then
7679 for i
:= 0 to High(Msgs
)-1 do
7680 Msgs
[i
] := Msgs
[i
+1];
7688 Msgs
[NextMsg
-1] := Text;
7692 PBarWasHere
:= false;
7695 g_ActiveWindow
:= nil;
7697 ProcessLoading(true);
7700 procedure g_Game_StepLoading(Value
: Integer = -1);
7711 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
7719 procedure g_Game_ClearLoading();
7728 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7729 if len
< 1 then len
:= 1;
7730 SetLength(Msgs
, len
);
7731 for len
:= Low(Msgs
) to High(Msgs
) do
7734 PBarWasHere
:= false;
7738 procedure Parse_Params(var pars
: TParamStrValues
);
7745 while i
<= ParamCount
do
7748 if (s
[1] = '-') and (Length(s
) > 1) then
7750 if (s
[2] = '-') and (Length(s
) > 2) then
7751 begin // Îäèíî÷íûé ïàðàìåòð
7752 SetLength(pars
, Length(pars
) + 1);
7753 with pars
[High(pars
)] do
7755 Name
:= LowerCase(s
);
7760 if (i
< ParamCount
) then
7761 begin // Ïàðàìåòð ñî çíà÷åíèåì
7763 SetLength(pars
, Length(pars
) + 1);
7764 with pars
[High(pars
)] do
7766 Name
:= LowerCase(s
);
7767 Value
:= LowerCase(ParamStr(i
));
7776 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
7781 for i
:= 0 to High(pars
) do
7782 if pars
[i
].Name
= aName
then
7784 Result
:= pars
[i
].Value
;
7789 procedure g_Game_Process_Params();
7791 pars
: TParamStrValues
;
7794 LimT
, LimS
: Integer;
7805 s
:= Find_Param_Value(pars
, '--debug');
7808 g_Game_SetDebugMode();
7809 s
:= Find_Param_Value(pars
, '--netdump');
7814 // Connect when game loads
7815 ip
:= Find_Param_Value(pars
, '-connect');
7819 s
:= Find_Param_Value(pars
, '-port');
7820 if (s
= '') or not TryStrToInt(s
, Port
) then
7823 s
:= Find_Param_Value(pars
, '-pw');
7825 g_Game_StartClient(ip
, Port
, s
);
7829 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
7832 gDefaultMegawadStart
:= s
;
7835 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
7836 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
7838 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
7841 // Start map when game loads:
7842 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
7843 if isWadPath(map
) then
7846 s
:= Find_Param_Value(pars
, '-gm');
7847 GMode
:= g_Game_TextToMode(s
);
7848 if GMode
= GM_NONE
then GMode
:= GM_DM
;
7849 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
7852 s
:= Find_Param_Value(pars
, '-limt');
7853 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
7859 s
:= Find_Param_Value(pars
, '-lims');
7860 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
7866 s
:= Find_Param_Value(pars
, '-lives');
7867 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
7873 s
:= Find_Param_Value(pars
, '-opt');
7875 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
7877 Opt
:= StrToIntDef(s
, 0);
7879 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
7882 s
:= Find_Param_Value(pars
, '--close');
7886 // Override map to test:
7887 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
7890 if e_IsValidResourceName(s
) then
7891 e_FindResource(AllMapDirs
, s
);
7892 gTestMap
:= ExpandFileName(s
);
7895 // Delete test map after play:
7896 s
:= Find_Param_Value(pars
, '--testdelete');
7899 //gMapToDelete := MapsDir + map;
7900 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
7904 // Delete temporary WAD after play:
7905 s
:= Find_Param_Value(pars
, '--tempdelete');
7906 if (s
<> '') and (gTestMap
<> '') then
7908 gMapToDelete
:= gTestMap
;
7909 gTempDelete
:= True;
7912 // Number of players:
7913 s
:= Find_Param_Value(pars
, '-pl');
7915 n
:= DEFAULT_PLAYERS
7917 n
:= StrToIntDef(s
, DEFAULT_PLAYERS
);
7920 s
:= Find_Param_Value(pars
, '-port');
7921 if (s
= '') or not TryStrToInt(s
, Port
) then
7922 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
7924 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
7927 // Execute script when game loads:
7928 s
:= Find_Param_Value(pars
, '-exec');
7931 // if not isWadPath(s) then
7932 // s := GameDir + '/' + s;
7937 if IOResult
<> 0 then
7939 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7940 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7944 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
7945 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7950 if IOResult
<> 0 then
7952 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7953 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7957 if Pos('#', s
) <> 1 then // script comment
7958 g_Console_Process(s
, True);
7969 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7970 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7971 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7972 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7974 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7975 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7976 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7977 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7979 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7980 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7982 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7983 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7985 {$IFDEF ENABLE_HOLMES}
7986 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7989 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7991 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
7993 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7994 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7996 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7997 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7999 conRegVar('r_showfps', @gShowFPS
, 'draw fps counter', 'draw fps counter');
8000 conRegVar('r_showtime', @gShowTime
, 'show game time', 'show game time');