1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 g_basic
, g_player
, e_graphics
, g_res_downloader
,
25 g_sound
, g_gui
, utils
, md5
, mempool
, xprofiler
,
29 TGameSettings
= record
45 TDelayedEvent
= record
54 Sound
: TPlayableSound
;
55 Tags
: Array of String;
59 TPlayerSettings
= record
78 function g_Game_IsNet(): Boolean;
79 function g_Game_IsServer(): Boolean;
80 function g_Game_IsClient(): Boolean;
81 procedure g_Game_Init();
82 procedure g_Game_Free (freeTextures
: Boolean=true);
83 procedure g_Game_LoadData();
84 procedure g_Game_FreeData();
85 procedure g_Game_Update();
86 procedure g_Game_Draw();
87 procedure g_Game_Quit();
88 procedure g_Game_SetupScreenSize();
89 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
90 function g_Game_ModeToText(Mode
: Byte): string;
91 function g_Game_TextToMode(Mode
: string): Byte;
92 procedure g_Game_ExecuteEvent(Name
: String);
93 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
94 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
95 procedure g_Game_RemovePlayer();
96 procedure g_Game_Spectate();
97 procedure g_Game_SpectateCenterView();
98 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
99 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
100 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
101 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
102 procedure g_Game_Restart();
103 procedure g_Game_RestartLevel();
104 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
105 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
106 procedure g_Game_SaveOptions();
107 function g_Game_StartMap(Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
108 procedure g_Game_ChangeMap(const MapPath
: String);
109 procedure g_Game_ExitLevel(const Map
: AnsiString);
110 function g_Game_GetFirstMap(WAD
: String): String;
111 function g_Game_GetNextMap(): String;
112 procedure g_Game_NextLevel();
113 procedure g_Game_Pause(Enable
: Boolean);
114 procedure g_Game_HolmesPause(Enable
: Boolean);
115 procedure g_Game_InGameMenu(Show
: Boolean);
116 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
117 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
118 procedure g_Game_Message(Msg
: String; Time
: Word);
119 procedure g_Game_LoadMapList(FileName
: String);
120 procedure g_Game_PauseAllSounds(Enable
: Boolean);
121 procedure g_Game_StopAllSounds(all
: Boolean);
122 procedure g_Game_UpdateTriggerSounds();
123 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
124 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
125 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
126 procedure g_Game_Announce_KillCombo(Param
: Integer);
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();
145 { procedure SetWinPause(Enable: Boolean); }
150 LOADING_SHOW_STEP
= 100;
151 LOADING_INTERLINE
= 20;
166 MESSAGE_DIKEY
= WM_USER
+ 1;
171 EXIT_ENDLEVELSINGLE
= 4;
172 EXIT_ENDLEVELCUSTOM
= 5;
174 GAME_OPTION_RESERVED
= 1;
175 GAME_OPTION_TEAMDAMAGE
= 2;
176 GAME_OPTION_ALLOWEXIT
= 4;
177 GAME_OPTION_WEAPONSTAY
= 8;
178 GAME_OPTION_MONSTERS
= 16;
179 GAME_OPTION_BOTVSPLAYER
= 32;
180 GAME_OPTION_BOTVSMONSTER
= 64;
185 STATE_INTERCUSTOM
= 3;
186 STATE_INTERSINGLE
= 4;
192 LMS_RESPAWN_NONE
= 0;
193 LMS_RESPAWN_WARMUP
= 1;
194 LMS_RESPAWN_FINAL
= 2;
210 CONFIG_FILENAME
= 'Doom2DF.cfg';
211 LOG_FILENAME
= 'Doom2DF.log';
213 TEST_MAP_NAME
= '$$$_TEST_$$$';
215 STD_PLAYER_MODEL
= 'Doomer';
219 gGameSettings
: TGameSettings
;
220 gPlayer1Settings
: TPlayerSettings
;
221 gPlayer2Settings
: TPlayerSettings
;
223 gPlayerScreenSize
: TDFPoint
;
224 gPlayer1ScreenCoord
: TDFPoint
;
225 gPlayer2ScreenCoord
: TDFPoint
;
226 gPlayer1
: TPlayer
= nil;
227 gPlayer2
: TPlayer
= nil;
228 gPlayerDrawn
: TPlayer
= nil;
230 gSwitchGameMode
: Byte = GM_DM
;
231 gHearPoint1
, gHearPoint2
: THearPoint
;
232 gSoundEffectsDF
: Boolean = False;
233 gSoundTriggerTime
: Word = 0;
234 gAnnouncer
: Byte = ANNOUNCE_NONE
;
235 goodsnd
: array[0..3] of TPlayableSound
;
236 killsnd
: array[0..3] of TPlayableSound
;
237 gDefInterTime
: ShortInt = -1;
238 gInterEndTime
: LongWord = 0;
239 gInterTime
: LongWord = 0;
240 gServInterTime
: Byte = 0;
241 gGameStartTime
: LongWord = 0;
242 gTotalMonsters
: Integer = 0;
243 gPauseMain
: Boolean = false;
244 gPauseHolmes
: Boolean = false;
245 gShowTime
: Boolean = True;
246 gShowFPS
: Boolean = False;
247 gShowGoals
: Boolean = True;
248 gShowStat
: Boolean = True;
249 gShowKillMsg
: Boolean = True;
250 gShowLives
: Boolean = True;
251 gShowPing
: Boolean = False;
252 gShowMap
: Boolean = False;
254 gState
: Byte = STATE_NONE
;
256 sWidth
, sHeight
: Word;
257 gSpectMode
: Byte = SPECT_NONE
;
258 gSpectHUD
: Boolean = True;
259 gSpectKeyPress
: Boolean = False;
260 gSpectX
: Integer = 0;
261 gSpectY
: Integer = 0;
262 gSpectStep
: Byte = 8;
263 gSpectViewTwo
: Boolean = False;
264 gSpectPID1
: Integer = -1;
265 gSpectPID2
: Integer = -1;
266 gMusic
: TMusic
= nil;
267 gLoadGameMode
: Boolean;
268 gCheats
: Boolean = False;
269 gMapOnce
: Boolean = False;
270 gMapToDelete
: String;
271 gTempDelete
: Boolean = False;
272 gLastMap
: Boolean = False;
273 gWinPosX
, gWinPosY
: Integer;
274 gWinSizeX
, gWinSizeY
: Integer;
275 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
276 gWinActive
: Boolean = True; // by default window is active, lol
277 gResolutionChange
: Boolean = False;
278 gRC_Width
, gRC_Height
: Word;
279 gRC_FullScreen
, gRC_Maximized
: Boolean;
280 gLanguageChange
: Boolean = False;
281 gDebugMode
: Boolean = False;
282 g_debug_Sounds
: Boolean = False;
283 g_debug_Frames
: Boolean = False;
284 g_debug_WinMsgs
: Boolean = False;
285 g_debug_MonsterOff
: Boolean = False;
286 g_debug_BotAIOff
: Byte = 0;
287 g_debug_HealthBar
: Boolean = False;
288 g_Debug_Player
: Boolean = False;
289 gCoopMonstersKilled
: Word = 0;
290 gCoopSecretsFound
: Word = 0;
291 gCoopTotalMonstersKilled
: Word = 0;
292 gCoopTotalSecretsFound
: Word = 0;
293 gCoopTotalMonsters
: Word = 0;
294 gCoopTotalSecrets
: Word = 0;
295 gStatsOff
: Boolean = False;
296 gStatsPressed
: Boolean = False;
297 gExitByTrigger
: Boolean = False;
298 gNextMap
: String = '';
299 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
300 gLMSRespawnTime
: Cardinal = 0;
301 gLMSSoftSpawn
: Boolean = False;
302 gMissionFailed
: Boolean = False;
303 gVoteInProgress
: Boolean = False;
304 gVotePassed
: Boolean = False;
305 gVoteCommand
: string = '';
306 gVoteTimer
: Cardinal = 0;
307 gVoteCmdTimer
: Cardinal = 0;
308 gVoteCount
: Integer = 0;
309 gVoteTimeout
: Cardinal = 30;
310 gVoted
: Boolean = False;
311 gVotesEnabled
: Boolean = True;
312 gEvents
: Array of TGameEvent
;
313 gDelayedEvents
: Array of TDelayedEvent
;
314 gUseChatSounds
: Boolean = True;
315 gChatSounds
: Array of TChatSound
;
317 g_dbg_ignore_bounds
: Boolean = false;
318 r_smallmap_h
: Integer = 0; // 0: left; 1: center; 2: right
319 r_smallmap_v
: Integer = 2; // 0: top; 1: center; 2: bottom
321 // move button values:
322 // bits 0-1: l/r state:
323 // 0: neither left, nor right pressed
326 // bits 4-5: l/r state when strafe was pressed
327 P1MoveButton
: Byte = 0;
328 P2MoveButton
: Byte = 0;
330 g_profile_frame_update
: Boolean = false;
331 g_profile_frame_draw
: Boolean = false;
332 g_profile_collision
: Boolean = false;
333 g_profile_los
: Boolean = false;
334 g_profile_history_size
: Integer = 1000;
336 g_rlayer_back
: Boolean = true;
337 g_rlayer_step
: Boolean = true;
338 g_rlayer_wall
: Boolean = true;
339 g_rlayer_door
: Boolean = true;
340 g_rlayer_acid1
: Boolean = true;
341 g_rlayer_acid2
: Boolean = true;
342 g_rlayer_water
: Boolean = true;
343 g_rlayer_fore
: Boolean = true;
346 procedure g_ResetDynlights ();
347 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
348 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
350 function conIsCheatsEnabled (): Boolean; inline;
351 function gPause (): Boolean; inline;
362 {$IFDEF ENABLE_HOLMES}
365 e_texture
, g_textures
, g_main
, g_window
, g_menu
,
366 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
367 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
368 g_triggers
, g_monsters
, e_sound
, CONFIG
,
370 ENet
, e_msg
, g_netmsg
, g_netmaster
,
375 hasPBarGfx
: Boolean = false;
378 // ////////////////////////////////////////////////////////////////////////// //
379 function gPause (): Boolean; inline; begin result
:= gPauseMain
or gPauseHolmes
; end;
382 // ////////////////////////////////////////////////////////////////////////// //
383 function conIsCheatsEnabled (): Boolean; inline;
386 if g_Game_IsNet
then exit
;
387 if not gDebugMode
then
389 //if not gCheats then exit;
390 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
391 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then exit
;
397 // ////////////////////////////////////////////////////////////////////////// //
399 profileFrameDraw
: TProfiler
= nil;
402 // ////////////////////////////////////////////////////////////////////////// //
405 x
, y
, radius
: Integer;
408 exploRadius
: Integer;
412 g_dynLights
: array of TDynLight
= nil;
413 g_dynLightCount
: Integer = 0;
414 g_playerLight
: Boolean = false;
416 procedure g_ResetDynlights ();
420 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
422 for idx
:= 0 to g_dynLightCount
-1 do
424 if g_dynLights
[idx
].exploCount
= -666 then
431 Inc(g_dynLights
[idx
].exploCount
);
432 if (g_dynLights
[idx
].exploCount
< 10) then
434 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
435 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
436 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
437 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
442 g_dynLightCount
:= lnum
;
445 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
447 if not gwin_has_stencil
then exit
;
448 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
449 g_dynLights
[g_dynLightCount
].x
:= x
;
450 g_dynLights
[g_dynLightCount
].y
:= y
;
451 g_dynLights
[g_dynLightCount
].radius
:= radius
;
452 g_dynLights
[g_dynLightCount
].r
:= r
;
453 g_dynLights
[g_dynLightCount
].g
:= g
;
454 g_dynLights
[g_dynLightCount
].b
:= b
;
455 g_dynLights
[g_dynLightCount
].a
:= a
;
456 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
457 Inc(g_dynLightCount
);
460 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: 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
:= 0;
467 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
468 g_dynLights
[g_dynLightCount
].r
:= r
;
469 g_dynLights
[g_dynLightCount
].g
:= g
;
470 g_dynLights
[g_dynLightCount
].b
:= b
;
471 g_dynLights
[g_dynLightCount
].a
:= 0;
472 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
473 Inc(g_dynLightCount
);
477 // ////////////////////////////////////////////////////////////////////////// //
478 function calcProfilesHeight (prof
: TProfiler
): Integer;
481 if (prof
= nil) then exit
;
482 if (length(prof
.bars
) = 0) then exit
;
483 result
:= length(prof
.bars
)*(16+2);
487 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
494 if (prof
= nil) then exit
;
496 if (length(prof
.bars
) = 0) then exit
;
498 hgt
:= calcProfilesHeight(prof
);
499 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
500 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
502 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
503 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
504 e_DarkenQuadWH(x
, y
, wdt
, hgt
, 150);
507 for ii
:= 0 to High(prof
.bars
) do
509 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);
516 // ////////////////////////////////////////////////////////////////////////// //
518 TEndCustomGameStat
= record
519 PlayerStat
: TPlayerStatArray
;
523 Map
, MapName
: String;
526 TEndSingleGameStat
= record
527 PlayerStat
: Array [0..1] of record
533 TotalSecrets
: Integer;
536 TLoadingStat
= record
540 Msgs
: Array of String;
542 PBarWasHere
: Boolean; // did we draw a progress bar for this message?
545 TParamStrValue
= record
550 TParamStrValues
= Array of TParamStrValue
;
553 INTER_ACTION_TEXT
= 1;
554 INTER_ACTION_PIC
= 2;
555 INTER_ACTION_MUSIC
= 3;
559 FPSCounter
, UPSCounter
: Word;
560 FPSTime
, UPSTime
: LongWord;
561 DataLoaded
: Boolean = False;
562 LastScreenShot
: Int64;
563 IsDrawStat
: Boolean = False;
564 CustomStat
: TEndCustomGameStat
;
565 SingleStat
: TEndSingleGameStat
;
566 LoadingStat
: TLoadingStat
;
567 EndingGameCounter
: Byte = 0;
570 MessageLineLength
: Integer = 80;
571 MapList
: SSArray
= nil;
572 MapIndex
: Integer = -1;
578 text: Array of ShortString;
579 anim
: Array of ShortString;
580 pic
: Array of ShortString;
581 mus
: Array of ShortString;
583 triggers
: Array of record
585 actions
: Array of record
586 action
, p1
, p2
: Integer;
589 cur_trigger
: Integer;
602 function Compare(a
, b
: TPlayerStat
): Integer;
604 if a
.Spectator
then Result
:= 1
605 else if b
.Spectator
then Result
:= -1
606 else if a
.Frags
< b
.Frags
then Result
:= 1
607 else if a
.Frags
> b
.Frags
then Result
:= -1
608 else if a
.Deaths
< b
.Deaths
then Result
:= -1
609 else if a
.Deaths
> b
.Deaths
then Result
:= 1
610 else if a
.Kills
< b
.Kills
then Result
:= -1
614 procedure SortGameStat(var stat
: TPlayerStatArray
);
619 if stat
= nil then Exit
;
621 for I
:= High(stat
) downto Low(stat
) do
622 for J
:= Low(stat
) to High(stat
) - 1 do
623 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
626 stat
[J
] := stat
[J
+ 1];
631 function g_Game_ModeToText(Mode
: Byte): string;
635 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
636 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
637 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
638 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
639 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
643 function g_Game_TextToMode(Mode
: string): Byte;
646 Mode
:= UpperCase(Mode
);
647 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
652 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
657 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
662 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
667 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
674 function g_Game_IsNet(): Boolean;
676 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
679 function g_Game_IsServer(): Boolean;
681 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
684 function g_Game_IsClient(): Boolean;
686 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
689 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
696 Result
.name
:= ExtractFileName(WAD
);
697 Result
.description
:= '';
700 w
:= TWADFile
.Create();
703 if not w
.GetResource('INTERSCRIPT', p
, len
) then
709 cfg
:= TConfig
.CreateMem(p
, len
);
710 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
711 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
712 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
713 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
719 procedure g_Game_FreeWAD();
723 for a
:= 0 to High(MegaWAD
.res
.pic
) do
724 if MegaWAD
.res
.pic
[a
] <> '' then
725 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
727 for a
:= 0 to High(MegaWAD
.res
.mus
) do
728 if MegaWAD
.res
.mus
[a
] <> '' then
729 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
731 MegaWAD
.res
.pic
:= nil;
732 MegaWAD
.res
.text := nil;
733 MegaWAD
.res
.anim
:= nil;
734 MegaWAD
.res
.mus
:= nil;
735 MegaWAD
.triggers
:= nil;
737 g_Texture_Delete('TEXTURE_endpic');
738 g_Sound_Delete('MUSIC_endmus');
740 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
741 gGameSettings
.WAD
:= '';
744 procedure g_Game_LoadWAD(WAD
: string);
753 gGameSettings
.WAD
:= WAD
;
754 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
757 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
759 w
:= TWADFile
.Create();
760 w
.ReadFile(MapsDir
+ WAD
);
762 if not w
.GetResource('INTERSCRIPT', p
, len
) then
768 cfg
:= TConfig
.CreateMem(p
, len
);
773 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
774 if s = '' then Break;
777 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
778 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
780 g_Texture_CreateWADEx(s, s);
786 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
787 if s = '' then Break;
790 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
791 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
793 g_Music_CreateWADEx(s, s);
796 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
797 if MegaWAD
.endpic
<> '' then
799 s
:= g_ExtractWadName(MegaWAD
.endpic
);
800 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
801 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
803 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
804 if MegaWAD
.endmus
<> '' then
806 s
:= g_ExtractWadName(MegaWAD
.endmus
);
807 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
808 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
816 {procedure start_trigger(t: string);
820 function next_trigger(): Boolean;
824 procedure DisableCheats();
830 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
831 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
832 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
833 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
835 {$IF DEFINED(D2F_DEBUG)}
836 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= True;
837 gAimLine
:= g_dbg_aimline_on
;
841 procedure g_Game_ExecuteEvent(Name
: String);
847 if gEvents
= nil then
849 for a
:= 0 to High(gEvents
) do
850 if gEvents
[a
].Name
= Name
then
852 if gEvents
[a
].Command
<> '' then
853 g_Console_Process(gEvents
[a
].Command
, True);
858 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
863 if gDelayedEvents
<> nil then
864 for a
:= 0 to High(gDelayedEvents
) do
865 if not gDelayedEvents
[a
].Pending
then
872 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
873 n
:= High(gDelayedEvents
);
875 gDelayedEvents
[n
].Pending
:= True;
876 gDelayedEvents
[n
].DEType
:= DEType
;
877 gDelayedEvents
[n
].DENum
:= Num
;
878 gDelayedEvents
[n
].DEStr
:= Str
;
879 if DEType
= DE_GLOBEVENT
then
880 gDelayedEvents
[n
].Time
:= (GetTimer() {div 1000}) + Time
882 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
891 if g_Game_IsNet
and g_Game_IsServer
then
892 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
896 gPauseHolmes
:= false;
899 g_Game_StopAllSounds(False);
904 EndingGameCounter
:= 0;
905 g_ActiveWindow
:= nil;
907 gLMSRespawn
:= LMS_RESPAWN_NONE
;
908 gLMSRespawnTime
:= 0;
911 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
916 begin // Ýòî áûë òåñò
920 begin // Âûõîä â ãëàâíîå ìåíþ
921 gMusic
.SetByName('MUSIC_MENU');
923 if gState
<> STATE_SLIST
then
925 g_GUI_ShowWindow('MainMenu');
926 gState
:= STATE_MENU
;
929 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
930 slReturnPressed
:= True;
931 if g_Net_Slist_Fetch(slCurrent
) then
933 if slCurrent
= nil then
934 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
937 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
940 g_Game_ExecuteEvent('ongameend');
944 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
946 if not g_Game_IsClient
then g_Game_Restart();
949 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
951 // Ñòàòèñòèêà Ñâîåé èãðû:
952 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
954 CustomStat
.GameTime
:= gTime
;
955 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
956 CustomStat
.MapName
:= gMapInfo
.Name
;
957 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
958 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
959 CustomStat
.TeamStat
:= gTeamStat
;
961 CustomStat
.PlayerStat
:= nil;
963 // Ñòàòèñòèêà èãðîêîâ:
964 if gPlayers
<> nil then
966 for a
:= 0 to High(gPlayers
) do
967 if gPlayers
[a
] <> nil then
969 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
970 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
972 Name
:= gPlayers
[a
].Name
;
973 Frags
:= gPlayers
[a
].Frags
;
974 Deaths
:= gPlayers
[a
].Death
;
975 Kills
:= gPlayers
[a
].Kills
;
976 Team
:= gPlayers
[a
].Team
;
977 Color
:= gPlayers
[a
].Model
.Color
;
978 Spectator
:= gPlayers
[a
].FSpectator
;
982 SortGameStat(CustomStat
.PlayerStat
);
985 g_Game_ExecuteEvent('onmapend');
988 EndingGameCounter
:= 255;
989 gState
:= STATE_FOLD
;
991 if gDefInterTime
< 0 then
992 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
994 gInterEndTime
:= gDefInterTime
* 1000;
997 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
999 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1000 SingleStat
.GameTime
:= gTime
;
1001 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
1002 SingleStat
.TotalSecrets
:= gSecretsCount
;
1003 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1004 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
1005 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
1006 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1007 if SingleStat
.TwoPlayers
then
1009 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
1010 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
1013 g_Game_ExecuteEvent('onmapend');
1016 if gNextMap
<> '' then
1018 gMusic
.SetByName('MUSIC_INTERMUS');
1020 gState
:= STATE_INTERSINGLE
;
1023 g_Game_ExecuteEvent('oninter');
1025 else // Áîëüøå íåò êàðò
1027 // Çàòóõàþùèé ýêðàí:
1028 EndingGameCounter
:= 255;
1029 gState
:= STATE_FOLD
;
1034 // Îêîí÷àíèå îáðàáîòàíî:
1035 if gExit
<> EXIT_QUIT
then
1039 procedure drawTime(X
, Y
: Integer); inline;
1041 e_TextureFontPrint(x
, y
,
1042 Format('%d:%.2d:%.2d', [
1043 gTime
div 1000 div 3600,
1044 (gTime
div 1000 div 60) mod 60,
1045 gTime
div 1000 mod 60
1050 procedure DrawStat();
1052 pc
, x
, y
, w
, h
: Integer;
1053 w1
, w2
, w3
, w4
: Integer;
1055 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
1058 stat
: TPlayerStatArray
;
1065 pc
:= g_Player_GetCount
;
1066 e_TextureFontGetSize(gStdFont
, cw
, ch
);
1068 w
:= gScreenWidth
-(gScreenWidth
div 5);
1069 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1072 h
:= 40+ch
*5+(ch
+8)*pc
;
1073 x
:= (gScreenWidth
div 2)-(w
div 2);
1074 y
:= (gScreenHeight
div 2)-(h
div 2);
1076 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
1077 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
1079 drawTime(x
+w
-78, y
+8);
1081 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
1082 map
:= g_ExtractFileName(gMapInfo
.Map
);
1083 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
1085 case gGameSettings
.GameMode
of
1088 if gGameSettings
.MaxLives
= 0 then
1089 s1
:= _lc
[I_GAME_DM
]
1091 s1
:= _lc
[I_GAME_LMS
];
1092 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1093 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1098 if gGameSettings
.MaxLives
= 0 then
1099 s1
:= _lc
[I_GAME_TDM
]
1101 s1
:= _lc
[I_GAME_TLMS
];
1102 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1103 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1108 s1
:= _lc
[I_GAME_CTF
];
1109 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1110 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1115 if gGameSettings
.MaxLives
= 0 then
1116 s1
:= _lc
[I_GAME_COOP
]
1118 s1
:= _lc
[I_GAME_SURV
];
1119 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1120 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1131 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1133 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1135 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1137 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1138 gStdFont
, 200, 200, 200, 1);
1140 if NetMode
= NET_SERVER
then
1141 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1143 if NetMode
= NET_CLIENT
then
1144 e_TextureFontPrintEx(x
+8, y
+ 8,
1145 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1149 stat
:= g_Player_GetStats();
1152 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1153 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1155 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1157 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1161 for a
:= TEAM_RED
to TEAM_BLUE
do
1163 if a
= TEAM_RED
then
1165 s1
:= _lc
[I_GAME_TEAM_RED
];
1172 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1178 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1179 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1180 gStdFont
, r
, g
, b
, 1);
1182 _y
:= _y
+ch
+(ch
div 4);
1183 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1184 _y
:= _y
+(ch
div 4);
1186 for aa
:= 0 to High(stat
) do
1187 if stat
[aa
].Team
= a
then
1203 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1205 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1207 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1209 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1216 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1219 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1220 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1221 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1222 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1225 for aa
:= 0 to High(stat
) do
1239 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1240 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1242 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1244 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1246 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1248 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1254 procedure g_Game_Init();
1260 gTempDelete
:= False;
1262 sfsGCDisable(); // temporary disable removing of temporary volumes
1265 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1266 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1267 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1268 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1270 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1271 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1272 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1274 g_Game_ClearLoading();
1275 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1276 g_Game_SetLoadingText('', 0, False);
1278 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1281 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1282 g_PlayerModel_LoadData();
1284 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1286 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1287 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1288 until FindNext(SR
) <> 0;
1291 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1293 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1294 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1295 until FindNext(SR
) <> 0;
1298 if FindFirst(ModelsDir
+'*.zip', faAnyFile
, SR
) = 0 then
1300 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1301 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), TMsgType
.Warning
);
1302 until FindNext(SR
) <> 0;
1306 gPauseMain
:= false;
1307 gPauseHolmes
:= false;
1309 LastScreenShot
:= 0;
1311 {e_MouseInfo.Accel := 1.0;}
1313 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1316 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1317 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1318 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1319 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1320 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1322 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1325 gMusic
:= TMusic
.Create();
1326 gMusic
.SetByName('MUSIC_MENU');
1329 gGameSettings
.WarmupTime
:= 30;
1331 gState
:= STATE_MENU
;
1333 SetLength(gEvents
, 6);
1334 gEvents
[0].Name
:= 'ongamestart';
1335 gEvents
[1].Name
:= 'ongameend';
1336 gEvents
[2].Name
:= 'onmapstart';
1337 gEvents
[3].Name
:= 'onmapend';
1338 gEvents
[4].Name
:= 'oninter';
1339 gEvents
[5].Name
:= 'onwadend';
1341 sfsGCEnable(); // enable releasing unused volumes
1345 procedure g_Game_Free(freeTextures
: Boolean=true);
1347 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1348 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1350 g_Map_Free(freeTextures
);
1352 g_Player_RemoveAllCorpses();
1354 gGameSettings
.GameType
:= GT_NONE
;
1355 if gGameSettings
.GameMode
= GM_SINGLE
then
1356 gGameSettings
.GameMode
:= GM_DM
;
1357 gSwitchGameMode
:= gGameSettings
.GameMode
;
1360 gExitByTrigger
:= False;
1363 function IsActivePlayer(p
: TPlayer
): Boolean;
1368 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1371 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1378 if gPlayers
= nil then
1380 for a
:= Low(gPlayers
) to High(gPlayers
) do
1381 if IsActivePlayer(gPlayers
[a
]) then
1383 if gPlayers
[a
].UID
<> ID
then
1385 Result
:= gPlayers
[a
];
1390 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1396 if gPlayers
= nil then
1400 for a
:= Low(gPlayers
) to High(gPlayers
) do
1401 if IsActivePlayer(gPlayers
[a
]) then
1403 SetLength(ids
, Length(ids
) + 1);
1404 ids
[High(ids
)] := gPlayers
[a
].UID
;
1405 if gPlayers
[a
].UID
= Skip
then
1408 if Length(ids
) = 0 then
1413 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1416 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1422 if gPlayers
= nil then
1426 for a
:= Low(gPlayers
) to High(gPlayers
) do
1427 if IsActivePlayer(gPlayers
[a
]) then
1429 SetLength(ids
, Length(ids
) + 1);
1430 ids
[High(ids
)] := gPlayers
[a
].UID
;
1431 if gPlayers
[a
].UID
= Skip
then
1434 if Length(ids
) = 0 then
1437 Result
:= ids
[Length(ids
) - 1]
1439 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1442 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
1444 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
1445 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
1449 procedure processPlayerControls (plr
: TPlayer
; var ctrl
: TPlayerControl
; var MoveButton
: Byte; p2hack
: Boolean=false);
1455 if (plr
= nil) then exit
;
1456 if (p2hack
) then time
:= 1000 else time
:= 1;
1457 strafeDir
:= MoveButton
shr 4;
1458 MoveButton
:= MoveButton
and $0F;
1461 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1462 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1463 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1465 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1466 if MoveButton
= 1 then plr
.PressKey(KEY_LEFT
, time
)
1467 else if MoveButton
= 2 then plr
.PressKey(KEY_RIGHT
, time
);
1469 // if we have "strafe" key, turn off old strafe mechanics
1470 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
1472 // new strafe mechanics
1473 if (strafeDir
= 0) then strafeDir
:= MoveButton
; // start strafing
1474 // now set direction according to strafe (reversed)
1475 if (strafeDir
= 2) then plr
.SetDirection(TDirection
.D_LEFT
)
1476 else if (strafeDir
= 1) then plr
.SetDirection(TDirection
.D_RIGHT
);
1480 strafeDir
:= 0; // not strafing anymore
1481 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1482 if (MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then plr
.SetDirection(TDirection
.D_LEFT
)
1483 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1484 else if (MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then plr
.SetDirection(TDirection
.D_RIGHT
)
1485 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1486 else if MoveButton
<> 0 then plr
.SetDirection(TDirection(MoveButton
-1));
1489 // fix movebutton state
1490 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1492 // Îñòàëüíûå êëàâèøè:
1493 if isKeyPressed(KeyJump
, KeyJump2
) then plr
.PressKey(KEY_JUMP
, time
);
1494 if isKeyPressed(KeyUp
, KeyUp2
) then plr
.PressKey(KEY_UP
, time
);
1495 if isKeyPressed(KeyDown
, KeyDown2
) then plr
.PressKey(KEY_DOWN
, time
);
1496 if isKeyPressed(KeyFire
, KeyFire2
) then plr
.PressKey(KEY_FIRE
);
1497 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then plr
.PressKey(KEY_NEXTWEAPON
);
1498 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then plr
.PressKey(KEY_PREVWEAPON
);
1499 if isKeyPressed(KeyOpen
, KeyOpen2
) then plr
.PressKey(KEY_OPEN
);
1501 for i
:= 0 to High(KeyWeapon
) do
1502 if isKeyPressed(KeyWeapon
[i
], KeyWeapon2
[i
]) then
1503 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1506 // HACK: add dynlight here
1507 if gwin_k8_enable_light_experiments
then
1509 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1511 g_playerLight
:= true;
1513 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1515 g_playerLight
:= false;
1519 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1522 procedure g_Game_Update();
1524 Msg
: g_gui
.TMessage
;
1530 function sendMonsPos (mon
: TMonster
): Boolean;
1532 result
:= false; // don't stop
1533 // this will also reset "need-send" flag
1534 if mon
.gncNeedSend
then
1536 MH_SEND_MonsterPos(mon
.UID
);
1538 else if (mon
.MonsterType
= MONSTER_BARREL
) then
1540 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1542 else if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1544 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1548 function sendMonsPosUnexpected (mon
: TMonster
): Boolean;
1550 result
:= false; // don't stop
1551 // this will also reset "need-send" flag
1552 if mon
.gncNeedSend
then MH_SEND_MonsterPos(mon
.UID
);
1556 reliableUpdate
: Boolean;
1561 // Ïîðà âûêëþ÷àòü èãðó:
1562 if gExit
= EXIT_QUIT
then
1564 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1568 if gExit
= EXIT_QUIT
then
1572 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1573 // no need to, as we'll do it in event handler
1575 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1578 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1580 gExit
:= EXIT_SIMPLE
;
1586 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1587 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1588 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1589 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1591 if g_Game_IsNet
and g_Game_IsServer
then
1593 gInterTime
:= gInterTime
+ GAME_TICK
;
1594 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1595 if a
<> gServInterTime
then
1597 gServInterTime
:= a
;
1598 MH_SEND_TimeSync(gServInterTime
);
1602 if (not g_Game_IsClient
) and
1606 e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
) or
1607 e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
)
1609 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1610 and (g_ActiveWindow
= nil)
1612 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1615 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1616 g_Game_StopAllSounds(True);
1618 if gMapOnce
then // Ýòî áûë òåñò
1619 gExit
:= EXIT_SIMPLE
1621 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1622 g_Game_ChangeMap(gNextMap
)
1623 else // Ñëåäóþùåé êàðòû íåò
1625 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1627 // Âûõîä â ãëàâíîå ìåíþ:
1629 g_GUI_ShowWindow('MainMenu');
1630 gMusic
.SetByName('MUSIC_MENU');
1632 gState
:= STATE_MENU
;
1635 // Ôèíàëüíàÿ êàðòèíêà:
1636 g_Game_ExecuteEvent('onwadend');
1638 if not gMusic
.SetByName('MUSIC_endmus') then
1639 gMusic
.SetByName('MUSIC_STDENDMUS');
1641 gState
:= STATE_ENDPIC
;
1643 g_Game_ExecuteEvent('ongameend');
1649 if gState
= STATE_INTERTEXT
then
1650 if InterText
.counter
> 0 then
1651 InterText
.counter
:= InterText
.counter
- 1;
1654 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1656 if EndingGameCounter
= 0 then
1658 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1659 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1661 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1663 g_Game_ExecuteEvent('onwadend');
1664 if not gMusic
.SetByName('MUSIC_endmus') then
1665 gMusic
.SetByName('MUSIC_STDENDMUS');
1668 gMusic
.SetByName('MUSIC_ROUNDMUS');
1671 gState
:= STATE_INTERCUSTOM
;
1674 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1676 gMusic
.SetByName('MUSIC_INTERMUS');
1678 gState
:= STATE_INTERSINGLE
;
1681 g_Game_ExecuteEvent('oninter');
1684 DecMin(EndingGameCounter
, 6, 0);
1687 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1689 if gMapOnce
then // Ýòî áûë òåñò
1691 gExit
:= EXIT_SIMPLE
;
1697 g_Serverlist_Control(slCurrent
);
1700 if g_Game_IsNet
then
1701 if not gConsoleShow
then
1702 if not gChatShow
then
1704 if g_ActiveWindow
= nil then
1706 if e_KeyPressed(gGameControls
.GameControls
.Chat
) or e_KeyPressed(VK_CHAT
) then
1707 g_Console_Chat_Switch(False)
1708 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
) or e_KeyPressed(VK_TEAM
)) and
1709 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1710 g_Console_Chat_Switch(True);
1713 if not gChatEnter
then
1714 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1715 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
))
1716 and (not e_KeyPressed(VK_CHAT
))
1717 and (not e_KeyPressed(VK_TEAM
)) then
1720 // Ñòàòèñòèêà ïî Tab:
1722 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1723 (gGameSettings
.GameType
<> GT_SINGLE
) and
1724 (e_KeyPressed(gGameControls
.GameControls
.Stat
) or e_KeyPressed(VK_STATUS
));
1727 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1729 // Âðåìÿ += 28 ìèëëèñåêóíä:
1730 gTime
:= gTime
+ GAME_TICK
;
1732 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1733 if MessageTime
= 0 then
1735 if MessageTime
> 0 then
1736 MessageTime
:= MessageTime
- 1;
1738 if (g_Game_IsServer
) then
1740 // Áûë çàäàí ëèìèò âðåìåíè:
1741 if (gGameSettings
.TimeLimit
> 0) then
1742 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1743 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1748 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1749 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1750 g_Game_RestartRound(gLMSSoftSpawn
);
1752 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1753 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1755 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1757 g_Console_Process(gVoteCommand
);
1759 gVotePassed
:= False;
1762 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1763 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1764 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1765 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1766 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1768 // Áûë çàäàí ëèìèò ïîáåä:
1769 if (gGameSettings
.GoalLimit
> 0) then
1773 if gGameSettings
.GameMode
= GM_DM
then
1774 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1775 for i
:= 0 to High(gPlayers
) do
1776 if gPlayers
[i
] <> nil then
1777 if gPlayers
[i
].Frags
> b
then
1778 b
:= gPlayers
[i
].Frags
;
1781 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1782 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1783 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1786 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1787 if b
>= gGameSettings
.GoalLimit
then
1794 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1795 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1796 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1797 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1799 processPlayerControls(gPlayer1
, gGameControls
.P1Control
, P1MoveButton
);
1800 processPlayerControls(gPlayer2
, gGameControls
.P2Control
, P2MoveButton
, true);
1801 end // if not console
1804 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1806 // process weapon switch queue
1810 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1811 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1813 if not gSpectKeyPress
then
1815 if isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
) then
1817 // switch spect mode
1819 SPECT_NONE
: ; // not spectator
1821 SPECT_MAPVIEW
: Inc(gSpectMode
);
1822 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1824 gSpectKeyPress
:= True;
1826 if gSpectMode
= SPECT_MAPVIEW
then
1828 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1829 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1830 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1831 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1832 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1833 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1834 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1835 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1836 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1839 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1840 gSpectKeyPress
:= True;
1842 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1845 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1846 gSpectKeyPress
:= True;
1849 if gSpectMode
= SPECT_PLAYERS
then
1851 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1854 gSpectViewTwo
:= True;
1855 gSpectKeyPress
:= True;
1857 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1859 // remove second view
1860 gSpectViewTwo
:= False;
1861 gSpectKeyPress
:= True;
1863 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1865 // prev player (view 1)
1866 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1867 gSpectKeyPress
:= True;
1869 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1871 // next player (view 1)
1872 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1873 gSpectKeyPress
:= True;
1875 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1877 // prev player (view 2)
1878 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1879 gSpectKeyPress
:= True;
1881 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1883 // next player (view 2)
1884 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1885 gSpectKeyPress
:= True;
1890 if (not isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)) and
1891 (not isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
)) and
1892 (not isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
)) and
1893 (not isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
)) and
1894 (not isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
)) and
1895 (not isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
)) and
1896 (not isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
)) then
1897 gSpectKeyPress
:= False;
1900 // Îáíîâëÿåì âñå îñòàëüíîå:
1903 g_Triggers_Update();
1905 g_Monsters_Update();
1907 g_Player_UpdateAll();
1908 g_Player_UpdatePhysicalObjects();
1910 // server: send newly spawned monsters unconditionally
1911 if (gGameSettings
.GameType
= GT_SERVER
) then
1913 if (Length(gMonstersSpawned
) > 0) then
1915 for I
:= 0 to High(gMonstersSpawned
) do MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1916 SetLength(gMonstersSpawned
, 0);
1920 if (gSoundTriggerTime
> 8) then
1922 g_Game_UpdateTriggerSounds();
1923 gSoundTriggerTime
:= 0;
1927 Inc(gSoundTriggerTime
);
1930 if (NetMode
= NET_SERVER
) then
1932 Inc(NetTimeToUpdate
);
1933 Inc(NetTimeToReliable
);
1935 // send monster updates
1936 if (NetTimeToReliable
>= NetRelupdRate
) or (NetTimeToUpdate
>= NetUpdateRate
) then
1938 // send all monsters (periodic sync)
1939 reliableUpdate
:= (NetTimeToReliable
>= NetRelupdRate
);
1941 for I
:= 0 to High(gPlayers
) do
1943 if (gPlayers
[I
] <> nil) then MH_SEND_PlayerPos(reliableUpdate
, gPlayers
[I
].UID
);
1946 g_Mons_ForEach(sendMonsPos
);
1948 if reliableUpdate
then
1950 NetTimeToReliable
:= 0;
1951 NetTimeToUpdate
:= NetUpdateRate
;
1955 NetTimeToUpdate
:= 0;
1960 // send only mosters with some unexpected changes
1961 g_Mons_ForEach(sendMonsPosUnexpected
);
1964 // send unexpected platform changes
1965 g_Map_NetSendInterestingPanels();
1967 if NetUseMaster
then
1969 if gTime
>= NetTimeToMaster
then
1971 if (NetMHost
= nil) or (NetMPeer
= nil) then
1973 if not g_Net_Slist_Connect
then g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1977 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1981 else if (NetMode
= NET_CLIENT
) then
1983 MC_SEND_PlayerPos();
1985 end; // if gameOn ...
1987 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1988 if g_ActiveWindow
<> nil then
1990 w
:= e_GetFirstKeyPressed();
1992 if (w
<> IK_INVALID
) then
1994 Msg
.Msg
:= MESSAGE_DIKEY
;
1996 g_ActiveWindow
.OnMessage(Msg
);
1999 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2000 if g_ActiveWindow
<> nil then
2001 g_ActiveWindow
.Update();
2003 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2004 if gResolutionChange
then
2006 e_WriteLog('Changing resolution', TMsgType
.Notify
);
2007 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
2008 gResolutionChange
:= False;
2009 g_ActiveWindow
:= nil;
2012 // Íóæíî ñìåíèòü ÿçûê:
2013 if gLanguageChange
then
2015 //e_WriteLog('Read language file', MSG_NOTIFY);
2016 //g_Language_Load(DataDir + gLanguage + '.txt');
2017 g_Language_Set(gLanguage
);
2019 gLanguageChange
:= False;
2023 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
2024 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) or e_KeyPressed(VK_PRINTSCR
) then
2025 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
2028 LastScreenShot
:= GetTimer();
2031 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2032 if e_KeyPressed(IK_F10
) and
2034 (not gConsoleShow
) and
2035 (g_ActiveWindow
= nil) then
2040 Time
:= GetTimer() {div 1000};
2042 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2043 if gDelayedEvents
<> nil then
2044 for a
:= 0 to High(gDelayedEvents
) do
2045 if gDelayedEvents
[a
].Pending
and
2047 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
2048 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
2051 case gDelayedEvents
[a
].DEType
of
2053 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
2056 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
2060 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
2061 if g_Game_IsNet
and g_Game_IsServer
then
2062 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
2065 gDelayedEvents
[a
].Pending
:= False;
2068 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2069 UPSCounter
:= UPSCounter
+ 1;
2070 if Time
- UPSTime
>= 1000 then
2079 g_Weapon_AddDynLights();
2080 g_Items_AddDynLights();
2084 procedure g_Game_LoadChatSounds(Resource
: string);
2087 FileName
, Snd
: string;
2089 len
, cnt
, tags
, i
, j
: Integer;
2092 FileName
:= g_ExtractWadName(Resource
);
2094 WAD
:= TWADFile
.Create();
2095 WAD
.ReadFile(FileName
);
2097 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), p
, len
) then
2104 cfg
:= TConfig
.CreateMem(p
, len
);
2105 cnt
:= cfg
.ReadInt('ChatSounds', 'Count', 0);
2107 SetLength(gChatSounds
, cnt
);
2108 for i
:= 0 to Length(gChatSounds
) - 1 do
2110 gChatSounds
[i
].Sound
:= nil;
2111 Snd
:= Trim(cfg
.ReadStr(IntToStr(i
), 'Sound', ''));
2112 tags
:= cfg
.ReadInt(IntToStr(i
), 'Tags', 0);
2113 if (Snd
= '') or (Tags
<= 0) then
2115 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i
), GameWAD
+':'+Snd
);
2116 gChatSounds
[i
].Sound
:= TPlayableSound
.Create();
2117 gChatSounds
[i
].Sound
.SetByName('SOUND_CHAT_MACRO' + IntToStr(i
));
2118 SetLength(gChatSounds
[i
].Tags
, tags
);
2119 for j
:= 0 to tags
- 1 do
2120 gChatSounds
[i
].Tags
[j
] := toLowerCase1251(cfg
.ReadStr(IntToStr(i
), 'Tag' + IntToStr(j
), ''));
2121 gChatSounds
[i
].FullWord
:= cfg
.ReadBool(IntToStr(i
), 'FullWord', False);
2128 procedure g_Game_FreeChatSounds();
2132 for i
:= 0 to Length(gChatSounds
) - 1 do
2134 gChatSounds
[i
].Sound
.Free();
2135 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i
));
2137 SetLength(gChatSounds
, 0);
2141 procedure g_Game_LoadData();
2148 if DataLoaded
then Exit
;
2150 e_WriteLog('Loading game data...', TMsgType
.Notify
);
2152 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
2153 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
2154 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
2155 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
2156 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
2157 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
2158 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_R_BASE');
2159 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_R_STOLEN');
2160 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_R_DROP');
2161 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_B_BASE');
2162 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_B_STOLEN');
2163 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_B_DROP');
2164 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
2165 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
2168 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD
+':TEXTURES\LLEFT') then hasPBarGfx
:= false;
2169 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD
+':TEXTURES\LMARKER') then hasPBarGfx
:= false;
2170 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD
+':TEXTURES\LMIDDLE') then hasPBarGfx
:= false;
2171 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD
+':TEXTURES\LRIGHT') then hasPBarGfx
:= false;
2175 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2176 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2177 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2178 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2179 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
2185 hasPBarGfx
:= false;
2189 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
2190 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD
+':TEXTURES\PUNCH', 64, 64, 4, False);
2191 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
2192 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
2193 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
2194 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
2195 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
2196 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
2197 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
2198 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
2199 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
2200 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
2201 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
2202 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
2203 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
2204 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
2205 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
2206 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
2207 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
2208 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
2209 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
2211 goodsnd
[0] := TPlayableSound
.Create();
2212 goodsnd
[1] := TPlayableSound
.Create();
2213 goodsnd
[2] := TPlayableSound
.Create();
2214 goodsnd
[3] := TPlayableSound
.Create();
2216 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2217 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2218 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2219 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2221 killsnd
[0] := TPlayableSound
.Create();
2222 killsnd
[1] := TPlayableSound
.Create();
2223 killsnd
[2] := TPlayableSound
.Create();
2224 killsnd
[3] := TPlayableSound
.Create();
2226 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2227 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2228 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2229 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2231 g_Game_LoadChatSounds(GameWAD
+':CHATSND\SNDCFG');
2233 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2236 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2237 g_Weapon_LoadData();
2239 g_Monsters_LoadData();
2244 procedure g_Game_FreeData();
2246 if not DataLoaded
then Exit
;
2249 g_Weapon_FreeData();
2250 g_Monsters_FreeData();
2252 e_WriteLog('Releasing game data...', TMsgType
.Notify
);
2254 g_Texture_Delete('NOTEXTURE');
2255 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2256 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2257 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2258 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2259 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2260 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2261 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2262 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2263 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2264 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2265 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2266 g_Frames_DeleteByName('FRAMES_TELEPORT');
2267 g_Frames_DeleteByName('FRAMES_PUNCH');
2268 g_Sound_Delete('SOUND_GAME_TELEPORT');
2269 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2270 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2271 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2272 g_Sound_Delete('SOUND_GAME_BULK1');
2273 g_Sound_Delete('SOUND_GAME_BULK2');
2274 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2275 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2276 g_Sound_Delete('SOUND_GAME_SWITCH1');
2277 g_Sound_Delete('SOUND_GAME_SWITCH0');
2284 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2285 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2286 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2287 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2294 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2295 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2296 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2297 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2299 g_Game_FreeChatSounds();
2301 DataLoaded
:= False;
2304 procedure DrawCustomStat();
2310 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2311 s1
, s2
, topstr
: String;
2313 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2315 g_ProcessMessages();
2317 if e_KeyPressed(IK_TAB
) or e_KeyPressed(VK_STATUS
) then
2319 if not gStatsPressed
then
2321 gStatsOff
:= not gStatsOff
;
2322 gStatsPressed
:= True;
2326 gStatsPressed
:= False;
2330 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2331 w
:= (Length(s1
) * ww2
) div 2;
2332 x
:= gScreenWidth
div 2 - w
;
2334 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2338 if (gGameSettings
.GameMode
= GM_COOP
) then
2340 if gMissionFailed
then
2341 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2343 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2346 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2348 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2349 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2351 if g_Game_IsNet
then
2353 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2354 if not gChatShow
then
2355 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2356 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2359 if g_Game_IsClient
then
2360 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2362 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2363 if not gChatShow
then
2364 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2365 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2370 w
:= gScreenWidth
-x
*2;
2376 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2377 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2379 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2381 case CustomStat
.GameMode
of
2384 if gGameSettings
.MaxLives
= 0 then
2385 s1
:= _lc
[I_GAME_DM
]
2387 s1
:= _lc
[I_GAME_LMS
];
2391 if gGameSettings
.MaxLives
= 0 then
2392 s1
:= _lc
[I_GAME_TDM
]
2394 s1
:= _lc
[I_GAME_TLMS
];
2396 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2399 if gGameSettings
.MaxLives
= 0 then
2400 s1
:= _lc
[I_GAME_COOP
]
2402 s1
:= _lc
[I_GAME_SURV
];
2408 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2412 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2413 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2416 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2417 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2418 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2419 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2421 pc
:= Length(CustomStat
.PlayerStat
);
2422 if pc
= 0 then Exit
;
2424 if CustomStat
.GameMode
= GM_COOP
then
2426 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2428 s2
:= _lc
[I_GAME_MONSTERS
];
2429 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2430 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2432 s2
:= _lc
[I_GAME_SECRETS
];
2433 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2434 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2437 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2439 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2440 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2441 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2443 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2444 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2445 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2449 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2454 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2455 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2456 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2458 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2461 for t
:= TEAM_RED
to TEAM_BLUE
do
2463 if t
= TEAM_RED
then
2465 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2466 gStdFont
, 255, 0, 0, 1);
2467 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2468 gStdFont
, 255, 0, 0, 1);
2475 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2476 gStdFont
, 0, 0, 255, 1);
2477 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2478 gStdFont
, 0, 0, 255, 1);
2484 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2487 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2488 if CustomStat
.PlayerStat
[p
].Team
= t
then
2489 with CustomStat
.PlayerStat
[p
] do
2503 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2504 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2505 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2512 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2515 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2516 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2517 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2520 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2521 with CustomStat
.PlayerStat
[p
] do
2523 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2530 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2531 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2532 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2538 procedure DrawSingleStat();
2540 tm
, key_x
, val_x
, y
: Integer;
2544 procedure player_stat(n
: Integer);
2550 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2551 s2
:= Format(' %d', [gTotalMonsters
]);
2553 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2554 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2555 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2556 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2558 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2559 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2561 // "Kills-per-minute: ##.#":
2562 s1
:= _lc
[I_MENU_INTER_KPM
];
2564 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2566 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2567 s2
:= Format(' %.1f', [kpm
]);
2569 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2570 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2572 // "Secrets found: # / #":
2573 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2574 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2576 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2577 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2578 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2579 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2581 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2582 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2586 // "Level Complete":
2587 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2588 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2590 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2591 s1
:= _lc
[I_MENU_INTER_KPM
];
2592 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2595 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2597 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2598 val_x
:= key_x
+ w1
;
2601 tm
:= SingleStat
.GameTime
div 1000;
2602 s1
:= _lc
[I_MENU_INTER_TIME
];
2603 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2605 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2606 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2608 if SingleStat
.TwoPlayers
then
2611 s1
:= _lc
[I_MENU_PLAYER_1
];
2612 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2613 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2615 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2620 s1
:= _lc
[I_MENU_PLAYER_2
];
2621 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2622 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2624 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2630 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2636 procedure DrawLoadingStat();
2637 procedure drawRect (x
, y
, w
, h
: Integer);
2639 if (w
< 1) or (h
< 1) then exit
;
2641 glVertex2f(x
+0.375, y
+0.375);
2642 glVertex2f(x
+w
+0.375, y
+0.375);
2643 glVertex2f(x
+w
+0.375, y
+h
+0.375);
2644 glVertex2f(x
+0.375, y
+h
+0.375);
2648 function drawPBar (cur
, total
: Integer; washere
: Boolean): Boolean;
2650 rectW
, rectH
: Integer;
2657 idl
, idr
, idb
, idm
: LongWord;
2661 if (total
< 1) then exit
;
2662 if (cur
< 1) then exit
; // don't blink
2663 if (not washere
) and (cur
>= total
) then exit
; // don't blink
2664 //if (cur < 0) then cur := 0;
2665 //if (cur > total) then cur := total;
2668 if (hasPBarGfx
) then
2670 g_Texture_Get('UI_GFX_PBAR_LEFT', idl
);
2671 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl
, hl
);
2672 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr
);
2673 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr
, hr
);
2674 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb
);
2675 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb
, hb
);
2676 g_Texture_Get('UI_GFX_PBAR_MARKER', idm
);
2677 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm
, hm
);
2679 //rectW := gScreenWidth-360;
2680 rectW
:= trunc(624.0*gScreenWidth
/1024.0);
2683 x0
:= (gScreenWidth
-rectW
) div 2;
2684 y0
:= gScreenHeight
-rectH
-64;
2685 if (y0
< 2) then y0
:= 2;
2687 glEnable(GL_SCISSOR_TEST
);
2690 glScissor(x0
, gScreenHeight
-y0
-rectH
, rectW
, rectH
);
2691 e_DrawSize(idl
, x0
, y0
, 0, true, false, wl
, hl
);
2692 e_DrawSize(idr
, x0
+rectW
-wr
, y0
, 0, true, false, wr
, hr
);
2695 glScissor(x0
+wl
, gScreenHeight
-y0
-rectH
, rectW
-wl
-wr
, rectH
);
2697 while (f
< x0
+rectW
) do
2699 e_DrawSize(idb
, f
, y0
, 0, true, false, wb
, hb
);
2704 wdt
:= (rectW
-wl
-wr
)*cur
div total
;
2705 if (wdt
> rectW
-wl
-wr
) then wdt
:= rectW
-wr
-wr
;
2708 my
:= y0
; // don't be so smart, ketmar: +(rectH-wm) div 2;
2709 glScissor(x0
+wl
, gScreenHeight
-my
-rectH
, wdt
, hm
);
2713 e_DrawSize(idm
, f
, y0
, 0, true, false, wm
, hm
);
2719 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
2723 rectW
:= gScreenWidth
-64;
2726 x0
:= (gScreenWidth
-rectW
) div 2;
2727 y0
:= gScreenHeight
-rectH
-64;
2728 if (y0
< 2) then y0
:= 2;
2730 glDisable(GL_BLEND
);
2731 glDisable(GL_TEXTURE_2D
);
2733 //glClearColor(0, 0, 0, 0);
2734 //glClear(GL_COLOR_BUFFER_BIT);
2736 glColor4ub(127, 127, 127, 255);
2737 drawRect(x0
-2, y0
-2, rectW
+4, rectH
+4);
2739 glColor4ub(0, 0, 0, 255);
2740 drawRect(x0
-1, y0
-1, rectW
+2, rectH
+2);
2742 glColor4ub(127, 127, 127, 255);
2743 wdt
:= rectW
*cur
div total
;
2744 if (wdt
> rectW
) then wdt
:= rectW
;
2745 drawRect(x0
, y0
, wdt
, rectH
);
2754 if (Length(LoadingStat
.Msgs
) = 0) then exit
;
2756 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2757 yy
:= (gScreenHeight
div 3);
2758 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2759 xx
:= (gScreenWidth
div 3);
2763 for i
:= 0 to NextMsg
-1 do
2765 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2766 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2770 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2771 yy
:= yy
+ LOADING_INTERLINE
;
2772 PBarWasHere
:= drawPBar(CurValue
, MaxValue
, PBarWasHere
);
2777 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2779 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2781 function monDraw (mon
: TMonster
): Boolean;
2783 result
:= false; // don't stop
2788 // Ëåâûé âåðõíèé óãîë
2789 aX
:= Obj
.X
div ScaleSz
+ 1;
2790 aY
:= Obj
.Y
div ScaleSz
+ 1;
2792 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2793 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2794 // Ïðàâûé íèæíèé óãîë
2795 aX2
:= aX
+ aX2
- 1;
2796 aY2
:= aY
+ aY2
- 1;
2797 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2803 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2804 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2807 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2808 ScaleSz
:= 16 div Scale
;
2809 // Ðàçìåðû ìèíè-êàðòû:
2810 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2811 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2813 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2815 if gWalls
<> nil then
2818 for a
:= 0 to High(gWalls
) do
2820 if PanelType
<> 0 then
2822 // Ëåâûé âåðõíèé óãîë:
2823 aX
:= X
div ScaleSz
;
2824 aY
:= Y
div ScaleSz
;
2826 aX2
:= max(Width
div ScaleSz
, 1);
2827 aY2
:= max(Height
div ScaleSz
, 1);
2828 // Ïðàâûé íèæíèé óãîë:
2829 aX2
:= aX
+ aX2
- 1;
2830 aY2
:= aY
+ aY2
- 1;
2833 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2834 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2835 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2839 if gSteps
<> nil then
2842 for a
:= 0 to High(gSteps
) do
2844 if PanelType
<> 0 then
2846 // Ëåâûé âåðõíèé óãîë:
2847 aX
:= X
div ScaleSz
;
2848 aY
:= Y
div ScaleSz
;
2850 aX2
:= max(Width
div ScaleSz
, 1);
2851 aY2
:= max(Height
div ScaleSz
, 1);
2852 // Ïðàâûé íèæíèé óãîë:
2853 aX2
:= aX
+ aX2
- 1;
2854 aY2
:= aY
+ aY2
- 1;
2856 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2859 if gLifts
<> nil then
2862 for a
:= 0 to High(gLifts
) do
2864 if PanelType
<> 0 then
2866 // Ëåâûé âåðõíèé óãîë:
2867 aX
:= X
div ScaleSz
;
2868 aY
:= Y
div ScaleSz
;
2870 aX2
:= max(Width
div ScaleSz
, 1);
2871 aY2
:= max(Height
div ScaleSz
, 1);
2872 // Ïðàâûé íèæíèé óãîë:
2873 aX2
:= aX
+ aX2
- 1;
2874 aY2
:= aY
+ aY2
- 1;
2877 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2878 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2879 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2880 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2884 if gWater
<> nil then
2887 for a
:= 0 to High(gWater
) do
2889 if PanelType
<> 0 then
2891 // Ëåâûé âåðõíèé óãîë:
2892 aX
:= X
div ScaleSz
;
2893 aY
:= Y
div ScaleSz
;
2895 aX2
:= max(Width
div ScaleSz
, 1);
2896 aY2
:= max(Height
div ScaleSz
, 1);
2897 // Ïðàâûé íèæíèé óãîë:
2898 aX2
:= aX
+ aX2
- 1;
2899 aY2
:= aY
+ aY2
- 1;
2901 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2904 if gAcid1
<> nil then
2906 // Ðèñóåì êèñëîòó 1:
2907 for a
:= 0 to High(gAcid1
) do
2909 if PanelType
<> 0 then
2911 // Ëåâûé âåðõíèé óãîë:
2912 aX
:= X
div ScaleSz
;
2913 aY
:= Y
div ScaleSz
;
2915 aX2
:= max(Width
div ScaleSz
, 1);
2916 aY2
:= max(Height
div ScaleSz
, 1);
2917 // Ïðàâûé íèæíèé óãîë:
2918 aX2
:= aX
+ aX2
- 1;
2919 aY2
:= aY
+ aY2
- 1;
2921 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2924 if gAcid2
<> nil then
2926 // Ðèñóåì êèñëîòó 2:
2927 for a
:= 0 to High(gAcid2
) do
2929 if PanelType
<> 0 then
2931 // Ëåâûé âåðõíèé óãîë:
2932 aX
:= X
div ScaleSz
;
2933 aY
:= Y
div ScaleSz
;
2935 aX2
:= max(Width
div ScaleSz
, 1);
2936 aY2
:= max(Height
div ScaleSz
, 1);
2937 // Ïðàâûé íèæíèé óãîë:
2938 aX2
:= aX
+ aX2
- 1;
2939 aY2
:= aY
+ aY2
- 1;
2941 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2944 if gPlayers
<> nil then
2947 for a
:= 0 to High(gPlayers
) do
2948 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2950 // Ëåâûé âåðõíèé óãîë:
2951 aX
:= Obj
.X
div ScaleSz
+ 1;
2952 aY
:= Obj
.Y
div ScaleSz
+ 1;
2954 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2955 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2956 // Ïðàâûé íèæíèé óãîë:
2957 aX2
:= aX
+ aX2
- 1;
2958 aY2
:= aY
+ aY2
- 1;
2960 if gPlayers
[a
] = p
then
2961 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2964 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2965 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2966 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2971 g_Mons_ForEach(monDraw
);
2976 procedure renderAmbientQuad (hasAmbient
: Boolean; constref ambColor
: TDFColor
);
2978 if not hasAmbient
then exit
;
2979 e_AmbientQuad(sX
, sY
, sWidth
, sHeight
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
2983 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
2984 //FIXME: broken for splitscreen mode
2985 procedure renderDynLightsInternal ();
2987 //hasAmbient: Boolean;
2988 //ambColor: TDFColor;
2990 lx
, ly
, lrad
: Integer;
2991 scxywh
: array[0..3] of GLint
;
2994 if e_NoGraphics
then exit
;
2996 //TODO: lights should be in separate grid, i think
2997 // but on the other side: grid may be slower for dynlights, as their lifetime is short
2998 if (not gwin_k8_enable_light_experiments
) or (not gwin_has_stencil
) or (g_dynLightCount
< 1) then exit
;
3001 //ambColor := gCurrentMap['light_ambient'].rgba;
3002 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3004 { // this will multiply incoming color to alpha from framebuffer
3006 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3010 * light rendering: (INVALID!)
3011 * glStencilFunc(GL_EQUAL, 0, $ff);
3013 * glClear(GL_STENCIL_BUFFER_BIT);
3014 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3015 * draw shadow volume into stencil buffer
3016 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3017 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3019 * draw color-less quad with light alpha (WARNING! don't touch color!)
3020 * glEnable(GL_BLEND);
3021 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3022 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3024 wassc
:= (glIsEnabled(GL_SCISSOR_TEST
) <> 0);
3025 if wassc
then glGetIntegerv(GL_SCISSOR_BOX
, @scxywh
[0]) else glGetIntegerv(GL_VIEWPORT
, @scxywh
[0]);
3027 // setup OpenGL parameters
3028 glStencilMask($FFFFFFFF);
3029 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
3030 glEnable(GL_STENCIL_TEST
);
3031 glEnable(GL_SCISSOR_TEST
);
3032 glClear(GL_STENCIL_BUFFER_BIT
);
3033 glStencilFunc(GL_EQUAL
, 0, $ff);
3035 for lln
:= 0 to g_dynLightCount
-1 do
3037 lx
:= g_dynLights
[lln
].x
;
3038 ly
:= g_dynLights
[lln
].y
;
3039 lrad
:= g_dynLights
[lln
].radius
;
3040 if (lrad
< 3) then continue
;
3042 if (lx
-sX
+lrad
< 0) then continue
;
3043 if (ly
-sY
+lrad
< 0) then continue
;
3044 if (lx
-sX
-lrad
>= gPlayerScreenSize
.X
) then continue
;
3045 if (ly
-sY
-lrad
>= gPlayerScreenSize
.Y
) then continue
;
3047 // set scissor to optimize drawing
3048 if (g_dbg_scale
= 1.0) then
3050 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
3054 glScissor(0, 0, gWinSizeX
, gWinSizeY
);
3056 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3057 if (g_dbg_scale
<> 1.0) then glClear(GL_STENCIL_BUFFER_BIT
);
3058 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
3059 // draw extruded panels
3060 glDisable(GL_TEXTURE_2D
);
3061 glDisable(GL_BLEND
);
3062 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
3063 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
3064 // render light texture
3065 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
3066 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
3069 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
3070 glEnable(GL_TEXTURE_2D
);
3071 // color and opacity
3072 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
3073 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
3075 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
3076 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
3077 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
3078 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
3083 glDisable(GL_STENCIL_TEST
);
3084 glDisable(GL_BLEND
);
3085 glDisable(GL_SCISSOR_TEST
);
3086 //glScissor(0, 0, sWidth, sHeight);
3088 glScissor(scxywh
[0], scxywh
[1], scxywh
[2], scxywh
[3]);
3089 if wassc
then glEnable(GL_SCISSOR_TEST
) else glDisable(GL_SCISSOR_TEST
);
3093 function fixViewportForScale (): Boolean;
3095 nx0
, ny0
, nw
, nh
: Integer;
3098 if (g_dbg_scale
<> 1.0) then
3101 nx0
:= round(sX
-(gPlayerScreenSize
.X
-(sWidth
*g_dbg_scale
))/2/g_dbg_scale
);
3102 ny0
:= round(sY
-(gPlayerScreenSize
.Y
-(sHeight
*g_dbg_scale
))/2/g_dbg_scale
);
3103 nw
:= round(sWidth
/g_dbg_scale
);
3104 nh
:= round(sHeight
/g_dbg_scale
);
3113 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3114 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3115 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; setTransMatrix
: Boolean);
3117 TDrawCB
= procedure ();
3120 hasAmbient
: Boolean;
3122 doAmbient
: Boolean = false;
3124 procedure drawPanelType (profname
: AnsiString; panType
: DWord
; doDraw
: Boolean);
3129 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3130 if gdbg_map_use_accel_render
then
3132 tagmask
:= panelTypeToTag(panType
);
3133 while (gDrawPanelList
.count
> 0) do
3135 pan
:= TPanel(gDrawPanelList
.front());
3136 if ((pan
.tag
and tagmask
) = 0) then break
;
3137 if doDraw
then pan
.Draw(doAmbient
, ambColor
);
3138 gDrawPanelList
.popFront();
3143 if doDraw
then g_Map_DrawPanels(panType
, hasAmbient
, ambColor
);
3145 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3148 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
3150 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin(profname
);
3151 if assigned(cb
) then cb();
3152 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3156 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('total');
3158 // our accelerated renderer will collect all panels to gDrawPanelList
3159 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3160 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('collect');
3161 if gdbg_map_use_accel_render
then
3163 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
3165 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3167 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionBegin('skyback');
3168 g_Map_DrawBack(backXOfs
, backYOfs
);
3169 if (profileFrameDraw
<> nil) then profileFrameDraw
.sectionEnd();
3171 if setTransMatrix
then
3173 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3174 glScalef(g_dbg_scale
, g_dbg_scale
, 1.0);
3175 glTranslatef(-sX
, -sY
, 0);
3179 ambColor
:= gCurrentMap
['light_ambient'].rgba
;
3180 hasAmbient
:= (not ambColor
.isOpaque
) or (not ambColor
.isBlack
);
3185 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3186 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3187 glClear(GL_COLOR_BUFFER_BIT);
3190 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3193 drawPanelType('*back', PANEL_BACK
, g_rlayer_back
);
3194 drawPanelType('*step', PANEL_STEP
, g_rlayer_step
);
3195 drawOther('items', @g_Items_Draw
);
3196 drawOther('weapons', @g_Weapon_Draw
);
3197 drawOther('shells', @g_Player_DrawShells
);
3198 drawOther('drawall', @g_Player_DrawAll
);
3199 drawOther('corpses', @g_Player_DrawCorpses
);
3200 drawPanelType('*wall', PANEL_WALL
, g_rlayer_wall
);
3201 drawOther('monsters', @g_Monsters_Draw
);
3202 drawOther('itemdrop', @g_Items_DrawDrop
);
3203 drawPanelType('*door', PANEL_CLOSEDOOR
, g_rlayer_door
);
3204 drawOther('gfx', @g_GFX_Draw
);
3205 drawOther('flags', @g_Map_DrawFlags
);
3206 drawPanelType('*acid1', PANEL_ACID1
, g_rlayer_acid1
);
3207 drawPanelType('*acid2', PANEL_ACID2
, g_rlayer_acid2
);
3208 drawPanelType('*water', PANEL_WATER
, g_rlayer_water
);
3209 drawOther('dynlights', @renderDynLightsInternal
);
3211 if hasAmbient
{and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3213 renderAmbientQuad(hasAmbient
, ambColor
);
3217 drawPanelType('*fore', PANEL_FORE
, g_rlayer_fore
);
3220 if g_debug_HealthBar
then
3222 g_Monsters_DrawHealth();
3223 g_Player_DrawHealth();
3226 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainEnd(); // map rendering
3230 procedure DrawMapView(x
, y
, w
, h
: Integer);
3237 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
3238 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
3245 fixViewportForScale();
3246 renderMapInternal(-bx
, -by
, true);
3252 procedure DrawPlayer(p
: TPlayer
);
3254 px
, py
, a
, b
, c
, d
: Integer;
3257 if (p
= nil) or (p
.FDummy
) then
3260 g_Map_DrawBack(0, 0);
3265 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
3266 if (profileFrameDraw
<> nil) then profileFrameDraw
.mainBegin(g_profile_frame_draw
);
3272 px
:= p
.GameX
+ PLAYER_RECT_CX
;
3273 py
:= p
.GameY
+ PLAYER_RECT_CY
+p
.Obj
.slopeUpLeft
;
3275 if (g_dbg_scale
= 1.0) and (not g_dbg_ignore_bounds
) then
3277 if (px
> (gPlayerScreenSize
.X
div 2)) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
3278 if (py
> (gPlayerScreenSize
.Y
div 2)) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
3280 if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
3281 if (py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
3283 if (gMapInfo
.Width
= gPlayerScreenSize
.X
) then a
:= 0
3284 else if (gMapInfo
.Width
< gPlayerScreenSize
.X
) then
3287 a
:= (gPlayerScreenSize
.X
-gMapInfo
.Width
) div 2;
3290 if (gMapInfo
.Height
= gPlayerScreenSize
.Y
) then b
:= 0
3291 else if (gMapInfo
.Height
< gPlayerScreenSize
.Y
) then
3294 b
:= (gPlayerScreenSize
.Y
-gMapInfo
.Height
) div 2;
3299 // scaled, ignore level bounds
3300 a
:= -px
+(gPlayerScreenSize
.X
div 2);
3301 b
:= -py
+(gPlayerScreenSize
.Y
div 2);
3304 if p
.IncCam
<> 0 then
3306 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
3308 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
3310 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
3314 if py
< gPlayerScreenSize
.Y
div 2 then
3316 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
3318 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
3322 if p
.IncCam
< 0 then
3324 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
3327 if p
.IncCam
> 0 then
3329 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
3333 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
3334 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
3335 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
3337 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
3338 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
3339 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
3342 sY
:= -(b
+p
.IncCam
);
3343 sWidth
:= gPlayerScreenSize
.X
;
3344 sHeight
:= gPlayerScreenSize
.Y
;
3346 //glTranslatef(a, b+p.IncCam, 0);
3348 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3350 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3351 fixViewportForScale();
3352 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3354 if (g_dbg_scale
<> 1.0) and (not g_dbg_ignore_bounds
) then
3356 if (sX
+sWidth
> gMapInfo
.Width
) then sX
:= gMapInfo
.Width
-sWidth
;
3357 if (sY
+sHeight
> gMapInfo
.Height
) then sY
:= gMapInfo
.Height
-sHeight
;
3358 if (sX
< 0) then sX
:= 0;
3359 if (sY
< 0) then sY
:= 0;
3361 if (gBackSize
.X
<= gPlayerScreenSize
.X
) or (gMapInfo
.Width
<= sWidth
) then c
:= 0 else c
:= trunc((gBackSize
.X
-gPlayerScreenSize
.X
)*sX
/(gMapInfo
.Width
-sWidth
));
3362 if (gBackSize
.Y
<= gPlayerScreenSize
.Y
) or (gMapInfo
.Height
<= sHeight
) then d
:= 0 else d
:= trunc((gBackSize
.Y
-gPlayerScreenSize
.Y
)*sY
/(gMapInfo
.Height
-sHeight
));
3365 //r_smallmap_h: 0: left; 1: center; 2: right
3366 //r_smallmap_v: 0: top; 1: center; 2: bottom
3368 if (gMapInfo
.Width
= sWidth
) then
3372 else if (gMapInfo
.Width
< sWidth
) then
3374 case r_smallmap_h
of
3375 1: sX
:= -((sWidth
-gMapInfo
.Width
) div 2); // center
3376 2: sX
:= -(sWidth
-gMapInfo
.Width
); // right
3377 else sX
:= 0; // left
3381 if (gMapInfo
.Height
= sHeight
) then
3385 else if (gMapInfo
.Height
< sHeight
) then
3387 case r_smallmap_v
of
3388 1: sY
:= -((sHeight
-gMapInfo
.Height
) div 2); // center
3389 2: sY
:= -(sHeight
-gMapInfo
.Height
); // bottom
3390 else sY
:= 0; // top
3396 p
.viewPortW
:= sWidth
;
3397 p
.viewPortH
:= sHeight
;
3399 {$IFDEF ENABLE_HOLMES}
3400 if (p
= gPlayer1
) then
3402 g_Holmes_plrViewPos(sX
, sY
);
3403 g_Holmes_plrViewSize(sWidth
, sHeight
);
3407 renderMapInternal(-c
, -d
, true);
3409 if p
.FSpectator
then
3410 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
3411 p
.GameY
+ PLAYER_RECT_CY
- 4,
3412 'X', gStdFont
, 255, 255, 255, 1, True);
3414 for a := 0 to High(gCollideMap) do
3415 for b := 0 to High(gCollideMap[a]) do
3418 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3420 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3424 1: e_DrawPoint(1, b, a, 200, 200, 200);
3425 2: e_DrawPoint(1, b, a, 64, 64, 255);
3426 3: e_DrawPoint(1, b, a, 255, 0, 255);
3436 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
3437 if g_Debug_Player
then
3438 g_Player_DrawDebug(p
);
3442 procedure drawProfilers ();
3447 if g_profile_frame_draw
and (profileFrameDraw
<> nil) then px
:= px
-drawProfiles(px
, py
, profileFrameDraw
);
3448 if g_profile_collision
and (profMapCollision
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMapCollision
); py
-= calcProfilesHeight(profMonsLOS
); end;
3449 if g_profile_los
and (profMonsLOS
<> nil) then begin px
:= px
-drawProfiles(px
, py
, profMonsLOS
); py
-= calcProfilesHeight(profMonsLOS
); end;
3452 procedure g_Game_Draw();
3459 plView1
, plView2
: TPlayer
;
3462 if gExit
= EXIT_QUIT
then Exit
;
3464 Time
:= GetTimer() {div 1000};
3465 FPSCounter
:= FPSCounter
+1;
3466 if Time
- FPSTime
>= 1000 then
3473 if gGameOn
or (gState
= STATE_FOLD
) then
3475 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3477 gSpectMode
:= SPECT_NONE
;
3478 if not gRevertPlayers
then
3480 plView1
:= gPlayer1
;
3481 plView2
:= gPlayer2
;
3485 plView1
:= gPlayer2
;
3486 plView2
:= gPlayer1
;
3490 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
3492 gSpectMode
:= SPECT_NONE
;
3493 if gPlayer2
= nil then
3496 plView1
:= gPlayer2
;
3505 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
3506 gSpectMode
:= SPECT_STATS
;
3508 if gSpectMode
= SPECT_PLAYERS
then
3509 if gPlayers
<> nil then
3511 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3512 if plView1
= nil then
3514 gSpectPID1
:= GetActivePlayerID_Next();
3515 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3517 if gSpectViewTwo
then
3519 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3520 if plView2
= nil then
3522 gSpectPID2
:= GetActivePlayerID_Next();
3523 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3528 if gSpectMode
= SPECT_MAPVIEW
then
3530 // Ðåæèì ïðîñìîòðà êàðòû
3532 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3533 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3534 gHearPoint1
.Active
:= True;
3535 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3536 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3537 gHearPoint2
.Active
:= False;
3541 Split
:= (plView1
<> nil) and (plView2
<> nil);
3543 // Òî÷êè ñëóõà èãðîêîâ
3544 if plView1
<> nil then
3546 gHearPoint1
.Active
:= True;
3547 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
3548 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
3550 gHearPoint1
.Active
:= False;
3551 if plView2
<> nil then
3553 gHearPoint2
.Active
:= True;
3554 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
3555 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
3557 gHearPoint2
.Active
:= False;
3559 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3560 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3563 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3564 if gScreenHeight
mod 2 = 0 then
3565 Dec(gPlayerScreenSize
.Y
);
3568 gPlayerScreenSize
.Y
:= gScreenHeight
;
3571 if gScreenHeight
mod 2 = 0 then
3572 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3574 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3576 DrawPlayer(plView1
);
3577 gPlayer1ScreenCoord
.X
:= sX
;
3578 gPlayer1ScreenCoord
.Y
:= sY
;
3582 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3584 DrawPlayer(plView2
);
3585 gPlayer2ScreenCoord
.X
:= sX
;
3586 gPlayer2ScreenCoord
.Y
:= sY
;
3589 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3592 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3595 {$IFDEF ENABLE_HOLMES}
3597 if (g_holmes_enabled
) then g_Holmes_Draw();
3600 if MessageText
<> '' then
3604 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3606 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3607 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3609 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3610 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3613 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3615 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
3617 // Draw spectator GUI
3620 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3623 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3625 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3627 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3629 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3630 if gSpectMode
= SPECT_MAPVIEW
then
3632 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
3633 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
3634 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
3635 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
3636 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
3638 if gSpectMode
= SPECT_PLAYERS
then
3640 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
3641 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
3642 if gSpectViewTwo
then
3644 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
3645 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
3646 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3647 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3651 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3652 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3658 if gPauseMain
and gGameOn
and (g_ActiveWindow
= nil) then
3660 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3661 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3663 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
3664 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3665 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
3670 if (gState
= STATE_MENU
) then
3672 if (g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '') then
3674 if g_Texture_Get('MENU_BACKGROUND', ID
) then e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3675 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3677 // F3 at menu will show game loading dialog
3678 if e_KeyPressed(IK_F3
) then g_Menu_Show_LoadMenu(true);
3679 if (g_ActiveWindow
<> nil) then
3681 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3682 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3686 // F3 at titlepic will show game loading dialog
3687 if e_KeyPressed(IK_F3
) then
3689 g_Menu_Show_LoadMenu(true);
3690 if (g_ActiveWindow
<> nil) then e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3695 if gState
= STATE_FOLD
then
3697 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3700 if gState
= STATE_INTERCUSTOM
then
3702 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
3704 back
:= 'TEXTURE_endpic';
3705 if not g_Texture_Get(back
, ID
) then
3706 back
:= _lc
[I_TEXTURE_ENDPIC
];
3711 if g_Texture_Get(back
, ID
) then
3712 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3714 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3718 if g_ActiveWindow
<> nil then
3720 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3721 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3725 if gState
= STATE_INTERSINGLE
then
3727 if EndingGameCounter
> 0 then
3729 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3735 if g_Texture_Get(back
, ID
) then
3736 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3738 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3742 if g_ActiveWindow
<> nil then
3744 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3745 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3750 if gState
= STATE_ENDPIC
then
3753 if not g_Texture_Get('TEXTURE_endpic', ID
) then
3754 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
3756 if ID
<> DWORD(-1) then
3757 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3759 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3761 if g_ActiveWindow
<> nil then
3763 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3764 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3768 if gState
= STATE_SLIST
then
3770 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3772 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
3773 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3774 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3776 g_Serverlist_Draw(slCurrent
);
3780 if g_ActiveWindow
<> nil then
3784 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3785 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
3787 g_ActiveWindow
.Draw();
3792 if g_debug_Sounds
and gGameOn
then
3794 for w
:= 0 to High(e_SoundsArray
) do
3795 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
3796 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
3801 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3802 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3805 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3806 drawTime(gScreenWidth
-72, gScreenHeight
-16);
3808 if gGameOn
then drawProfilers();
3810 {$IFDEF ENABLE_HOLMES}
3817 procedure g_Game_Quit();
3819 g_Game_StopAllSounds(True);
3821 g_Game_SaveOptions();
3823 g_PlayerModel_FreeData();
3824 g_Texture_DeleteAll();
3825 g_Frames_DeleteAll();
3826 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
3828 if NetInitDone
then g_Net_Free
;
3830 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3831 if gMapToDelete
<> '' then
3832 g_Game_DeleteTestMap();
3838 procedure g_FatalError(Text: String);
3840 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3841 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), TMsgType
.Warning
);
3843 gExit
:= EXIT_SIMPLE
;
3846 procedure g_SimpleError(Text: String);
3848 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3849 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), TMsgType
.Warning
);
3852 procedure g_Game_SetupScreenSize();
3854 RES_FACTOR
= 4.0 / 3.0;
3860 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3861 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3862 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3863 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3865 gPlayerScreenSize
.Y
:= gScreenHeight
;
3867 // Ðàçìåð çàäíåãî ïëàíà:
3868 if BackID
<> DWORD(-1) then
3871 if (gScreenWidth
*s
> gMapInfo
.Width
) or
3872 (gScreenHeight
*s
> gMapInfo
.Height
) then
3874 gBackSize
.X
:= gScreenWidth
;
3875 gBackSize
.Y
:= gScreenHeight
;
3879 e_GetTextureSize(BackID
, @bw
, @bh
);
3880 rf
:= Single(bw
) / Single(bh
);
3881 if (rf
> RES_FACTOR
) then bw
:= Round(Single(bh
) * RES_FACTOR
)
3882 else if (rf
< RES_FACTOR
) then bh
:= Round(Single(bw
) / RES_FACTOR
);
3883 s
:= Max(gScreenWidth
/ bw
, gScreenHeight
/ bh
);
3884 if (s
< 1.0) then s
:= 1.0;
3885 gBackSize
.X
:= Round(bw
*s
);
3886 gBackSize
.Y
:= Round(bh
*s
);
3891 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3893 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3896 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3898 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3899 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3901 if gPlayer1
= nil then
3903 if g_Game_IsClient
then
3905 if NetPlrUID1
> -1 then
3907 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3908 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3913 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3914 Team
:= gPlayer1Settings
.Team
;
3916 // Ñîçäàíèå ïåðâîãî èãðîêà:
3917 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3918 gPlayer1Settings
.Color
,
3920 if gPlayer1
= nil then
3921 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3924 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3925 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3926 if g_Game_IsServer
and g_Game_IsNet
then
3927 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3928 gPlayer1
.Respawn(False, True);
3930 if g_Game_IsNet
and NetUseMaster
then
3936 if gPlayer2
= nil then
3938 if g_Game_IsClient
then
3940 if NetPlrUID2
> -1 then
3941 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3945 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3946 Team
:= gPlayer2Settings
.Team
;
3948 // Ñîçäàíèå âòîðîãî èãðîêà:
3949 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3950 gPlayer2Settings
.Color
,
3952 if gPlayer2
= nil then
3953 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3956 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3957 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3958 if g_Game_IsServer
and g_Game_IsNet
then
3959 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3960 gPlayer2
.Respawn(False, True);
3962 if g_Game_IsNet
and NetUseMaster
then
3970 procedure g_Game_RemovePlayer();
3974 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3975 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3980 if g_Game_IsServer
then
3983 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3984 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3985 g_Player_Remove(Pl
.UID
);
3987 if g_Game_IsNet
and NetUseMaster
then
3996 if g_Game_IsServer
then
3999 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
4000 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
4001 g_Player_Remove(Pl
.UID
);
4003 if g_Game_IsNet
and NetUseMaster
then
4008 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
4014 procedure g_Game_Spectate();
4016 g_Game_RemovePlayer();
4017 if gPlayer1
<> nil then
4018 g_Game_RemovePlayer();
4021 procedure g_Game_SpectateCenterView();
4023 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
4024 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
4027 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
4034 e_WriteLog('Starting singleplayer game...', TMsgType
.Notify
);
4036 g_Game_ClearLoading();
4039 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
4042 gGameSettings
.GameType
:= GT_SINGLE
;
4043 gGameSettings
.MaxLives
:= 0;
4044 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
4045 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
4046 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
4047 gSwitchGameMode
:= GM_SINGLE
;
4049 g_Game_ExecuteEvent('ongamestart');
4051 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4052 g_Game_SetupScreenSize();
4054 // Ñîçäàíèå ïåðâîãî èãðîêà:
4055 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4056 gPlayer1Settings
.Color
,
4057 gPlayer1Settings
.Team
, False));
4058 if gPlayer1
= nil then
4060 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4064 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4067 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4070 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4071 gPlayer2Settings
.Color
,
4072 gPlayer2Settings
.Team
, False));
4073 if gPlayer2
= nil then
4075 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4079 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4083 // Çàãðóçêà è çàïóñê êàðòû:
4084 if not g_Game_StartMap(MAP
, True) then
4086 if (Pos(':\', Map
) > 0) or (Pos(':/', Map
) > 0) then tmps
:= Map
else tmps
:= gGameSettings
.WAD
+ ':\' + MAP
;
4087 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [tmps
]));
4091 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4095 for i
:= nPl
+1 to nPlayers
do
4096 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4099 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
4100 TimeLimit
, GoalLimit
: Word;
4102 Options
: LongWord; nPlayers
: Byte);
4108 e_WriteLog('Starting custom game...', TMsgType
.Notify
);
4110 g_Game_ClearLoading();
4113 gGameSettings
.GameType
:= GT_CUSTOM
;
4114 gGameSettings
.GameMode
:= GameMode
;
4115 gSwitchGameMode
:= GameMode
;
4116 gGameSettings
.TimeLimit
:= TimeLimit
;
4117 gGameSettings
.GoalLimit
:= GoalLimit
;
4118 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4119 gGameSettings
.Options
:= Options
;
4121 gCoopTotalMonstersKilled
:= 0;
4122 gCoopTotalSecretsFound
:= 0;
4123 gCoopTotalMonsters
:= 0;
4124 gCoopTotalSecrets
:= 0;
4128 g_Game_ExecuteEvent('ongamestart');
4130 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4131 g_Game_SetupScreenSize();
4133 // Ðåæèì íàáëþäàòåëÿ:
4134 if nPlayers
= 0 then
4141 if nPlayers
>= 1 then
4143 // Ñîçäàíèå ïåðâîãî èãðîêà:
4144 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4145 gPlayer1Settings
.Color
,
4146 gPlayer1Settings
.Team
, False));
4147 if gPlayer1
= nil then
4149 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4153 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4157 if nPlayers
>= 2 then
4159 // Ñîçäàíèå âòîðîãî èãðîêà:
4160 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4161 gPlayer2Settings
.Color
,
4162 gPlayer2Settings
.Team
, False));
4163 if gPlayer2
= nil then
4165 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4169 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4173 // Çàãðóçêà è çàïóñê êàðòû:
4174 if not g_Game_StartMap(Map
, True) then
4176 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4180 // Íåò òî÷åê ïîÿâëåíèÿ:
4181 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4182 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4183 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4184 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4185 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4187 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4191 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4195 for i
:= nPl
+1 to nPlayers
do
4196 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
4199 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
4200 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
4201 Options
: LongWord; nPlayers
: Byte;
4202 IPAddr
: LongWord; Port
: Word);
4206 e_WriteLog('Starting net game (server)...', TMsgType
.Notify
);
4208 g_Game_ClearLoading();
4211 gGameSettings
.GameType
:= GT_SERVER
;
4212 gGameSettings
.GameMode
:= GameMode
;
4213 gSwitchGameMode
:= GameMode
;
4214 gGameSettings
.TimeLimit
:= TimeLimit
;
4215 gGameSettings
.GoalLimit
:= GoalLimit
;
4216 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
4217 gGameSettings
.Options
:= Options
;
4219 gCoopTotalMonstersKilled
:= 0;
4220 gCoopTotalSecretsFound
:= 0;
4221 gCoopTotalMonsters
:= 0;
4222 gCoopTotalSecrets
:= 0;
4226 g_Game_ExecuteEvent('ongamestart');
4228 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4229 g_Game_SetupScreenSize();
4231 // Ðåæèì íàáëþäàòåëÿ:
4232 if nPlayers
= 0 then
4238 if nPlayers
>= 1 then
4240 // Ñîçäàíèå ïåðâîãî èãðîêà:
4241 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4242 gPlayer1Settings
.Color
,
4243 gPlayer1Settings
.Team
, False));
4244 if gPlayer1
= nil then
4246 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4250 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4253 if nPlayers
>= 2 then
4255 // Ñîçäàíèå âòîðîãî èãðîêà:
4256 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
4257 gPlayer2Settings
.Color
,
4258 gPlayer2Settings
.Team
, False));
4259 if gPlayer2
= nil then
4261 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
4265 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
4268 g_Game_SetLoadingText(_lc
[I_LOAD_HOST
], 0, False);
4269 if NetForwardPorts
then
4270 g_Game_SetLoadingText(_lc
[I_LOAD_PORTS
], 0, False);
4273 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
4275 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
4279 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
4281 // Çàãðóçêà è çàïóñê êàðòû:
4282 if not g_Game_StartMap(Map
, True) then
4284 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
4288 // Íåò òî÷åê ïîÿâëåíèÿ:
4289 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
4290 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
4291 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
4292 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
4293 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
4295 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4299 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4302 NetState
:= NET_STATE_GAME
;
4305 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
4320 e_WriteLog('Starting net game (client)...', TMsgType
.Notify
);
4321 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', TMsgType
.Notify
);
4323 g_Game_ClearLoading();
4326 gGameSettings
.GameType
:= GT_CLIENT
;
4328 gCoopTotalMonstersKilled
:= 0;
4329 gCoopTotalSecretsFound
:= 0;
4330 gCoopTotalMonsters
:= 0;
4331 gCoopTotalSecrets
:= 0;
4335 g_Game_ExecuteEvent('ongamestart');
4337 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4338 g_Game_SetupScreenSize();
4340 NetState
:= NET_STATE_AUTH
;
4342 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
4344 if not g_Net_Connect(Addr
, Port
) then
4346 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4347 NetState
:= NET_STATE_NONE
;
4351 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
4353 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
4358 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
4360 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
4362 Ptr
:= NetEvent
.packet
^.data
;
4363 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
4366 MID
:= InMsg
.ReadByte();
4368 if (MID
= NET_MSG_INFO
) and (State
= 0) then
4370 NetMyID
:= InMsg
.ReadByte();
4371 NetPlrUID1
:= InMsg
.ReadWord();
4373 WadName
:= InMsg
.ReadString();
4374 Map
:= InMsg
.ReadString();
4376 gWADHash
:= InMsg
.ReadMD5();
4378 gGameSettings
.GameMode
:= InMsg
.ReadByte();
4379 gSwitchGameMode
:= gGameSettings
.GameMode
;
4380 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
4381 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
4382 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
4383 gGameSettings
.Options
:= InMsg
.ReadLongWord();
4384 T
:= InMsg
.ReadLongWord();
4386 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
4387 if newResPath
= '' then
4389 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4390 newResPath
:= g_Res_DownloadWAD(WadName
);
4391 if newResPath
= '' then
4393 g_FatalError(_lc
[I_NET_ERR_HASH
]);
4394 enet_packet_destroy(NetEvent
.packet
);
4395 NetState
:= NET_STATE_NONE
;
4399 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
4401 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
4402 gPlayer1Settings
.Color
,
4403 gPlayer1Settings
.Team
, False));
4405 if gPlayer1
= nil then
4407 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
4409 enet_packet_destroy(NetEvent
.packet
);
4410 NetState
:= NET_STATE_NONE
;
4414 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
4415 gPlayer1
.UID
:= NetPlrUID1
;
4416 gPlayer1
.Reset(True);
4418 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
4420 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
4422 enet_packet_destroy(NetEvent
.packet
);
4423 NetState
:= NET_STATE_NONE
;
4431 enet_packet_destroy(NetEvent
.packet
);
4435 enet_packet_destroy(NetEvent
.packet
);
4439 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
4442 if (NetEvent
.data
<= NET_DISC_MAX
) then
4443 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
4444 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
4451 ProcessLoading(true);
4453 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) or e_KeyPressed(VK_ESCAPE
) then
4462 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
4463 NetState
:= NET_STATE_NONE
;
4467 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4468 gLMSRespawnTime
:= 0;
4471 NetState
:= NET_STATE_GAME
;
4472 MC_SEND_FullStateRequest
;
4473 e_WriteLog('NET: Connection successful.', TMsgType
.Notify
);
4476 procedure g_Game_SaveOptions();
4478 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
4481 procedure g_Game_ChangeMap(const MapPath
: String);
4485 g_Game_ClearLoading();
4487 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
4488 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4489 if gExitByTrigger
then
4492 gExitByTrigger
:= False;
4494 if not g_Game_StartMap(MapPath
, Force
) then
4495 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
4498 procedure g_Game_Restart();
4502 if g_Game_IsClient
then
4504 map
:= g_ExtractFileName(gMapInfo
.Map
);
4508 g_Game_ClearLoading();
4509 g_Game_StartMap(Map
, True, gCurrentMapFileName
);
4512 function g_Game_StartMap(Map
: String; Force
: Boolean = False; const oldMapPath
: AnsiString=''): Boolean;
4514 NewWAD
, ResName
: String;
4517 g_Map_Free((Map
<> gCurrentMapFileName
) and (oldMapPath
<> gCurrentMapFileName
));
4518 g_Player_RemoveAllCorpses();
4520 if (not g_Game_IsClient
) and
4521 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
4522 (gGameSettings
.GameMode
<> GM_SINGLE
) then
4524 if gSwitchGameMode
= GM_CTF
then
4525 gGameSettings
.MaxLives
:= 0;
4526 gGameSettings
.GameMode
:= gSwitchGameMode
;
4529 gSwitchGameMode
:= gGameSettings
.GameMode
;
4531 g_Player_ResetTeams();
4533 if isWadPath(Map
) then
4535 NewWAD
:= g_ExtractWadName(Map
);
4536 ResName
:= g_ExtractFileName(Map
);
4537 if g_Game_IsServer
then
4539 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
4540 g_Game_LoadWAD(NewWAD
);
4542 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4543 g_Game_ClientWAD(NewWAD
, gWADHash
);
4547 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
4550 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
4552 gState
:= STATE_NONE
;
4553 g_ActiveWindow
:= nil;
4559 if gGameSettings
.GameMode
= GM_CTF
then
4561 g_Map_ResetFlag(FLAG_RED
);
4562 g_Map_ResetFlag(FLAG_BLUE
);
4563 // CTF, à ôëàãîâ íåò:
4564 if not g_Map_HaveFlagPoints() then
4565 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
4570 gState
:= STATE_MENU
;
4575 gPauseMain
:= false;
4576 gPauseHolmes
:= false;
4578 NetTimeToUpdate
:= 1;
4579 NetTimeToReliable
:= 0;
4580 NetTimeToMaster
:= NetMasterRate
;
4581 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4582 gLMSRespawnTime
:= 0;
4583 gMissionFailed
:= False;
4586 gCoopMonstersKilled
:= 0;
4587 gCoopSecretsFound
:= 0;
4589 gVoteInProgress
:= False;
4590 gVotePassed
:= False;
4596 if not gGameOn
then Exit
;
4598 g_Game_SpectateCenterView();
4600 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
4602 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4603 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
4604 gLMSSoftSpawn
:= True;
4605 if NetMode
= NET_SERVER
then
4606 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
4608 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
4611 if NetMode
= NET_SERVER
then
4613 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
4616 if NetUseMaster
then
4618 if (NetMHost
= nil) or (NetMPeer
= nil) then
4619 if not g_Net_Slist_Connect
then
4620 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4625 if NetClients
<> nil then
4626 for I
:= 0 to High(NetClients
) do
4627 if NetClients
[I
].Used
then
4629 NetClients
[I
].Voted
:= False;
4630 if NetClients
[I
].RequestedFullUpdate
then
4632 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
4633 NetClients
[I
].RequestedFullUpdate
:= False;
4637 g_Net_UnbanNonPermHosts();
4642 gCoopTotalMonstersKilled
:= 0;
4643 gCoopTotalSecretsFound
:= 0;
4644 gCoopTotalMonsters
:= 0;
4645 gCoopTotalSecrets
:= 0;
4649 g_Game_ExecuteEvent('onmapstart');
4652 procedure SetFirstLevel();
4656 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4657 if MapList
= nil then
4660 SortSArray(MapList
);
4661 gNextMap
:= MapList
[Low(MapList
)];
4666 procedure g_Game_ExitLevel(const Map
: AnsiString);
4670 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
4671 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
4672 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
4673 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
4675 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4676 if gGameSettings
.GameType
= GT_SINGLE
then
4677 gExit
:= EXIT_ENDLEVELSINGLE
4678 else // Âûøëè â âûõîä â Ñâîåé èãðå
4680 gExit
:= EXIT_ENDLEVELCUSTOM
;
4681 if gGameSettings
.GameMode
= GM_COOP
then
4682 g_Player_RememberAll
;
4684 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4687 if gGameSettings
.GameMode
= GM_COOP
then
4690 gStatsPressed
:= True;
4691 gNextMap
:= 'MAP01';
4693 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4696 if g_Game_IsNet
then
4698 MH_SEND_GameStats();
4699 MH_SEND_CoopStats();
4705 procedure g_Game_RestartLevel();
4709 if gGameSettings
.GameMode
= GM_SINGLE
then
4714 gExit
:= EXIT_ENDLEVELCUSTOM
;
4715 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4719 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
4723 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
4725 if not g_Game_IsClient
then
4727 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
4730 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4731 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
4735 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
4739 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
4740 g_Game_LoadWAD(NewWAD
);
4743 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
4745 i
, n
, nb
, nr
: Integer;
4747 function monRespawn (mon
: TMonster
): Boolean;
4749 result
:= false; // don't stop
4750 if not mon
.FNoRespawn
then mon
.Respawn();
4754 if not g_Game_IsServer
then Exit
;
4755 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
4756 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4757 gLMSRespawnTime
:= 0;
4760 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
4762 gMissionFailed
:= True;
4763 g_Game_RestartLevel
;
4767 n
:= 0; nb
:= 0; nr
:= 0;
4768 for i
:= Low(gPlayers
) to High(gPlayers
) do
4769 if (gPlayers
[i
] <> nil) and
4770 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
4771 (gPlayers
[i
] is TBot
)) then
4774 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
4775 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
4778 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
4780 // wait a second until the fuckers finally decide to join
4781 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4782 gLMSRespawnTime
:= gTime
+ 1000;
4783 gLMSSoftSpawn
:= NoMapRestart
;
4787 g_Player_RemoveAllCorpses
;
4788 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
4789 if g_Game_IsNet
then
4790 MH_SEND_GameEvent(NET_EV_LMS_START
);
4792 for i
:= Low(gPlayers
) to High(gPlayers
) do
4794 if gPlayers
[i
] = nil then continue
;
4795 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
4796 // don't touch normal spectators
4797 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
4799 gPlayers
[i
].FNoRespawn
:= True;
4800 gPlayers
[i
].Lives
:= 0;
4801 if g_Game_IsNet
then
4802 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
4805 gPlayers
[i
].FNoRespawn
:= False;
4806 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
4807 gPlayers
[i
].Respawn(False, True);
4808 if gGameSettings
.GameMode
= GM_COOP
then
4810 gPlayers
[i
].Frags
:= 0;
4811 gPlayers
[i
].RecallState
;
4813 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
4814 gPlayer1
:= g_Player_Get(gLMSPID1
);
4815 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
4816 gPlayer2
:= g_Player_Get(gLMSPID2
);
4819 g_Items_RestartRound();
4822 g_Mons_ForEach(monRespawn
);
4824 gLMSSoftSpawn
:= False;
4827 function g_Game_GetFirstMap(WAD
: String): String;
4831 MapList
:= g_Map_GetMapsList(WAD
);
4832 if MapList
= nil then
4835 SortSArray(MapList
);
4836 Result
:= MapList
[Low(MapList
)];
4838 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4844 function g_Game_GetNextMap(): String;
4851 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4852 if MapList
= nil then
4855 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4857 SortSArray(MapList
);
4859 for I
:= Low(MapList
) to High(MapList
) do
4860 if Map
= MapList
[I
] then
4866 if MapIndex
<> -255 then
4868 if MapIndex
= High(MapList
) then
4869 Result
:= MapList
[Low(MapList
)]
4871 Result
:= MapList
[MapIndex
+ 1];
4873 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4879 procedure g_Game_NextLevel();
4881 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4882 gExit
:= EXIT_ENDLEVELCUSTOM
4885 gExit
:= EXIT_ENDLEVELSINGLE
;
4889 if gNextMap
<> '' then Exit
;
4890 gNextMap
:= g_Game_GetNextMap();
4893 function g_Game_IsTestMap(): Boolean;
4895 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4898 procedure g_Game_DeleteTestMap();
4901 //MapName: AnsiString;
4909 a
:= Pos('.wad:\', toLowerCase1251(gMapToDelete
));
4910 if (a
= 0) then a
:= Pos('.wad:/', toLowerCase1251(gMapToDelete
));
4911 if (a
= 0) then exit
;
4913 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
4914 WadName
:= Copy(gMapToDelete
, 1, a
+3);
4915 Delete(gMapToDelete
, 1, a
+5);
4916 gMapToDelete
:= UpperCase(gMapToDelete
);
4918 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
4921 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4922 if MapName <> TEST_MAP_NAME then
4925 if not gTempDelete then
4927 time := g_GetFileTime(WadName);
4928 WAD := TWADFile.Create();
4931 if not WAD.ReadFile(WadName) then
4932 begin // Íåò òàêîãî WAD-ôàéëà
4937 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4939 MapList := WAD.GetResourcesList('');
4941 if MapList <> nil then
4942 for a := 0 to High(MapList) do
4943 if MapList[a] = MapName then
4945 // Óäàëÿåì è ñîõðàíÿåì:
4946 WAD.RemoveResource('', MapName);
4947 WAD.SaveTo(WadName);
4952 g_SetFileTime(WadName, time);
4955 if gTempDelete
then DeleteFile(WadName
);
4958 procedure GameCVars(P
: SSArray
);
4961 stat
: TPlayerStatArray
;
4966 cmd
:= LowerCase(P
[0]);
4967 if cmd
= 'r_showfps' then
4969 if (Length(P
) > 1) and
4970 ((P
[1] = '1') or (P
[1] = '0')) then
4971 gShowFPS
:= (P
[1][1] = '1');
4974 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4976 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4978 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4980 with gGameSettings
do
4982 if (Length(P
) > 1) and
4983 ((P
[1] = '1') or (P
[1] = '0')) then
4985 if (P
[1][1] = '1') then
4986 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4988 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4991 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4992 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4994 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4996 if g_Game_IsNet
then MH_SEND_GameSettings
;
4999 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
5001 with gGameSettings
do
5003 if (Length(P
) > 1) and
5004 ((P
[1] = '1') or (P
[1] = '0')) then
5006 if (P
[1][1] = '1') then
5007 Options
:= Options
or GAME_OPTION_WEAPONSTAY
5009 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
5012 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
5013 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
5015 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
5017 if g_Game_IsNet
then MH_SEND_GameSettings
;
5020 else if cmd
= 'g_gamemode' then
5022 a
:= g_Game_TextToMode(P
[1]);
5023 if a
= GM_SINGLE
then a
:= GM_COOP
;
5024 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
5026 gSwitchGameMode
:= a
;
5027 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
5028 (gState
= STATE_INTERSINGLE
) then
5029 gSwitchGameMode
:= GM_SINGLE
;
5031 gGameSettings
.GameMode
:= gSwitchGameMode
;
5033 if gSwitchGameMode
= gGameSettings
.GameMode
then
5034 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
5035 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
5037 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
5038 [g_Game_ModeToText(gGameSettings
.GameMode
),
5039 g_Game_ModeToText(gSwitchGameMode
)]));
5041 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
5043 with gGameSettings
do
5045 if (Length(P
) > 1) and
5046 ((P
[1] = '1') or (P
[1] = '0')) then
5048 if (P
[1][1] = '1') then
5049 Options
:= Options
or GAME_OPTION_ALLOWEXIT
5051 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
5054 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
5055 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
5057 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
5058 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5060 if g_Game_IsNet
then MH_SEND_GameSettings
;
5063 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
5065 with gGameSettings
do
5067 if (Length(P
) > 1) and
5068 ((P
[1] = '1') or (P
[1] = '0')) then
5070 if (P
[1][1] = '1') then
5071 Options
:= Options
or GAME_OPTION_MONSTERS
5073 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
5076 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
5077 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
5079 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
5080 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5082 if g_Game_IsNet
then MH_SEND_GameSettings
;
5085 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
5087 with gGameSettings
do
5089 if (Length(P
) > 1) and
5090 ((P
[1] = '1') or (P
[1] = '0')) then
5092 if (P
[1][1] = '1') then
5093 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
5095 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
5098 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
5099 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
5101 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
5103 if g_Game_IsNet
then MH_SEND_GameSettings
;
5106 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
5108 with gGameSettings
do
5110 if (Length(P
) > 1) and
5111 ((P
[1] = '1') or (P
[1] = '0')) then
5113 if (P
[1][1] = '1') then
5114 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
5116 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
5119 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
5120 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
5122 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
5124 if g_Game_IsNet
then MH_SEND_GameSettings
;
5127 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
5129 if Length(P
) > 1 then
5131 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
5132 gGameSettings
.WarmupTime
:= 30
5134 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
5137 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
5138 [gGameSettings
.WarmupTime
]));
5139 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
5141 else if cmd
= 'net_interp' then
5143 if (Length(P
) > 1) then
5144 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
5146 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
5147 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5148 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
5149 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5152 else if cmd
= 'net_forceplayerupdate' then
5154 if (Length(P
) > 1) and
5155 ((P
[1] = '1') or (P
[1] = '0')) then
5156 NetForcePlayerUpdate
:= (P
[1][1] = '1');
5158 if NetForcePlayerUpdate
then
5159 g_Console_Add('net_forceplayerupdate = 1')
5161 g_Console_Add('net_forceplayerupdate = 0');
5162 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5163 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
5164 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5167 else if cmd
= 'net_predictself' then
5169 if (Length(P
) > 1) and
5170 ((P
[1] = '1') or (P
[1] = '0')) then
5171 NetPredictSelf
:= (P
[1][1] = '1');
5173 if NetPredictSelf
then
5174 g_Console_Add('net_predictself = 1')
5176 g_Console_Add('net_predictself = 0');
5177 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
5178 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
5179 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
5182 else if cmd
= 'sv_name' then
5184 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5186 NetServerName
:= P
[1];
5187 if Length(NetServerName
) > 64 then
5188 SetLength(NetServerName
, 64);
5189 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
5193 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
5195 else if cmd
= 'sv_passwd' then
5197 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
5199 NetPassword
:= P
[1];
5200 if Length(NetPassword
) > 24 then
5201 SetLength(NetPassword
, 24);
5202 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
5206 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
5208 else if cmd
= 'sv_maxplrs' then
5210 if (Length(P
) > 1) then
5212 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
5213 if g_Game_IsServer
and g_Game_IsNet
then
5216 for a
:= 0 to High(NetClients
) do
5217 if NetClients
[a
].Used
then
5220 if b
> NetMaxClients
then
5222 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
5223 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
5224 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5225 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5228 if NetUseMaster
then
5233 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
5235 else if cmd
= 'sv_public' then
5237 if (Length(P
) > 1) then
5239 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
5240 if g_Game_IsServer
and g_Game_IsNet
then
5241 if NetUseMaster
then
5243 if NetMPeer
= nil then
5244 if not g_Net_Slist_Connect() then
5245 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
5246 g_Net_Slist_Update();
5249 if NetMPeer
<> nil then
5250 g_Net_Slist_Disconnect();
5253 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
5255 else if cmd
= 'sv_intertime' then
5257 if (Length(P
) > 1) then
5258 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
5260 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
5262 else if cmd
= 'p1_name' then
5264 if (Length(P
) > 1) and gGameOn
then
5266 if g_Game_IsClient
then
5268 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5269 MC_SEND_PlayerSettings
;
5272 if gPlayer1
<> nil then
5274 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
5275 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5278 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
5281 else if cmd
= 'p2_name' then
5283 if (Length(P
) > 1) and gGameOn
then
5285 if g_Game_IsClient
then
5287 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5288 MC_SEND_PlayerSettings
;
5291 if gPlayer2
<> nil then
5293 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
5294 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5297 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
5300 else if cmd
= 'p1_color' then
5302 if Length(P
) > 3 then
5303 if g_Game_IsClient
then
5305 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5306 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5307 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5308 MC_SEND_PlayerSettings
;
5311 if gPlayer1
<> nil then
5313 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5314 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5315 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5316 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
5319 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5320 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5321 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5323 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
5325 if Length(P
) > 3 then
5326 if g_Game_IsClient
then
5328 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5329 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5330 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5331 MC_SEND_PlayerSettings
;
5334 if gPlayer2
<> nil then
5336 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5337 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5338 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5339 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
5342 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
5343 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
5344 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
5346 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5348 if cmd
= 'r_showtime' then
5350 if (Length(P
) > 1) and
5351 ((P
[1] = '1') or (P
[1] = '0')) then
5352 gShowTime
:= (P
[1][1] = '1');
5355 g_Console_Add(_lc
[I_MSG_TIME_ON
])
5357 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
5359 else if cmd
= 'r_showscore' then
5361 if (Length(P
) > 1) and
5362 ((P
[1] = '1') or (P
[1] = '0')) then
5363 gShowGoals
:= (P
[1][1] = '1');
5366 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
5368 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
5370 else if cmd
= 'r_showstat' then
5372 if (Length(P
) > 1) and
5373 ((P
[1] = '1') or (P
[1] = '0')) then
5374 gShowStat
:= (P
[1][1] = '1');
5377 g_Console_Add(_lc
[I_MSG_STATS_ON
])
5379 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
5381 else if cmd
= 'r_showkillmsg' then
5383 if (Length(P
) > 1) and
5384 ((P
[1] = '1') or (P
[1] = '0')) then
5385 gShowKillMsg
:= (P
[1][1] = '1');
5387 if gShowKillMsg
then
5388 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
5390 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
5392 else if cmd
= 'r_showlives' then
5394 if (Length(P
) > 1) and
5395 ((P
[1] = '1') or (P
[1] = '0')) then
5396 gShowLives
:= (P
[1][1] = '1');
5399 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
5401 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
5403 else if cmd
= 'r_showspect' then
5405 if (Length(P
) > 1) and
5406 ((P
[1] = '1') or (P
[1] = '0')) then
5407 gSpectHUD
:= (P
[1][1] = '1');
5410 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
5412 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
5414 else if cmd
= 'r_showping' then
5416 if (Length(P
) > 1) and
5417 ((P
[1] = '1') or (P
[1] = '0')) then
5418 gShowPing
:= (P
[1][1] = '1');
5421 g_Console_Add(_lc
[I_MSG_PING_ON
])
5423 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
5425 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
5427 if Length(P
) > 1 then
5429 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
5430 gGameSettings
.GoalLimit
:= 0
5435 if gGameSettings
.GameMode
= GM_DM
then
5437 stat
:= g_Player_GetStats();
5439 for a
:= 0 to High(stat
) do
5440 if stat
[a
].Frags
> b
then
5444 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
5446 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
5449 if g_Game_IsNet
then MH_SEND_GameSettings
;
5452 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
5454 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
5456 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
5457 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
5459 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
5460 [gGameSettings
.TimeLimit
div 3600,
5461 (gGameSettings
.TimeLimit
div 60) mod 60,
5462 gGameSettings
.TimeLimit
mod 60]));
5463 if g_Game_IsNet
then MH_SEND_GameSettings
;
5465 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
5467 if Length(P
) > 1 then
5469 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
5470 gGameSettings
.MaxLives
:= 0
5474 stat
:= g_Player_GetStats();
5476 for a
:= 0 to High(stat
) do
5477 if stat
[a
].Lives
> b
then
5479 gGameSettings
.MaxLives
:=
5480 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
5484 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
5485 [gGameSettings
.MaxLives
]));
5486 if g_Game_IsNet
then MH_SEND_GameSettings
;
5491 procedure PrintHeapStats();
5495 hs
:= GetFPCHeapStatus();
5496 e_LogWriteLn ('v===== heap status =====v');
5497 e_LogWriteFln('max heap size = %d k', [hs
.MaxHeapSize
div 1024]);
5498 e_LogWriteFln('max heap used = %d k', [hs
.MaxHeapUsed
div 1024]);
5499 e_LogWriteFln('cur heap size = %d k', [hs
.CurrHeapSize
div 1024]);
5500 e_LogWriteFln('cur heap used = %d k', [hs
.CurrHeapUsed
div 1024]);
5501 e_LogWriteFln('cur heap free = %d k', [hs
.CurrHeapFree
div 1024]);
5502 e_LogWriteLn ('^=======================^');
5505 procedure DebugCommands(P
: SSArray
);
5512 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5513 if {gDebugMode}conIsCheatsEnabled
then
5515 cmd
:= LowerCase(P
[0]);
5516 if cmd
= 'd_window' then
5518 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
5519 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
5520 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5521 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5522 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
5524 else if cmd
= 'd_sounds' then
5526 if (Length(P
) > 1) and
5527 ((P
[1] = '1') or (P
[1] = '0')) then
5528 g_Debug_Sounds
:= (P
[1][1] = '1');
5530 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5532 else if cmd
= 'd_frames' then
5534 if (Length(P
) > 1) and
5535 ((P
[1] = '1') or (P
[1] = '0')) then
5536 g_Debug_Frames
:= (P
[1][1] = '1');
5538 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5540 else if cmd
= 'd_winmsg' then
5542 if (Length(P
) > 1) and
5543 ((P
[1] = '1') or (P
[1] = '0')) then
5544 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5546 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5548 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5550 if (Length(P
) > 1) and
5551 ((P
[1] = '1') or (P
[1] = '0')) then
5552 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5554 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5556 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5558 if Length(P
) > 1 then
5560 '0': g_debug_BotAIOff
:= 0;
5561 '1': g_debug_BotAIOff
:= 1;
5562 '2': g_debug_BotAIOff
:= 2;
5563 '3': g_debug_BotAIOff
:= 3;
5566 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5568 else if cmd
= 'd_monster' then
5570 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.alive
) and (not g_Game_IsNet
) then
5571 if Length(P
) < 2 then
5573 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5574 g_Console_Add('ID | Name');
5575 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5576 g_Console_Add(Format('%2d | %s', [b
, g_Mons_NameByTypeId(b
)]));
5577 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5580 a
:= StrToIntDef(P
[1], 0);
5581 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5582 a
:= g_Mons_TypeIdByName(P
[1]);
5584 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5585 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5588 with gPlayer1
.Obj
do
5590 mon
:= g_Monsters_Create(a
,
5591 X
+ Rect
.X
+ (Rect
.Width
div 2),
5592 Y
+ Rect
.Y
+ Rect
.Height
,
5593 gPlayer1
.Direction
, True);
5595 if (Length(P
) > 2) and (mon
<> nil) then
5597 if (CompareText(P
[2], 'normal') = 0) then mon
.MonsterBehaviour
:= BH_NORMAL
5598 else if (CompareText(P
[2], 'killer') = 0) then mon
.MonsterBehaviour
:= BH_KILLER
5599 else if (CompareText(P
[2], 'maniac') = 0) then mon
.MonsterBehaviour
:= BH_MANIAC
5600 else if (CompareText(P
[2], 'insane') = 0) then mon
.MonsterBehaviour
:= BH_INSANE
5601 else if (CompareText(P
[2], 'cannibal') = 0) then mon
.MonsterBehaviour
:= BH_CANNIBAL
5602 else if (CompareText(P
[2], 'good') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5603 else if (CompareText(P
[2], 'friend') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5604 else if (CompareText(P
[2], 'friendly') = 0) then mon
.MonsterBehaviour
:= BH_GOOD
5605 else mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5610 else if (cmd
= 'd_health') then
5612 if (Length(P
) > 1) and
5613 ((P
[1] = '1') or (P
[1] = '0')) then
5614 g_debug_HealthBar
:= (P
[1][1] = '1');
5616 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5618 else if (cmd
= 'd_player') then
5620 if (Length(P
) > 1) and
5621 ((P
[1] = '1') or (P
[1] = '0')) then
5622 g_debug_Player
:= (P
[1][1] = '1');
5624 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5626 else if (cmd
= 'd_joy') then
5629 g_Console_Add(e_JoystickStateToString(a
));
5631 else if (cmd
= 'd_mem') then
5637 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5641 procedure GameCheats(P
: SSArray
);
5647 if (not gGameOn
) or (not conIsCheatsEnabled
) then
5649 g_Console_Add('not available');
5655 g_Console_Add('where is the player?!');
5658 cmd
:= LowerCase(P
[0]);
5662 plr
.GodMode
:= not plr
.GodMode
;
5663 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5666 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5667 if cmd
= 'give' then
5669 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
5670 for f
:= 1 to High(P
) do
5672 cmd
:= LowerCase(P
[f
]);
5673 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
5674 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
5675 if cmd
= 'exit' then
5677 if gTriggers
<> nil then
5679 for a
:= 0 to High(gTriggers
) do
5681 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5683 g_Console_Add('player left the map');
5684 gExitByTrigger
:= True;
5685 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
5686 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
5694 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
5695 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
5696 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
5697 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
5698 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
5700 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
5701 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
5703 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
5704 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;
5706 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
5707 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
5709 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
5710 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
5712 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
5713 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
5715 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
5716 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
5717 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
5719 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
5720 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
5721 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
5722 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;
5723 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
5724 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
5726 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;
5727 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;
5728 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;
5729 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;
5730 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;
5731 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;
5733 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
5734 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;
5736 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;
5737 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;
5739 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
5741 if cmd
= 'ammo' then
5743 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
5744 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
5745 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
5746 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
5747 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
5748 g_Console_Add('player got some ammo');
5752 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
5753 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
5755 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
5756 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
5758 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
5759 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
5761 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
5762 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
5764 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
5766 if cmd
= 'weapons' then
5768 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
5769 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
5770 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
5771 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
5772 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
5773 plr
.GiveItem(ITEM_WEAPON_BFG
);
5774 g_Console_Add('player got weapons');
5778 if cmd
= 'keys' then
5780 plr
.GiveItem(ITEM_KEY_RED
);
5781 plr
.GiveItem(ITEM_KEY_GREEN
);
5782 plr
.GiveItem(ITEM_KEY_BLUE
);
5783 g_Console_Add('player got all keys');
5787 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
5792 if cmd
= 'open' then
5794 g_Console_Add('player activated sesame');
5795 g_Triggers_OpenAll();
5802 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
5806 if cmd
= 'noclip' then
5809 g_Console_Add('wall hardeness adjusted');
5813 if cmd
= 'notarget' then
5815 plr
.NoTarget
:= not plr
.NoTarget
;
5816 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
5820 if cmd
= 'noreload' then
5822 plr
.NoReload
:= not plr
.NoReload
;
5823 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
5827 if cmd
= 'speedy' then
5829 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
5830 g_Console_Add('speed adjusted');
5834 if cmd
= 'jumpy' then
5836 VEL_JUMP
:= 30-VEL_JUMP
;
5837 g_Console_Add('jump height adjusted');
5841 if cmd
= 'automap' then
5843 gShowMap
:= not gShowMap
;
5844 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
5848 if cmd
= 'aimline' then
5850 gAimLine
:= not gAimLine
;
5851 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
5856 procedure GameCommands(P
: SSArray
);
5862 pl
: pTNetClient
= nil;
5869 cmd
:= LowerCase(P
[0]);
5871 if (cmd
= 'quit') or
5878 else if cmd
= 'pause' then
5880 if (g_ActiveWindow
= nil) then
5881 g_Game_Pause(not gPauseMain
);
5883 else if cmd
= 'endgame' then
5884 gExit
:= EXIT_SIMPLE
5885 else if cmd
= 'restart' then
5887 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5889 if g_Game_IsClient
then
5891 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5896 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5898 else if cmd
= 'kick' then
5900 if g_Game_IsServer
then
5902 if Length(P
) < 2 then
5904 g_Console_Add('kick <name>');
5909 g_Console_Add('kick <name>');
5913 if g_Game_IsNet
then
5914 pl
:= g_Net_Client_ByName(P
[1]);
5917 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5918 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
5919 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5920 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5921 if NetUseMaster
then
5923 end else if gPlayers
<> nil then
5924 for a
:= Low(gPlayers
) to High(gPlayers
) do
5925 if gPlayers
[a
] <> nil then
5926 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5928 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
5929 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5931 gPlayers
[a
].Lives
:= 0;
5932 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5933 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5934 g_Player_Remove(gPlayers
[a
].UID
);
5935 if NetUseMaster
then
5937 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
5941 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5943 else if cmd
= 'kick_id' then
5945 if g_Game_IsServer
and g_Game_IsNet
then
5947 if Length(P
) < 2 then
5949 g_Console_Add('kick_id <client ID>');
5954 g_Console_Add('kick_id <client ID>');
5958 a
:= StrToIntDef(P
[1], 0);
5959 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5961 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5963 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5964 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5965 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5966 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5967 if NetUseMaster
then
5972 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5974 else if cmd
= 'ban' then
5976 if g_Game_IsServer
and g_Game_IsNet
then
5978 if Length(P
) < 2 then
5980 g_Console_Add('ban <name>');
5985 g_Console_Add('ban <name>');
5989 pl
:= g_Net_Client_ByName(P
[1]);
5992 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5993 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5994 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5995 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5996 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5997 if NetUseMaster
then
6000 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6002 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6004 else if cmd
= 'ban_id' then
6006 if g_Game_IsServer
and g_Game_IsNet
then
6008 if Length(P
) < 2 then
6010 g_Console_Add('ban_id <client ID>');
6015 g_Console_Add('ban_id <client ID>');
6019 a
:= StrToIntDef(P
[1], 0);
6020 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6021 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6023 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6024 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
6025 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
6026 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6027 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6028 if NetUseMaster
then
6032 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6034 else if cmd
= 'permban' then
6036 if g_Game_IsServer
and g_Game_IsNet
then
6038 if Length(P
) < 2 then
6040 g_Console_Add('permban <name>');
6045 g_Console_Add('permban <name>');
6049 pl
:= g_Net_Client_ByName(P
[1]);
6052 s
:= g_Net_ClientName_ByID(pl
^.ID
);
6053 g_Net_BanHost(pl
^.Peer
^.address
.host
);
6054 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
6055 g_Net_SaveBanList();
6056 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6057 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6058 if NetUseMaster
then
6061 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6063 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6065 else if cmd
= 'permban_id' then
6067 if g_Game_IsServer
and g_Game_IsNet
then
6069 if Length(P
) < 2 then
6071 g_Console_Add('permban_id <client ID>');
6076 g_Console_Add('permban_id <client ID>');
6080 a
:= StrToIntDef(P
[1], 0);
6081 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
6082 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6084 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
6085 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
6086 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
6087 g_Net_SaveBanList();
6088 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
6089 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
6090 if NetUseMaster
then
6094 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6096 else if cmd
= 'unban' then
6098 if g_Game_IsServer
and g_Game_IsNet
then
6100 if Length(P
) < 2 then
6102 g_Console_Add('unban <IP Address>');
6107 g_Console_Add('unban <IP Address>');
6111 if g_Net_UnbanHost(P
[1]) then
6113 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
6114 g_Net_SaveBanList();
6116 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
6118 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6120 else if cmd
= 'clientlist' then
6122 if g_Game_IsServer
and g_Game_IsNet
then
6125 if NetClients
<> nil then
6126 for a
:= Low(NetClients
) to High(NetClients
) do
6127 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
6129 plr
:= g_Player_Get(NetClients
[a
].Player
);
6130 if plr
= nil then continue
;
6132 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
6133 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
6136 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
6138 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6140 else if cmd
= 'connect' then
6142 if (NetMode
= NET_NONE
) then
6144 if Length(P
) < 2 then
6146 g_Console_Add('connect <IP> [port] [password]');
6151 g_Console_Add('connect <IP> [port] [password]');
6155 if Length(P
) > 2 then
6156 prt
:= StrToIntDef(P
[2], 25666)
6160 if Length(P
) > 3 then
6165 g_Game_StartClient(P
[1], prt
, pw
);
6168 else if cmd
= 'disconnect' then
6170 if (NetMode
= NET_CLIENT
) then
6173 else if cmd
= 'reconnect' then
6175 if (NetMode
= NET_SERVER
) then
6178 if (NetMode
= NET_CLIENT
) then
6181 gExit
:= EXIT_SIMPLE
;
6185 //TODO: Use last successful password to reconnect, instead of ''
6186 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
6188 else if (cmd
= 'addbot') or
6189 (cmd
= 'bot_add') then
6191 if Length(P
) > 1 then
6192 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
6194 g_Bot_Add(TEAM_NONE
, 2);
6196 else if cmd
= 'bot_addlist' then
6198 if Length(P
) > 1 then
6199 if Length(P
) = 2 then
6200 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
6202 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
6204 else if cmd
= 'bot_removeall' then
6206 else if cmd
= 'chat' then
6208 if g_Game_IsNet
then
6210 if Length(P
) > 1 then
6212 for a
:= 1 to High(P
) do
6213 chstr
:= chstr
+ P
[a
] + ' ';
6215 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6217 if Length(chstr
) < 1 then
6219 g_Console_Add('chat <text>');
6223 chstr
:= b_Text_Format(chstr
);
6224 if g_Game_IsClient
then
6225 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
6227 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
6230 g_Console_Add('chat <text>');
6232 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6234 else if cmd
= 'teamchat' then
6236 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
6238 if Length(P
) > 1 then
6240 for a
:= 1 to High(P
) do
6241 chstr
:= chstr
+ P
[a
] + ' ';
6243 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6245 if Length(chstr
) < 1 then
6247 g_Console_Add('teamchat <text>');
6251 chstr
:= b_Text_Format(chstr
);
6252 if g_Game_IsClient
then
6253 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
6255 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
6256 gPlayer1Settings
.Team
);
6259 g_Console_Add('teamchat <text>');
6261 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6263 else if cmd
= 'game' then
6265 if gGameSettings
.GameType
<> GT_NONE
then
6267 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6270 if Length(P
) = 1 then
6272 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
6275 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
6276 P
[1] := addWadExtension(P
[1]);
6277 if FileExists(MapsDir
+ P
[1]) then
6279 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6280 if Length(P
) < 3 then
6283 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6286 s
:= P
[1] + ':\' + UpperCase(P
[2]);
6288 if g_Map_Exist(MapsDir
+ s
) then
6290 // Çàïóñêàåì ñâîþ èãðó
6292 with gGameSettings
do
6294 GameMode
:= g_Game_TextToMode(gcGameMode
);
6295 if gSwitchGameMode
<> GM_NONE
then
6296 GameMode
:= gSwitchGameMode
;
6297 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6298 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6300 if Length(P
) >= 4 then
6301 b
:= StrToIntDef(P
[3], 1);
6302 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
6303 GoalLimit
, MaxLives
, Options
, b
);
6308 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6310 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[2]), P
[1]]));
6312 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6314 else if cmd
= 'host' then
6316 if gGameSettings
.GameType
<> GT_NONE
then
6318 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6321 if Length(P
) < 4 then
6323 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
6326 if not StrToIp(P
[1], listen
) then
6328 prt
:= StrToIntDef(P
[2], 25666);
6330 P
[3] := addWadExtension(P
[3]);
6331 if FileExists(MapsDir
+ P
[3]) then
6333 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6334 if Length(P
) < 5 then
6337 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6340 s
:= P
[3] + ':\' + UpperCase(P
[4]);
6342 if g_Map_Exist(MapsDir
+ s
) then
6344 // Çàïóñêàåì ñâîþ èãðó
6346 with gGameSettings
do
6348 GameMode
:= g_Game_TextToMode(gcGameMode
);
6349 if gSwitchGameMode
<> GM_NONE
then
6350 GameMode
:= gSwitchGameMode
;
6351 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
6352 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
6354 if Length(P
) >= 6 then
6355 b
:= StrToIntDef(P
[5], 0);
6356 g_Game_StartServer(s
, GameMode
, TimeLimit
,
6357 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
6362 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
6364 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [UpperCase(P
[4]), P
[3]]));
6366 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
6368 else if cmd
= 'map' then
6370 if Length(P
) = 1 then
6372 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6374 g_Console_Add(cmd
+ ' <MAP>');
6375 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6377 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6379 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6381 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
6382 if Length(P
) < 3 then
6384 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6385 s
:= UpperCase(P
[1]);
6386 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6387 begin // Êàðòà íàøëàñü
6388 gExitByTrigger
:= False;
6390 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6392 gExit
:= EXIT_ENDLEVELCUSTOM
;
6394 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6395 g_Game_ChangeMap(s
);
6398 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6399 P
[1] := addWadExtension(P
[1]);
6400 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6401 if FileExists(MapsDir
+ P
[1]) then
6403 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6405 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6407 s
:= P
[1] + ':\' + P
[2];
6409 if g_Map_Exist(MapsDir
+ s
) then
6411 gExitByTrigger
:= False;
6413 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6415 gExit
:= EXIT_ENDLEVELCUSTOM
;
6417 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6418 g_Game_ChangeMap(s
);
6421 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6423 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6425 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6429 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6430 P
[1] := addWadExtension(P
[1]);
6431 if FileExists(MapsDir
+ P
[1]) then
6434 P
[2] := UpperCase(P
[2]);
6435 s
:= P
[1] + ':\' + P
[2];
6437 if g_Map_Exist(MapsDir
+ s
) then
6438 begin // Íàøëè êàðòó
6439 gExitByTrigger
:= False;
6441 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6443 gExit
:= EXIT_ENDLEVELCUSTOM
;
6445 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6446 g_Game_ChangeMap(s
);
6448 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6450 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6453 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6455 else if cmd
= 'nextmap' then
6457 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
6458 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6461 if Length(P
) = 1 then
6463 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6465 g_Console_Add(cmd
+ ' <MAP>');
6466 g_Console_Add(cmd
+ ' <WAD> [MAP]');
6469 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6474 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6476 if Length(P
) < 3 then
6478 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6479 s
:= UpperCase(P
[1]);
6480 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
6481 begin // Êàðòà íàøëàñü
6482 gExitByTrigger
:= False;
6487 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6488 P
[1] := addWadExtension(P
[1]);
6489 g_Console_Add(Format(_lc
[I_MSG_NO_MAP_FALLBACK
], [s
, P
[1]]));
6490 if FileExists(MapsDir
+ P
[1]) then
6492 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6494 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
6496 s
:= P
[1] + ':\' + P
[2];
6498 if g_Map_Exist(MapsDir
+ s
) then
6499 begin // Óñòàíàâëèâàåì êàðòó
6500 gExitByTrigger
:= False;
6505 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6507 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6509 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6513 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6514 P
[1] := addWadExtension(P
[1]);
6515 if FileExists(MapsDir
+ P
[1]) then
6518 P
[2] := UpperCase(P
[2]);
6519 s
:= P
[1] + ':\' + P
[2];
6521 if g_Map_Exist(MapsDir
+ s
) then
6522 begin // Íàøëè êàðòó
6523 gExitByTrigger
:= False;
6527 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6529 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6532 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6535 if gNextMap
= '' then
6536 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
6538 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
6541 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
6544 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6546 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6548 gExitByTrigger
:= False;
6549 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6550 if (gNextMap
= '') and (gTriggers
<> nil) then
6551 for a
:= 0 to High(gTriggers
) do
6552 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6554 gExitByTrigger
:= True;
6555 //gNextMap := gTriggers[a].Data.MapName;
6556 gNextMap
:= gTriggers
[a
].tgcMap
;
6559 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6560 if gNextMap
= '' then
6561 gNextMap
:= g_Game_GetNextMap();
6562 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6563 if not isWadPath(gNextMap
) then
6564 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
6567 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6568 if g_Map_Exist(MapsDir
+ s
) then
6569 gExit
:= EXIT_ENDLEVELCUSTOM
6571 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
6573 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6575 else if (cmd
= 'event') then
6577 if (Length(P
) <= 1) then
6579 for a
:= 0 to High(gEvents
) do
6580 if gEvents
[a
].Command
= '' then
6581 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6583 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6586 if (Length(P
) = 2) then
6588 for a
:= 0 to High(gEvents
) do
6589 if gEvents
[a
].Name
= P
[1] then
6590 if gEvents
[a
].Command
= '' then
6591 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6593 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6596 for a
:= 0 to High(gEvents
) do
6597 if gEvents
[a
].Name
= P
[1] then
6599 gEvents
[a
].Command
:= '';
6600 for b
:= 2 to High(P
) do
6601 if Pos(' ', P
[b
]) = 0 then
6602 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6604 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6605 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6609 else if cmd
= 'suicide' then
6613 if g_Game_IsClient
then
6614 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6617 if gPlayer1
<> nil then
6618 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6619 if gPlayer2
<> nil then
6620 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6624 // Êîìàíäû Ñâîåé èãðû:
6625 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6627 if cmd
= 'bot_addred' then
6629 if Length(P
) > 1 then
6630 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6632 g_Bot_Add(TEAM_RED
, 2);
6634 else if cmd
= 'bot_addblue' then
6636 if Length(P
) > 1 then
6637 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6639 g_Bot_Add(TEAM_BLUE
, 2);
6641 else if cmd
= 'spectate' then
6647 else if cmd
= 'say' then
6649 if g_Game_IsServer
and g_Game_IsNet
then
6651 if Length(P
) > 1 then
6654 for a
:= 1 to High(P
) do
6655 chstr
:= chstr
+ P
[a
] + ' ';
6657 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6659 if Length(chstr
) < 1 then
6661 g_Console_Add('say <text>');
6665 chstr
:= b_Text_Format(chstr
);
6666 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6668 else g_Console_Add('say <text>');
6670 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6672 else if cmd
= 'tell' then
6674 if g_Game_IsServer
and g_Game_IsNet
then
6676 if (Length(P
) > 2) and (P
[1] <> '') then
6679 for a
:= 2 to High(P
) do
6680 chstr
:= chstr
+ P
[a
] + ' ';
6682 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6684 if Length(chstr
) < 1 then
6686 g_Console_Add('tell <playername> <text>');
6690 pl
:= g_Net_Client_ByName(P
[1]);
6692 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6694 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6696 else g_Console_Add('tell <playername> <text>');
6698 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6700 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6702 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6704 // Äîïîëíèòåëüíîå âðåìÿ:
6705 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6707 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6708 [gGameSettings
.TimeLimit
div 3600,
6709 (gGameSettings
.TimeLimit
div 60) mod 60,
6710 gGameSettings
.TimeLimit
mod 60]));
6711 if g_Game_IsNet
then MH_SEND_GameSettings
;
6713 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6715 if (Length(P
) <= 1) then
6716 g_Console_Add('rcon_password <password>')
6718 MC_SEND_RCONPassword(P
[1]);
6720 else if cmd
= 'rcon' then
6722 if g_Game_IsClient
then
6724 if Length(P
) > 1 then
6727 for a
:= 1 to High(P
) do
6728 chstr
:= chstr
+ P
[a
] + ' ';
6730 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6732 if Length(chstr
) < 1 then
6734 g_Console_Add('rcon <command>');
6738 MC_SEND_RCONCommand(chstr
);
6740 else g_Console_Add('rcon <command>');
6743 else if cmd
= 'ready' then
6745 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6746 gLMSRespawnTime
:= gTime
+ 100;
6748 else if (cmd
= 'callvote') and g_Game_IsNet
then
6750 if Length(P
) > 1 then
6753 for a
:= 1 to High(P
) do begin
6754 if a
> 1 then chstr
:= chstr
+ ' ';
6755 chstr
:= chstr
+ P
[a
];
6758 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6760 if Length(chstr
) < 1 then
6762 g_Console_Add('callvote <command>');
6766 if g_Game_IsClient
then
6767 MC_SEND_Vote(True, chstr
)
6769 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6770 g_Console_Process('vote', True);
6773 g_Console_Add('callvote <command>');
6775 else if (cmd
= 'vote') and g_Game_IsNet
then
6777 if g_Game_IsClient
then
6779 else if gVoteInProgress
then
6781 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6782 a
:= Floor((NetClientCount
+1)/2.0) + 1
6784 a
:= Floor(NetClientCount
/2.0) + 1;
6789 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6790 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6796 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6797 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6805 procedure g_TakeScreenShot();
6813 if e_NoGraphics
then Exit
;
6814 ssdir
:= GameDir
+'/screenshots';
6815 if not findFileCI(ssdir
, true) then
6817 // try to create dir
6822 if not findFileCI(ssdir
, true) then exit
; // alas
6825 for a
:= 1 to High(Word) do
6827 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
6829 if findFileCI(t
, true) then continue
;
6830 if not findFileCI(FileName
) then
6833 st
:= createDiskFile(FileName
);
6835 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
6840 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
6848 procedure g_Game_InGameMenu(Show
: Boolean);
6850 if (g_ActiveWindow
= nil) and Show
then
6852 if gGameSettings
.GameType
= GT_SINGLE
then
6853 g_GUI_ShowWindow('GameSingleMenu')
6856 if g_Game_IsClient
then
6857 g_GUI_ShowWindow('GameClientMenu')
6859 if g_Game_IsNet
then
6860 g_GUI_ShowWindow('GameServerMenu')
6862 g_GUI_ShowWindow('GameCustomMenu');
6864 g_Sound_PlayEx('MENU_OPEN');
6866 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6867 if (not g_Game_IsNet
) then
6871 if (g_ActiveWindow
<> nil) and (not Show
) then
6873 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6874 if (not g_Game_IsNet
) then
6875 g_Game_Pause(False);
6879 procedure g_Game_Pause (Enable
: Boolean);
6883 if not gGameOn
then exit
;
6885 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6888 gPauseMain
:= Enable
;
6890 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6893 procedure g_Game_HolmesPause (Enable
: Boolean);
6897 if not gGameOn
then exit
;
6898 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then exit
;
6901 gPauseHolmes
:= Enable
;
6903 if (gPause
<> oldPause
) then g_Game_PauseAllSounds(gPause
);
6906 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6911 if gTriggers
<> nil then
6912 for i
:= 0 to High(gTriggers
) do
6913 with gTriggers
[i
] do
6914 if (TriggerType
= TRIGGER_SOUND
) and
6916 Sound
.IsPlaying() then
6918 Sound
.Pause(Enable
);
6922 if gPlayers
<> nil then
6923 for i
:= 0 to High(gPlayers
) do
6924 if gPlayers
[i
] <> nil then
6925 gPlayers
[i
].PauseSounds(Enable
);
6928 if gMusic
<> nil then
6929 gMusic
.Pause(Enable
);
6932 procedure g_Game_StopAllSounds(all
: Boolean);
6936 if gTriggers
<> nil then
6937 for i
:= 0 to High(gTriggers
) do
6938 with gTriggers
[i
] do
6939 if (TriggerType
= TRIGGER_SOUND
) and
6943 if gMusic
<> nil then
6950 procedure g_Game_UpdateTriggerSounds();
6954 if gTriggers
<> nil then
6955 for i
:= 0 to High(gTriggers
) do
6956 with gTriggers
[i
] do
6957 if (TriggerType
= TRIGGER_SOUND
) and
6960 Sound
.IsPlaying() then
6962 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
6963 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
6965 Sound
.SetPan(0.5 - tgcPan
/255.0);
6966 Sound
.SetVolume(tgcVolume
/255.0);
6969 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), tgcVolume
/255.0);
6973 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6976 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6981 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6986 if gSpectMode
<> SPECT_PLAYERS
then
6988 if gSpectPID1
= UID
then
6993 if gSpectViewTwo
and (gSpectPID2
= UID
) then
7000 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
7005 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
7010 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
7015 if gSpectMode
<> SPECT_PLAYERS
then
7017 Pl
:= g_Player_Get(gSpectPID1
);
7018 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7023 if gSpectViewTwo
then
7025 Pl
:= g_Player_Get(gSpectPID2
);
7026 if (Pl
<> nil) and (Pl
.Team
= Team
) then
7034 procedure g_Game_Message(Msg
: string; Time
: Word);
7036 MessageLineLength
:= (gScreenWidth
- 204) div e_CharFont_GetMaxWidth(gMenuFont
);
7037 MessageText
:= b_Text_Wrap(b_Text_Format(Msg
), MessageLineLength
);
7038 MessageTime
:= Time
;
7041 procedure g_Game_ChatSound(Text: String; Taunt
: Boolean = True);
7043 punct
: Array[0..13] of String =
7044 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7050 function IsPunctuation(S
: String): Boolean;
7055 if Length(S
) <> 1 then
7057 for i
:= Low(punct
) to High(punct
) do
7058 if S
= punct
[i
] then
7064 function FilterPunctuation(S
: String): String;
7068 for i
:= Low(punct
) to High(punct
) do
7069 S
:= StringReplace(S
, punct
[i
], ' ', [rfReplaceAll
]);
7075 if gUseChatSounds
and Taunt
and (gChatSounds
<> nil) and (Pos(': ', Text) > 0) then
7077 // remove player name
7078 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7079 // for FullWord check
7080 Text := toLowerCase1251(' ' + Text + ' ');
7081 fpText
:= FilterPunctuation(Text);
7083 for i
:= 0 to Length(gChatSounds
) - 1 do
7086 for j
:= 0 to Length(gChatSounds
[i
].Tags
) - 1 do
7088 if gChatSounds
[i
].FullWord
and (not IsPunctuation(gChatSounds
[i
].Tags
[j
])) then
7089 ok
:= Pos(' ' + gChatSounds
[i
].Tags
[j
] + ' ', fpText
) > 0
7091 ok
:= Pos(gChatSounds
[i
].Tags
[j
], Text) > 0;
7097 gChatSounds
[i
].Sound
.Play();
7103 g_Sound_PlayEx('SOUND_GAME_RADIO');
7106 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
7115 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
7119 if goodsnd
[a
].IsPlaying() then
7122 goodsnd
[Random(4)].Play();
7125 procedure g_Game_Announce_KillCombo(Param
: Integer);
7132 UID
:= Param
and $FFFF;
7137 Pl
:= g_Player_Get(UID
);
7146 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
7150 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
7154 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
7158 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
7166 if not g_Game_IsWatchedPlayer(UID
) then
7169 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
7173 if killsnd
[n
].IsPlaying() then
7178 procedure g_Game_StartVote(Command
, Initiator
: string);
7182 if not gVotesEnabled
then Exit
;
7183 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7184 if gVoteInProgress
or gVotePassed
then
7186 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
7187 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
7190 gVoteInProgress
:= True;
7191 gVotePassed
:= False;
7192 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
7195 gVoteCommand
:= Command
;
7197 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7198 Need
:= Floor((NetClientCount
+1)/2.0)+1
7200 Need
:= Floor(NetClientCount
/2.0)+1;
7201 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
7202 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
7205 procedure g_Game_CheckVote
;
7209 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
7210 if not gVoteInProgress
then Exit
;
7212 if (gTime
>= gVoteTimer
) then
7214 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7215 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7217 Need
:= Floor(NetClientCount
/2.0) + 1;
7218 if gVoteCount
>= Need
then
7220 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7221 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7222 gVotePassed
:= True;
7223 gVoteCmdTimer
:= gTime
+ 5000;
7227 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
7228 MH_SEND_VoteEvent(NET_VE_FAILED
);
7230 if NetClients
<> nil then
7231 for I
:= Low(NetClients
) to High(NetClients
) do
7232 if NetClients
[i
].Used
then
7233 NetClients
[i
].Voted
:= False;
7234 gVoteInProgress
:= False;
7240 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
7241 Need
:= Floor((NetClientCount
+1)/2.0) + 1
7243 Need
:= Floor(NetClientCount
/2.0) + 1;
7244 if gVoteCount
>= Need
then
7246 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
7247 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
7248 gVoteInProgress
:= False;
7249 gVotePassed
:= True;
7250 gVoteCmdTimer
:= gTime
+ 5000;
7253 if NetClients
<> nil then
7254 for I
:= Low(NetClients
) to High(NetClients
) do
7255 if NetClients
[i
].Used
then
7256 NetClients
[i
].Voted
:= False;
7261 procedure g_Game_LoadMapList(FileName
: string);
7269 if not FileExists(FileName
) then Exit
;
7271 AssignFile(ListFile
, FileName
);
7273 while not EOF(ListFile
) do
7275 ReadLn(ListFile
, s
);
7278 if s
= '' then Continue
;
7280 SetLength(MapList
, Length(MapList
)+1);
7281 MapList
[High(MapList
)] := s
;
7283 CloseFile(ListFile
);
7286 procedure g_Game_SetDebugMode();
7289 // ×èòû (äàæå â ñâîåé èãðå):
7293 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
7297 if Length(LoadingStat
.Msgs
) = 0 then
7303 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7304 if NextMsg
= Length(Msgs
) then
7306 for i
:= 0 to High(Msgs
)-1 do
7307 Msgs
[i
] := Msgs
[i
+1];
7315 Msgs
[NextMsg
-1] := Text;
7319 PBarWasHere
:= false;
7322 g_ActiveWindow
:= nil;
7324 ProcessLoading(true);
7327 procedure g_Game_StepLoading(Value
: Integer = -1);
7338 if (ShowCount
> LOADING_SHOW_STEP
) or (Value
> -1) then
7346 procedure g_Game_ClearLoading();
7355 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
7356 if len
< 1 then len
:= 1;
7357 SetLength(Msgs
, len
);
7358 for len
:= Low(Msgs
) to High(Msgs
) do
7361 PBarWasHere
:= false;
7365 procedure Parse_Params(var pars
: TParamStrValues
);
7372 while i
<= ParamCount
do
7375 if (s
[1] = '-') and (Length(s
) > 1) then
7377 if (s
[2] = '-') and (Length(s
) > 2) then
7378 begin // Îäèíî÷íûé ïàðàìåòð
7379 SetLength(pars
, Length(pars
) + 1);
7380 with pars
[High(pars
)] do
7382 Name
:= LowerCase(s
);
7387 if (i
< ParamCount
) then
7388 begin // Ïàðàìåòð ñî çíà÷åíèåì
7390 SetLength(pars
, Length(pars
) + 1);
7391 with pars
[High(pars
)] do
7393 Name
:= LowerCase(s
);
7394 Value
:= LowerCase(ParamStr(i
));
7403 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
7408 for i
:= 0 to High(pars
) do
7409 if pars
[i
].Name
= aName
then
7411 Result
:= pars
[i
].Value
;
7416 procedure g_Game_Process_Params();
7418 pars
: TParamStrValues
;
7421 LimT
, LimS
: Integer;
7432 s
:= Find_Param_Value(pars
, '--debug');
7435 g_Game_SetDebugMode();
7436 s
:= Find_Param_Value(pars
, '--netdump');
7441 // Connect when game loads
7442 ip
:= Find_Param_Value(pars
, '-connect');
7446 s
:= Find_Param_Value(pars
, '-port');
7447 if (s
= '') or not TryStrToInt(s
, Port
) then
7450 s
:= Find_Param_Value(pars
, '-pw');
7452 g_Game_StartClient(ip
, Port
, s
);
7456 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
7459 gDefaultMegawadStart
:= s
;
7462 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
7463 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
7465 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
7468 // Start map when game loads:
7469 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
7470 if isWadPath(map
) then
7473 s
:= Find_Param_Value(pars
, '-gm');
7474 GMode
:= g_Game_TextToMode(s
);
7475 if GMode
= GM_NONE
then GMode
:= GM_DM
;
7476 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
7479 s
:= Find_Param_Value(pars
, '-limt');
7480 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
7486 s
:= Find_Param_Value(pars
, '-lims');
7487 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
7493 s
:= Find_Param_Value(pars
, '-lives');
7494 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
7500 s
:= Find_Param_Value(pars
, '-opt');
7502 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
7504 Opt
:= StrToIntDef(s
, 0);
7506 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
7509 s
:= Find_Param_Value(pars
, '--close');
7513 // Override map to test:
7514 s
:= LowerCase(Find_Param_Value(pars
, '-testmap'));
7516 gTestMap
:= MapsDir
+ s
;
7518 // Delete test map after play:
7519 s
:= Find_Param_Value(pars
, '--testdelete');
7522 gMapToDelete
:= MapsDir
+ map
;
7523 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType
.Fatal
);
7527 // Delete temporary WAD after play:
7528 s
:= Find_Param_Value(pars
, '--tempdelete');
7529 if (s
<> '') and (gTestMap
<> '') then
7531 gMapToDelete
:= gTestMap
;
7532 gTempDelete
:= True;
7535 // Number of players:
7536 s
:= Find_Param_Value(pars
, '-pl');
7540 n
:= StrToIntDef(s
, 1);
7543 s
:= Find_Param_Value(pars
, '-port');
7544 if (s
= '') or not TryStrToInt(s
, Port
) then
7545 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
7547 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
7550 // Execute script when game loads:
7551 s
:= Find_Param_Value(pars
, '-exec');
7554 if not isWadPath(s
) then
7555 s
:= GameDir
+ '/' + s
;
7560 if IOResult
<> 0 then
7562 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7563 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7567 e_WriteLog('Executing script: ' + s
, TMsgType
.Notify
);
7568 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
7573 if IOResult
<> 0 then
7575 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), TMsgType
.Warning
);
7576 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
7580 if Pos('#', s
) <> 1 then // script comment
7581 g_Console_Process(s
, True);
7592 conRegVar('pf_draw_frame', @g_profile_frame_draw
, 'draw frame rendering profiles', 'render profiles');
7593 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7594 conRegVar('pf_coldet', @g_profile_collision
, 'draw collision detection profiles', 'coldet profiles');
7595 conRegVar('pf_los', @g_profile_los
, 'draw monster LOS profiles', 'monster LOS profiles');
7597 conRegVar('r_sq_draw', @gdbg_map_use_accel_render
, 'accelerated spatial queries in rendering', 'accelerated rendering');
7598 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet
, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7599 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel
, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7600 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace
, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7602 conRegVar('pr_enabled', @gpart_dbg_enabled
, 'enable/disable particles', 'particles');
7603 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled
, 'enable/disable particle physics', 'particle physics');
7605 conRegVar('los_enabled', @gmon_dbg_los_enabled
, 'enable/disable monster LOS calculations', 'monster LOS', true);
7606 conRegVar('mon_think', @gmon_debug_think
, 'enable/disable monster thinking', 'monster thinking', true);
7608 {$IFDEF ENABLE_HOLMES}
7609 conRegVar('dbg_holmes', @g_holmes_enabled
, 'enable/disable Holmes', 'Holmes', true);
7612 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds
, 'ignore level bounds', '', false);
7614 conRegVar('r_scale', @g_dbg_scale
, 0.01, 100.0, 'render scale', '', false);
7616 conRegVar('light_enabled', @gwin_k8_enable_light_experiments
, 'enable/disable dynamic lighting', 'lighting');
7617 conRegVar('light_player_halo', @g_playerLight
, 'enable/disable player halo', 'player light halo');
7619 conRegVar('r_smallmap_align_h', @r_smallmap_h
, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7620 conRegVar('r_smallmap_align_v', @r_smallmap_v
, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');