1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 g_basic
, g_player
, e_graphics
, Classes
, g_res_downloader
,
23 SysUtils
, g_sound
, g_gui
, MAPSTRUCT
, wadreader
, md5
, xprofiler
;
26 TGameSettings
= record
42 TDelayedEvent
= record
50 TPlayerSettings
= record
69 function g_Game_IsNet(): Boolean;
70 function g_Game_IsServer(): Boolean;
71 function g_Game_IsClient(): Boolean;
72 procedure g_Game_Init();
73 procedure g_Game_Free();
74 procedure g_Game_LoadData();
75 procedure g_Game_FreeData();
76 procedure g_Game_Update();
77 procedure g_Game_Draw();
78 procedure g_Game_Quit();
79 procedure g_Game_SetupScreenSize();
80 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
81 function g_Game_ModeToText(Mode
: Byte): string;
82 function g_Game_TextToMode(Mode
: string): Byte;
83 procedure g_Game_ExecuteEvent(Name
: String);
84 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
85 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
86 procedure g_Game_RemovePlayer();
87 procedure g_Game_Spectate();
88 procedure g_Game_SpectateCenterView();
89 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
90 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte);
91 procedure g_Game_StartServer(Map
: String; GameMode
: Byte; TimeLimit
, GoalLimit
: Word; MaxLives
: Byte; Options
: LongWord; nPlayers
: Byte; IPAddr
: LongWord; Port
: Word);
92 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
93 procedure g_Game_Restart();
94 procedure g_Game_RestartLevel();
95 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
96 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
97 procedure g_Game_SaveOptions();
98 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
99 procedure g_Game_ChangeMap(MapPath
: String);
100 procedure g_Game_ExitLevel(Map
: Char16
);
101 function g_Game_GetFirstMap(WAD
: String): String;
102 function g_Game_GetNextMap(): String;
103 procedure g_Game_NextLevel();
104 procedure g_Game_Pause(Enable
: Boolean);
105 procedure g_Game_InGameMenu(Show
: Boolean);
106 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
107 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
108 procedure g_Game_Message(Msg
: String; Time
: Word);
109 procedure g_Game_LoadMapList(FileName
: String);
110 procedure g_Game_PauseAllSounds(Enable
: Boolean);
111 procedure g_Game_StopAllSounds(all
: Boolean);
112 procedure g_Game_UpdateTriggerSounds();
113 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
114 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
115 procedure g_Game_Announce_KillCombo(Param
: Integer);
116 procedure g_Game_StartVote(Command
, Initiator
: string);
117 procedure g_Game_CheckVote
;
118 procedure g_TakeScreenShot();
119 procedure g_FatalError(Text: String);
120 procedure g_SimpleError(Text: String);
121 function g_Game_IsTestMap(): Boolean;
122 procedure g_Game_DeleteTestMap();
123 procedure GameCVars(P
: SArray
);
124 procedure GameCommands(P
: SArray
);
125 procedure GameCheats(P
: SArray
);
126 procedure DebugCommands(P
: SArray
);
127 procedure ProfilerCommands(P
: SArray
);
128 procedure g_Game_Process_Params
;
129 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
130 procedure g_Game_StepLoading();
131 procedure g_Game_ClearLoading();
132 procedure g_Game_SetDebugMode();
133 procedure DrawLoadingStat();
135 { procedure SetWinPause(Enable: Boolean); }
140 LOADING_SHOW_STEP
= 100;
141 LOADING_INTERLINE
= 20;
156 MESSAGE_DIKEY
= WM_USER
+ 1;
161 EXIT_ENDLEVELSINGLE
= 4;
162 EXIT_ENDLEVELCUSTOM
= 5;
164 GAME_OPTION_RESERVED
= 1;
165 GAME_OPTION_TEAMDAMAGE
= 2;
166 GAME_OPTION_ALLOWEXIT
= 4;
167 GAME_OPTION_WEAPONSTAY
= 8;
168 GAME_OPTION_MONSTERS
= 16;
169 GAME_OPTION_BOTVSPLAYER
= 32;
170 GAME_OPTION_BOTVSMONSTER
= 64;
175 STATE_INTERCUSTOM
= 3;
176 STATE_INTERSINGLE
= 4;
182 LMS_RESPAWN_NONE
= 0;
183 LMS_RESPAWN_WARMUP
= 1;
184 LMS_RESPAWN_FINAL
= 2;
200 CONFIG_FILENAME
= 'Doom2DF.cfg';
201 LOG_FILENAME
= 'Doom2DF.log';
203 TEST_MAP_NAME
= '$$$_TEST_$$$';
205 STD_PLAYER_MODEL
= 'Doomer';
209 gGameSettings
: TGameSettings
;
210 gPlayer1Settings
: TPlayerSettings
;
211 gPlayer2Settings
: TPlayerSettings
;
213 gPlayerScreenSize
: TPoint
;
214 gPlayer1ScreenCoord
: TPoint
;
215 gPlayer2ScreenCoord
: TPoint
;
216 gPlayer1
: TPlayer
= nil;
217 gPlayer2
: TPlayer
= nil;
218 gPlayerDrawn
: TPlayer
= nil;
220 gSwitchGameMode
: Byte = GM_DM
;
221 gHearPoint1
, gHearPoint2
: THearPoint
;
222 gSoundEffectsDF
: Boolean = False;
223 gSoundTriggerTime
: Word = 0;
224 gAnnouncer
: Byte = ANNOUNCE_NONE
;
225 goodsnd
: array[0..3] of TPlayableSound
;
226 killsnd
: array[0..3] of TPlayableSound
;
227 gDefInterTime
: ShortInt = -1;
228 gInterEndTime
: LongWord = 0;
229 gInterTime
: LongWord = 0;
230 gServInterTime
: Byte = 0;
231 gGameStartTime
: LongWord = 0;
232 gTotalMonsters
: Integer = 0;
234 gShowTime
: Boolean = True;
235 gShowFPS
: Boolean = False;
236 gShowGoals
: Boolean = True;
237 gShowStat
: Boolean = True;
238 gShowKillMsg
: Boolean = True;
239 gShowLives
: Boolean = True;
240 gShowPing
: Boolean = False;
241 gShowMap
: Boolean = False;
243 gState
: Byte = STATE_NONE
;
245 sWidth
, sHeight
: Word;
246 gSpectMode
: Byte = SPECT_NONE
;
247 gSpectHUD
: Boolean = True;
248 gSpectKeyPress
: Boolean = False;
249 gSpectX
: Integer = 0;
250 gSpectY
: Integer = 0;
251 gSpectStep
: Byte = 8;
252 gSpectViewTwo
: Boolean = False;
253 gSpectPID1
: Integer = -1;
254 gSpectPID2
: Integer = -1;
255 gMusic
: TMusic
= nil;
256 gLoadGameMode
: Boolean;
257 gCheats
: Boolean = False;
258 gMapOnce
: Boolean = False;
259 gMapToDelete
: String;
260 gTempDelete
: Boolean = False;
261 gLastMap
: Boolean = False;
262 gWinPosX
, gWinPosY
: Integer;
263 gWinSizeX
, gWinSizeY
: Integer;
264 gWinFrameX
, gWinFrameY
, gWinCaption
: Integer;
265 gWinActive
: Boolean = True; // by default window is active, lol
266 gResolutionChange
: Boolean = False;
267 gRC_Width
, gRC_Height
: Word;
268 gRC_FullScreen
, gRC_Maximized
: Boolean;
269 gLanguageChange
: Boolean = False;
270 gDebugMode
: Boolean = False;
271 g_debug_Sounds
: Boolean = False;
272 g_debug_Frames
: Boolean = False;
273 g_debug_WinMsgs
: Boolean = False;
274 g_debug_MonsterOff
: Boolean = False;
275 g_debug_BotAIOff
: Byte = 0;
276 g_debug_HealthBar
: Boolean = False;
277 g_Debug_Player
: Boolean = False;
278 gCoopMonstersKilled
: Word = 0;
279 gCoopSecretsFound
: Word = 0;
280 gCoopTotalMonstersKilled
: Word = 0;
281 gCoopTotalSecretsFound
: Word = 0;
282 gCoopTotalMonsters
: Word = 0;
283 gCoopTotalSecrets
: Word = 0;
284 gStatsOff
: Boolean = False;
285 gStatsPressed
: Boolean = False;
286 gExitByTrigger
: Boolean = False;
287 gNextMap
: String = '';
288 gLMSRespawn
: Byte = LMS_RESPAWN_NONE
;
289 gLMSRespawnTime
: Cardinal = 0;
290 gLMSSoftSpawn
: Boolean = False;
291 gMissionFailed
: Boolean = False;
292 gVoteInProgress
: Boolean = False;
293 gVotePassed
: Boolean = False;
294 gVoteCommand
: string = '';
295 gVoteTimer
: Cardinal = 0;
296 gVoteCmdTimer
: Cardinal = 0;
297 gVoteCount
: Integer = 0;
298 gVoteTimeout
: Cardinal = 30;
299 gVoted
: Boolean = False;
300 gVotesEnabled
: Boolean = True;
301 gEvents
: Array of TGameEvent
;
302 gDelayedEvents
: Array of TDelayedEvent
;
304 // move button values:
305 // bits 0-1: l/r state:
306 // 0: neither left, nor right pressed
309 // bits 4-5: l/r state when strafe was pressed
310 P1MoveButton
: Byte = 0;
311 P2MoveButton
: Byte = 0;
313 g_profile_frame_update
: Boolean = false;
314 g_profile_frame_draw
: Boolean = false;
315 g_profile_collision
: Boolean = false;
316 g_profile_history_size
: Integer = 1000;
318 procedure g_ResetDynlights ();
319 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
320 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
325 g_textures
, g_main
, g_window
, g_menu
,
326 e_input
, e_log
, g_console
, g_items
, g_map
, g_panel
,
327 g_playermodel
, g_gfx
, g_options
, g_weapons
, Math
,
328 g_triggers
, MAPDEF
, g_monsters
, e_sound
, CONFIG
,
329 BinEditor
, g_language
, g_net
, SDL
,
330 ENet
, e_msg
, g_netmsg
, g_netmaster
, GL
, GLExt
,
334 // ////////////////////////////////////////////////////////////////////////// //
336 profileFrameDraw
: TProfiler
= nil;
339 // ////////////////////////////////////////////////////////////////////////// //
342 x
, y
, radius
: Integer;
345 exploRadius
: Integer;
349 g_dynLights
: array of TDynLight
= nil;
350 g_dynLightCount
: Integer = 0;
351 g_playerLight
: Boolean = false;
353 procedure g_ResetDynlights ();
357 if not gwin_has_stencil
then begin g_dynLightCount
:= 0; exit
; end;
359 for idx
:= 0 to g_dynLightCount
-1 do
361 if g_dynLights
[idx
].exploCount
= -666 then
368 Inc(g_dynLights
[idx
].exploCount
);
369 if (g_dynLights
[idx
].exploCount
< 10) then
371 g_dynLights
[idx
].radius
:= g_dynLights
[idx
].exploRadius
+g_dynLights
[idx
].exploCount
*8;
372 g_dynLights
[idx
].a
:= 0.4+g_dynLights
[idx
].exploCount
/10;
373 if (g_dynLights
[idx
].a
> 0.8) then g_dynLights
[idx
].a
:= 0.8;
374 if lnum
<> idx
then g_dynLights
[lnum
] := g_dynLights
[idx
];
379 g_dynLightCount
:= lnum
;
382 procedure g_AddDynLight (x
, y
, radius
: Integer; r
, g
, b
, a
: Single);
384 if not gwin_has_stencil
then exit
;
385 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
386 g_dynLights
[g_dynLightCount
].x
:= x
;
387 g_dynLights
[g_dynLightCount
].y
:= y
;
388 g_dynLights
[g_dynLightCount
].radius
:= radius
;
389 g_dynLights
[g_dynLightCount
].r
:= r
;
390 g_dynLights
[g_dynLightCount
].g
:= g
;
391 g_dynLights
[g_dynLightCount
].b
:= b
;
392 g_dynLights
[g_dynLightCount
].a
:= a
;
393 g_dynLights
[g_dynLightCount
].exploCount
:= -666;
394 Inc(g_dynLightCount
);
397 procedure g_DynLightExplosion (x
, y
, radius
: Integer; r
, g
, b
: Single);
399 if not gwin_has_stencil
then exit
;
400 if g_dynLightCount
= length(g_dynLights
) then SetLength(g_dynLights
, g_dynLightCount
+1024);
401 g_dynLights
[g_dynLightCount
].x
:= x
;
402 g_dynLights
[g_dynLightCount
].y
:= y
;
403 g_dynLights
[g_dynLightCount
].radius
:= 0;
404 g_dynLights
[g_dynLightCount
].exploRadius
:= radius
;
405 g_dynLights
[g_dynLightCount
].r
:= r
;
406 g_dynLights
[g_dynLightCount
].g
:= g
;
407 g_dynLights
[g_dynLightCount
].b
:= b
;
408 g_dynLights
[g_dynLightCount
].a
:= 0;
409 g_dynLights
[g_dynLightCount
].exploCount
:= 0;
410 Inc(g_dynLightCount
);
414 // ////////////////////////////////////////////////////////////////////////// //
415 function calcProfilesHeight (prof
: TProfiler
): Integer;
418 if (prof
= nil) then exit
;
419 if (length(prof
.bars
) = 0) then exit
;
420 result
:= length(prof
.bars
)*(16+2);
424 function drawProfiles (x
, y
: Integer; prof
: TProfiler
): Integer;
431 if (prof
= nil) then exit
;
433 if (length(prof
.bars
) = 0) then exit
;
435 hgt
:= calcProfilesHeight(prof
);
436 if (x
< 0) then x
:= gScreenWidth
-(wdt
-1)+x
;
437 if (y
< 0) then y
:= gScreenHeight
-(hgt
-1)+y
;
439 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
440 e_DrawFillQuad(x
, y
, x
+wdt
-1, y
+hgt
-1, 20, 20, 20, 0, B_NONE
);
443 for ii
:= 0 to High(prof
.bars
) do
445 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);
452 // ////////////////////////////////////////////////////////////////////////// //
454 TEndCustomGameStat
= record
455 PlayerStat
: TPlayerStatArray
;
459 Map
, MapName
: String;
462 TEndSingleGameStat
= record
463 PlayerStat
: Array [0..1] of record
469 TotalSecrets
: Integer;
472 TLoadingStat
= record
476 Msgs
: Array of String;
480 TParamStrValue
= record
485 TParamStrValues
= Array of TParamStrValue
;
488 INTER_ACTION_TEXT
= 1;
489 INTER_ACTION_PIC
= 2;
490 INTER_ACTION_MUSIC
= 3;
494 FPSCounter
, UPSCounter
: Word;
495 FPSTime
, UPSTime
: LongWord;
496 DataLoaded
: Boolean = False;
497 LastScreenShot
: Int64;
498 IsDrawStat
: Boolean = False;
499 CustomStat
: TEndCustomGameStat
;
500 SingleStat
: TEndSingleGameStat
;
501 LoadingStat
: TLoadingStat
;
502 EndingGameCounter
: Byte = 0;
505 MapList
: SArray
= nil;
506 MapIndex
: Integer = -1;
512 text: Array of ShortString;
513 anim
: Array of ShortString;
514 pic
: Array of ShortString;
515 mus
: Array of ShortString;
517 triggers
: Array of record
519 actions
: Array of record
520 action
, p1
, p2
: Integer;
523 cur_trigger
: Integer;
536 function Compare(a
, b
: TPlayerStat
): Integer;
538 if a
.Spectator
then Result
:= 1
539 else if b
.Spectator
then Result
:= -1
540 else if a
.Frags
< b
.Frags
then Result
:= 1
541 else if a
.Frags
> b
.Frags
then Result
:= -1
542 else if a
.Deaths
< b
.Deaths
then Result
:= -1
543 else if a
.Deaths
> b
.Deaths
then Result
:= 1
544 else if a
.Kills
< b
.Kills
then Result
:= -1
548 procedure SortGameStat(var stat
: TPlayerStatArray
);
553 if stat
= nil then Exit
;
555 for I
:= High(stat
) downto Low(stat
) do
556 for J
:= Low(stat
) to High(stat
) - 1 do
557 if Compare(stat
[J
], stat
[J
+ 1]) = 1 then
560 stat
[J
] := stat
[J
+ 1];
565 function g_Game_ModeToText(Mode
: Byte): string;
569 GM_DM
: Result
:= _lc
[I_MENU_GAME_TYPE_DM
];
570 GM_TDM
: Result
:= _lc
[I_MENU_GAME_TYPE_TDM
];
571 GM_CTF
: Result
:= _lc
[I_MENU_GAME_TYPE_CTF
];
572 GM_COOP
: Result
:= _lc
[I_MENU_GAME_TYPE_COOP
];
573 GM_SINGLE
: Result
:= _lc
[I_MENU_GAME_TYPE_SINGLE
];
577 function g_Game_TextToMode(Mode
: string): Byte;
580 Mode
:= UpperCase(Mode
);
581 if Mode
= _lc
[I_MENU_GAME_TYPE_DM
] then
586 if Mode
= _lc
[I_MENU_GAME_TYPE_TDM
] then
591 if Mode
= _lc
[I_MENU_GAME_TYPE_CTF
] then
596 if Mode
= _lc
[I_MENU_GAME_TYPE_COOP
] then
601 if Mode
= _lc
[I_MENU_GAME_TYPE_SINGLE
] then
608 function g_Game_IsNet(): Boolean;
610 Result
:= (gGameSettings
.GameType
in [GT_SERVER
, GT_CLIENT
]);
613 function g_Game_IsServer(): Boolean;
615 Result
:= (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
, GT_SERVER
]);
618 function g_Game_IsClient(): Boolean;
620 Result
:= (gGameSettings
.GameType
= GT_CLIENT
);
623 function g_Game_GetMegaWADInfo(WAD
: String): TMegaWADInfo
;
630 Result
.name
:= ExtractFileName(WAD
);
631 Result
.description
:= '';
634 w
:= TWADFile
.Create();
637 if not w
.GetResource('INTERSCRIPT', p
, len
) then
643 cfg
:= TConfig
.CreateMem(p
, len
);
644 Result
.name
:= cfg
.ReadStr('megawad', 'name', ExtractFileName(WAD
));
645 Result
.description
:= cfg
.ReadStr('megawad', 'description', '');
646 Result
.author
:= cfg
.ReadStr('megawad', 'author', '');
647 Result
.pic
:= cfg
.ReadStr('megawad', 'pic', '');
653 procedure g_Game_FreeWAD();
657 for a
:= 0 to High(MegaWAD
.res
.pic
) do
658 if MegaWAD
.res
.pic
[a
] <> '' then
659 g_Texture_Delete(MegaWAD
.res
.pic
[a
]);
661 for a
:= 0 to High(MegaWAD
.res
.mus
) do
662 if MegaWAD
.res
.mus
[a
] <> '' then
663 g_Sound_Delete(MegaWAD
.res
.mus
[a
]);
665 MegaWAD
.res
.pic
:= nil;
666 MegaWAD
.res
.text := nil;
667 MegaWAD
.res
.anim
:= nil;
668 MegaWAD
.res
.mus
:= nil;
669 MegaWAD
.triggers
:= nil;
671 g_Texture_Delete('TEXTURE_endpic');
672 g_Sound_Delete('MUSIC_endmus');
674 ZeroMemory(@MegaWAD
, SizeOf(MegaWAD
));
675 gGameSettings
.WAD
:= '';
678 procedure g_Game_LoadWAD(WAD
: string);
687 gGameSettings
.WAD
:= WAD
;
688 if not (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) then
691 MegaWAD
.info
:= g_Game_GetMegaWADInfo(MapsDir
+ WAD
);
693 w
:= TWADFile
.Create();
694 w
.ReadFile(MapsDir
+ WAD
);
696 if not w
.GetResource('INTERSCRIPT', p
, len
) then
702 cfg
:= TConfig
.CreateMem(p
, len
);
707 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
708 if s = '' then Break;
711 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
712 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
714 g_Texture_CreateWADEx(s, s);
720 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
721 if s = '' then Break;
724 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
725 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
727 g_Music_CreateWADEx(s, s);
730 MegaWAD
.endpic
:= cfg
.ReadStr('megawad', 'endpic', '');
731 if MegaWAD
.endpic
<> '' then
733 s
:= g_ExtractWadName(MegaWAD
.endpic
);
734 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
735 g_Texture_CreateWADEx('TEXTURE_endpic', s
+MegaWAD
.endpic
);
737 MegaWAD
.endmus
:= cfg
.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
738 if MegaWAD
.endmus
<> '' then
740 s
:= g_ExtractWadName(MegaWAD
.endmus
);
741 if s
= '' then s
:= MapsDir
+WAD
else s
:= GameDir
+'/wads/';
742 g_Sound_CreateWADEx('MUSIC_endmus', s
+MegaWAD
.endmus
, True);
750 {procedure start_trigger(t: string);
754 function next_trigger(): Boolean;
758 procedure DisableCheats();
764 if gPlayer1
<> nil then gPlayer1
.GodMode
:= False;
765 if gPlayer2
<> nil then gPlayer2
.GodMode
:= False;
766 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= False;
767 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= False;
770 procedure g_Game_ExecuteEvent(Name
: String);
776 if gEvents
= nil then
778 for a
:= 0 to High(gEvents
) do
779 if gEvents
[a
].Name
= Name
then
781 if gEvents
[a
].Command
<> '' then
782 g_Console_Process(gEvents
[a
].Command
, True);
787 function g_Game_DelayEvent(DEType
: Byte; Time
: LongWord; Num
: Integer = 0; Str
: String = ''): Integer;
792 if gDelayedEvents
<> nil then
793 for a
:= 0 to High(gDelayedEvents
) do
794 if not gDelayedEvents
[a
].Pending
then
801 SetLength(gDelayedEvents
, Length(gDelayedEvents
) + 1);
802 n
:= High(gDelayedEvents
);
804 gDelayedEvents
[n
].Pending
:= True;
805 gDelayedEvents
[n
].DEType
:= DEType
;
806 gDelayedEvents
[n
].DENum
:= Num
;
807 gDelayedEvents
[n
].DEStr
:= Str
;
808 if DEType
= DE_GLOBEVENT
then
809 gDelayedEvents
[n
].Time
:= (GetTimer() {div 1000}) + Time
811 gDelayedEvents
[n
].Time
:= gTime
+ Time
;
820 if g_Game_IsNet
and g_Game_IsServer
then
821 MH_SEND_GameEvent(NET_EV_MAPEND
, Byte(gMissionFailed
));
827 g_Game_StopAllSounds(False);
832 EndingGameCounter
:= 0;
833 g_ActiveWindow
:= nil;
835 gLMSRespawn
:= LMS_RESPAWN_NONE
;
836 gLMSRespawnTime
:= 0;
839 EXIT_SIMPLE
: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
844 begin // Ýòî áûë òåñò
848 begin // Âûõîä â ãëàâíîå ìåíþ
849 gMusic
.SetByName('MUSIC_MENU');
851 if gState
<> STATE_SLIST
then
853 g_GUI_ShowWindow('MainMenu');
854 gState
:= STATE_MENU
;
857 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
858 slReturnPressed
:= True;
859 if g_Net_Slist_Fetch(slCurrent
) then
861 if slCurrent
= nil then
862 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
865 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
868 g_Game_ExecuteEvent('ongameend');
872 EXIT_RESTART
: // Íà÷àòü óðîâåíü ñíà÷àëà
874 if not g_Game_IsClient
then g_Game_Restart();
877 EXIT_ENDLEVELCUSTOM
: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
879 // Ñòàòèñòèêà Ñâîåé èãðû:
880 FileName
:= g_ExtractWadName(gMapInfo
.Map
);
882 CustomStat
.GameTime
:= gTime
;
883 CustomStat
.Map
:= ExtractFileName(FileName
)+':'+g_ExtractFileName(gMapInfo
.Map
); //ResName;
884 CustomStat
.MapName
:= gMapInfo
.Name
;
885 CustomStat
.GameMode
:= gGameSettings
.GameMode
;
886 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
887 CustomStat
.TeamStat
:= gTeamStat
;
889 CustomStat
.PlayerStat
:= nil;
891 // Ñòàòèñòèêà èãðîêîâ:
892 if gPlayers
<> nil then
894 for a
:= 0 to High(gPlayers
) do
895 if gPlayers
[a
] <> nil then
897 SetLength(CustomStat
.PlayerStat
, Length(CustomStat
.PlayerStat
)+1);
898 with CustomStat
.PlayerStat
[High(CustomStat
.PlayerStat
)] do
900 Name
:= gPlayers
[a
].Name
;
901 Frags
:= gPlayers
[a
].Frags
;
902 Deaths
:= gPlayers
[a
].Death
;
903 Kills
:= gPlayers
[a
].Kills
;
904 Team
:= gPlayers
[a
].Team
;
905 Color
:= gPlayers
[a
].Model
.Color
;
906 Spectator
:= gPlayers
[a
].FSpectator
;
910 SortGameStat(CustomStat
.PlayerStat
);
913 g_Game_ExecuteEvent('onmapend');
916 EndingGameCounter
:= 255;
917 gState
:= STATE_FOLD
;
919 if gDefInterTime
< 0 then
920 gInterEndTime
:= IfThen((gGameSettings
.GameType
= GT_SERVER
) and (gPlayer1
= nil), 15000, 25000)
922 gInterEndTime
:= gDefInterTime
* 1000;
925 EXIT_ENDLEVELSINGLE
: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
927 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
928 SingleStat
.GameTime
:= gTime
;
929 SingleStat
.TwoPlayers
:= gPlayer2
<> nil;
930 SingleStat
.TotalSecrets
:= gSecretsCount
;
931 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
932 SingleStat
.PlayerStat
[0].Kills
:= gPlayer1
.MonsterKills
;
933 SingleStat
.PlayerStat
[0].Secrets
:= gPlayer1
.Secrets
;
934 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
935 if SingleStat
.TwoPlayers
then
937 SingleStat
.PlayerStat
[1].Kills
:= gPlayer2
.MonsterKills
;
938 SingleStat
.PlayerStat
[1].Secrets
:= gPlayer2
.Secrets
;
941 g_Game_ExecuteEvent('onmapend');
944 if gNextMap
<> '' then
946 gMusic
.SetByName('MUSIC_INTERMUS');
948 gState
:= STATE_INTERSINGLE
;
950 g_Game_ExecuteEvent('oninter');
952 else // Áîëüøå íåò êàðò
955 EndingGameCounter
:= 255;
956 gState
:= STATE_FOLD
;
961 // Îêîí÷àíèå îáðàáîòàíî:
962 if gExit
<> EXIT_QUIT
then
966 procedure DrawStat();
968 pc
, x
, y
, w
, h
: Integer;
969 w1
, w2
, w3
, w4
: Integer;
971 cw
, ch
, r
, g
, b
, rr
, gg
, bb
: Byte;
974 stat
: TPlayerStatArray
;
981 pc
:= g_Player_GetCount
;
982 e_TextureFontGetSize(gStdFont
, cw
, ch
);
984 w
:= gScreenWidth
-(gScreenWidth
div 5);
985 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
988 h
:= 40+ch
*5+(ch
+8)*pc
;
989 x
:= (gScreenWidth
div 2)-(w
div 2);
990 y
:= (gScreenHeight
div 2)-(h
div 2);
992 e_DrawFillQuad(x
, y
, x
+w
-1, y
+h
-1, 64, 64, 64, 32);
993 e_DrawQuad(x
, y
, x
+w
-1, y
+h
-1, 255, 127, 0);
995 wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
996 map
:= g_ExtractFileName(gMapInfo
.Map
);
997 mapstr
:= wad
+ ':\' + map
+ ' - ' + gMapInfo
.Name
;
999 case gGameSettings
.GameMode
of
1002 if gGameSettings
.MaxLives
= 0 then
1003 s1
:= _lc
[I_GAME_DM
]
1005 s1
:= _lc
[I_GAME_LMS
];
1006 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1007 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1012 if gGameSettings
.MaxLives
= 0 then
1013 s1
:= _lc
[I_GAME_TDM
]
1015 s1
:= _lc
[I_GAME_TLMS
];
1016 s2
:= Format(_lc
[I_GAME_FRAG_LIMIT
], [gGameSettings
.GoalLimit
]);
1017 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1022 s1
:= _lc
[I_GAME_CTF
];
1023 s2
:= Format(_lc
[I_GAME_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]);
1024 s3
:= Format(_lc
[I_GAME_TIME_LIMIT
], [gGameSettings
.TimeLimit
div 3600, (gGameSettings
.TimeLimit
div 60) mod 60, gGameSettings
.TimeLimit
mod 60]);
1029 if gGameSettings
.MaxLives
= 0 then
1030 s1
:= _lc
[I_GAME_COOP
]
1032 s1
:= _lc
[I_GAME_SURV
];
1033 s2
:= _lc
[I_GAME_MONSTERS
] + ' ' + IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
);
1034 s3
:= _lc
[I_GAME_SECRETS
] + ' ' + IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
);
1045 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*cw
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
1047 e_TextureFontPrintEx(x
+(w
div 2)-(Length(mapstr
)*cw
div 2), _y
, mapstr
, gStdFont
, 200, 200, 200, 1);
1049 e_TextureFontPrintEx(x
+16, _y
, s2
, gStdFont
, 200, 200, 200, 1);
1051 e_TextureFontPrintEx(x
+w
-16-(Length(s3
))*cw
, _y
, s3
,
1052 gStdFont
, 200, 200, 200, 1);
1054 if NetMode
= NET_SERVER
then
1055 e_TextureFontPrintEx(x
+8, y
+ 8, _lc
[I_NET_SERVER
], gStdFont
, 255, 255, 255, 1)
1057 if NetMode
= NET_CLIENT
then
1058 e_TextureFontPrintEx(x
+8, y
+ 8,
1059 NetClientIP
+ ':' + IntToStr(NetClientPort
), gStdFont
, 255, 255, 255, 1);
1063 stat
:= g_Player_GetStats();
1066 w2
:= (w
-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1067 w3
:= (w
-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1069 w1
:= w
-16-w2
-w3
-w4
; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1071 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1075 for a
:= TEAM_RED
to TEAM_BLUE
do
1077 if a
= TEAM_RED
then
1079 s1
:= _lc
[I_GAME_TEAM_RED
];
1086 s1
:= _lc
[I_GAME_TEAM_BLUE
];
1092 e_TextureFontPrintEx(x
+16, _y
, s1
, gStdFont
, r
, g
, b
, 1);
1093 e_TextureFontPrintEx(x
+w1
+16, _y
, IntToStr(gTeamStat
[a
].Goals
),
1094 gStdFont
, r
, g
, b
, 1);
1096 _y
:= _y
+ch
+(ch
div 4);
1097 e_DrawLine(1, x
+16, _y
, x
+w
-16, _y
, r
, g
, b
);
1098 _y
:= _y
+(ch
div 4);
1100 for aa
:= 0 to High(stat
) do
1101 if stat
[aa
].Team
= a
then
1117 e_TextureFontPrintEx(x
+16, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
1119 e_TextureFontPrintEx(x
+w1
+16, _y
, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, rr
, gg
, bb
, 1);
1121 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
1123 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
1130 else if gGameSettings
.GameMode
in [GM_DM
, GM_COOP
] then
1133 e_TextureFontPrintEx(x
+16, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
1134 e_TextureFontPrintEx(x
+16+w1
, _y
, _lc
[I_GAME_PING
], gStdFont
, 255, 127, 0, 1);
1135 e_TextureFontPrintEx(x
+16+w1
+w2
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
1136 e_TextureFontPrintEx(x
+16+w1
+w2
+w3
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
1139 for aa
:= 0 to High(stat
) do
1153 e_DrawFillQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
1154 e_DrawQuad(x
+16, _y
+4, x
+32-1, _y
+16+4-1, 192, 192, 192);
1156 e_TextureFontPrintEx(x
+16+16+8, _y
+4, Name
, gStdFont
, r
, g
, 0, 1);
1158 e_TextureFontPrintEx(x
+w1
+16, _y
+4, Format(_lc
[I_GAME_PING_MS
], [Ping
, Loss
]), gStdFont
, r
, g
, 0, 1);
1160 e_TextureFontPrintEx(x
+w1
+w2
+16, _y
+4, IntToStr(Frags
), gStdFont
, r
, g
, 0, 1);
1162 e_TextureFontPrintEx(x
+w1
+w2
+w3
+16, _y
+4, IntToStr(Deaths
), gStdFont
, r
, g
, 0, 1);
1168 procedure g_Game_Init();
1174 gTempDelete
:= False;
1176 sfsGCDisable(); // temporary disable removing of temporary volumes
1179 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD
+':TEXTURES\TITLE');
1180 g_Texture_CreateWADEx('INTER', GameWAD
+':TEXTURES\INTER');
1181 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD
+':TEXTURES\ENDGAME_EN');
1182 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD
+':TEXTURES\ENDGAME_RU');
1184 LoadStdFont('STDTXT', 'STDFONT', gStdFont
);
1185 LoadFont('MENUTXT', 'MENUFONT', gMenuFont
);
1186 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont
);
1188 g_Game_ClearLoading();
1189 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION
]), 0, False);
1190 g_Game_SetLoadingText('', 0, False);
1192 g_Game_SetLoadingText(_lc
[I_LOAD_CONSOLE
], 0, False);
1195 g_Game_SetLoadingText(_lc
[I_LOAD_MODELS
], 0, False);
1196 g_PlayerModel_LoadData();
1198 if FindFirst(ModelsDir
+'*.wad', faAnyFile
, SR
) = 0 then
1200 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1201 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1202 until FindNext(SR
) <> 0;
1205 if FindFirst(ModelsDir
+'*.pk3', faAnyFile
, SR
) = 0 then
1207 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1208 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1209 until FindNext(SR
) <> 0;
1212 if FindFirst(ModelsDir
+'*.zip', faAnyFile
, SR
) = 0 then
1214 if not g_PlayerModel_Load(ModelsDir
+SR
.Name
) then
1215 e_WriteLog(Format('Error loading model %s', [SR
.Name
]), MSG_WARNING
);
1216 until FindNext(SR
) <> 0;
1222 LastScreenShot
:= 0;
1224 {e_MouseInfo.Accel := 1.0;}
1226 g_Game_SetLoadingText(_lc
[I_LOAD_GAME_DATA
], 0, False);
1229 g_Game_SetLoadingText(_lc
[I_LOAD_MUSIC
], 0, False);
1230 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD
+':MUSIC\INTERMUS', True);
1231 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD
+':MUSIC\MENU', True);
1232 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD
+':MUSIC\ROUNDMUS', True);
1233 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD
+':MUSIC\ENDMUS', True);
1235 g_Game_SetLoadingText(_lc
[I_LOAD_MENUS
], 0, False);
1238 gMusic
:= TMusic
.Create();
1239 gMusic
.SetByName('MUSIC_MENU');
1242 gGameSettings
.WarmupTime
:= 30;
1244 gState
:= STATE_MENU
;
1246 SetLength(gEvents
, 6);
1247 gEvents
[0].Name
:= 'ongamestart';
1248 gEvents
[1].Name
:= 'ongameend';
1249 gEvents
[2].Name
:= 'onmapstart';
1250 gEvents
[3].Name
:= 'onmapend';
1251 gEvents
[4].Name
:= 'oninter';
1252 gEvents
[5].Name
:= 'onwadend';
1254 sfsGCEnable(); // enable releasing unused volumes
1258 procedure g_Game_Free();
1260 if NetMode
= NET_CLIENT
then g_Net_Disconnect();
1261 if NetMode
= NET_SERVER
then g_Net_Host_Die();
1265 g_Player_RemoveAllCorpses();
1267 gGameSettings
.GameType
:= GT_NONE
;
1268 if gGameSettings
.GameMode
= GM_SINGLE
then
1269 gGameSettings
.GameMode
:= GM_DM
;
1270 gSwitchGameMode
:= gGameSettings
.GameMode
;
1273 gExitByTrigger
:= False;
1276 function IsActivePlayer(p
: TPlayer
): Boolean;
1281 Result
:= (not p
.FDummy
) and (not p
.FSpectator
);
1284 function GetActivePlayer_ByID(ID
: Integer): TPlayer
;
1291 if gPlayers
= nil then
1293 for a
:= Low(gPlayers
) to High(gPlayers
) do
1294 if IsActivePlayer(gPlayers
[a
]) then
1296 if gPlayers
[a
].UID
<> ID
then
1298 Result
:= gPlayers
[a
];
1303 function GetActivePlayerID_Next(Skip
: Integer = -1): Integer;
1309 if gPlayers
= nil then
1313 for a
:= Low(gPlayers
) to High(gPlayers
) do
1314 if IsActivePlayer(gPlayers
[a
]) then
1316 SetLength(ids
, Length(ids
) + 1);
1317 ids
[High(ids
)] := gPlayers
[a
].UID
;
1318 if gPlayers
[a
].UID
= Skip
then
1321 if Length(ids
) = 0 then
1326 Result
:= ids
[(idx
+ 1) mod Length(ids
)];
1329 function GetActivePlayerID_Prev(Skip
: Integer = -1): Integer;
1335 if gPlayers
= nil then
1339 for a
:= Low(gPlayers
) to High(gPlayers
) do
1340 if IsActivePlayer(gPlayers
[a
]) then
1342 SetLength(ids
, Length(ids
) + 1);
1343 ids
[High(ids
)] := gPlayers
[a
].UID
;
1344 if gPlayers
[a
].UID
= Skip
then
1347 if Length(ids
) = 0 then
1350 Result
:= ids
[Length(ids
) - 1]
1352 Result
:= ids
[(Length(ids
) - 1 + idx
) mod Length(ids
)];
1355 function isKeyPressed (key1
: Word; key2
: Word): Boolean;
1357 if (key1
<> 0) and e_KeyPressed(key1
) then begin result
:= true; exit
; end;
1358 if (key2
<> 0) and e_KeyPressed(key2
) then begin result
:= true; exit
; end;
1362 procedure processPlayerControls (plr
: TPlayer
; var ctrl
: TPlayerControl
; var MoveButton
: Byte; p2hack
: Boolean=false);
1368 if (plr
= nil) then exit
;
1369 if (p2hack
) then time
:= 1000 else time
:= 1;
1370 strafeDir
:= MoveButton
shr 4;
1371 MoveButton
:= MoveButton
and $0F;
1374 if isKeyPressed(KeyLeft
, KeyLeft2
) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 1 // Íàæàòà òîëüêî "Âëåâî"
1375 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and isKeyPressed(KeyRight
, KeyRight2
) then MoveButton
:= 2 // Íàæàòà òîëüêî "Âïðàâî"
1376 else if (not isKeyPressed(KeyLeft
, KeyLeft2
)) and (not isKeyPressed(KeyRight
, KeyRight2
)) then MoveButton
:= 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1378 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1379 if MoveButton
= 1 then plr
.PressKey(KEY_LEFT
, time
)
1380 else if MoveButton
= 2 then plr
.PressKey(KEY_RIGHT
, time
);
1382 // if we have "strafe" key, turn off old strafe mechanics
1383 if isKeyPressed(KeyStrafe
, KeyStrafe2
) then
1385 // new strafe mechanics
1386 if (strafeDir
= 0) then strafeDir
:= MoveButton
; // start strafing
1387 // now set direction according to strafe (reversed)
1388 if (strafeDir
= 2) then plr
.SetDirection(D_LEFT
)
1389 else if (strafeDir
= 1) then plr
.SetDirection(D_RIGHT
);
1393 strafeDir
:= 0; // not strafing anymore
1394 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1395 if (MoveButton
= 2) and isKeyPressed(KeyLeft
, KeyLeft2
) then plr
.SetDirection(D_LEFT
)
1396 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1397 else if (MoveButton
= 1) and isKeyPressed(KeyRight
, KeyRight2
) then plr
.SetDirection(D_RIGHT
)
1398 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1399 else if MoveButton
<> 0 then plr
.SetDirection(TDirection(MoveButton
-1));
1402 // fix movebutton state
1403 MoveButton
:= MoveButton
or (strafeDir
shl 4);
1405 // Îñòàëüíûå êëàâèøè:
1406 if isKeyPressed(KeyJump
, KeyJump2
) then plr
.PressKey(KEY_JUMP
, time
);
1407 if isKeyPressed(KeyUp
, KeyUp2
) then plr
.PressKey(KEY_UP
, time
);
1408 if isKeyPressed(KeyDown
, KeyDown2
) then plr
.PressKey(KEY_DOWN
, time
);
1409 if isKeyPressed(KeyFire
, KeyFire2
) then plr
.PressKey(KEY_FIRE
);
1410 if isKeyPressed(KeyNextWeapon
, KeyNextWeapon2
) then plr
.PressKey(KEY_NEXTWEAPON
);
1411 if isKeyPressed(KeyPrevWeapon
, KeyPrevWeapon2
) then plr
.PressKey(KEY_PREVWEAPON
);
1412 if isKeyPressed(KeyOpen
, KeyOpen2
) then plr
.PressKey(KEY_OPEN
);
1414 for i
:= 0 to High(KeyWeapon
) do
1415 if isKeyPressed(KeyWeapon
[i
], KeyWeapon2
[i
]) then
1416 plr
.QueueWeaponSwitch(i
); // all choices are passed there, and god will take the best
1419 // HACK: add dynlight here
1420 if gwin_k8_enable_light_experiments
then
1422 if e_KeyPressed(IK_F8
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1424 g_playerLight
:= true;
1426 if e_KeyPressed(IK_F9
) and gGameOn
and (not gConsoleShow
) and (g_ActiveWindow
= nil) then
1428 g_playerLight
:= false;
1432 if gwin_has_stencil
and g_playerLight
then g_AddDynLight(plr
.GameX
+32, plr
.GameY
+40, 128, 1, 1, 0, 0.6);
1435 procedure g_Game_Update();
1437 Msg
: g_gui
.TMessage
;
1443 function sendMonsPos (mon
: TMonster
): Boolean;
1445 result
:= false; // don't stop
1446 if (mon
.MonsterType
= MONSTER_BARREL
) then
1448 if (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then MH_SEND_MonsterPos(mon
.UID
);
1451 if (mon
.MonsterState
<> MONSTATE_SLEEP
) then
1453 if (mon
.MonsterState
<> MONSTATE_DEAD
) or (mon
.GameVelX
<> 0) or (mon
.GameVelY
<> 0) then
1455 MH_SEND_MonsterPos(mon
.UID
);
1462 // Ïîðà âûêëþ÷àòü èãðó:
1463 if gExit
= EXIT_QUIT
then
1465 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1469 if gExit
= EXIT_QUIT
then
1473 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
1476 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1479 if (NetMode
= NET_NONE
) and (g_Game_IsNet
) and (gGameOn
or (gState
in [STATE_FOLD
, STATE_INTERCUSTOM
])) then
1481 gExit
:= EXIT_SIMPLE
;
1487 STATE_INTERSINGLE
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1488 STATE_INTERCUSTOM
, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1489 STATE_INTERTEXT
, // Òåêñò ìåæäó óðîâíÿìè
1490 STATE_INTERPIC
: // Êàðòèíêà ìåæäó óðîâíÿìè
1492 if g_Game_IsNet
and g_Game_IsServer
then
1494 gInterTime
:= gInterTime
+ GAME_TICK
;
1495 a
:= Min((gInterEndTime
- gInterTime
) div 1000 + 1, 255);
1496 if a
<> gServInterTime
then
1498 gServInterTime
:= a
;
1499 MH_SEND_TimeSync(gServInterTime
);
1503 if (not g_Game_IsClient
) and
1506 (e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(IK_SPACE
))
1507 and (not gJustChatted
) and (not gConsoleShow
) and (not gChatShow
)
1508 and (g_ActiveWindow
= nil)
1510 or (g_Game_IsNet
and (gInterTime
> gInterEndTime
))
1513 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1514 g_Game_StopAllSounds(True);
1516 if gMapOnce
then // Ýòî áûë òåñò
1517 gExit
:= EXIT_SIMPLE
1519 if gNextMap
<> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1520 g_Game_ChangeMap(gNextMap
)
1521 else // Ñëåäóþùåé êàðòû íåò
1523 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
] then
1525 // Âûõîä â ãëàâíîå ìåíþ:
1527 g_GUI_ShowWindow('MainMenu');
1528 gMusic
.SetByName('MUSIC_MENU');
1530 gState
:= STATE_MENU
;
1533 // Ôèíàëüíàÿ êàðòèíêà:
1534 g_Game_ExecuteEvent('onwadend');
1536 if not gMusic
.SetByName('MUSIC_endmus') then
1537 gMusic
.SetByName('MUSIC_STDENDMUS');
1539 gState
:= STATE_ENDPIC
;
1541 g_Game_ExecuteEvent('ongameend');
1547 if gState
= STATE_INTERTEXT
then
1548 if InterText
.counter
> 0 then
1549 InterText
.counter
:= InterText
.counter
- 1;
1552 STATE_FOLD
: // Çàòóõàíèå ýêðàíà
1554 if EndingGameCounter
= 0 then
1556 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1557 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
1559 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
1561 g_Game_ExecuteEvent('onwadend');
1562 if not gMusic
.SetByName('MUSIC_endmus') then
1563 gMusic
.SetByName('MUSIC_STDENDMUS');
1566 gMusic
.SetByName('MUSIC_ROUNDMUS');
1569 gState
:= STATE_INTERCUSTOM
;
1571 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1573 gMusic
.SetByName('MUSIC_INTERMUS');
1575 gState
:= STATE_INTERSINGLE
;
1577 g_Game_ExecuteEvent('oninter');
1580 DecMin(EndingGameCounter
, 6, 0);
1583 STATE_ENDPIC
: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1585 if gMapOnce
then // Ýòî áûë òåñò
1587 gExit
:= EXIT_SIMPLE
;
1593 g_Serverlist_Control(slCurrent
);
1596 if g_Game_IsNet
then
1597 if not gConsoleShow
then
1598 if not gChatShow
then
1600 if g_ActiveWindow
= nil then
1602 if e_KeyPressed(gGameControls
.GameControls
.Chat
) then
1603 g_Console_Chat_Switch(False)
1604 else if (e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) and
1605 (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1606 g_Console_Chat_Switch(True);
1609 if not gChatEnter
then
1610 if (not e_KeyPressed(gGameControls
.GameControls
.Chat
))
1611 and (not e_KeyPressed(gGameControls
.GameControls
.TeamChat
)) then
1614 // Ñòàòèñòèêà ïî Tab:
1616 IsDrawStat
:= (not gConsoleShow
) and (not gChatShow
) and
1617 (gGameSettings
.GameType
<> GT_SINGLE
) and
1618 e_KeyPressed(gGameControls
.GameControls
.Stat
);
1621 if gGameOn
and not gPause
and (gState
<> STATE_FOLD
) then
1623 // Âðåìÿ += 28 ìèëëèñåêóíä:
1624 gTime
:= gTime
+ GAME_TICK
;
1626 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1627 if MessageTime
= 0 then
1629 if MessageTime
> 0 then
1630 MessageTime
:= MessageTime
- 1;
1632 if (g_Game_IsServer
) then
1634 // Áûë çàäàí ëèìèò âðåìåíè:
1635 if (gGameSettings
.TimeLimit
> 0) then
1636 if (gTime
- gGameStartTime
) div 1000 >= gGameSettings
.TimeLimit
then
1637 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1642 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1643 if (gLMSRespawn
> LMS_RESPAWN_NONE
) and (gLMSRespawnTime
< gTime
) then
1644 g_Game_RestartRound(gLMSSoftSpawn
);
1646 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1647 if gVoteInProgress
and (gVoteTimer
< gTime
) then
1649 else if gVotePassed
and (gVoteCmdTimer
< gTime
) then
1651 g_Console_Process(gVoteCommand
);
1653 gVotePassed
:= False;
1656 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1657 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
1658 gFlags
[FLAG_RED
].CaptureTime
:= gFlags
[FLAG_RED
].CaptureTime
+ GAME_TICK
;
1659 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
1660 gFlags
[FLAG_BLUE
].CaptureTime
:= gFlags
[FLAG_BLUE
].CaptureTime
+ GAME_TICK
;
1662 // Áûë çàäàí ëèìèò ïîáåä:
1663 if (gGameSettings
.GoalLimit
> 0) then
1667 if gGameSettings
.GameMode
= GM_DM
then
1668 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1669 for i
:= 0 to High(gPlayers
) do
1670 if gPlayers
[i
] <> nil then
1671 if gPlayers
[i
].Frags
> b
then
1672 b
:= gPlayers
[i
].Frags
;
1675 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
1676 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1677 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
1680 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1681 if b
>= gGameSettings
.GoalLimit
then
1688 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1689 if gPlayer1
<> nil then gPlayer1
.ReleaseKeys();
1690 if gPlayer2
<> nil then gPlayer2
.ReleaseKeys();
1691 if (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1693 processPlayerControls(gPlayer1
, gGameControls
.P1Control
, P1MoveButton
);
1694 processPlayerControls(gPlayer2
, gGameControls
.P2Control
, P2MoveButton
, true);
1695 end // if not console
1698 if g_Game_IsNet
and (gPlayer1
<> nil) then gPlayer1
.PressKey(KEY_CHAT
, 10000);
1700 // process weapon switch queue
1704 if (gPlayer1
= nil) and (gPlayer2
= nil) and
1705 (not gConsoleShow
) and (not gChatShow
) and (g_ActiveWindow
= nil) then
1707 if not gSpectKeyPress
then
1709 if isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
) then
1711 // switch spect mode
1713 SPECT_NONE
: ; // not spectator
1715 SPECT_MAPVIEW
: Inc(gSpectMode
);
1716 SPECT_PLAYERS
: gSpectMode
:= SPECT_STATS
; // reset to 1
1718 gSpectKeyPress
:= True;
1720 if gSpectMode
= SPECT_MAPVIEW
then
1722 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1723 gSpectX
:= Max(gSpectX
- gSpectStep
, 0);
1724 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1725 gSpectX
:= Min(gSpectX
+ gSpectStep
, gMapInfo
.Width
- gScreenWidth
);
1726 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1727 gSpectY
:= Max(gSpectY
- gSpectStep
, 0);
1728 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1729 gSpectY
:= Min(gSpectY
+ gSpectStep
, gMapInfo
.Height
- gScreenHeight
);
1730 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1733 if gSpectStep
> 4 then gSpectStep
:= gSpectStep
shr 1;
1734 gSpectKeyPress
:= True;
1736 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1739 if gSpectStep
< 64 then gSpectStep
:= gSpectStep
shl 1;
1740 gSpectKeyPress
:= True;
1743 if gSpectMode
= SPECT_PLAYERS
then
1745 if isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
) then
1748 gSpectViewTwo
:= True;
1749 gSpectKeyPress
:= True;
1751 if isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
) then
1753 // remove second view
1754 gSpectViewTwo
:= False;
1755 gSpectKeyPress
:= True;
1757 if isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
) then
1759 // prev player (view 1)
1760 gSpectPID1
:= GetActivePlayerID_Prev(gSpectPID1
);
1761 gSpectKeyPress
:= True;
1763 if isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
) then
1765 // next player (view 1)
1766 gSpectPID1
:= GetActivePlayerID_Next(gSpectPID1
);
1767 gSpectKeyPress
:= True;
1769 if isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
) then
1771 // prev player (view 2)
1772 gSpectPID2
:= GetActivePlayerID_Prev(gSpectPID2
);
1773 gSpectKeyPress
:= True;
1775 if isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
) then
1777 // next player (view 2)
1778 gSpectPID2
:= GetActivePlayerID_Next(gSpectPID2
);
1779 gSpectKeyPress
:= True;
1784 if (not isKeyPressed(gGameControls
.P1Control
.KeyJump
, gGameControls
.P1Control
.KeyJump2
)) and
1785 (not isKeyPressed(gGameControls
.P1Control
.KeyLeft
, gGameControls
.P1Control
.KeyLeft2
)) and
1786 (not isKeyPressed(gGameControls
.P1Control
.KeyRight
, gGameControls
.P1Control
.KeyRight2
)) and
1787 (not isKeyPressed(gGameControls
.P1Control
.KeyUp
, gGameControls
.P1Control
.KeyUp2
)) and
1788 (not isKeyPressed(gGameControls
.P1Control
.KeyDown
, gGameControls
.P1Control
.KeyDown2
)) and
1789 (not isKeyPressed(gGameControls
.P1Control
.KeyPrevWeapon
, gGameControls
.P1Control
.KeyPrevWeapon2
)) and
1790 (not isKeyPressed(gGameControls
.P1Control
.KeyNextWeapon
, gGameControls
.P1Control
.KeyNextWeapon2
)) then
1791 gSpectKeyPress
:= False;
1794 // Îáíîâëÿåì âñå îñòàëüíîå:
1797 g_Triggers_Update();
1799 g_Monsters_Update();
1801 g_Player_UpdateAll();
1802 g_Player_UpdatePhysicalObjects();
1803 if gGameSettings
.GameType
= GT_SERVER
then
1804 if Length(gMonstersSpawned
) > 0 then
1806 for I
:= 0 to High(gMonstersSpawned
) do
1807 MH_SEND_MonsterSpawn(gMonstersSpawned
[I
]);
1808 SetLength(gMonstersSpawned
, 0);
1811 if (gSoundTriggerTime
> 8) then
1813 g_Game_UpdateTriggerSounds();
1814 gSoundTriggerTime
:= 0;
1817 Inc(gSoundTriggerTime
);
1819 if (NetMode
= NET_SERVER
) then
1821 Inc(NetTimeToUpdate
);
1822 Inc(NetTimeToReliable
);
1823 if NetTimeToReliable
>= NetRelupdRate
then
1825 for I
:= 0 to High(gPlayers
) do
1826 if gPlayers
[I
] <> nil then
1827 MH_SEND_PlayerPos(True, gPlayers
[I
].UID
);
1829 g_Mons_ForEach(sendMonsPos
);
1831 NetTimeToReliable
:= 0;
1832 NetTimeToUpdate
:= NetUpdateRate
;
1834 else if NetTimeToUpdate
>= NetUpdateRate
then
1836 if gPlayers
<> nil then
1837 for I
:= 0 to High(gPlayers
) do
1838 if gPlayers
[I
] <> nil then
1839 MH_SEND_PlayerPos(False, gPlayers
[I
].UID
);
1841 g_Mons_ForEach(sendMonsPos
);
1843 NetTimeToUpdate
:= 0;
1846 if NetUseMaster
then
1847 if gTime
>= NetTimeToMaster
then
1849 if (NetMHost
= nil) or (NetMPeer
= nil) then
1850 if not g_Net_Slist_Connect
then
1851 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
1854 NetTimeToMaster
:= gTime
+ NetMasterRate
;
1858 if NetMode
= NET_CLIENT
then
1859 MC_SEND_PlayerPos();
1860 end; // if gameOn ...
1862 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1863 if g_ActiveWindow
<> nil then
1865 w
:= e_GetFirstKeyPressed();
1867 if (w
<> IK_INVALID
) then
1869 Msg
.Msg
:= MESSAGE_DIKEY
;
1871 g_ActiveWindow
.OnMessage(Msg
);
1874 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1875 if g_ActiveWindow
<> nil then
1876 g_ActiveWindow
.Update();
1878 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1879 if gResolutionChange
then
1881 e_WriteLog('Changing resolution', MSG_NOTIFY
);
1882 g_Game_ChangeResolution(gRC_Width
, gRC_Height
, gRC_FullScreen
, gRC_Maximized
);
1883 gResolutionChange
:= False;
1886 // Íóæíî ñìåíèòü ÿçûê:
1887 if gLanguageChange
then
1889 //e_WriteLog('Read language file', MSG_NOTIFY);
1890 //g_Language_Load(DataDir + gLanguage + '.txt');
1891 g_Language_Set(gLanguage
);
1893 gLanguageChange
:= False;
1897 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1898 if e_KeyPressed(gGameControls
.GameControls
.TakeScreenshot
) then
1899 if (GetTimer()-LastScreenShot
) > 200000 div 1000 then
1902 LastScreenShot
:= GetTimer();
1905 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
1906 if e_KeyPressed(IK_F10
) and
1908 (not gConsoleShow
) and
1909 (g_ActiveWindow
= nil) then
1914 Time
:= GetTimer() {div 1000};
1916 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
1917 if gDelayedEvents
<> nil then
1918 for a
:= 0 to High(gDelayedEvents
) do
1919 if gDelayedEvents
[a
].Pending
and
1921 ((gDelayedEvents
[a
].DEType
= DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= Time
)) or
1922 ((gDelayedEvents
[a
].DEType
> DE_GLOBEVENT
) and (gDelayedEvents
[a
].Time
<= gTime
))
1925 case gDelayedEvents
[a
].DEType
of
1927 g_Game_ExecuteEvent(gDelayedEvents
[a
].DEStr
);
1930 g_Game_Announce_GoodShot(gDelayedEvents
[a
].DENum
);
1934 g_Game_Announce_KillCombo(gDelayedEvents
[a
].DENum
);
1935 if g_Game_IsNet
and g_Game_IsServer
then
1936 MH_SEND_GameEvent(NET_EV_KILLCOMBO
, gDelayedEvents
[a
].DENum
);
1939 gDelayedEvents
[a
].Pending
:= False;
1942 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
1943 UPSCounter
:= UPSCounter
+ 1;
1944 if Time
- UPSTime
>= 1000 then
1951 if gGameOn
then g_Weapon_AddDynLights();
1954 procedure g_Game_LoadData();
1956 if DataLoaded
then Exit
;
1958 e_WriteLog('Loading game data...', MSG_NOTIFY
);
1960 g_Texture_CreateWADEx('NOTEXTURE', GameWAD
+':TEXTURES\NOTEXTURE');
1961 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD
+':TEXTURES\HUD');
1962 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD
+':TEXTURES\AIRBAR');
1963 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD
+':TEXTURES\JETBAR');
1964 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD
+':TEXTURES\HUDBG');
1965 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD
+':TEXTURES\ARMORHUD');
1966 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD
+':TEXTURES\FLAGHUD_RB');
1967 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_RS');
1968 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_RD');
1969 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD
+':TEXTURES\FLAGHUD_BB');
1970 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD
+':TEXTURES\FLAGHUD_BS');
1971 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD
+':TEXTURES\FLAGHUD_BD');
1972 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD
+':TEXTURES\TALKBUBBLE');
1973 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD
+':TEXTURES\PENTA');
1974 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD
+':TEXTURES\TELEPORT', 64, 64, 10, False);
1975 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD
+':SOUNDS\TELEPORT');
1976 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD
+':SOUNDS\NOTELEPORT');
1977 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD
+':SOUNDS\DOOROPEN');
1978 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD
+':SOUNDS\DOORCLOSE');
1979 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD
+':SOUNDS\BULK1');
1980 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD
+':SOUNDS\BULK2');
1981 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD
+':SOUNDS\BUBBLE1');
1982 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD
+':SOUNDS\BUBBLE2');
1983 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD
+':SOUNDS\SWITCH1');
1984 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD
+':SOUNDS\SWITCH0');
1985 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD
+':SOUNDS\RADIO');
1986 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD
+':SOUNDS\GOOD1');
1987 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD
+':SOUNDS\GOOD2');
1988 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD
+':SOUNDS\GOOD3');
1989 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD
+':SOUNDS\GOOD4');
1990 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD
+':SOUNDS\KILL2X');
1991 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD
+':SOUNDS\KILL3X');
1992 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD
+':SOUNDS\KILL4X');
1993 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD
+':SOUNDS\KILLMX');
1995 goodsnd
[0] := TPlayableSound
.Create();
1996 goodsnd
[1] := TPlayableSound
.Create();
1997 goodsnd
[2] := TPlayableSound
.Create();
1998 goodsnd
[3] := TPlayableSound
.Create();
2000 goodsnd
[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2001 goodsnd
[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2002 goodsnd
[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2003 goodsnd
[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2005 killsnd
[0] := TPlayableSound
.Create();
2006 killsnd
[1] := TPlayableSound
.Create();
2007 killsnd
[2] := TPlayableSound
.Create();
2008 killsnd
[3] := TPlayableSound
.Create();
2010 killsnd
[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2011 killsnd
[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2012 killsnd
[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2013 killsnd
[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2015 g_Game_SetLoadingText(_lc
[I_LOAD_ITEMS_DATA
], 0, False);
2018 g_Game_SetLoadingText(_lc
[I_LOAD_WEAPONS_DATA
], 0, False);
2019 g_Weapon_LoadData();
2021 g_Monsters_LoadData();
2026 procedure g_Game_FreeData();
2028 if not DataLoaded
then Exit
;
2031 g_Weapon_FreeData();
2032 g_Monsters_FreeData();
2034 e_WriteLog('Releasing game data...', MSG_NOTIFY
);
2036 g_Texture_Delete('NOTEXTURE');
2037 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2038 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2039 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2040 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2041 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2042 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2043 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2044 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2045 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2046 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2047 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2048 g_Frames_DeleteByName('FRAMES_TELEPORT');
2049 g_Sound_Delete('SOUND_GAME_TELEPORT');
2050 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2051 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2052 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2053 g_Sound_Delete('SOUND_GAME_BULK1');
2054 g_Sound_Delete('SOUND_GAME_BULK2');
2055 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2056 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2057 g_Sound_Delete('SOUND_GAME_SWITCH1');
2058 g_Sound_Delete('SOUND_GAME_SWITCH0');
2065 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2066 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2067 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2068 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2075 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2076 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2077 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2078 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2080 DataLoaded
:= False;
2083 procedure DrawCustomStat();
2089 ww2
, hh2
, r
, g
, b
, rr
, gg
, bb
: Byte;
2090 s1
, s2
, topstr
: String;
2092 e_TextureFontGetSize(gStdFont
, ww2
, hh2
);
2095 if e_KeyPressed(IK_TAB
) then
2097 if not gStatsPressed
then
2099 gStatsOff
:= not gStatsOff
;
2100 gStatsPressed
:= True;
2104 gStatsPressed
:= False;
2108 s1
:= _lc
[I_MENU_INTER_NOTICE_TAB
];
2109 w
:= (Length(s1
) * ww2
) div 2;
2110 x
:= gScreenWidth
div 2 - w
;
2112 e_TextureFontPrint(x
, y
, s1
, gStdFont
);
2116 if (gGameSettings
.GameMode
= GM_COOP
) then
2118 if gMissionFailed
then
2119 topstr
:= _lc
[I_MENU_INTER_MISSION_FAIL
]
2121 topstr
:= _lc
[I_MENU_INTER_LEVEL_COMPLETE
];
2124 topstr
:= _lc
[I_MENU_INTER_ROUND_OVER
];
2126 e_CharFont_GetSize(gMenuFont
, topstr
, ww1
, hh1
);
2127 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww1
div 2), 16, topstr
);
2129 if g_Game_IsNet
then
2131 topstr
:= Format(_lc
[I_MENU_INTER_NOTICE_TIME
], [gServInterTime
]);
2132 if not gChatShow
then
2133 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2134 gScreenHeight
-(hh2
+4)*2, topstr
, gStdFont
, 255, 255, 255, 1);
2137 if g_Game_IsClient
then
2138 topstr
:= _lc
[I_MENU_INTER_NOTICE_MAP
]
2140 topstr
:= _lc
[I_MENU_INTER_NOTICE_SPACE
];
2141 if not gChatShow
then
2142 e_TextureFontPrintEx((gScreenWidth
div 2)-(Length(topstr
)*ww2
div 2),
2143 gScreenHeight
-(hh2
+4), topstr
, gStdFont
, 255, 255, 255, 1);
2148 w
:= gScreenWidth
-x
*2;
2154 e_DrawFillQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 64, 64, 64, 32);
2155 e_DrawQuad(x
, y
, gScreenWidth
-x
-1, gScreenHeight
-y
-1, 255, 127, 0);
2157 m
:= Max(Length(_lc
[I_MENU_MAP
])+1, Length(_lc
[I_GAME_GAME_TIME
])+1)*ww2
;
2159 case CustomStat
.GameMode
of
2162 if gGameSettings
.MaxLives
= 0 then
2163 s1
:= _lc
[I_GAME_DM
]
2165 s1
:= _lc
[I_GAME_LMS
];
2169 if gGameSettings
.MaxLives
= 0 then
2170 s1
:= _lc
[I_GAME_TDM
]
2172 s1
:= _lc
[I_GAME_TLMS
];
2174 GM_CTF
: s1
:= _lc
[I_GAME_CTF
];
2177 if gGameSettings
.MaxLives
= 0 then
2178 s1
:= _lc
[I_GAME_COOP
]
2180 s1
:= _lc
[I_GAME_SURV
];
2186 e_TextureFontPrintEx(x
+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2190 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_MENU_MAP
], gStdFont
, 255, 127, 0, 1);
2191 e_TextureFontPrint(x
+8+m
, _y
, Format('%s - %s', [CustomStat
.Map
, CustomStat
.MapName
]), gStdFont
);
2194 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_GAME_TIME
], gStdFont
, 255, 127, 0, 1);
2195 e_TextureFontPrint(x
+8+m
, _y
, Format('%d:%.2d:%.2d', [CustomStat
.GameTime
div 1000 div 3600,
2196 (CustomStat
.GameTime
div 1000 div 60) mod 60,
2197 CustomStat
.GameTime
div 1000 mod 60]), gStdFont
);
2199 pc
:= Length(CustomStat
.PlayerStat
);
2200 if pc
= 0 then Exit
;
2202 if CustomStat
.GameMode
= GM_COOP
then
2204 m
:= Max(Length(_lc
[I_GAME_MONSTERS
])+1, Length(_lc
[I_GAME_SECRETS
])+1)*ww2
;
2206 s2
:= _lc
[I_GAME_MONSTERS
];
2207 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2208 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopMonstersKilled
) + '/' + IntToStr(gTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2210 s2
:= _lc
[I_GAME_SECRETS
];
2211 e_TextureFontPrintEx(x
+8, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2212 e_TextureFontPrintEx(x
+8+m
, _y
, IntToStr(gCoopSecretsFound
) + '/' + IntToStr(gSecretsCount
), gStdFont
, 255, 255, 255, 1);
2215 m
:= Max(Length(_lc
[I_GAME_MONSTERS_TOTAL
])+1, Length(_lc
[I_GAME_SECRETS_TOTAL
])+1)*ww2
;
2217 s2
:= _lc
[I_GAME_MONSTERS_TOTAL
];
2218 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2219 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalMonstersKilled
) + '/' + IntToStr(gCoopTotalMonsters
), gStdFont
, 255, 255, 255, 1);
2221 s2
:= _lc
[I_GAME_SECRETS_TOTAL
];
2222 e_TextureFontPrintEx(x
+250, _y
, s2
, gStdFont
, 255, 127, 0, 1);
2223 e_TextureFontPrintEx(x
+250+m
, _y
, IntToStr(gCoopTotalSecretsFound
) + '/' + IntToStr(gCoopTotalSecrets
), gStdFont
, 255, 255, 255, 1);
2227 if CustomStat
.GameMode
in [GM_TDM
, GM_CTF
] then
2232 if TeamStat
[TEAM_RED
].Goals
> TeamStat
[TEAM_BLUE
].Goals
then s1
:= _lc
[I_GAME_WIN_RED
]
2233 else if TeamStat
[TEAM_BLUE
].Goals
> TeamStat
[TEAM_RED
].Goals
then s1
:= _lc
[I_GAME_WIN_BLUE
]
2234 else s1
:= _lc
[I_GAME_WIN_DRAW
];
2236 e_TextureFontPrintEx(x
+8+(w
div 2)-(Length(s1
)*ww2
div 2), _y
, s1
, gStdFont
, 255, 255, 255, 1);
2239 for t
:= TEAM_RED
to TEAM_BLUE
do
2241 if t
= TEAM_RED
then
2243 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_RED
],
2244 gStdFont
, 255, 0, 0, 1);
2245 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_RED
].Goals
),
2246 gStdFont
, 255, 0, 0, 1);
2253 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_TEAM_BLUE
],
2254 gStdFont
, 0, 0, 255, 1);
2255 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(CustomStat
.TeamStat
[TEAM_BLUE
].Goals
),
2256 gStdFont
, 0, 0, 255, 1);
2262 e_DrawLine(1, x
+8, _y
+20, x
-8+w
, _y
+20, r
, g
, b
);
2265 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2266 if CustomStat
.PlayerStat
[p
].Team
= t
then
2267 with CustomStat
.PlayerStat
[p
] do
2281 e_TextureFontPrintEx(x
+8, _y
, Name
, gStdFont
, rr
, gg
, bb
, 1);
2282 e_TextureFontPrintEx(x
+w1
+8, _y
, IntToStr(Frags
), gStdFont
, rr
, gg
, bb
, 1);
2283 e_TextureFontPrintEx(x
+w1
+w2
+8, _y
, IntToStr(Deaths
), gStdFont
, rr
, gg
, bb
, 1);
2290 else if CustomStat
.GameMode
in [GM_DM
, GM_COOP
] then
2293 e_TextureFontPrintEx(x
+8, _y
, _lc
[I_GAME_PLAYER_NAME
], gStdFont
, 255, 127, 0, 1);
2294 e_TextureFontPrintEx(x
+8+w1
, _y
, _lc
[I_GAME_FRAGS
], gStdFont
, 255, 127, 0, 1);
2295 e_TextureFontPrintEx(x
+8+w1
+w2
, _y
, _lc
[I_GAME_DEATHS
], gStdFont
, 255, 127, 0, 1);
2298 for p
:= 0 to High(CustomStat
.PlayerStat
) do
2299 with CustomStat
.PlayerStat
[p
] do
2301 e_DrawFillQuad(x
+8, _y
+4, x
+24-1, _y
+16+4-1, Color
.R
, Color
.G
, Color
.B
, 0);
2308 e_TextureFontPrintEx(x
+8+16+8, _y
+4, Name
, gStdFont
, r
, r
, r
, 1, True);
2309 e_TextureFontPrintEx(x
+w1
+8+16+8, _y
+4, IntToStr(Frags
), gStdFont
, r
, r
, r
, 1, True);
2310 e_TextureFontPrintEx(x
+w1
+w2
+8+16+8, _y
+4, IntToStr(Deaths
), gStdFont
, r
, r
, r
, 1, True);
2316 procedure DrawSingleStat();
2318 tm
, key_x
, val_x
, y
: Integer;
2322 procedure player_stat(n
: Integer);
2328 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Kills
]);
2329 s2
:= Format(' %d', [gTotalMonsters
]);
2331 e_CharFont_Print(gMenuFont
, key_x
, y
, _lc
[I_MENU_INTER_KILLS
]);
2332 e_CharFont_PrintEx(gMenuFont
, val_x
, y
, s1
, _RGB(255, 0, 0));
2333 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2334 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
, '/');
2336 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2337 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
, s2
, _RGB(255, 0, 0));
2339 // "Kills-per-minute: ##.#":
2340 s1
:= _lc
[I_MENU_INTER_KPM
];
2342 kpm
:= (SingleStat
.PlayerStat
[n
].Kills
/ tm
) * 60
2344 kpm
:= SingleStat
.PlayerStat
[n
].Kills
;
2345 s2
:= Format(' %.1f', [kpm
]);
2347 e_CharFont_Print(gMenuFont
, key_x
, y
+32, s1
);
2348 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+32, s2
, _RGB(255, 0, 0));
2350 // "Secrets found: # / #":
2351 s1
:= Format(' %d ', [SingleStat
.PlayerStat
[n
].Secrets
]);
2352 s2
:= Format(' %d', [SingleStat
.TotalSecrets
]);
2354 e_CharFont_Print(gMenuFont
, key_x
, y
+64, _lc
[I_MENU_INTER_SECRETS
]);
2355 e_CharFont_PrintEx(gMenuFont
, val_x
, y
+64, s1
, _RGB(255, 0, 0));
2356 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2357 e_CharFont_Print(gMenuFont
, val_x
+w1
, y
+64, '/');
2359 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2360 e_CharFont_PrintEx(gMenuFont
, val_x
+w1
, y
+64, s2
, _RGB(255, 0, 0));
2364 // "Level Complete":
2365 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_INTER_LEVEL_COMPLETE
], w1
, h
);
2366 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 32, _lc
[I_MENU_INTER_LEVEL_COMPLETE
]);
2368 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2369 s1
:= _lc
[I_MENU_INTER_KPM
];
2370 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2373 e_CharFont_GetSize(gMenuFont
, s1
, w2
, h
);
2375 key_x
:= (gScreenWidth
-w1
-w2
) div 2;
2376 val_x
:= key_x
+ w1
;
2379 tm
:= SingleStat
.GameTime
div 1000;
2380 s1
:= _lc
[I_MENU_INTER_TIME
];
2381 s2
:= Format(' %d:%.2d:%.2d', [tm
div (60*60), (tm
mod (60*60)) div 60, tm
mod 60]);
2383 e_CharFont_Print(gMenuFont
, key_x
, 80, s1
);
2384 e_CharFont_PrintEx(gMenuFont
, val_x
, 80, s2
, _RGB(255, 0, 0));
2386 if SingleStat
.TwoPlayers
then
2389 s1
:= _lc
[I_MENU_PLAYER_1
];
2390 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2391 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 128, s1
);
2393 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2398 s1
:= _lc
[I_MENU_PLAYER_2
];
2399 e_CharFont_GetSize(gMenuFont
, s1
, w1
, h
);
2400 e_CharFont_Print(gMenuFont
, (gScreenWidth
-w1
) div 2, 288, s1
);
2402 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2408 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2414 procedure DrawLoadingStat();
2420 if Length(LoadingStat
.Msgs
) = 0 then
2423 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_LOADING
], ww
, hh
);
2424 yy
:= (gScreenHeight
div 3);
2425 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(ww
div 2), yy
-2*hh
, _lc
[I_MENU_LOADING
]);
2426 xx
:= (gScreenWidth
div 3);
2429 for i
:= 0 to NextMsg
-1 do
2431 if (i
= (NextMsg
-1)) and (MaxValue
> 0) then
2432 s
:= Format('%s: %d/%d', [Msgs
[i
], CurValue
, MaxValue
])
2436 e_CharFont_PrintEx(gMenuSmallFont
, xx
, yy
, s
, _RGB(255, 0, 0));
2437 yy
:= yy
+ LOADING_INTERLINE
;
2441 procedure DrawMinimap(p
: TPlayer
; RenderRect
: e_graphics
.TRect
);
2443 a
, aX
, aY
, aX2
, aY2
, Scale
, ScaleSz
: Integer;
2445 function monDraw (mon
: TMonster
): Boolean;
2447 result
:= false; // don't stop
2452 // Ëåâûé âåðõíèé óãîë
2453 aX
:= Obj
.X
div ScaleSz
+ 1;
2454 aY
:= Obj
.Y
div ScaleSz
+ 1;
2456 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2457 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2458 // Ïðàâûé íèæíèé óãîë
2459 aX2
:= aX
+ aX2
- 1;
2460 aY2
:= aY
+ aY2
- 1;
2461 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 255, 0, 0);
2467 if (gMapInfo
.Width
> RenderRect
.Right
- RenderRect
.Left
) or
2468 (gMapInfo
.Height
> RenderRect
.Bottom
- RenderRect
.Top
) then
2471 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2472 ScaleSz
:= 16 div Scale
;
2473 // Ðàçìåðû ìèíè-êàðòû:
2474 aX
:= max(gMapInfo
.Width
div ScaleSz
, 1);
2475 aY
:= max(gMapInfo
.Height
div ScaleSz
, 1);
2477 e_DrawFillQuad(0, 0, aX
-1, aY
-1, 0, 0, 0, 0);
2479 if gWalls
<> nil then
2482 for a
:= 0 to High(gWalls
) do
2484 if PanelType
<> 0 then
2486 // Ëåâûé âåðõíèé óãîë:
2487 aX
:= X
div ScaleSz
;
2488 aY
:= Y
div ScaleSz
;
2490 aX2
:= max(Width
div ScaleSz
, 1);
2491 aY2
:= max(Height
div ScaleSz
, 1);
2492 // Ïðàâûé íèæíèé óãîë:
2493 aX2
:= aX
+ aX2
- 1;
2494 aY2
:= aY
+ aY2
- 1;
2497 PANEL_WALL
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 208, 208, 208, 0);
2498 PANEL_OPENDOOR
, PANEL_CLOSEDOOR
:
2499 if Enabled
then e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 160, 160, 160, 0);
2503 if gSteps
<> nil then
2506 for a
:= 0 to High(gSteps
) do
2508 if PanelType
<> 0 then
2510 // Ëåâûé âåðõíèé óãîë:
2511 aX
:= X
div ScaleSz
;
2512 aY
:= Y
div ScaleSz
;
2514 aX2
:= max(Width
div ScaleSz
, 1);
2515 aY2
:= max(Height
div ScaleSz
, 1);
2516 // Ïðàâûé íèæíèé óãîë:
2517 aX2
:= aX
+ aX2
- 1;
2518 aY2
:= aY
+ aY2
- 1;
2520 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 128, 128, 128, 0);
2523 if gLifts
<> nil then
2526 for a
:= 0 to High(gLifts
) do
2528 if PanelType
<> 0 then
2530 // Ëåâûé âåðõíèé óãîë:
2531 aX
:= X
div ScaleSz
;
2532 aY
:= Y
div ScaleSz
;
2534 aX2
:= max(Width
div ScaleSz
, 1);
2535 aY2
:= max(Height
div ScaleSz
, 1);
2536 // Ïðàâûé íèæíèé óãîë:
2537 aX2
:= aX
+ aX2
- 1;
2538 aY2
:= aY
+ aY2
- 1;
2541 0: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 72, 36, 0);
2542 1: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 116, 124, 96, 0);
2543 2: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 200, 80, 4, 0);
2544 3: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 252, 140, 56, 0);
2548 if gWater
<> nil then
2551 for a
:= 0 to High(gWater
) do
2553 if PanelType
<> 0 then
2555 // Ëåâûé âåðõíèé óãîë:
2556 aX
:= X
div ScaleSz
;
2557 aY
:= Y
div ScaleSz
;
2559 aX2
:= max(Width
div ScaleSz
, 1);
2560 aY2
:= max(Height
div ScaleSz
, 1);
2561 // Ïðàâûé íèæíèé óãîë:
2562 aX2
:= aX
+ aX2
- 1;
2563 aY2
:= aY
+ aY2
- 1;
2565 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 192, 0);
2568 if gAcid1
<> nil then
2570 // Ðèñóåì êèñëîòó 1:
2571 for a
:= 0 to High(gAcid1
) do
2573 if PanelType
<> 0 then
2575 // Ëåâûé âåðõíèé óãîë:
2576 aX
:= X
div ScaleSz
;
2577 aY
:= Y
div ScaleSz
;
2579 aX2
:= max(Width
div ScaleSz
, 1);
2580 aY2
:= max(Height
div ScaleSz
, 1);
2581 // Ïðàâûé íèæíèé óãîë:
2582 aX2
:= aX
+ aX2
- 1;
2583 aY2
:= aY
+ aY2
- 1;
2585 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 176, 0, 0);
2588 if gAcid2
<> nil then
2590 // Ðèñóåì êèñëîòó 2:
2591 for a
:= 0 to High(gAcid2
) do
2593 if PanelType
<> 0 then
2595 // Ëåâûé âåðõíèé óãîë:
2596 aX
:= X
div ScaleSz
;
2597 aY
:= Y
div ScaleSz
;
2599 aX2
:= max(Width
div ScaleSz
, 1);
2600 aY2
:= max(Height
div ScaleSz
, 1);
2601 // Ïðàâûé íèæíèé óãîë:
2602 aX2
:= aX
+ aX2
- 1;
2603 aY2
:= aY
+ aY2
- 1;
2605 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 176, 0, 0, 0);
2608 if gPlayers
<> nil then
2611 for a
:= 0 to High(gPlayers
) do
2612 if gPlayers
[a
] <> nil then with gPlayers
[a
] do
2614 // Ëåâûé âåðõíèé óãîë:
2615 aX
:= Obj
.X
div ScaleSz
+ 1;
2616 aY
:= Obj
.Y
div ScaleSz
+ 1;
2618 aX2
:= max(Obj
.Rect
.Width
div ScaleSz
, 1);
2619 aY2
:= max(Obj
.Rect
.Height
div ScaleSz
, 1);
2620 // Ïðàâûé íèæíèé óãîë:
2621 aX2
:= aX
+ aX2
- 1;
2622 aY2
:= aY
+ aY2
- 1;
2624 if gPlayers
[a
] = p
then
2625 e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 255, 0, 0)
2628 TEAM_RED
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 0, 0, 0);
2629 TEAM_BLUE
: e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 0, 0, 255, 0);
2630 else e_DrawFillQuad(aX
, aY
, aX2
, aY2
, 255, 128, 0, 0);
2635 g_Mons_ForEach(monDraw
);
2640 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
2641 procedure renderDynLightsInternal ();
2644 lx
, ly
, lrad
: Integer;
2646 //TODO: lights should be in separate grid, i think
2647 // but on the other side: grid may be slower for dynlights, as their lifetime is short
2648 if not gwin_has_stencil
or (g_dynLightCount
< 1) then exit
;
2650 // setup OpenGL parameters
2651 glStencilMask($FFFFFFFF);
2652 glStencilFunc(GL_ALWAYS
, 0, $FFFFFFFF);
2653 glEnable(GL_STENCIL_TEST
);
2654 glEnable(GL_SCISSOR_TEST
);
2655 glClear(GL_STENCIL_BUFFER_BIT
);
2656 glStencilFunc(GL_EQUAL
, 0, $ff);
2658 for lln
:= 0 to g_dynLightCount
-1 do
2660 lx
:= g_dynLights
[lln
].x
;
2661 ly
:= g_dynLights
[lln
].y
;
2662 lrad
:= g_dynLights
[lln
].radius
;
2663 if lrad
< 3 then continue
;
2665 if lx
-sX
+lrad
< 0 then continue
;
2666 if ly
-sY
+lrad
< 0 then continue
;
2667 if lx
-sX
-lrad
>= gPlayerScreenSize
.X
then continue
;
2668 if ly
-sY
-lrad
>= gPlayerScreenSize
.Y
then continue
;
2670 // set scissor to optimize drawing
2671 glScissor((lx
-sX
)-lrad
+2, gPlayerScreenSize
.Y
-(ly
-sY
)-lrad
-1+2, lrad
*2-4, lrad
*2-4);
2672 // no need to clear stencil buffer, light blitting will do it for us
2673 glStencilOp(GL_KEEP
, GL_KEEP
, GL_INCR
);
2674 // draw extruded panels
2675 glDisable(GL_TEXTURE_2D
);
2676 glDisable(GL_BLEND
);
2677 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
); // no need to modify color buffer
2678 if (lrad
> 4) then g_Map_DrawPanelShadowVolumes(lx
, ly
, lrad
);
2679 // render light texture
2680 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
); // modify color buffer
2681 glStencilOp(GL_ZERO
, GL_ZERO
, GL_ZERO
); // draw light, and clear stencil buffer
2684 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
2685 glEnable(GL_TEXTURE_2D
);
2686 // color and opacity
2687 glColor4f(g_dynLights
[lln
].r
, g_dynLights
[lln
].g
, g_dynLights
[lln
].b
, g_dynLights
[lln
].a
);
2688 glBindTexture(GL_TEXTURE_2D
, g_Texture_Light());
2690 glTexCoord2f(0.0, 0.0); glVertex2i(lx
-lrad
, ly
-lrad
); // top-left
2691 glTexCoord2f(1.0, 0.0); glVertex2i(lx
+lrad
, ly
-lrad
); // top-right
2692 glTexCoord2f(1.0, 1.0); glVertex2i(lx
+lrad
, ly
+lrad
); // bottom-right
2693 glTexCoord2f(0.0, 1.0); glVertex2i(lx
-lrad
, ly
+lrad
); // bottom-left
2698 glDisable(GL_STENCIL_TEST
);
2699 glDisable(GL_BLEND
);
2700 glDisable(GL_SCISSOR_TEST
);
2701 glScissor(0, 0, sWidth
, sHeight
);
2705 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
2706 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
2707 procedure renderMapInternal (backXOfs
, backYOfs
: Integer; transX
, transY
: Integer; setTransMatrix
: Boolean);
2709 TDrawCB
= procedure ();
2711 procedure drawPanelType (profname
: AnsiString; panType
: DWord
);
2716 profileFrameDraw
.sectionBegin(profname
);
2717 if gdbg_map_use_accel_render
then
2719 tagmask
:= panelTypeToTag(panType
);
2721 while (gDrawPanelList
.count
> 0) do
2723 pan
:= TPanel(gDrawPanelList
.front());
2724 if ((pan
.tag
and tagmask
) = 0) then break
;
2726 gDrawPanelList
.popFront();
2729 e_WriteLog(Format('=== PANELS: %d ===', [gDrawPanelList
.count
]), MSG_NOTIFY
);
2730 while (gDrawPanelList
.count
> 0) do
2732 pan
:= TPanel(gDrawPanelList
.front());
2733 e_WriteLog(Format('tagmask: 0x%04x; pan.tag: 0x%04x; pan.ArrIdx: %d', [tagmask
, pan
.tag
, pan
.ArrIdx
]), MSG_NOTIFY
);
2735 gDrawPanelList
.popFront();
2741 g_Map_DrawPanels(panType
);
2743 profileFrameDraw
.sectionEnd();
2746 procedure drawOther (profname
: AnsiString; cb
: TDrawCB
);
2748 profileFrameDraw
.sectionBegin(profname
);
2749 if assigned(cb
) then cb();
2750 profileFrameDraw
.sectionEnd();
2754 profileFrameDraw
.sectionBegin('total');
2756 // our accelerated renderer will collect all panels to gDrawPanelList
2757 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
2758 profileFrameDraw
.sectionBegin('collect');
2759 if gdbg_map_use_accel_render
then
2761 g_Map_CollectDrawPanels(sX
, sY
, sWidth
, sHeight
);
2763 profileFrameDraw
.sectionEnd();
2765 profileFrameDraw
.sectionBegin('skyback');
2766 g_Map_DrawBack(backXOfs
, backYOfs
);
2767 profileFrameDraw
.sectionEnd();
2769 if (setTransMatrix
) then glTranslatef(transX
, transY
, 0);
2771 drawPanelType('*back', PANEL_BACK
);
2772 drawPanelType('*step', PANEL_STEP
);
2773 drawOther('items', @g_Items_Draw
);
2774 drawOther('weapons', @g_Weapon_Draw
);
2775 drawOther('shells', @g_Player_DrawShells
);
2776 drawOther('drawall', @g_Player_DrawAll
);
2777 drawOther('corpses', @g_Player_DrawCorpses
);
2778 drawPanelType('*wall', PANEL_WALL
);
2779 drawOther('monsters', @g_Monsters_Draw
);
2780 drawPanelType('*door', PANEL_CLOSEDOOR
);
2781 drawOther('gfx', @g_GFX_Draw
);
2782 drawOther('flags', @g_Map_DrawFlags
);
2783 drawPanelType('*acid1', PANEL_ACID1
);
2784 drawPanelType('*acid2', PANEL_ACID2
);
2785 drawPanelType('*water', PANEL_WATER
);
2786 drawOther('dynlights', @renderDynLightsInternal
);
2787 drawPanelType('*fore', PANEL_FORE
);
2789 if g_debug_HealthBar
then
2791 g_Monsters_DrawHealth();
2792 g_Player_DrawHealth();
2795 profileFrameDraw
.mainEnd(); // map rendering
2799 procedure DrawMapView(x
, y
, w
, h
: Integer);
2806 bx
:= Round(x
/(gMapInfo
.Width
- w
)*(gBackSize
.X
- w
));
2807 by
:= Round(y
/(gMapInfo
.Height
- h
)*(gBackSize
.Y
- h
));
2814 renderMapInternal(-bx
, -by
, -x
, -y
, true);
2820 procedure DrawPlayer(p
: TPlayer
);
2822 px
, py
, a
, b
, c
, d
: Integer;
2826 if (p
= nil) or (p
.FDummy
) then
2829 g_Map_DrawBack(0, 0);
2834 if (profileFrameDraw
= nil) then profileFrameDraw
:= TProfiler
.Create('RENDER', g_profile_history_size
);
2835 profileFrameDraw
.mainBegin(g_profile_frame_draw
);
2841 px
:= p
.GameX
+ PLAYER_RECT_CX
;
2842 py
:= p
.GameY
+ PLAYER_RECT_CY
;
2844 if px
> (gPlayerScreenSize
.X
div 2) then a
:= -px
+(gPlayerScreenSize
.X
div 2) else a
:= 0;
2845 if py
> (gPlayerScreenSize
.Y
div 2) then b
:= -py
+(gPlayerScreenSize
.Y
div 2) else b
:= 0;
2847 if px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2) then a
:= -gMapInfo
.Width
+gPlayerScreenSize
.X
;
2848 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then b
:= -gMapInfo
.Height
+gPlayerScreenSize
.Y
;
2850 if gMapInfo
.Width
<= gPlayerScreenSize
.X
then a
:= 0;
2851 if gMapInfo
.Height
<= gPlayerScreenSize
.Y
then b
:= 0;
2853 if p
.IncCam
<> 0 then
2855 if py
> gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2) then
2857 if p
.IncCam
> 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2))) then
2859 p
.IncCam
:= 120-(py
-(gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)));
2863 if py
< gPlayerScreenSize
.Y
div 2 then
2865 if p
.IncCam
< -120+((gPlayerScreenSize
.Y
div 2)-py
) then
2867 p
.IncCam
:= -120+((gPlayerScreenSize
.Y
div 2)-py
);
2871 if p
.IncCam
< 0 then
2873 while (py
+(gPlayerScreenSize
.Y
div 2)-p
.IncCam
> gMapInfo
.Height
) and (p
.IncCam
< 0) do p
.IncCam
:= p
.IncCam
+1; //Inc(p.IncCam);
2876 if p
.IncCam
> 0 then
2878 while (py
-(gPlayerScreenSize
.Y
div 2)-p
.IncCam
< 0) and (p
.IncCam
> 0) do p
.IncCam
:= p
.IncCam
-1; //Dec(p.IncCam);
2882 if (px
< gPlayerScreenSize
.X
div 2) or (gMapInfo
.Width
-gPlayerScreenSize
.X
<= 256) then c
:= 0
2883 else if (px
> gMapInfo
.Width
-(gPlayerScreenSize
.X
div 2)) then c
:= gBackSize
.X
-gPlayerScreenSize
.X
2884 else c
:= round((px
-(gPlayerScreenSize
.X
div 2))/(gMapInfo
.Width
-gPlayerScreenSize
.X
)*(gBackSize
.X
-gPlayerScreenSize
.X
));
2886 if (py
-p
.IncCam
<= gPlayerScreenSize
.Y
div 2) or (gMapInfo
.Height
-gPlayerScreenSize
.Y
<= 256) then d
:= 0
2887 else if (py
-p
.IncCam
>= gMapInfo
.Height
-(gPlayerScreenSize
.Y
div 2)) then d
:= gBackSize
.Y
-gPlayerScreenSize
.Y
2888 else d
:= round((py
-p
.IncCam
-(gPlayerScreenSize
.Y
div 2))/(gMapInfo
.Height
-gPlayerScreenSize
.Y
)*(gBackSize
.Y
-gPlayerScreenSize
.Y
));
2891 sY
:= -(b
+p
.IncCam
);
2892 sWidth
:= gPlayerScreenSize
.X
;
2893 sHeight
:= gPlayerScreenSize
.Y
;
2895 //glTranslatef(a, b+p.IncCam, 0);
2897 renderMapInternal(-c
, -d
, a
, b
+p
.IncCam
, true);
2899 if p
.FSpectator
then
2900 e_TextureFontPrintEx(p
.GameX
+ PLAYER_RECT_CX
- 4,
2901 p
.GameY
+ PLAYER_RECT_CY
- 4,
2902 'X', gStdFont
, 255, 255, 255, 1, True);
2904 for a := 0 to High(gCollideMap) do
2905 for b := 0 to High(gCollideMap[a]) do
2908 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
2910 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
2914 1: e_DrawPoint(1, b, a, 200, 200, 200);
2915 2: e_DrawPoint(1, b, a, 64, 64, 255);
2916 3: e_DrawPoint(1, b, a, 255, 0, 255);
2926 if gShowMap
then DrawMinimap(p
, _TRect(0, 0, 128, 128));
2927 if g_Debug_Player
then
2928 g_Player_DrawDebug(p
);
2932 procedure drawProfilers ();
2936 if g_profile_frame_draw
then px
:= px
-drawProfiles(px
, -1, profileFrameDraw
);
2937 if g_profile_collision
then px
:= px
-drawProfiles(px
, -1, profMapCollision
);
2940 procedure g_Game_Draw();
2947 plView1
, plView2
: TPlayer
;
2950 if gExit
= EXIT_QUIT
then Exit
;
2952 Time
:= GetTimer() {div 1000};
2953 FPSCounter
:= FPSCounter
+1;
2954 if Time
- FPSTime
>= 1000 then
2961 if gGameOn
or (gState
= STATE_FOLD
) then
2963 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
2965 gSpectMode
:= SPECT_NONE
;
2966 if not gRevertPlayers
then
2968 plView1
:= gPlayer1
;
2969 plView2
:= gPlayer2
;
2973 plView1
:= gPlayer2
;
2974 plView2
:= gPlayer1
;
2978 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
2980 gSpectMode
:= SPECT_NONE
;
2981 if gPlayer2
= nil then
2984 plView1
:= gPlayer2
;
2993 if (plView1
= nil) and (plView2
= nil) and (gSpectMode
= SPECT_NONE
) then
2994 gSpectMode
:= SPECT_STATS
;
2996 if gSpectMode
= SPECT_PLAYERS
then
2997 if gPlayers
<> nil then
2999 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3000 if plView1
= nil then
3002 gSpectPID1
:= GetActivePlayerID_Next();
3003 plView1
:= GetActivePlayer_ByID(gSpectPID1
);
3005 if gSpectViewTwo
then
3007 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3008 if plView2
= nil then
3010 gSpectPID2
:= GetActivePlayerID_Next();
3011 plView2
:= GetActivePlayer_ByID(gSpectPID2
);
3016 if gSpectMode
= SPECT_MAPVIEW
then
3018 // Ðåæèì ïðîñìîòðà êàðòû
3020 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3021 DrawMapView(gSpectX
, gSpectY
, gScreenWidth
, gScreenHeight
);
3022 gHearPoint1
.Active
:= True;
3023 gHearPoint1
.Coords
.X
:= gScreenWidth
div 2 + gSpectX
;
3024 gHearPoint1
.Coords
.Y
:= gScreenHeight
div 2 + gSpectY
;
3025 gHearPoint2
.Active
:= False;
3029 Split
:= (plView1
<> nil) and (plView2
<> nil);
3031 // Òî÷êè ñëóõà èãðîêîâ
3032 if plView1
<> nil then
3034 gHearPoint1
.Active
:= True;
3035 gHearPoint1
.Coords
.X
:= plView1
.GameX
;
3036 gHearPoint1
.Coords
.Y
:= plView1
.GameY
;
3038 gHearPoint1
.Active
:= False;
3039 if plView2
<> nil then
3041 gHearPoint2
.Active
:= True;
3042 gHearPoint2
.Coords
.X
:= plView2
.GameX
;
3043 gHearPoint2
.Coords
.Y
:= plView2
.GameY
;
3045 gHearPoint2
.Active
:= False;
3047 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3048 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3051 gPlayerScreenSize
.Y
:= gScreenHeight
div 2;
3052 if gScreenHeight
mod 2 = 0 then
3053 Dec(gPlayerScreenSize
.Y
);
3056 gPlayerScreenSize
.Y
:= gScreenHeight
;
3059 if gScreenHeight
mod 2 = 0 then
3060 e_SetViewPort(0, gPlayerScreenSize
.Y
+2, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
)
3062 e_SetViewPort(0, gPlayerScreenSize
.Y
+1, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3064 DrawPlayer(plView1
);
3065 gPlayer1ScreenCoord
.X
:= sX
;
3066 gPlayer1ScreenCoord
.Y
:= sY
;
3070 e_SetViewPort(0, 0, gPlayerScreenSize
.X
+196, gPlayerScreenSize
.Y
);
3072 DrawPlayer(plView2
);
3073 gPlayer2ScreenCoord
.X
:= sX
;
3074 gPlayer2ScreenCoord
.Y
:= sY
;
3077 e_SetViewPort(0, 0, gScreenWidth
, gScreenHeight
);
3080 e_DrawLine(2, 0, gScreenHeight
div 2, gScreenWidth
, gScreenHeight
div 2, 0, 0, 0);
3083 if MessageText
<> '' then
3087 e_CharFont_GetSizeFmt(gMenuFont
, MessageText
, w
, h
);
3089 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3090 (gScreenHeight
div 2)-(h
div 2), MessageText
)
3092 e_CharFont_PrintFmt(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3093 Round(gScreenHeight
/ 2.75)-(h
div 2), MessageText
);
3096 if IsDrawStat
or (gSpectMode
= 1) then DrawStat();
3098 if gSpectHUD
and (not gChatShow
) and (gSpectMode
<> SPECT_NONE
) then
3100 // Draw spectator GUI
3103 e_TextureFontGetSize(gStdFont
, ww
, hh
);
3106 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Stats', gStdFont
, 255, 255, 255, 1);
3108 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Observe Map', gStdFont
, 255, 255, 255, 1);
3110 e_TextureFontPrintEx(0, gScreenHeight
- (hh
+2)*2, 'MODE: Watch Players', gStdFont
, 255, 255, 255, 1);
3112 e_TextureFontPrintEx(2*ww
, gScreenHeight
- (hh
+2), '< jump >', gStdFont
, 255, 255, 255, 1);
3113 if gSpectMode
= SPECT_MAPVIEW
then
3115 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, '[-]', gStdFont
, 255, 255, 255, 1);
3116 e_TextureFontPrintEx(26*ww
, gScreenHeight
- (hh
+2)*2, 'Step ' + IntToStr(gSpectStep
), gStdFont
, 255, 255, 255, 1);
3117 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2)*2, '[+]', gStdFont
, 255, 255, 255, 1);
3118 e_TextureFontPrintEx(18*ww
, gScreenHeight
- (hh
+2), '<prev weap>', gStdFont
, 255, 255, 255, 1);
3119 e_TextureFontPrintEx(30*ww
, gScreenHeight
- (hh
+2), '<next weap>', gStdFont
, 255, 255, 255, 1);
3121 if gSpectMode
= SPECT_PLAYERS
then
3123 e_TextureFontPrintEx(22*ww
, gScreenHeight
- (hh
+2)*2, 'Player 1', gStdFont
, 255, 255, 255, 1);
3124 e_TextureFontPrintEx(20*ww
, gScreenHeight
- (hh
+2), '<left/right>', gStdFont
, 255, 255, 255, 1);
3125 if gSpectViewTwo
then
3127 e_TextureFontPrintEx(37*ww
, gScreenHeight
- (hh
+2)*2, 'Player 2', gStdFont
, 255, 255, 255, 1);
3128 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<prev w/next w>', gStdFont
, 255, 255, 255, 1);
3129 e_TextureFontPrintEx(52*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3130 e_TextureFontPrintEx(51*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3134 e_TextureFontPrintEx(35*ww
, gScreenHeight
- (hh
+2)*2, '2x View', gStdFont
, 255, 255, 255, 1);
3135 e_TextureFontPrintEx(34*ww
, gScreenHeight
- (hh
+2), '<up/down>', gStdFont
, 255, 255, 255, 1);
3141 if gPause
and gGameOn
and (g_ActiveWindow
= nil) then
3143 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3145 e_CharFont_GetSize(gMenuFont
, _lc
[I_MENU_PAUSE
], w
, h
);
3146 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2)-(w
div 2),
3147 (gScreenHeight
div 2)-(h
div 2), _lc
[I_MENU_PAUSE
]);
3152 if (gState
= STATE_MENU
) then
3154 if ((g_ActiveWindow
= nil) or (g_ActiveWindow
.BackTexture
= '')) then
3156 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3157 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3158 else e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3160 if g_ActiveWindow
<> nil then
3161 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3164 if gState
= STATE_FOLD
then
3165 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
);
3167 if gState
= STATE_INTERCUSTOM
then
3169 if gLastMap
and (gGameSettings
.GameMode
= GM_COOP
) then
3171 back
:= 'TEXTURE_endpic';
3172 if not g_Texture_Get(back
, ID
) then
3173 back
:= _lc
[I_TEXTURE_ENDPIC
];
3178 if g_Texture_Get(back
, ID
) then
3179 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3181 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3185 if g_ActiveWindow
<> nil then
3186 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3189 if gState
= STATE_INTERSINGLE
then
3191 if EndingGameCounter
> 0 then
3192 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 0, 0, 0, EndingGameCounter
)
3197 if g_Texture_Get(back
, ID
) then
3198 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3200 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3204 if g_ActiveWindow
<> nil then
3205 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3209 if gState
= STATE_ENDPIC
then
3212 if not g_Texture_Get('TEXTURE_endpic', ID
) then
3213 g_Texture_Get(_lc
[I_TEXTURE_ENDPIC
], ID
);
3215 if ID
<> DWORD(-1) then
3216 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
3218 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
3220 if g_ActiveWindow
<> nil then
3221 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3224 if gState
= STATE_SLIST
then
3226 if g_Texture_Get('MENU_BACKGROUND', ID
) then
3228 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
);
3229 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3231 g_Serverlist_Draw(slCurrent
);
3235 if g_ActiveWindow
<> nil then
3238 e_DrawFillQuad(0, 0, gScreenWidth
-1, gScreenHeight
-1, 48, 48, 48, 180);
3239 g_ActiveWindow
.Draw();
3244 if g_debug_Sounds
and gGameOn
then
3246 for w
:= 0 to High(e_SoundsArray
) do
3247 for h
:= 0 to e_SoundsArray
[w
].nRefs
do
3248 e_DrawPoint(1, w
+100, h
+100, 255, 0, 0);
3253 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS
]), gStdFont
);
3254 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS
]), gStdFont
);
3257 if gGameOn
and gShowTime
and (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
]) then
3258 e_TextureFontPrint(gScreenWidth
-72, 0,
3259 Format('%d:%.2d:%.2d', [gTime
div 1000 div 3600, (gTime
div 1000 div 60) mod 60, gTime
div 1000 mod 60]),
3262 if gGameOn
then drawProfilers();
3265 procedure g_Game_Quit();
3267 g_Game_StopAllSounds(True);
3269 g_Game_SaveOptions();
3271 g_PlayerModel_FreeData();
3272 g_Texture_DeleteAll();
3273 g_Frames_DeleteAll();
3276 if NetInitDone
then g_Net_Free
;
3278 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3279 if gMapToDelete
<> '' then
3280 g_Game_DeleteTestMap();
3286 procedure g_FatalError(Text: String);
3288 g_Console_Add(Format(_lc
[I_FATAL_ERROR
], [Text]), True);
3289 e_WriteLog(Format(_lc
[I_FATAL_ERROR
], [Text]), MSG_WARNING
);
3291 gExit
:= EXIT_SIMPLE
;
3294 procedure g_SimpleError(Text: String);
3296 g_Console_Add(Format(_lc
[I_SIMPLE_ERROR
], [Text]), True);
3297 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], [Text]), MSG_WARNING
);
3300 procedure g_Game_SetupScreenSize();
3304 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3305 gPlayerScreenSize
.X
:= gScreenWidth
-196;
3306 if (gPlayer1
<> nil) and (gPlayer2
<> nil) then
3307 gPlayerScreenSize
.Y
:= gScreenHeight
div 2
3309 gPlayerScreenSize
.Y
:= gScreenHeight
;
3311 // Ðàçìåð çàäíåãî ïëàíà:
3312 if BackID
<> DWORD(-1) then
3316 if (gScreenWidth
*d
> gMapInfo
.Width
) or
3317 (gScreenHeight
*d
> gMapInfo
.Height
) then
3320 gBackSize
.X
:= Round(gScreenWidth
*d
);
3321 gBackSize
.Y
:= Round(gScreenHeight
*d
);
3325 procedure g_Game_ChangeResolution(newWidth
, newHeight
: Word; nowFull
, nowMax
: Boolean);
3327 g_Window_SetSize(newWidth
, newHeight
, nowFull
);
3330 procedure g_Game_AddPlayer(Team
: Byte = TEAM_NONE
);
3332 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3333 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3335 if gPlayer1
= nil then
3337 if g_Game_IsClient
then
3339 if NetPlrUID1
> -1 then
3341 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3342 gPlayer1
:= g_Player_Get(NetPlrUID1
);
3347 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3348 Team
:= gPlayer1Settings
.Team
;
3350 // Ñîçäàíèå ïåðâîãî èãðîêà:
3351 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3352 gPlayer1Settings
.Color
,
3354 if gPlayer1
= nil then
3355 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]))
3358 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3359 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer1
.Name
]), True);
3360 if g_Game_IsServer
and g_Game_IsNet
then
3361 MH_SEND_PlayerCreate(gPlayer1
.UID
);
3362 gPlayer1
.Respawn(False, True);
3364 if g_Game_IsNet
and NetUseMaster
then
3370 if gPlayer2
= nil then
3372 if g_Game_IsClient
then
3374 if NetPlrUID2
> -1 then
3375 gPlayer2
:= g_Player_Get(NetPlrUID2
);
3379 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
3380 Team
:= gPlayer2Settings
.Team
;
3382 // Ñîçäàíèå âòîðîãî èãðîêà:
3383 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3384 gPlayer2Settings
.Color
,
3386 if gPlayer2
= nil then
3387 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]))
3390 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3391 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [gPlayer2
.Name
]), True);
3392 if g_Game_IsServer
and g_Game_IsNet
then
3393 MH_SEND_PlayerCreate(gPlayer2
.UID
);
3394 gPlayer2
.Respawn(False, True);
3396 if g_Game_IsNet
and NetUseMaster
then
3404 procedure g_Game_RemovePlayer();
3408 if ((not gGameOn
) and (gState
<> STATE_INTERCUSTOM
))
3409 or (not (gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
])) then
3414 if g_Game_IsServer
then
3417 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3418 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3419 g_Player_Remove(Pl
.UID
);
3421 if g_Game_IsNet
and NetUseMaster
then
3430 if g_Game_IsServer
then
3433 Pl
.Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
3434 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [Pl
.Name
]), True);
3435 g_Player_Remove(Pl
.UID
);
3437 if g_Game_IsNet
and NetUseMaster
then
3442 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE
);
3448 procedure g_Game_Spectate();
3450 g_Game_RemovePlayer();
3451 if gPlayer1
<> nil then
3452 g_Game_RemovePlayer();
3455 procedure g_Game_SpectateCenterView();
3457 gSpectX
:= Max(gMapInfo
.Width
div 2 - gScreenWidth
div 2, 0);
3458 gSpectY
:= Max(gMapInfo
.Height
div 2 - gScreenHeight
div 2, 0);
3461 procedure g_Game_StartSingle(Map
: String; TwoPlayers
: Boolean; nPlayers
: Byte);
3467 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY
);
3469 g_Game_ClearLoading();
3472 FillByte(gGameSettings
, SizeOf(TGameSettings
), 0);
3475 gGameSettings
.GameType
:= GT_SINGLE
;
3476 gGameSettings
.MaxLives
:= 0;
3477 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_ALLOWEXIT
;
3478 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_MONSTERS
;
3479 gGameSettings
.Options
:= gGameSettings
.Options
+ GAME_OPTION_BOTVSMONSTER
;
3480 gSwitchGameMode
:= GM_SINGLE
;
3482 g_Game_ExecuteEvent('ongamestart');
3484 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3485 g_Game_SetupScreenSize();
3487 // Ñîçäàíèå ïåðâîãî èãðîêà:
3488 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3489 gPlayer1Settings
.Color
,
3490 gPlayer1Settings
.Team
, False));
3491 if gPlayer1
= nil then
3493 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3497 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3500 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3503 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3504 gPlayer2Settings
.Color
,
3505 gPlayer2Settings
.Team
, False));
3506 if gPlayer2
= nil then
3508 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3512 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3516 // Çàãðóçêà è çàïóñê êàðòû:
3517 if not g_Game_StartMap(MAP
, True) then
3519 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [gGameSettings
.WAD
+ ':\' + MAP
]));
3523 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3527 for i
:= nPl
+1 to nPlayers
do
3528 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3531 procedure g_Game_StartCustom(Map
: String; GameMode
: Byte;
3532 TimeLimit
, GoalLimit
: Word;
3534 Options
: LongWord; nPlayers
: Byte);
3540 e_WriteLog('Starting custom game...', MSG_NOTIFY
);
3542 g_Game_ClearLoading();
3545 gGameSettings
.GameType
:= GT_CUSTOM
;
3546 gGameSettings
.GameMode
:= GameMode
;
3547 gSwitchGameMode
:= GameMode
;
3548 gGameSettings
.TimeLimit
:= TimeLimit
;
3549 gGameSettings
.GoalLimit
:= GoalLimit
;
3550 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3551 gGameSettings
.Options
:= Options
;
3553 gCoopTotalMonstersKilled
:= 0;
3554 gCoopTotalSecretsFound
:= 0;
3555 gCoopTotalMonsters
:= 0;
3556 gCoopTotalSecrets
:= 0;
3560 g_Game_ExecuteEvent('ongamestart');
3562 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3563 g_Game_SetupScreenSize();
3565 // Ðåæèì íàáëþäàòåëÿ:
3566 if nPlayers
= 0 then
3573 if nPlayers
>= 1 then
3575 // Ñîçäàíèå ïåðâîãî èãðîêà:
3576 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3577 gPlayer1Settings
.Color
,
3578 gPlayer1Settings
.Team
, False));
3579 if gPlayer1
= nil then
3581 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3585 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3589 if nPlayers
>= 2 then
3591 // Ñîçäàíèå âòîðîãî èãðîêà:
3592 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3593 gPlayer2Settings
.Color
,
3594 gPlayer2Settings
.Team
, False));
3595 if gPlayer2
= nil then
3597 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3601 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3605 // Çàãðóçêà è çàïóñê êàðòû:
3606 if not g_Game_StartMap(Map
, True) then
3608 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3612 // Íåò òî÷åê ïîÿâëåíèÿ:
3613 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3614 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3615 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3616 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3617 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3619 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3623 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3627 for i
:= nPl
+1 to nPlayers
do
3628 g_Player_Create(STD_PLAYER_MODEL
, _RGB(0, 0, 0), 0, True);
3631 procedure g_Game_StartServer(Map
: String; GameMode
: Byte;
3632 TimeLimit
, GoalLimit
: Word; MaxLives
: Byte;
3633 Options
: LongWord; nPlayers
: Byte;
3634 IPAddr
: LongWord; Port
: Word);
3638 e_WriteLog('Starting net game (server)...', MSG_NOTIFY
);
3640 g_Game_ClearLoading();
3643 gGameSettings
.GameType
:= GT_SERVER
;
3644 gGameSettings
.GameMode
:= GameMode
;
3645 gSwitchGameMode
:= GameMode
;
3646 gGameSettings
.TimeLimit
:= TimeLimit
;
3647 gGameSettings
.GoalLimit
:= GoalLimit
;
3648 gGameSettings
.MaxLives
:= IfThen(GameMode
= GM_CTF
, 0, MaxLives
);
3649 gGameSettings
.Options
:= Options
;
3651 gCoopTotalMonstersKilled
:= 0;
3652 gCoopTotalSecretsFound
:= 0;
3653 gCoopTotalMonsters
:= 0;
3654 gCoopTotalSecrets
:= 0;
3658 g_Game_ExecuteEvent('ongamestart');
3660 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3661 g_Game_SetupScreenSize();
3663 // Ðåæèì íàáëþäàòåëÿ:
3664 if nPlayers
= 0 then
3670 if nPlayers
>= 1 then
3672 // Ñîçäàíèå ïåðâîãî èãðîêà:
3673 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3674 gPlayer1Settings
.Color
,
3675 gPlayer1Settings
.Team
, False));
3676 if gPlayer1
= nil then
3678 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3682 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3685 if nPlayers
>= 2 then
3687 // Ñîçäàíèå âòîðîãî èãðîêà:
3688 gPlayer2
:= g_Player_Get(g_Player_Create(gPlayer2Settings
.Model
,
3689 gPlayer2Settings
.Color
,
3690 gPlayer2Settings
.Team
, False));
3691 if gPlayer2
= nil then
3693 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [2]));
3697 gPlayer2
.Name
:= gPlayer2Settings
.Name
;
3701 if not g_Net_Host(IPAddr
, Port
, NetMaxClients
) then
3703 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_HOST
]);
3707 g_Net_Slist_Set(NetSlistIP
, NetSlistPort
);
3709 // Çàãðóçêà è çàïóñê êàðòû:
3710 if not g_Game_StartMap(Map
, True) then
3712 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [Map
]));
3716 // Íåò òî÷åê ïîÿâëåíèÿ:
3717 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) +
3718 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) +
3719 g_Map_GetPointCount(RESPAWNPOINT_DM
) +
3720 g_Map_GetPointCount(RESPAWNPOINT_RED
)+
3721 g_Map_GetPointCount(RESPAWNPOINT_BLUE
)) < 1 then
3723 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3727 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3730 NetState
:= NET_STATE_GAME
;
3733 procedure g_Game_StartClient(Addr
: String; Port
: Word; PW
: String);
3748 e_WriteLog('Starting net game (client)...', MSG_NOTIFY
);
3749 e_WriteLog('NET: Trying to connect to ' + Addr
+ ':' + IntToStr(Port
) + '...', MSG_NOTIFY
);
3751 g_Game_ClearLoading();
3754 gGameSettings
.GameType
:= GT_CLIENT
;
3756 gCoopTotalMonstersKilled
:= 0;
3757 gCoopTotalSecretsFound
:= 0;
3758 gCoopTotalMonsters
:= 0;
3759 gCoopTotalSecrets
:= 0;
3763 g_Game_ExecuteEvent('ongamestart');
3765 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3766 g_Game_SetupScreenSize();
3768 NetState
:= NET_STATE_AUTH
;
3770 g_Game_SetLoadingText(_lc
[I_LOAD_CONNECT
], 0, False);
3772 if not g_Net_Connect(Addr
, Port
) then
3774 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3775 NetState
:= NET_STATE_NONE
;
3779 g_Game_SetLoadingText(_lc
[I_LOAD_SEND_INFO
], 0, False);
3781 g_Game_SetLoadingText(_lc
[I_LOAD_WAIT_INFO
], 0, False);
3786 while (enet_host_service(NetHost
, @NetEvent
, 0) > 0) do
3788 if (NetEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
) then
3790 Ptr
:= NetEvent
.packet
^.data
;
3791 if not InMsg
.Init(Ptr
, NetEvent
.packet
^.dataLength
, True) then
3794 MID
:= InMsg
.ReadByte();
3796 if (MID
= NET_MSG_INFO
) and (State
= 0) then
3798 NetMyID
:= InMsg
.ReadByte();
3799 NetPlrUID1
:= InMsg
.ReadWord();
3801 WadName
:= InMsg
.ReadString();
3802 Map
:= InMsg
.ReadString();
3804 gWADHash
:= InMsg
.ReadMD5();
3806 gGameSettings
.GameMode
:= InMsg
.ReadByte();
3807 gSwitchGameMode
:= gGameSettings
.GameMode
;
3808 gGameSettings
.GoalLimit
:= InMsg
.ReadWord();
3809 gGameSettings
.TimeLimit
:= InMsg
.ReadWord();
3810 gGameSettings
.MaxLives
:= InMsg
.ReadByte();
3811 gGameSettings
.Options
:= InMsg
.ReadLongWord();
3812 T
:= InMsg
.ReadLongWord();
3814 newResPath
:= g_Res_SearchSameWAD(MapsDir
, WadName
, gWADHash
);
3815 if newResPath
= '' then
3817 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
3818 newResPath
:= g_Res_DownloadWAD(WadName
);
3819 if newResPath
= '' then
3821 g_FatalError(_lc
[I_NET_ERR_HASH
]);
3822 enet_packet_destroy(NetEvent
.packet
);
3823 NetState
:= NET_STATE_NONE
;
3827 newResPath
:= ExtractRelativePath(MapsDir
, newResPath
);
3829 gPlayer1
:= g_Player_Get(g_Player_Create(gPlayer1Settings
.Model
,
3830 gPlayer1Settings
.Color
,
3831 gPlayer1Settings
.Team
, False));
3833 if gPlayer1
= nil then
3835 g_FatalError(Format(_lc
[I_GAME_ERROR_PLAYER_CREATE
], [1]));
3837 enet_packet_destroy(NetEvent
.packet
);
3838 NetState
:= NET_STATE_NONE
;
3842 gPlayer1
.Name
:= gPlayer1Settings
.Name
;
3843 gPlayer1
.UID
:= NetPlrUID1
;
3844 gPlayer1
.Reset(True);
3846 if not g_Game_StartMap(newResPath
+ ':\' + Map
, True) then
3848 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [WadName
+ ':\' + Map
]));
3850 enet_packet_destroy(NetEvent
.packet
);
3851 NetState
:= NET_STATE_NONE
;
3859 enet_packet_destroy(NetEvent
.packet
);
3863 enet_packet_destroy(NetEvent
.packet
);
3866 if (NetEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
) then
3869 if (NetEvent
.data
<= NET_DISC_MAX
) then
3870 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CONN
] + ' ' +
3871 _lc
[TStrings_Locale(Cardinal(I_NET_DISC_NONE
) + NetEvent
.data
)], True);
3881 if e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(IK_SPACE
) then
3890 g_FatalError(_lc
[I_NET_MSG
] + _lc
[I_NET_ERR_CONN
]);
3891 NetState
:= NET_STATE_NONE
;
3895 gLMSRespawn
:= LMS_RESPAWN_NONE
;
3896 gLMSRespawnTime
:= 0;
3899 NetState
:= NET_STATE_GAME
;
3900 MC_SEND_FullStateRequest
;
3901 e_WriteLog('NET: Connection successful.', MSG_NOTIFY
);
3904 procedure g_Game_SaveOptions();
3906 g_Options_Write_Video(GameDir
+'/'+CONFIG_FILENAME
);
3909 procedure g_Game_ChangeMap(MapPath
: String);
3913 g_Game_ClearLoading();
3915 Force
:= gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
];
3916 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3917 if gExitByTrigger
then
3920 gExitByTrigger
:= False;
3922 if not g_Game_StartMap(MapPath
, Force
) then
3923 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_LOAD
], [MapPath
]));
3926 procedure g_Game_Restart();
3930 if g_Game_IsClient
then
3932 map
:= g_ExtractFileName(gMapInfo
.Map
);
3936 g_Game_ClearLoading();
3937 g_Game_StartMap(Map
, True);
3940 function g_Game_StartMap(Map
: String; Force
: Boolean = False): Boolean;
3942 NewWAD
, ResName
: String;
3946 g_Player_RemoveAllCorpses();
3948 if (not g_Game_IsClient
) and
3949 (gSwitchGameMode
<> gGameSettings
.GameMode
) and
3950 (gGameSettings
.GameMode
<> GM_SINGLE
) then
3952 if gSwitchGameMode
= GM_CTF
then
3953 gGameSettings
.MaxLives
:= 0;
3954 gGameSettings
.GameMode
:= gSwitchGameMode
;
3957 gSwitchGameMode
:= gGameSettings
.GameMode
;
3959 g_Player_ResetTeams();
3961 if Pos(':\', Map
) > 0 then
3963 NewWAD
:= g_ExtractWadName(Map
);
3964 ResName
:= g_ExtractFileName(Map
);
3965 if g_Game_IsServer
then
3967 gWADHash
:= MD5File(MapsDir
+ NewWAD
);
3968 g_Game_LoadWAD(NewWAD
);
3970 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3971 g_Game_ClientWAD(NewWAD
, gWADHash
);
3975 Result
:= g_Map_Load(MapsDir
+ gGameSettings
.WAD
+ ':\' + ResName
);
3978 g_Player_ResetAll(Force
or gLastMap
, gGameSettings
.GameType
= GT_SINGLE
);
3980 gState
:= STATE_NONE
;
3981 g_ActiveWindow
:= nil;
3987 if gGameSettings
.GameMode
= GM_CTF
then
3989 g_Map_ResetFlag(FLAG_RED
);
3990 g_Map_ResetFlag(FLAG_BLUE
);
3991 // CTF, à ôëàãîâ íåò:
3992 if not g_Map_HaveFlagPoints() then
3993 g_SimpleError(_lc
[I_GAME_ERROR_CTF
]);
3998 gState
:= STATE_MENU
;
4005 NetTimeToUpdate
:= 1;
4006 NetTimeToReliable
:= 0;
4007 NetTimeToMaster
:= NetMasterRate
;
4008 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4009 gLMSRespawnTime
:= 0;
4010 gMissionFailed
:= False;
4013 gCoopMonstersKilled
:= 0;
4014 gCoopSecretsFound
:= 0;
4016 gVoteInProgress
:= False;
4017 gVotePassed
:= False;
4023 if not gGameOn
then Exit
;
4025 g_Game_SpectateCenterView();
4027 if (gGameSettings
.MaxLives
> 0) and (gGameSettings
.WarmupTime
> 0) then
4029 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4030 gLMSRespawnTime
:= gTime
+ gGameSettings
.WarmupTime
*1000;
4031 gLMSSoftSpawn
:= True;
4032 if NetMode
= NET_SERVER
then
4033 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
4035 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
4038 if NetMode
= NET_SERVER
then
4040 MH_SEND_GameEvent(NET_EV_MAPSTART
, gGameSettings
.GameMode
, Map
);
4043 if NetUseMaster
then
4045 if (NetMHost
= nil) or (NetMPeer
= nil) then
4046 if not g_Net_Slist_Connect
then
4047 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4052 if NetClients
<> nil then
4053 for I
:= 0 to High(NetClients
) do
4054 if NetClients
[I
].Used
then
4056 NetClients
[I
].Voted
:= False;
4057 if NetClients
[I
].RequestedFullUpdate
then
4059 MH_SEND_Everything((NetClients
[I
].State
= NET_STATE_AUTH
), I
);
4060 NetClients
[I
].RequestedFullUpdate
:= False;
4064 g_Net_UnbanNonPermHosts();
4069 gCoopTotalMonstersKilled
:= 0;
4070 gCoopTotalSecretsFound
:= 0;
4071 gCoopTotalMonsters
:= 0;
4072 gCoopTotalSecrets
:= 0;
4076 g_Game_ExecuteEvent('onmapstart');
4079 procedure SetFirstLevel();
4083 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4084 if MapList
= nil then
4087 SortSArray(MapList
);
4088 gNextMap
:= MapList
[Low(MapList
)];
4093 procedure g_Game_ExitLevel(Map
: Char16
);
4097 gCoopTotalMonstersKilled
:= gCoopTotalMonstersKilled
+ gCoopMonstersKilled
;
4098 gCoopTotalSecretsFound
:= gCoopTotalSecretsFound
+ gCoopSecretsFound
;
4099 gCoopTotalMonsters
:= gCoopTotalMonsters
+ gTotalMonsters
;
4100 gCoopTotalSecrets
:= gCoopTotalSecrets
+ gSecretsCount
;
4102 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4103 if gGameSettings
.GameType
= GT_SINGLE
then
4104 gExit
:= EXIT_ENDLEVELSINGLE
4105 else // Âûøëè â âûõîä â Ñâîåé èãðå
4107 gExit
:= EXIT_ENDLEVELCUSTOM
;
4108 if gGameSettings
.GameMode
= GM_COOP
then
4109 g_Player_RememberAll
;
4111 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4114 if gGameSettings
.GameMode
= GM_COOP
then
4117 gStatsPressed
:= True;
4118 gNextMap
:= 'MAP01';
4120 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + gNextMap
) then
4123 if g_Game_IsNet
then
4125 MH_SEND_GameStats();
4126 MH_SEND_CoopStats();
4132 procedure g_Game_RestartLevel();
4136 if gGameSettings
.GameMode
= GM_SINGLE
then
4141 gExit
:= EXIT_ENDLEVELCUSTOM
;
4142 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4146 procedure g_Game_ClientWAD(NewWAD
: String; WHash
: TMD5Digest
);
4150 if LowerCase(NewWAD
) = LowerCase(gGameSettings
.WAD
) then
4152 if not g_Game_IsClient
then
4154 gWAD
:= g_Res_SearchSameWAD(MapsDir
, ExtractFileName(NewWAD
), WHash
);
4157 g_Game_SetLoadingText(_lc
[I_LOAD_DL_RES
], 0, False);
4158 gWAD
:= g_Res_DownloadWAD(ExtractFileName(NewWAD
));
4162 g_FatalError(Format(_lc
[I_GAME_ERROR_MAP_WAD
], [ExtractFileName(NewWAD
)]));
4166 NewWAD
:= ExtractRelativePath(MapsDir
, gWAD
);
4167 g_Game_LoadWAD(NewWAD
);
4170 procedure g_Game_RestartRound(NoMapRestart
: Boolean = False);
4172 i
, n
, nb
, nr
: Integer;
4174 function monRespawn (mon
: TMonster
): Boolean;
4176 result
:= false; // don't stop
4177 if not mon
.FNoRespawn
then mon
.Respawn();
4181 if not g_Game_IsServer
then Exit
;
4182 if gLMSRespawn
= LMS_RESPAWN_NONE
then Exit
;
4183 gLMSRespawn
:= LMS_RESPAWN_NONE
;
4184 gLMSRespawnTime
:= 0;
4187 if (gGameSettings
.GameMode
= GM_COOP
) and not NoMapRestart
then
4189 gMissionFailed
:= True;
4190 g_Game_RestartLevel
;
4194 n
:= 0; nb
:= 0; nr
:= 0;
4195 for i
:= Low(gPlayers
) to High(gPlayers
) do
4196 if (gPlayers
[i
] <> nil) and
4197 ((not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
or
4198 (gPlayers
[i
] is TBot
)) then
4201 if gPlayers
[i
].Team
= TEAM_RED
then Inc(nr
)
4202 else if gPlayers
[i
].Team
= TEAM_BLUE
then Inc(nb
)
4205 if (n
< 2) or ((gGameSettings
.GameMode
= GM_TDM
) and ((nr
= 0) or (nb
= 0))) then
4207 // wait a second until the fuckers finally decide to join
4208 gLMSRespawn
:= LMS_RESPAWN_WARMUP
;
4209 gLMSRespawnTime
:= gTime
+ 1000;
4210 gLMSSoftSpawn
:= NoMapRestart
;
4214 g_Player_RemoveAllCorpses
;
4215 g_Game_Message(_lc
[I_MESSAGE_LMS_START
], 144);
4216 if g_Game_IsNet
then
4217 MH_SEND_GameEvent(NET_EV_LMS_START
);
4219 for i
:= Low(gPlayers
) to High(gPlayers
) do
4221 if gPlayers
[i
] = nil then continue
;
4222 if gPlayers
[i
] is TBot
then gPlayers
[i
].FWantsInGame
:= True;
4223 // don't touch normal spectators
4224 if gPlayers
[i
].FSpectator
and not gPlayers
[i
].FWantsInGame
then
4226 gPlayers
[i
].FNoRespawn
:= True;
4227 gPlayers
[i
].Lives
:= 0;
4228 if g_Game_IsNet
then
4229 MH_SEND_PlayerStats(gPlayers
[I
].UID
);
4232 gPlayers
[i
].FNoRespawn
:= False;
4233 gPlayers
[i
].Lives
:= gGameSettings
.MaxLives
;
4234 gPlayers
[i
].Respawn(False, True);
4235 if gGameSettings
.GameMode
= GM_COOP
then
4237 gPlayers
[i
].Frags
:= 0;
4238 gPlayers
[i
].RecallState
;
4240 if (gPlayer1
= nil) and (gLMSPID1
> 0) then
4241 gPlayer1
:= g_Player_Get(gLMSPID1
);
4242 if (gPlayer2
= nil) and (gLMSPID2
> 0) then
4243 gPlayer2
:= g_Player_Get(gLMSPID2
);
4246 g_Items_RestartRound();
4249 g_Mons_ForEach(monRespawn
);
4251 gLMSSoftSpawn
:= False;
4254 function g_Game_GetFirstMap(WAD
: String): String;
4258 MapList
:= g_Map_GetMapsList(WAD
);
4259 if MapList
= nil then
4262 SortSArray(MapList
);
4263 Result
:= MapList
[Low(MapList
)];
4265 if not g_Map_Exist(WAD
+ ':\' + Result
) then
4271 function g_Game_GetNextMap(): String;
4278 MapList
:= g_Map_GetMapsList(MapsDir
+ gGameSettings
.WAD
);
4279 if MapList
= nil then
4282 Map
:= g_ExtractFileName(gMapInfo
.Map
);
4284 SortSArray(MapList
);
4286 for I
:= Low(MapList
) to High(MapList
) do
4287 if Map
= MapList
[I
] then
4293 if MapIndex
<> -255 then
4295 if MapIndex
= High(MapList
) then
4296 Result
:= MapList
[Low(MapList
)]
4298 Result
:= MapList
[MapIndex
+ 1];
4300 if not g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + Result
) then Result
:= Map
;
4306 procedure g_Game_NextLevel();
4308 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
, GM_COOP
] then
4309 gExit
:= EXIT_ENDLEVELCUSTOM
4312 gExit
:= EXIT_ENDLEVELSINGLE
;
4316 if gNextMap
<> '' then Exit
;
4317 gNextMap
:= g_Game_GetNextMap();
4320 function g_Game_IsTestMap(): Boolean;
4322 result
:= StrEquCI1251(TEST_MAP_NAME
, g_ExtractFileName(gMapInfo
.Map
));
4325 procedure g_Game_DeleteTestMap();
4336 a
:= Pos('.wad:\', gMapToDelete
);
4340 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4341 WadName
:= Copy(gMapToDelete
, 1, a
+ 3);
4342 Delete(gMapToDelete
, 1, a
+ 5);
4343 gMapToDelete
:= UpperCase(gMapToDelete
);
4345 CopyMemory(@MapName
[0], @gMapToDelete
[1], Min(16, Length(gMapToDelete
)));
4348 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4349 if MapName <> TEST_MAP_NAME then
4352 if not gTempDelete then
4354 time := g_GetFileTime(WadName);
4355 WAD := TWADFile.Create();
4358 if not WAD.ReadFile(WadName) then
4359 begin // Íåò òàêîãî WAD-ôàéëà
4364 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4366 MapList := WAD.GetResourcesList('');
4368 if MapList <> nil then
4369 for a := 0 to High(MapList) do
4370 if MapList[a] = MapName then
4372 // Óäàëÿåì è ñîõðàíÿåì:
4373 WAD.RemoveResource('', MapName);
4374 WAD.SaveTo(WadName);
4379 g_SetFileTime(WadName, time);
4382 if gTempDelete
then DeleteFile(WadName
);
4385 procedure GameCVars(P
: SArray
);
4388 stat
: TPlayerStatArray
;
4393 cmd
:= LowerCase(P
[0]);
4394 if cmd
= 'r_showfps' then
4396 if (Length(P
) > 1) and
4397 ((P
[1] = '1') or (P
[1] = '0')) then
4398 gShowFPS
:= (P
[1][1] = '1');
4401 g_Console_Add(_lc
[I_MSG_SHOW_FPS_ON
])
4403 g_Console_Add(_lc
[I_MSG_SHOW_FPS_OFF
]);
4405 else if (cmd
= 'g_friendlyfire') and not g_Game_IsClient
then
4407 with gGameSettings
do
4409 if (Length(P
) > 1) and
4410 ((P
[1] = '1') or (P
[1] = '0')) then
4412 if (P
[1][1] = '1') then
4413 Options
:= Options
or GAME_OPTION_TEAMDAMAGE
4415 Options
:= Options
and (not GAME_OPTION_TEAMDAMAGE
);
4418 if (LongBool(Options
and GAME_OPTION_TEAMDAMAGE
)) then
4419 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_ON
])
4421 g_Console_Add(_lc
[I_MSG_FRIENDLY_FIRE_OFF
]);
4423 if g_Game_IsNet
then MH_SEND_GameSettings
;
4426 else if (cmd
= 'g_weaponstay') and not g_Game_IsClient
then
4428 with gGameSettings
do
4430 if (Length(P
) > 1) and
4431 ((P
[1] = '1') or (P
[1] = '0')) then
4433 if (P
[1][1] = '1') then
4434 Options
:= Options
or GAME_OPTION_WEAPONSTAY
4436 Options
:= Options
and (not GAME_OPTION_WEAPONSTAY
);
4439 if (LongBool(Options
and GAME_OPTION_WEAPONSTAY
)) then
4440 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_ON
])
4442 g_Console_Add(_lc
[I_MSG_WEAPONSTAY_OFF
]);
4444 if g_Game_IsNet
then MH_SEND_GameSettings
;
4447 else if cmd
= 'g_gamemode' then
4449 a
:= g_Game_TextToMode(P
[1]);
4450 if a
= GM_SINGLE
then a
:= GM_COOP
;
4451 if (Length(P
) > 1) and (a
<> GM_NONE
) and (not g_Game_IsClient
) then
4453 gSwitchGameMode
:= a
;
4454 if (gGameOn
and (gGameSettings
.GameMode
= GM_SINGLE
)) or
4455 (gState
= STATE_INTERSINGLE
) then
4456 gSwitchGameMode
:= GM_SINGLE
;
4458 gGameSettings
.GameMode
:= gSwitchGameMode
;
4460 if gSwitchGameMode
= gGameSettings
.GameMode
then
4461 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CURRENT
],
4462 [g_Game_ModeToText(gGameSettings
.GameMode
)]))
4464 g_Console_Add(Format(_lc
[I_MSG_GAMEMODE_CHANGE
],
4465 [g_Game_ModeToText(gGameSettings
.GameMode
),
4466 g_Game_ModeToText(gSwitchGameMode
)]));
4468 else if (cmd
= 'g_allow_exit') and not g_Game_IsClient
then
4470 with gGameSettings
do
4472 if (Length(P
) > 1) and
4473 ((P
[1] = '1') or (P
[1] = '0')) then
4475 if (P
[1][1] = '1') then
4476 Options
:= Options
or GAME_OPTION_ALLOWEXIT
4478 Options
:= Options
and (not GAME_OPTION_ALLOWEXIT
);
4481 if (LongBool(Options
and GAME_OPTION_ALLOWEXIT
)) then
4482 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_ON
])
4484 g_Console_Add(_lc
[I_MSG_ALLOWEXIT_OFF
]);
4485 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4487 if g_Game_IsNet
then MH_SEND_GameSettings
;
4490 else if (cmd
= 'g_allow_monsters') and not g_Game_IsClient
then
4492 with gGameSettings
do
4494 if (Length(P
) > 1) and
4495 ((P
[1] = '1') or (P
[1] = '0')) then
4497 if (P
[1][1] = '1') then
4498 Options
:= Options
or GAME_OPTION_MONSTERS
4500 Options
:= Options
and (not GAME_OPTION_MONSTERS
);
4503 if (LongBool(Options
and GAME_OPTION_MONSTERS
)) then
4504 g_Console_Add(_lc
[I_MSG_ALLOWMON_ON
])
4506 g_Console_Add(_lc
[I_MSG_ALLOWMON_OFF
]);
4507 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4509 if g_Game_IsNet
then MH_SEND_GameSettings
;
4512 else if (cmd
= 'g_bot_vsplayers') and not g_Game_IsClient
then
4514 with gGameSettings
do
4516 if (Length(P
) > 1) and
4517 ((P
[1] = '1') or (P
[1] = '0')) then
4519 if (P
[1][1] = '1') then
4520 Options
:= Options
or GAME_OPTION_BOTVSPLAYER
4522 Options
:= Options
and (not GAME_OPTION_BOTVSPLAYER
);
4525 if (LongBool(Options
and GAME_OPTION_BOTVSPLAYER
)) then
4526 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_ON
])
4528 g_Console_Add(_lc
[I_MSG_BOTSVSPLAYERS_OFF
]);
4530 if g_Game_IsNet
then MH_SEND_GameSettings
;
4533 else if (cmd
= 'g_bot_vsmonsters') and not g_Game_IsClient
then
4535 with gGameSettings
do
4537 if (Length(P
) > 1) and
4538 ((P
[1] = '1') or (P
[1] = '0')) then
4540 if (P
[1][1] = '1') then
4541 Options
:= Options
or GAME_OPTION_BOTVSMONSTER
4543 Options
:= Options
and (not GAME_OPTION_BOTVSMONSTER
);
4546 if (LongBool(Options
and GAME_OPTION_BOTVSMONSTER
)) then
4547 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_ON
])
4549 g_Console_Add(_lc
[I_MSG_BOTSVSMONSTERS_OFF
]);
4551 if g_Game_IsNet
then MH_SEND_GameSettings
;
4554 else if (cmd
= 'g_warmuptime') and not g_Game_IsClient
then
4556 if Length(P
) > 1 then
4558 if StrToIntDef(P
[1], gGameSettings
.WarmupTime
) = 0 then
4559 gGameSettings
.WarmupTime
:= 30
4561 gGameSettings
.WarmupTime
:= StrToIntDef(P
[1], gGameSettings
.WarmupTime
);
4564 g_Console_Add(Format(_lc
[I_MSG_WARMUP
],
4565 [gGameSettings
.WarmupTime
]));
4566 g_Console_Add(_lc
[I_MSG_ONMAPCHANGE
]);
4568 else if cmd
= 'net_interp' then
4570 if (Length(P
) > 1) then
4571 NetInterpLevel
:= StrToIntDef(P
[1], NetInterpLevel
);
4573 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel
));
4574 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4575 config
.WriteInt('Client', 'InterpolationSteps', NetInterpLevel
);
4576 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4579 else if cmd
= 'net_forceplayerupdate' then
4581 if (Length(P
) > 1) and
4582 ((P
[1] = '1') or (P
[1] = '0')) then
4583 NetForcePlayerUpdate
:= (P
[1][1] = '1');
4585 if NetForcePlayerUpdate
then
4586 g_Console_Add('net_forceplayerupdate = 1')
4588 g_Console_Add('net_forceplayerupdate = 0');
4589 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4590 config
.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate
);
4591 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4594 else if cmd
= 'net_predictself' then
4596 if (Length(P
) > 1) and
4597 ((P
[1] = '1') or (P
[1] = '0')) then
4598 NetPredictSelf
:= (P
[1][1] = '1');
4600 if NetPredictSelf
then
4601 g_Console_Add('net_predictself = 1')
4603 g_Console_Add('net_predictself = 0');
4604 config
:= TConfig
.CreateFile(GameDir
+'/'+CONFIG_FILENAME
);
4605 config
.WriteBool('Client', 'PredictSelf', NetPredictSelf
);
4606 config
.SaveFile(GameDir
+'/'+CONFIG_FILENAME
);
4609 else if cmd
= 'sv_name' then
4611 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4613 NetServerName
:= P
[1];
4614 if Length(NetServerName
) > 64 then
4615 SetLength(NetServerName
, 64);
4616 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4620 g_Console_Add(cmd
+ ' = "' + NetServerName
+ '"');
4622 else if cmd
= 'sv_passwd' then
4624 if (Length(P
) > 1) and (Length(P
[1]) > 0) then
4626 NetPassword
:= P
[1];
4627 if Length(NetPassword
) > 24 then
4628 SetLength(NetPassword
, 24);
4629 if g_Game_IsServer
and g_Game_IsNet
and NetUseMaster
then
4633 g_Console_Add(cmd
+ ' = "' + AnsiLowerCase(NetPassword
) + '"');
4635 else if cmd
= 'sv_maxplrs' then
4637 if (Length(P
) > 1) then
4639 NetMaxClients
:= Min(Max(StrToIntDef(P
[1], NetMaxClients
), 1), NET_MAXCLIENTS
);
4640 if g_Game_IsServer
and g_Game_IsNet
then
4643 for a
:= 0 to High(NetClients
) do
4644 if NetClients
[a
].Used
then
4647 if b
> NetMaxClients
then
4649 s
:= g_Player_Get(NetClients
[a
].Player
).Name
;
4650 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_FULL
);
4651 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
4652 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
4655 if NetUseMaster
then
4660 g_Console_Add(cmd
+ ' = ' + IntToStr(NetMaxClients
));
4662 else if cmd
= 'sv_public' then
4664 if (Length(P
) > 1) then
4666 NetUseMaster
:= StrToIntDef(P
[1], Byte(NetUseMaster
)) > 0;
4667 if g_Game_IsServer
and g_Game_IsNet
then
4668 if NetUseMaster
then
4670 if NetMPeer
= nil then
4671 if not g_Net_Slist_Connect() then
4672 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
]);
4673 g_Net_Slist_Update();
4676 if NetMPeer
<> nil then
4677 g_Net_Slist_Disconnect();
4680 g_Console_Add(cmd
+ ' = ' + IntToStr(Byte(NetUseMaster
)));
4682 else if cmd
= 'sv_intertime' then
4684 if (Length(P
) > 1) then
4685 gDefInterTime
:= Min(Max(StrToIntDef(P
[1], gDefInterTime
), -1), 120);
4687 g_Console_Add(cmd
+ ' = ' + IntToStr(gDefInterTime
));
4689 else if cmd
= 'p1_name' then
4691 if (Length(P
) > 1) and gGameOn
then
4693 if g_Game_IsClient
then
4695 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4696 MC_SEND_PlayerSettings
;
4699 if gPlayer1
<> nil then
4701 gPlayer1
.Name
:= b_Text_Unformat(P
[1]);
4702 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4705 gPlayer1Settings
.Name
:= b_Text_Unformat(P
[1]);
4708 else if cmd
= 'p2_name' then
4710 if (Length(P
) > 1) and gGameOn
then
4712 if g_Game_IsClient
then
4714 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4715 MC_SEND_PlayerSettings
;
4718 if gPlayer2
<> nil then
4720 gPlayer2
.Name
:= b_Text_Unformat(P
[1]);
4721 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4724 gPlayer2Settings
.Name
:= b_Text_Unformat(P
[1]);
4727 else if cmd
= 'p1_color' then
4729 if Length(P
) > 3 then
4730 if g_Game_IsClient
then
4732 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4733 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4734 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4735 MC_SEND_PlayerSettings
;
4738 if gPlayer1
<> nil then
4740 gPlayer1
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4741 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4742 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4743 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer1
.UID
);
4746 gPlayer1Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4747 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4748 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4750 else if (cmd
= 'p2_color') and not g_Game_IsNet
then
4752 if Length(P
) > 3 then
4753 if g_Game_IsClient
then
4755 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4756 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4757 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4758 MC_SEND_PlayerSettings
;
4761 if gPlayer2
<> nil then
4763 gPlayer2
.Model
.SetColor(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4764 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4765 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4766 if g_Game_IsNet
then MH_SEND_PlayerSettings(gPlayer2
.UID
);
4769 gPlayer2Settings
.Color
:= _RGB(EnsureRange(StrToIntDef(P
[1], 0), 0, 255),
4770 EnsureRange(StrToIntDef(P
[2], 0), 0, 255),
4771 EnsureRange(StrToIntDef(P
[3], 0), 0, 255));
4773 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4775 if cmd
= 'r_showtime' then
4777 if (Length(P
) > 1) and
4778 ((P
[1] = '1') or (P
[1] = '0')) then
4779 gShowTime
:= (P
[1][1] = '1');
4782 g_Console_Add(_lc
[I_MSG_TIME_ON
])
4784 g_Console_Add(_lc
[I_MSG_TIME_OFF
]);
4786 else if cmd
= 'r_showscore' then
4788 if (Length(P
) > 1) and
4789 ((P
[1] = '1') or (P
[1] = '0')) then
4790 gShowGoals
:= (P
[1][1] = '1');
4793 g_Console_Add(_lc
[I_MSG_SCORE_ON
])
4795 g_Console_Add(_lc
[I_MSG_SCORE_OFF
]);
4797 else if cmd
= 'r_showstat' then
4799 if (Length(P
) > 1) and
4800 ((P
[1] = '1') or (P
[1] = '0')) then
4801 gShowStat
:= (P
[1][1] = '1');
4804 g_Console_Add(_lc
[I_MSG_STATS_ON
])
4806 g_Console_Add(_lc
[I_MSG_STATS_OFF
]);
4808 else if cmd
= 'r_showkillmsg' then
4810 if (Length(P
) > 1) and
4811 ((P
[1] = '1') or (P
[1] = '0')) then
4812 gShowKillMsg
:= (P
[1][1] = '1');
4814 if gShowKillMsg
then
4815 g_Console_Add(_lc
[I_MSG_KILL_MSGS_ON
])
4817 g_Console_Add(_lc
[I_MSG_KILL_MSGS_OFF
]);
4819 else if cmd
= 'r_showlives' then
4821 if (Length(P
) > 1) and
4822 ((P
[1] = '1') or (P
[1] = '0')) then
4823 gShowLives
:= (P
[1][1] = '1');
4826 g_Console_Add(_lc
[I_MSG_LIVES_ON
])
4828 g_Console_Add(_lc
[I_MSG_LIVES_OFF
]);
4830 else if cmd
= 'r_showspect' then
4832 if (Length(P
) > 1) and
4833 ((P
[1] = '1') or (P
[1] = '0')) then
4834 gSpectHUD
:= (P
[1][1] = '1');
4837 g_Console_Add(_lc
[I_MSG_SPECT_HUD_ON
])
4839 g_Console_Add(_lc
[I_MSG_SPECT_HUD_OFF
]);
4841 else if cmd
= 'r_showping' then
4843 if (Length(P
) > 1) and
4844 ((P
[1] = '1') or (P
[1] = '0')) then
4845 gShowPing
:= (P
[1][1] = '1');
4848 g_Console_Add(_lc
[I_MSG_PING_ON
])
4850 g_Console_Add(_lc
[I_MSG_PING_OFF
]);
4852 else if (cmd
= 'g_scorelimit') and not g_Game_IsClient
then
4854 if Length(P
) > 1 then
4856 if StrToIntDef(P
[1], gGameSettings
.GoalLimit
) = 0 then
4857 gGameSettings
.GoalLimit
:= 0
4862 if gGameSettings
.GameMode
= GM_DM
then
4864 stat
:= g_Player_GetStats();
4866 for a
:= 0 to High(stat
) do
4867 if stat
[a
].Frags
> b
then
4871 b
:= Max(gTeamStat
[TEAM_RED
].Goals
, gTeamStat
[TEAM_BLUE
].Goals
);
4873 gGameSettings
.GoalLimit
:= Max(StrToIntDef(P
[1], gGameSettings
.GoalLimit
), b
);
4876 if g_Game_IsNet
then MH_SEND_GameSettings
;
4879 g_Console_Add(Format(_lc
[I_MSG_SCORE_LIMIT
], [gGameSettings
.GoalLimit
]));
4881 else if (cmd
= 'g_timelimit') and not g_Game_IsClient
then
4883 if (Length(P
) > 1) and (StrToIntDef(P
[1], -1) >= 0) then
4884 gGameSettings
.TimeLimit
:= StrToIntDef(P
[1], -1);
4886 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
4887 [gGameSettings
.TimeLimit
div 3600,
4888 (gGameSettings
.TimeLimit
div 60) mod 60,
4889 gGameSettings
.TimeLimit
mod 60]));
4890 if g_Game_IsNet
then MH_SEND_GameSettings
;
4892 else if (cmd
= 'g_maxlives') and not g_Game_IsClient
then
4894 if Length(P
) > 1 then
4896 if StrToIntDef(P
[1], gGameSettings
.MaxLives
) = 0 then
4897 gGameSettings
.MaxLives
:= 0
4901 stat
:= g_Player_GetStats();
4903 for a
:= 0 to High(stat
) do
4904 if stat
[a
].Lives
> b
then
4906 gGameSettings
.MaxLives
:=
4907 Max(StrToIntDef(P
[1], gGameSettings
.MaxLives
), b
);
4911 g_Console_Add(Format(_lc
[I_MSG_LIVES
],
4912 [gGameSettings
.MaxLives
]));
4913 if g_Game_IsNet
then MH_SEND_GameSettings
;
4918 // profiler console commands
4919 procedure ProfilerCommands (P
: SArray
);
4923 function getBool (idx
: Integer): Integer;
4925 if (idx
< 0) or (idx
> High(P
)) then begin result
:= -1; exit
; end;
4927 if (P
[idx
] = '1') or (P
[idx
] = 'on') or (P
[idx
] = 'true') or (P
[idx
] = 'tan') then result
:= 1;
4931 //if not gDebugMode then exit;
4932 cmd
:= LowerCase(P
[0]);
4934 if cmd
= 'pf_draw_frame' then
4936 g_profile_frame_draw
:= not g_profile_frame_draw
;
4940 if cmd
= 'pf_update_frame' then
4942 g_profile_frame_update
:= not g_profile_frame_update
;
4946 if cmd
= 'pf_coldet' then
4948 g_profile_collision
:= not g_profile_collision
;
4952 if cmd
= 'r_sq_draw' then
4956 0: gdbg_map_use_accel_render
:= false;
4957 1: gdbg_map_use_accel_render
:= true;
4959 if gdbg_map_use_accel_render
then g_Console_Add('accelerated rendering: tan') else g_Console_Add('accelerated rendering: ona');
4963 if cmd
= 'dbg_sq_coldet' then
4967 0: gdbg_map_use_accel_coldet
:= false;
4968 1: gdbg_map_use_accel_coldet
:= true;
4970 if gdbg_map_use_accel_coldet
then g_Console_Add('accelerated coldet: tan') else g_Console_Add('accelerated coldet: ona');
4974 if (cmd
= 'sq_use_grid') or (cmd
= 'sq_use_tree') then
4976 gdbg_map_use_tree_coldet
:= (cmd
= 'sq_use_tree');
4977 if gdbg_map_use_tree_coldet
then g_Console_Add('coldet acceleration: tree') else g_Console_Add('coldet acceleration: grid');
4981 if (cmd
= 'r_sq_use_grid') or (cmd
= 'r_sq_use_tree') then
4983 gdbg_map_use_tree_draw
:= (cmd
= 'r_sq_use_tree');
4984 if gdbg_map_use_tree_draw
then g_Console_Add('render acceleration: tree') else g_Console_Add('render acceleration: grid');
4988 if (cmd
= 't_dump_node_queries') then
4992 0: gdbg_map_dump_coldet_tree_queries
:= false;
4993 1: gdbg_map_dump_coldet_tree_queries
:= true;
4995 if gdbg_map_dump_coldet_tree_queries
then g_Console_Add('grid coldet tree queries: tan') else g_Console_Add('grid coldet tree queries: ona');
4999 if (cmd
= 'mon_sq_enabled') then
5003 0: gmon_debug_use_sqaccel
:= false;
5004 1: gmon_debug_use_sqaccel
:= true;
5006 if gmon_debug_use_sqaccel
then g_Console_Add('accelerated monster coldet: tan') else g_Console_Add('accelerated monster coldet: ona');
5010 if (cmd
= 'wtrace_sq_enabled') then
5014 0: gwep_debug_fast_trace
:= false;
5015 1: gwep_debug_fast_trace
:= true;
5017 if gwep_debug_fast_trace
then g_Console_Add('accelerated weapon hitscan: tan') else g_Console_Add('accelerated weapon hitscan: ona');
5022 procedure DebugCommands(P
: SArray
);
5029 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5032 cmd
:= LowerCase(P
[0]);
5033 if cmd
= 'd_window' then
5035 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX
, gWinPosY
]));
5036 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX
, gWinRealPosY
]));
5037 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth
, gScreenHeight
]));
5038 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX
, gWinSizeY
]));
5039 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX
, gWinFrameY
, gWinCaption
]));
5041 else if cmd
= 'd_sounds' then
5043 if (Length(P
) > 1) and
5044 ((P
[1] = '1') or (P
[1] = '0')) then
5045 g_Debug_Sounds
:= (P
[1][1] = '1');
5047 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds
)]));
5049 else if cmd
= 'd_frames' then
5051 if (Length(P
) > 1) and
5052 ((P
[1] = '1') or (P
[1] = '0')) then
5053 g_Debug_Frames
:= (P
[1][1] = '1');
5055 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames
)]));
5057 else if cmd
= 'd_winmsg' then
5059 if (Length(P
) > 1) and
5060 ((P
[1] = '1') or (P
[1] = '0')) then
5061 g_Debug_WinMsgs
:= (P
[1][1] = '1');
5063 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs
)]));
5065 else if (cmd
= 'd_monoff') and not g_Game_IsNet
then
5067 if (Length(P
) > 1) and
5068 ((P
[1] = '1') or (P
[1] = '0')) then
5069 g_Debug_MonsterOff
:= (P
[1][1] = '1');
5071 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff
)]));
5073 else if (cmd
= 'd_botoff') and not g_Game_IsNet
then
5075 if Length(P
) > 1 then
5077 '0': g_debug_BotAIOff
:= 0;
5078 '1': g_debug_BotAIOff
:= 1;
5079 '2': g_debug_BotAIOff
:= 2;
5080 '3': g_debug_BotAIOff
:= 3;
5083 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff
]));
5085 else if cmd
= 'd_monster' then
5087 if gGameOn
and (gPlayer1
<> nil) and (gPlayer1
.Live
) and (not g_Game_IsNet
) then
5088 if Length(P
) < 2 then
5090 g_Console_Add(cmd
+ ' [ID | Name] [behaviour]');
5091 g_Console_Add('ID | Name');
5092 for b
:= MONSTER_DEMON
to MONSTER_MAN
do
5093 g_Console_Add(Format('%2d | %s', [b
, g_Monsters_GetNameByID(b
)]));
5096 a
:= StrToIntDef(P
[1], 0);
5097 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5098 a
:= g_Monsters_GetIDByName(P
[1]);
5100 if (a
< MONSTER_DEMON
) or (a
> MONSTER_MAN
) then
5101 g_Console_Add(Format(_lc
[I_MSG_NO_MONSTER
], [P
[1]]))
5104 with gPlayer1
.Obj
do
5106 mon
:= g_Monsters_Create(a
,
5107 X
+ Rect
.X
+ (Rect
.Width
div 2),
5108 Y
+ Rect
.Y
+ Rect
.Height
,
5109 gPlayer1
.Direction
, True);
5111 if (Length(P
) > 2) and (mon
<> nil) then
5112 mon
.MonsterBehaviour
:= Min(Max(StrToIntDef(P
[2], BH_NORMAL
), BH_NORMAL
), BH_GOOD
);
5116 else if (cmd
= 'd_health') then
5118 if (Length(P
) > 1) and
5119 ((P
[1] = '1') or (P
[1] = '0')) then
5120 g_debug_HealthBar
:= (P
[1][1] = '1');
5122 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar
)]));
5124 else if (cmd
= 'd_player') then
5126 if (Length(P
) > 1) and
5127 ((P
[1] = '1') or (P
[1] = '0')) then
5128 g_debug_Player
:= (P
[1][1] = '1');
5130 g_Console_Add(Format(cmd
+ ' is %d', [Byte(g_Debug_Player
)]));
5132 else if (cmd
= 'd_joy') then
5135 g_Console_Add(e_JoystickStateToString(a
));
5139 g_Console_Add(_lc
[I_MSG_NOT_DEBUG
]);
5143 procedure GameCheats(P
: SArray
);
5149 if (not gGameOn
) or (not gCheats
) or ((gGameSettings
.GameType
<> GT_SINGLE
) and
5150 (gGameSettings
.GameMode
<> GM_COOP
) and (not gDebugMode
)) or g_Game_IsNet
then
5152 g_Console_Add('not available');
5158 g_Console_Add('where is the player?!');
5161 cmd
:= LowerCase(P
[0]);
5165 plr
.GodMode
:= not plr
.GodMode
;
5166 if plr
.GodMode
then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5169 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5170 if cmd
= 'give' then
5172 if length(P
) < 2 then begin g_Console_Add('give what?!'); exit
; end;
5173 for f
:= 1 to High(P
) do
5175 cmd
:= LowerCase(P
[f
]);
5176 if cmd
= 'health' then begin plr
.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue
; end;
5177 if (cmd
= 'all') {or (cmd = 'weapons')} then begin plr
.AllRulez(False); g_Console_Add('player got the gifts'); continue
; end;
5178 if cmd
= 'exit' then
5180 if gTriggers
<> nil then
5182 for a
:= 0 to High(gTriggers
) do
5184 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
5186 g_Console_Add('player left the map');
5187 gExitByTrigger
:= True;
5188 g_Game_ExitLevel(gTriggers
[a
].Data
.MapName
);
5196 if cmd
= 'air' then begin plr
.GiveItem(ITEM_OXYGEN
); g_Console_Add('player got some air'); continue
; end;
5197 if cmd
= 'jetpack' then begin plr
.GiveItem(ITEM_JETPACK
); g_Console_Add('player got a jetpack'); continue
; end;
5198 if cmd
= 'suit' then begin plr
.GiveItem(ITEM_SUIT
); g_Console_Add('player got an envirosuit'); continue
; end;
5199 if cmd
= 'berserk' then begin plr
.GiveItem(ITEM_MEDKIT_BLACK
); g_Console_Add('player got a berserk pack'); continue
; end;
5200 if cmd
= 'backpack' then begin plr
.GiveItem(ITEM_AMMO_BACKPACK
); g_Console_Add('player got a backpack'); continue
; end;
5202 if cmd
= 'helmet' then begin plr
.GiveItem(ITEM_HELMET
); g_Console_Add('player got a helmet'); continue
; end;
5203 if cmd
= 'bottle' then begin plr
.GiveItem(ITEM_BOTTLE
); g_Console_Add('player got a bottle of health'); continue
; end;
5205 if cmd
= 'stimpack' then begin plr
.GiveItem(ITEM_MEDKIT_SMALL
); g_Console_Add('player got a stimpack'); continue
; end;
5206 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;
5208 if cmd
= 'greenarmor' then begin plr
.GiveItem(ITEM_ARMOR_GREEN
); g_Console_Add('player got a security armor'); continue
; end;
5209 if cmd
= 'bluearmor' then begin plr
.GiveItem(ITEM_ARMOR_BLUE
); g_Console_Add('player got a combat armor'); continue
; end;
5211 if (cmd
= 'megasphere') or (cmd
= 'mega') then begin plr
.GiveItem(ITEM_SPHERE_BLUE
); g_Console_Add('player got a megasphere'); continue
; end;
5212 if (cmd
= 'soulsphere') or (cmd
= 'soul')then begin plr
.GiveItem(ITEM_SPHERE_WHITE
); g_Console_Add('player got a soul sphere'); continue
; end;
5214 if (cmd
= 'invul') or (cmd
= 'invulnerability') then begin plr
.GiveItem(ITEM_INVUL
); g_Console_Add('player got invulnerability'); continue
; end;
5215 if (cmd
= 'invis') or (cmd
= 'invisibility') then begin plr
.GiveItem(ITEM_INVIS
); g_Console_Add('player got invisibility'); continue
; end;
5217 if cmd
= 'redkey' then begin plr
.GiveItem(ITEM_KEY_RED
); g_Console_Add('player got the red key'); continue
; end;
5218 if cmd
= 'greenkey' then begin plr
.GiveItem(ITEM_KEY_GREEN
); g_Console_Add('player got the green key'); continue
; end;
5219 if cmd
= 'bluekey' then begin plr
.GiveItem(ITEM_KEY_BLUE
); g_Console_Add('player got the blue key'); continue
; end;
5221 if (cmd
= 'shotgun') or (cmd
= 'sg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
); g_Console_Add('player got a shotgun'); continue
; end;
5222 if (cmd
= 'supershotgun') or (cmd
= 'ssg') then begin plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
); g_Console_Add('player got a supershotgun'); continue
; end;
5223 if cmd
= 'chaingun' then begin plr
.GiveItem(ITEM_WEAPON_CHAINGUN
); g_Console_Add('player got a chaingun'); continue
; end;
5224 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;
5225 if cmd
= 'plasmagun' then begin plr
.GiveItem(ITEM_WEAPON_PLASMA
); g_Console_Add('player got a plasma gun'); continue
; end;
5226 if cmd
= 'bfg' then begin plr
.GiveItem(ITEM_WEAPON_BFG
); g_Console_Add('player got a BFG-9000'); continue
; end;
5228 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;
5229 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;
5230 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;
5231 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;
5232 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;
5233 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;
5235 if cmd
= 'superchaingun' then begin plr
.GiveItem(ITEM_WEAPON_SUPERPULEMET
); g_Console_Add('player got a superchaingun'); continue
; end;
5236 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;
5238 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;
5239 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;
5241 if cmd
= 'chainsaw' then begin plr
.GiveItem(ITEM_WEAPON_SAW
); g_Console_Add('player got a chainsaw'); continue
; end;
5243 if cmd
= 'ammo' then
5245 plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
);
5246 plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
);
5247 plr
.GiveItem(ITEM_AMMO_CELL_BIG
);
5248 plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
);
5249 plr
.GiveItem(ITEM_AMMO_FUELCAN
);
5250 g_Console_Add('player got some ammo');
5254 if cmd
= 'clip' then begin plr
.GiveItem(ITEM_AMMO_BULLETS
); g_Console_Add('player got some bullets'); continue
; end;
5255 if cmd
= 'bullets' then begin plr
.GiveItem(ITEM_AMMO_BULLETS_BOX
); g_Console_Add('player got a box of bullets'); continue
; end;
5257 if cmd
= 'shells' then begin plr
.GiveItem(ITEM_AMMO_SHELLS
); g_Console_Add('player got some shells'); continue
; end;
5258 if cmd
= 'shellbox' then begin plr
.GiveItem(ITEM_AMMO_SHELLS_BOX
); g_Console_Add('player got a box of shells'); continue
; end;
5260 if cmd
= 'cells' then begin plr
.GiveItem(ITEM_AMMO_CELL
); g_Console_Add('player got some cells'); continue
; end;
5261 if cmd
= 'battery' then begin plr
.GiveItem(ITEM_AMMO_CELL_BIG
); g_Console_Add('player got cell battery'); continue
; end;
5263 if cmd
= 'rocket' then begin plr
.GiveItem(ITEM_AMMO_ROCKET
); g_Console_Add('player got a rocket'); continue
; end;
5264 if cmd
= 'rocketbox' then begin plr
.GiveItem(ITEM_AMMO_ROCKET_BOX
); g_Console_Add('player got some rockets'); continue
; end;
5266 if (cmd
= 'fuel') or (cmd
= 'fuelcan') then begin plr
.GiveItem(ITEM_AMMO_FUELCAN
); g_Console_Add('player got fuel canister'); continue
; end;
5268 if cmd
= 'weapons' then
5270 plr
.GiveItem(ITEM_WEAPON_SHOTGUN1
);
5271 plr
.GiveItem(ITEM_WEAPON_SHOTGUN2
);
5272 plr
.GiveItem(ITEM_WEAPON_CHAINGUN
);
5273 plr
.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER
);
5274 plr
.GiveItem(ITEM_WEAPON_PLASMA
);
5275 plr
.GiveItem(ITEM_WEAPON_BFG
);
5276 g_Console_Add('player got weapons');
5280 if cmd
= 'keys' then
5282 plr
.GiveItem(ITEM_KEY_RED
);
5283 plr
.GiveItem(ITEM_KEY_GREEN
);
5284 plr
.GiveItem(ITEM_KEY_BLUE
);
5285 g_Console_Add('player got all keys');
5289 g_Console_Add('i don''t know how to give '''+cmd
+'''!');
5294 if cmd
= 'open' then
5296 g_Console_Add('player activated sesame');
5297 g_Triggers_OpenAll();
5304 if gFly
then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
5308 if cmd
= 'noclip' then
5311 g_Console_Add('wall hardeness adjusted');
5315 if cmd
= 'notarget' then
5317 plr
.NoTarget
:= not plr
.NoTarget
;
5318 if plr
.NoTarget
then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
5322 if cmd
= 'noreload' then
5324 plr
.NoReload
:= not plr
.NoReload
;
5325 if plr
.NoReload
then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
5329 if cmd
= 'speedy' then
5331 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
5332 g_Console_Add('speed adjusted');
5336 if cmd
= 'jumpy' then
5338 VEL_JUMP
:= 30-VEL_JUMP
;
5339 g_Console_Add('jump height adjusted');
5343 if cmd
= 'automap' then
5345 gShowMap
:= not gShowMap
;
5346 if gShowMap
then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
5350 if cmd
= 'aimline' then
5352 gAimLine
:= not gAimLine
;
5353 if gAimLine
then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
5358 procedure GameCommands(P
: SArray
);
5364 pl
: pTNetClient
= nil;
5371 cmd
:= LowerCase(P
[0]);
5373 if (cmd
= 'quit') or
5380 else if cmd
= 'pause' then
5382 if (g_ActiveWindow
= nil) then
5383 g_Game_Pause(not gPause
);
5385 else if cmd
= 'endgame' then
5386 gExit
:= EXIT_SIMPLE
5387 else if cmd
= 'restart' then
5389 if gGameOn
or (gState
in [STATE_INTERSINGLE
, STATE_INTERCUSTOM
]) then
5391 if g_Game_IsClient
then
5393 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5398 g_Console_Add(_lc
[I_MSG_NOT_GAME
]);
5400 else if cmd
= 'kick' then
5402 if g_Game_IsServer
then
5404 if Length(P
) < 2 then
5406 g_Console_Add('kick <name>');
5411 g_Console_Add('kick <name>');
5415 if g_Game_IsNet
then
5416 pl
:= g_Net_Client_ByName(P
[1]);
5419 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5420 enet_peer_disconnect(pl
^.Peer
, NET_DISC_KICK
);
5421 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5422 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5423 if NetUseMaster
then
5425 end else if gPlayers
<> nil then
5426 for a
:= Low(gPlayers
) to High(gPlayers
) do
5427 if gPlayers
[a
] <> nil then
5428 if Copy(LowerCase(gPlayers
[a
].Name
), 1, Length(P
[1])) = LowerCase(P
[1]) then
5430 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
5431 if not(gPlayers
[a
] is TBot
) and (gGameSettings
.GameType
= GT_SINGLE
) then
5433 gPlayers
[a
].Lives
:= 0;
5434 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
5435 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
5436 g_Player_Remove(gPlayers
[a
].UID
);
5437 if NetUseMaster
then
5439 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
5443 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5445 else if cmd
= 'kick_id' then
5447 if g_Game_IsServer
and g_Game_IsNet
then
5449 if Length(P
) < 2 then
5451 g_Console_Add('kick_id <client ID>');
5456 g_Console_Add('kick_id <client ID>');
5460 a
:= StrToIntDef(P
[1], 0);
5461 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5463 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5465 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5466 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_KICK
);
5467 g_Console_Add(Format(_lc
[I_PLAYER_KICK
], [s
]));
5468 MH_SEND_GameEvent(NET_EV_PLAYER_KICK
, 0, s
);
5469 if NetUseMaster
then
5474 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5476 else if cmd
= 'ban' then
5478 if g_Game_IsServer
and g_Game_IsNet
then
5480 if Length(P
) < 2 then
5482 g_Console_Add('ban <name>');
5487 g_Console_Add('ban <name>');
5491 pl
:= g_Net_Client_ByName(P
[1]);
5494 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5495 g_Net_BanHost(pl
^.Peer
^.address
.host
, False);
5496 enet_peer_disconnect(pl
^.Peer
, NET_DISC_TEMPBAN
);
5497 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5498 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5499 if NetUseMaster
then
5502 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5504 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5506 else if cmd
= 'ban_id' then
5508 if g_Game_IsServer
and g_Game_IsNet
then
5510 if Length(P
) < 2 then
5512 g_Console_Add('ban_id <client ID>');
5517 g_Console_Add('ban_id <client ID>');
5521 a
:= StrToIntDef(P
[1], 0);
5522 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5523 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5525 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5526 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
, False);
5527 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_TEMPBAN
);
5528 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5529 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5530 if NetUseMaster
then
5534 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5536 else if cmd
= 'permban' then
5538 if g_Game_IsServer
and g_Game_IsNet
then
5540 if Length(P
) < 2 then
5542 g_Console_Add('permban <name>');
5547 g_Console_Add('permban <name>');
5551 pl
:= g_Net_Client_ByName(P
[1]);
5554 s
:= g_Net_ClientName_ByID(pl
^.ID
);
5555 g_Net_BanHost(pl
^.Peer
^.address
.host
);
5556 enet_peer_disconnect(pl
^.Peer
, NET_DISC_BAN
);
5557 g_Net_SaveBanList();
5558 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5559 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5560 if NetUseMaster
then
5563 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
5565 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5567 else if cmd
= 'permban_id' then
5569 if g_Game_IsServer
and g_Game_IsNet
then
5571 if Length(P
) < 2 then
5573 g_Console_Add('permban_id <client ID>');
5578 g_Console_Add('permban_id <client ID>');
5582 a
:= StrToIntDef(P
[1], 0);
5583 if (NetClients
<> nil) and (a
<= High(NetClients
)) then
5584 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5586 s
:= g_Net_ClientName_ByID(NetClients
[a
].ID
);
5587 g_Net_BanHost(NetClients
[a
].Peer
^.address
.host
);
5588 enet_peer_disconnect(NetClients
[a
].Peer
, NET_DISC_BAN
);
5589 g_Net_SaveBanList();
5590 g_Console_Add(Format(_lc
[I_PLAYER_BAN
], [s
]));
5591 MH_SEND_GameEvent(NET_EV_PLAYER_BAN
, 0, s
);
5592 if NetUseMaster
then
5596 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5598 else if cmd
= 'unban' then
5600 if g_Game_IsServer
and g_Game_IsNet
then
5602 if Length(P
) < 2 then
5604 g_Console_Add('unban <IP Address>');
5609 g_Console_Add('unban <IP Address>');
5613 if g_Net_UnbanHost(P
[1]) then
5615 g_Console_Add(Format(_lc
[I_MSG_UNBAN_OK
], [P
[1]]));
5616 g_Net_SaveBanList();
5618 g_Console_Add(Format(_lc
[I_MSG_UNBAN_FAIL
], [P
[1]]));
5620 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5622 else if cmd
= 'clientlist' then
5624 if g_Game_IsServer
and g_Game_IsNet
then
5627 if NetClients
<> nil then
5628 for a
:= Low(NetClients
) to High(NetClients
) do
5629 if NetClients
[a
].Used
and (NetClients
[a
].Peer
<> nil) then
5631 plr
:= g_Player_Get(NetClients
[a
].Player
);
5632 if plr
= nil then continue
;
5634 g_Console_Add(Format('#%2d: %-15s | %s', [a
,
5635 IpToStr(NetClients
[a
].Peer
^.address
.host
), plr
.Name
]));
5638 g_Console_Add(_lc
[I_MSG_NOCLIENTS
]);
5640 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
5642 else if cmd
= 'connect' then
5644 if (NetMode
= NET_NONE
) then
5646 if Length(P
) < 2 then
5648 g_Console_Add('connect <IP> [port] [password]');
5653 g_Console_Add('connect <IP> [port] [password]');
5657 if Length(P
) > 2 then
5658 prt
:= StrToIntDef(P
[2], 25666)
5662 if Length(P
) > 3 then
5667 g_Game_StartClient(P
[1], prt
, pw
);
5670 else if cmd
= 'disconnect' then
5672 if (NetMode
= NET_CLIENT
) then
5675 else if cmd
= 'reconnect' then
5677 if (NetMode
= NET_SERVER
) then
5680 if (NetMode
= NET_CLIENT
) then
5683 gExit
:= EXIT_SIMPLE
;
5687 //TODO: Use last successful password to reconnect, instead of ''
5688 g_Game_StartClient(NetClientIP
, NetClientPort
, '');
5690 else if (cmd
= 'addbot') or
5691 (cmd
= 'bot_add') then
5693 if Length(P
) > 1 then
5694 g_Bot_Add(TEAM_NONE
, StrToIntDef(P
[1], 2))
5696 g_Bot_Add(TEAM_NONE
, 2);
5698 else if cmd
= 'bot_addlist' then
5700 if Length(P
) > 1 then
5701 if Length(P
) = 2 then
5702 g_Bot_AddList(TEAM_NONE
, P
[1], StrToIntDef(P
[1], -1))
5704 g_Bot_AddList(IfThen(P
[2] = 'red', TEAM_RED
, TEAM_BLUE
), P
[1], StrToIntDef(P
[1], -1));
5706 else if cmd
= 'bot_removeall' then
5708 else if cmd
= 'chat' then
5710 if g_Game_IsNet
then
5712 if Length(P
) > 1 then
5714 for a
:= 1 to High(P
) do
5715 chstr
:= chstr
+ P
[a
] + ' ';
5717 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5719 if Length(chstr
) < 1 then
5721 g_Console_Add('chat <text>');
5725 chstr
:= b_Text_Format(chstr
);
5726 if g_Game_IsClient
then
5727 MC_SEND_Chat(chstr
, NET_CHAT_PLAYER
)
5729 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_PLAYER
);
5732 g_Console_Add('chat <text>');
5734 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5736 else if cmd
= 'teamchat' then
5738 if g_Game_IsNet
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
5740 if Length(P
) > 1 then
5742 for a
:= 1 to High(P
) do
5743 chstr
:= chstr
+ P
[a
] + ' ';
5745 if Length(chstr
) > 200 then SetLength(chstr
, 200);
5747 if Length(chstr
) < 1 then
5749 g_Console_Add('teamchat <text>');
5753 chstr
:= b_Text_Format(chstr
);
5754 if g_Game_IsClient
then
5755 MC_SEND_Chat(chstr
, NET_CHAT_TEAM
)
5757 MH_SEND_Chat(gPlayer1Settings
.Name
+ ': ' + chstr
, NET_CHAT_TEAM
,
5758 gPlayer1Settings
.Team
);
5761 g_Console_Add('teamchat <text>');
5763 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5765 else if cmd
= 'game' then
5767 if gGameSettings
.GameType
<> GT_NONE
then
5769 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5772 if Length(P
) = 1 then
5774 g_Console_Add(cmd
+ ' <WAD> [MAP] [# players]');
5777 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5778 P
[1] := addWadExtension(P
[1]);
5779 if FileExists(MapsDir
+ P
[1]) then
5781 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5782 if Length(P
) < 3 then
5785 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5788 s
:= P
[1] + ':\' + UpperCase(P
[2]);
5790 if g_Map_Exist(MapsDir
+ s
) then
5792 // Çàïóñêàåì ñâîþ èãðó
5794 with gGameSettings
do
5796 GameMode
:= g_Game_TextToMode(gcGameMode
);
5797 if gSwitchGameMode
<> GM_NONE
then
5798 GameMode
:= gSwitchGameMode
;
5799 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5800 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5802 if Length(P
) >= 4 then
5803 b
:= StrToIntDef(P
[3], 1);
5804 g_Game_StartCustom(s
, GameMode
, TimeLimit
,
5805 GoalLimit
, MaxLives
, Options
, b
);
5810 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5812 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[2])]));
5814 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5816 else if cmd
= 'host' then
5818 if gGameSettings
.GameType
<> GT_NONE
then
5820 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5823 if Length(P
) < 4 then
5825 g_Console_Add(cmd
+ ' <listen IP> <port> <WAD> [MAP] [# players]');
5828 if not StrToIp(P
[1], listen
) then
5830 prt
:= StrToIntDef(P
[2], 25666);
5832 P
[3] := addWadExtension(P
[3]);
5833 if FileExists(MapsDir
+ P
[3]) then
5835 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5836 if Length(P
) < 5 then
5839 P
[4] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5842 s
:= P
[3] + ':\' + UpperCase(P
[4]);
5844 if g_Map_Exist(MapsDir
+ s
) then
5846 // Çàïóñêàåì ñâîþ èãðó
5848 with gGameSettings
do
5850 GameMode
:= g_Game_TextToMode(gcGameMode
);
5851 if gSwitchGameMode
<> GM_NONE
then
5852 GameMode
:= gSwitchGameMode
;
5853 if GameMode
= GM_NONE
then GameMode
:= GM_DM
;
5854 if GameMode
= GM_SINGLE
then GameMode
:= GM_COOP
;
5856 if Length(P
) >= 6 then
5857 b
:= StrToIntDef(P
[5], 0);
5858 g_Game_StartServer(s
, GameMode
, TimeLimit
,
5859 GoalLimit
, MaxLives
, Options
, b
, listen
, prt
);
5864 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[3]]))
5866 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [UpperCase(P
[4])]));
5868 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[3]]));
5870 else if cmd
= 'map' then
5872 if Length(P
) = 1 then
5874 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5876 g_Console_Add(cmd
+ ' <MAP>');
5877 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5879 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5881 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5883 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5884 if Length(P
) < 3 then
5886 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5887 s
:= UpperCase(P
[1]);
5888 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5889 begin // Êàðòà íàøëàñü
5890 gExitByTrigger
:= False;
5892 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5894 gExit
:= EXIT_ENDLEVELCUSTOM
;
5896 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5897 g_Game_ChangeMap(s
);
5900 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5901 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5902 P
[1] := addWadExtension(P
[1]);
5903 if FileExists(MapsDir
+ P
[1]) then
5905 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5907 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5909 s
:= P
[1] + ':\' + P
[2];
5911 if g_Map_Exist(MapsDir
+ s
) then
5913 gExitByTrigger
:= False;
5915 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5917 gExit
:= EXIT_ENDLEVELCUSTOM
;
5919 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5920 g_Game_ChangeMap(s
);
5923 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
5925 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5927 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5931 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5932 P
[1] := addWadExtension(P
[1]);
5933 if FileExists(MapsDir
+ P
[1]) then
5936 P
[2] := UpperCase(P
[2]);
5937 s
:= P
[1] + ':\' + P
[2];
5939 if g_Map_Exist(MapsDir
+ s
) then
5940 begin // Íàøëè êàðòó
5941 gExitByTrigger
:= False;
5943 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5945 gExit
:= EXIT_ENDLEVELCUSTOM
;
5947 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5948 g_Game_ChangeMap(s
);
5950 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
5952 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
5955 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5957 else if cmd
= 'nextmap' then
5959 if not(gGameOn
or (gState
= STATE_INTERCUSTOM
)) then
5960 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
5963 if Length(P
) = 1 then
5965 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5967 g_Console_Add(cmd
+ ' <MAP>');
5968 g_Console_Add(cmd
+ ' <WAD> [MAP]');
5971 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
5976 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
5978 if Length(P
) < 3 then
5980 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5981 s
:= UpperCase(P
[1]);
5982 if g_Map_Exist(MapsDir
+ gGameSettings
.WAD
+ ':\' + s
) then
5983 begin // Êàðòà íàøëàñü
5984 gExitByTrigger
:= False;
5989 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [s
]));
5990 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5991 P
[1] := addWadExtension(P
[1]);
5992 if FileExists(MapsDir
+ P
[1]) then
5994 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5996 P
[2] := g_Game_GetFirstMap(MapsDir
+ P
[1]);
5998 s
:= P
[1] + ':\' + P
[2];
6000 if g_Map_Exist(MapsDir
+ s
) then
6001 begin // Óñòàíàâëèâàåì êàðòó
6002 gExitByTrigger
:= False;
6007 g_Console_Add(Format(_lc
[I_MSG_NO_MAPS
], [P
[1]]))
6009 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6011 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6015 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6016 P
[1] := addWadExtension(P
[1]);
6017 if FileExists(MapsDir
+ P
[1]) then
6020 P
[2] := UpperCase(P
[2]);
6021 s
:= P
[1] + ':\' + P
[2];
6023 if g_Map_Exist(MapsDir
+ s
) then
6024 begin // Íàøëè êàðòó
6025 gExitByTrigger
:= False;
6029 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [P
[2]]));
6031 g_Console_Add(Format(_lc
[I_MSG_NO_WAD
], [P
[1]]));
6034 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6037 if gNextMap
= '' then
6038 g_Console_Add(_lc
[I_MSG_NEXTMAP_UNSET
])
6040 g_Console_Add(Format(_lc
[I_MSG_NEXTMAP_SET
], [gNextMap
]));
6043 else if (cmd
= 'endmap') or (cmd
= 'goodbye') then
6046 g_Console_Add(_lc
[I_MSG_NOT_GAME
])
6048 if g_Game_IsServer
and (gGameSettings
.GameType
<> GT_SINGLE
) then
6050 gExitByTrigger
:= False;
6051 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6052 if (gNextMap
= '') and (gTriggers
<> nil) then
6053 for a
:= 0 to High(gTriggers
) do
6054 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
6056 gExitByTrigger
:= True;
6057 gNextMap
:= gTriggers
[a
].Data
.MapName
;
6060 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6061 if gNextMap
= '' then
6062 gNextMap
:= g_Game_GetNextMap();
6063 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6064 if Pos(':\', gNextMap
) = 0 then
6065 s
:= gGameSettings
.WAD
+ ':\' + gNextMap
6068 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6069 if g_Map_Exist(MapsDir
+ s
) then
6070 gExit
:= EXIT_ENDLEVELCUSTOM
6072 g_Console_Add(Format(_lc
[I_MSG_NO_MAP
], [gNextMap
]));
6074 g_Console_Add(_lc
[I_MSG_GM_UNAVAIL
]);
6076 else if (cmd
= 'event') then
6078 if (Length(P
) <= 1) then
6080 for a
:= 0 to High(gEvents
) do
6081 if gEvents
[a
].Command
= '' then
6082 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6084 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6087 if (Length(P
) = 2) then
6089 for a
:= 0 to High(gEvents
) do
6090 if gEvents
[a
].Name
= P
[1] then
6091 if gEvents
[a
].Command
= '' then
6092 g_Console_Add(gEvents
[a
].Name
+ ' <none>')
6094 g_Console_Add(gEvents
[a
].Name
+ ' "' + gEvents
[a
].Command
+ '"');
6097 for a
:= 0 to High(gEvents
) do
6098 if gEvents
[a
].Name
= P
[1] then
6100 gEvents
[a
].Command
:= '';
6101 for b
:= 2 to High(P
) do
6102 if Pos(' ', P
[b
]) = 0 then
6103 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' ' + P
[b
]
6105 gEvents
[a
].Command
:= gEvents
[a
].Command
+ ' "' + P
[b
] + '"';
6106 gEvents
[a
].Command
:= Trim(gEvents
[a
].Command
);
6110 // Êîìàíäû Ñâîåé èãðû:
6111 else if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
6113 if cmd
= 'bot_addred' then
6115 if Length(P
) > 1 then
6116 g_Bot_Add(TEAM_RED
, StrToIntDef(P
[1], 2))
6118 g_Bot_Add(TEAM_RED
, 2);
6120 else if cmd
= 'bot_addblue' then
6122 if Length(P
) > 1 then
6123 g_Bot_Add(TEAM_BLUE
, StrToIntDef(P
[1], 2))
6125 g_Bot_Add(TEAM_BLUE
, 2);
6127 else if cmd
= 'suicide' then
6131 if g_Game_IsClient
then
6132 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE
)
6135 if gPlayer1
<> nil then
6136 gPlayer1
.Damage(SUICIDE_DAMAGE
, gPlayer1
.UID
, 0, 0, HIT_SELF
);
6137 if gPlayer2
<> nil then
6138 gPlayer2
.Damage(SUICIDE_DAMAGE
, gPlayer2
.UID
, 0, 0, HIT_SELF
);
6142 else if cmd
= 'spectate' then
6148 else if cmd
= 'say' then
6150 if g_Game_IsServer
and g_Game_IsNet
then
6152 if Length(P
) > 1 then
6155 for a
:= 1 to High(P
) do
6156 chstr
:= chstr
+ P
[a
] + ' ';
6158 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6160 if Length(chstr
) < 1 then
6162 g_Console_Add('say <text>');
6166 chstr
:= b_Text_Format(chstr
);
6167 MH_SEND_Chat(chstr
, NET_CHAT_PLAYER
);
6169 else g_Console_Add('say <text>');
6171 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6173 else if cmd
= 'tell' then
6175 if g_Game_IsServer
and g_Game_IsNet
then
6177 if (Length(P
) > 2) and (P
[1] <> '') then
6180 for a
:= 2 to High(P
) do
6181 chstr
:= chstr
+ P
[a
] + ' ';
6183 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6185 if Length(chstr
) < 1 then
6187 g_Console_Add('tell <playername> <text>');
6191 pl
:= g_Net_Client_ByName(P
[1]);
6193 MH_SEND_Chat(b_Text_Format(chstr
), NET_CHAT_PLAYER
, pl
^.ID
)
6195 g_Console_Add(Format(_lc
[I_NET_ERR_NAME404
], [P
[1]]));
6197 else g_Console_Add('tell <playername> <text>');
6199 g_Console_Add(_lc
[I_MSG_SERVERONLY
]);
6201 else if (cmd
= 'overtime') and not g_Game_IsClient
then
6203 if (Length(P
) = 1) or (StrToIntDef(P
[1], -1) <= 0) then
6205 // Äîïîëíèòåëüíîå âðåìÿ:
6206 gGameSettings
.TimeLimit
:= (gTime
- gGameStartTime
) div 1000 + Word(StrToIntDef(P
[1], 0));
6208 g_Console_Add(Format(_lc
[I_MSG_TIME_LIMIT
],
6209 [gGameSettings
.TimeLimit
div 3600,
6210 (gGameSettings
.TimeLimit
div 60) mod 60,
6211 gGameSettings
.TimeLimit
mod 60]));
6212 if g_Game_IsNet
then MH_SEND_GameSettings
;
6214 else if (cmd
= 'rcon_password') and g_Game_IsClient
then
6216 if (Length(P
) <= 1) then
6217 g_Console_Add('rcon_password <password>')
6219 MC_SEND_RCONPassword(P
[1]);
6221 else if cmd
= 'rcon' then
6223 if g_Game_IsClient
then
6225 if Length(P
) > 1 then
6228 for a
:= 1 to High(P
) do
6229 chstr
:= chstr
+ P
[a
] + ' ';
6231 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6233 if Length(chstr
) < 1 then
6235 g_Console_Add('rcon <command>');
6239 MC_SEND_RCONCommand(chstr
);
6241 else g_Console_Add('rcon <command>');
6244 else if cmd
= 'ready' then
6246 if g_Game_IsServer
and (gLMSRespawn
= LMS_RESPAWN_WARMUP
) then
6247 gLMSRespawnTime
:= gTime
+ 100;
6249 else if (cmd
= 'callvote') and g_Game_IsNet
then
6251 if Length(P
) > 1 then
6254 for a
:= 1 to High(P
) do begin
6255 if a
> 1 then chstr
:= chstr
+ ' ';
6256 chstr
:= chstr
+ P
[a
];
6259 if Length(chstr
) > 200 then SetLength(chstr
, 200);
6261 if Length(chstr
) < 1 then
6263 g_Console_Add('callvote <command>');
6267 if g_Game_IsClient
then
6268 MC_SEND_Vote(True, chstr
)
6270 g_Game_StartVote(chstr
, gPlayer1Settings
.Name
);
6271 g_Console_Process('vote', True);
6274 g_Console_Add('callvote <command>');
6276 else if (cmd
= 'vote') and g_Game_IsNet
then
6278 if g_Game_IsClient
then
6280 else if gVoteInProgress
then
6282 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6283 a
:= Floor((NetClientCount
+1)/2.0) + 1
6285 a
:= Floor(NetClientCount
/2.0) + 1;
6290 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_REVOKED
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6291 MH_SEND_VoteEvent(NET_VE_REVOKE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6297 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_VOTE
], [gPlayer1Settings
.Name
, gVoteCount
, a
]), True);
6298 MH_SEND_VoteEvent(NET_VE_VOTE
, gPlayer1Settings
.Name
, 'a', gVoteCount
, a
);
6306 procedure g_TakeScreenShot();
6314 if e_NoGraphics
then Exit
;
6315 ssdir
:= GameDir
+'/screenshots';
6316 if not findFileCI(ssdir
, true) then
6318 // try to create dir
6323 if not findFileCI(ssdir
, true) then exit
; // alas
6326 for a
:= 1 to High(Word) do
6328 FileName
:= Format(ssdir
+'screenshot%.3d.png', [a
]);
6330 if findFileCI(t
, true) then continue
;
6331 if not findFileCI(FileName
) then
6334 st
:= createDiskFile(FileName
);
6336 e_MakeScreenshot(st
, gScreenWidth
, gScreenHeight
);
6341 if not ok
then try DeleteFile(FileName
); except end else g_Console_Add(Format(_lc
[I_CONSOLE_SCREENSHOT
], [ExtractFileName(FileName
)]));
6349 procedure g_Game_InGameMenu(Show
: Boolean);
6351 if (g_ActiveWindow
= nil) and Show
then
6353 if gGameSettings
.GameType
= GT_SINGLE
then
6354 g_GUI_ShowWindow('GameSingleMenu')
6357 if g_Game_IsClient
then
6358 g_GUI_ShowWindow('GameClientMenu')
6360 if g_Game_IsNet
then
6361 g_GUI_ShowWindow('GameServerMenu')
6363 g_GUI_ShowWindow('GameCustomMenu');
6365 g_Sound_PlayEx('MENU_OPEN');
6367 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6368 if (not g_Game_IsNet
) then
6372 if (g_ActiveWindow
<> nil) and (not Show
) then
6374 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
6375 if (not g_Game_IsNet
) then
6376 g_Game_Pause(False);
6380 procedure g_Game_Pause(Enable
: Boolean);
6385 if gPause
= Enable
then
6388 if not (gGameSettings
.GameType
in [GT_SINGLE
, GT_CUSTOM
]) then
6392 g_Game_PauseAllSounds(Enable
);
6395 procedure g_Game_PauseAllSounds(Enable
: Boolean);
6400 if gTriggers
<> nil then
6401 for i
:= 0 to High(gTriggers
) do
6402 with gTriggers
[i
] do
6403 if (TriggerType
= TRIGGER_SOUND
) and
6405 Sound
.IsPlaying() then
6407 Sound
.Pause(Enable
);
6411 if gPlayers
<> nil then
6412 for i
:= 0 to High(gPlayers
) do
6413 if gPlayers
[i
] <> nil then
6414 gPlayers
[i
].PauseSounds(Enable
);
6417 if gMusic
<> nil then
6418 gMusic
.Pause(Enable
);
6421 procedure g_Game_StopAllSounds(all
: Boolean);
6425 if gTriggers
<> nil then
6426 for i
:= 0 to High(gTriggers
) do
6427 with gTriggers
[i
] do
6428 if (TriggerType
= TRIGGER_SOUND
) and
6432 if gMusic
<> nil then
6439 procedure g_Game_UpdateTriggerSounds();
6443 if gTriggers
<> nil then
6444 for i
:= 0 to High(gTriggers
) do
6445 with gTriggers
[i
] do
6446 if (TriggerType
= TRIGGER_SOUND
) and
6449 Sound
.IsPlaying() then
6451 if ((gPlayer1
<> nil) and g_CollidePoint(gPlayer1
.GameX
, gPlayer1
.GameY
, X
, Y
, Width
, Height
)) or
6452 ((gPlayer2
<> nil) and g_CollidePoint(gPlayer2
.GameX
, gPlayer2
.GameY
, X
, Y
, Width
, Height
)) then
6454 Sound
.SetPan(0.5 - Data
.Pan
/255.0);
6455 Sound
.SetVolume(Data
.Volume
/255.0);
6458 Sound
.SetCoords(X
+(Width
div 2), Y
+(Height
div 2), Data
.Volume
/255.0);
6462 function g_Game_IsWatchedPlayer(UID
: Word): Boolean;
6465 if (gPlayer1
<> nil) and (gPlayer1
.UID
= UID
) then
6470 if (gPlayer2
<> nil) and (gPlayer2
.UID
= UID
) then
6475 if gSpectMode
<> SPECT_PLAYERS
then
6477 if gSpectPID1
= UID
then
6482 if gSpectViewTwo
and (gSpectPID2
= UID
) then
6489 function g_Game_IsWatchedTeam(Team
: Byte): Boolean;
6494 if (gPlayer1
<> nil) and (gPlayer1
.Team
= Team
) then
6499 if (gPlayer2
<> nil) and (gPlayer2
.Team
= Team
) then
6504 if gSpectMode
<> SPECT_PLAYERS
then
6506 Pl
:= g_Player_Get(gSpectPID1
);
6507 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6512 if gSpectViewTwo
then
6514 Pl
:= g_Player_Get(gSpectPID2
);
6515 if (Pl
<> nil) and (Pl
.Team
= Team
) then
6523 procedure g_Game_Message(Msg
: string; Time
: Word);
6525 MessageText
:= b_Text_Format(Msg
);
6526 MessageTime
:= Time
;
6529 procedure g_Game_Announce_GoodShot(SpawnerUID
: Word);
6538 if not g_Game_IsWatchedPlayer(SpawnerUID
) then
6542 if goodsnd
[a
].IsPlaying() then
6545 goodsnd
[Random(4)].Play();
6548 procedure g_Game_Announce_KillCombo(Param
: Integer);
6555 UID
:= Param
and $FFFF;
6560 Pl
:= g_Player_Get(UID
);
6569 g_Console_Add(Format(_lc
[I_PLAYER_KILL_2X
], [Name
]), True);
6573 g_Console_Add(Format(_lc
[I_PLAYER_KILL_3X
], [Name
]), True);
6577 g_Console_Add(Format(_lc
[I_PLAYER_KILL_4X
], [Name
]), True);
6581 g_Console_Add(Format(_lc
[I_PLAYER_KILL_MX
], [Name
]), True);
6589 if not g_Game_IsWatchedPlayer(UID
) then
6592 if (not g_Game_IsWatchedPlayer(UID
)) and (c
< 4) then
6596 if killsnd
[n
].IsPlaying() then
6601 procedure g_Game_StartVote(Command
, Initiator
: string);
6605 if not gVotesEnabled
then Exit
;
6606 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6607 if gVoteInProgress
or gVotePassed
then
6609 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_INPROGRESS
], [gVoteCommand
]), True);
6610 MH_SEND_VoteEvent(NET_VE_INPROGRESS
, gVoteCommand
);
6613 gVoteInProgress
:= True;
6614 gVotePassed
:= False;
6615 gVoteTimer
:= gTime
+ gVoteTimeout
* 1000;
6618 gVoteCommand
:= Command
;
6620 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6621 Need
:= Floor((NetClientCount
+1)/2.0)+1
6623 Need
:= Floor(NetClientCount
/2.0)+1;
6624 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_STARTED
], [Initiator
, Command
, Need
]), True);
6625 MH_SEND_VoteEvent(NET_VE_STARTED
, Initiator
, Command
, Need
);
6628 procedure g_Game_CheckVote
;
6632 if gGameSettings
.GameType
<> GT_SERVER
then Exit
;
6633 if not gVoteInProgress
then Exit
;
6635 if (gTime
>= gVoteTimer
) then
6637 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6638 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6640 Need
:= Floor(NetClientCount
/2.0) + 1;
6641 if gVoteCount
>= Need
then
6643 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6644 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6645 gVotePassed
:= True;
6646 gVoteCmdTimer
:= gTime
+ 5000;
6650 g_Console_Add(_lc
[I_MESSAGE_VOTE_FAILED
], True);
6651 MH_SEND_VoteEvent(NET_VE_FAILED
);
6653 if NetClients
<> nil then
6654 for I
:= Low(NetClients
) to High(NetClients
) do
6655 if NetClients
[i
].Used
then
6656 NetClients
[i
].Voted
:= False;
6657 gVoteInProgress
:= False;
6663 if (gPlayer1
<> nil) or (gPlayer2
<> nil) then
6664 Need
:= Floor((NetClientCount
+1)/2.0) + 1
6666 Need
:= Floor(NetClientCount
/2.0) + 1;
6667 if gVoteCount
>= Need
then
6669 g_Console_Add(Format(_lc
[I_MESSAGE_VOTE_PASSED
], [gVoteCommand
]), True);
6670 MH_SEND_VoteEvent(NET_VE_PASSED
, gVoteCommand
);
6671 gVoteInProgress
:= False;
6672 gVotePassed
:= True;
6673 gVoteCmdTimer
:= gTime
+ 5000;
6676 if NetClients
<> nil then
6677 for I
:= Low(NetClients
) to High(NetClients
) do
6678 if NetClients
[i
].Used
then
6679 NetClients
[i
].Voted
:= False;
6684 procedure g_Game_LoadMapList(FileName
: string);
6692 if not FileExists(FileName
) then Exit
;
6694 AssignFile(ListFile
, FileName
);
6696 while not EOF(ListFile
) do
6698 ReadLn(ListFile
, s
);
6701 if s
= '' then Continue
;
6703 SetLength(MapList
, Length(MapList
)+1);
6704 MapList
[High(MapList
)] := s
;
6706 CloseFile(ListFile
);
6709 procedure g_Game_SetDebugMode();
6712 // ×èòû (äàæå â ñâîåé èãðå):
6716 procedure g_Game_SetLoadingText(Text: String; Max
: Integer; reWrite
: Boolean);
6720 if Length(LoadingStat
.Msgs
) = 0 then
6726 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6727 if NextMsg
= Length(Msgs
) then
6729 for i
:= 0 to High(Msgs
)-1 do
6730 Msgs
[i
] := Msgs
[i
+1];
6738 Msgs
[NextMsg
-1] := Text;
6744 g_ActiveWindow
:= nil;
6749 procedure g_Game_StepLoading();
6755 if (ShowCount
> LOADING_SHOW_STEP
) then
6763 procedure g_Game_ClearLoading();
6772 len
:= ((gScreenHeight
div 3)*2 - 50) div LOADING_INTERLINE
;
6773 if len
< 1 then len
:= 1;
6774 SetLength(Msgs
, len
);
6775 for len
:= Low(Msgs
) to High(Msgs
) do
6781 procedure Parse_Params(var pars
: TParamStrValues
);
6788 while i
<= ParamCount
do
6791 if (s
[1] = '-') and (Length(s
) > 1) then
6793 if (s
[2] = '-') and (Length(s
) > 2) then
6794 begin // Îäèíî÷íûé ïàðàìåòð
6795 SetLength(pars
, Length(pars
) + 1);
6796 with pars
[High(pars
)] do
6798 Name
:= LowerCase(s
);
6803 if (i
< ParamCount
) then
6804 begin // Ïàðàìåòð ñî çíà÷åíèåì
6806 SetLength(pars
, Length(pars
) + 1);
6807 with pars
[High(pars
)] do
6809 Name
:= LowerCase(s
);
6810 Value
:= LowerCase(ParamStr(i
));
6819 function Find_Param_Value(var pars
: TParamStrValues
; aName
: String): String;
6824 for i
:= 0 to High(pars
) do
6825 if pars
[i
].Name
= aName
then
6827 Result
:= pars
[i
].Value
;
6832 procedure g_Game_Process_Params();
6834 pars
: TParamStrValues
;
6837 LimT
, LimS
: Integer;
6847 s
:= Find_Param_Value(pars
, '--profile-render');
6848 if (s
<> '') then g_profile_frame_draw
:= true;
6850 s
:= Find_Param_Value(pars
, '--profile-coldet');
6851 if (s
<> '') then g_profile_collision
:= true;
6854 s
:= Find_Param_Value(pars
, '--debug');
6857 g_Game_SetDebugMode();
6858 s
:= Find_Param_Value(pars
, '--netdump');
6863 // Connect when game loads
6864 ip
:= Find_Param_Value(pars
, '-connect');
6868 s
:= Find_Param_Value(pars
, '-port');
6869 if (s
= '') or not TryStrToInt(s
, Port
) then
6872 s
:= Find_Param_Value(pars
, '-pw');
6874 g_Game_StartClient(ip
, Port
, s
);
6878 s
:= LowerCase(Find_Param_Value(pars
, '-dbg-mainwad'));
6881 gDefaultMegawadStart
:= s
;
6884 if (Find_Param_Value(pars
, '--dbg-mainwad-restore') <> '') or
6885 (Find_Param_Value(pars
, '--dbg-mainwad-default') <> '') then
6887 gDefaultMegawadStart
:= DF_Default_Megawad_Start
;
6890 // Start map when game loads:
6891 map
:= LowerCase(Find_Param_Value(pars
, '-map'));
6892 if isWadPath(map
) then
6895 s
:= Find_Param_Value(pars
, '-gm');
6896 GMode
:= g_Game_TextToMode(s
);
6897 if GMode
= GM_NONE
then GMode
:= GM_DM
;
6898 if GMode
= GM_SINGLE
then GMode
:= GM_COOP
;
6901 s
:= Find_Param_Value(pars
, '-limt');
6902 if (s
= '') or (not TryStrToInt(s
, LimT
)) then
6908 s
:= Find_Param_Value(pars
, '-lims');
6909 if (s
= '') or (not TryStrToInt(s
, LimS
)) then
6915 s
:= Find_Param_Value(pars
, '-lives');
6916 if (s
= '') or (not TryStrToInt(s
, Lives
)) then
6922 s
:= Find_Param_Value(pars
, '-opt');
6924 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
6926 Opt
:= StrToIntDef(s
, 0);
6928 Opt
:= GAME_OPTION_ALLOWEXIT
or GAME_OPTION_BOTVSPLAYER
or GAME_OPTION_BOTVSMONSTER
;
6931 s
:= Find_Param_Value(pars
, '--close');
6935 // Delete test map after play:
6936 s
:= Find_Param_Value(pars
, '--testdelete');
6939 gMapToDelete
:= MapsDir
+ map
;
6940 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR
);
6944 // Delete temporary WAD after play:
6945 s
:= Find_Param_Value(pars
, '--tempdelete');
6948 gMapToDelete
:= MapsDir
+ map
;
6949 gTempDelete
:= True;
6952 // Number of players:
6953 s
:= Find_Param_Value(pars
, '-pl');
6957 n
:= StrToIntDef(s
, 1);
6960 s
:= Find_Param_Value(pars
, '-port');
6961 if (s
= '') or not TryStrToInt(s
, Port
) then
6962 g_Game_StartCustom(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
)
6964 g_Game_StartServer(map
, GMode
, LimT
, LimS
, Lives
, Opt
, n
, 0, Port
);
6967 // Execute script when game loads:
6968 s
:= Find_Param_Value(pars
, '-exec');
6971 if Pos(':\', s
) = 0 then
6972 s
:= GameDir
+ '/' + s
;
6977 if IOResult
<> 0 then
6979 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6980 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6984 e_WriteLog('Executing script: ' + s
, MSG_NOTIFY
);
6985 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
6990 if IOResult
<> 0 then
6992 e_WriteLog(Format(_lc
[I_SIMPLE_ERROR
], ['Failed to read file: ' + s
]), MSG_WARNING
);
6993 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
6997 if Pos('#', s
) <> 1 then // script comment
6998 g_Console_Process(s
, True);